From: Andrea Zagli Date: Mon, 31 May 2010 14:59:43 +0000 (+0200) Subject: Database definition. X-Git-Tag: 0.5.0~19 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=7f3e1142265d8c17fb85a53c9c070da71955c2d4;p=zakaudit%2Flibzakaudit Database definition. --- diff --git a/doc/sql/audit.sql b/doc/sql/audit.sql index ad93857..db5c2d1 100644 --- a/doc/sql/audit.sql +++ b/doc/sql/audit.sql @@ -1,143 +1,40 @@ --- --- PostgreSQL database dump --- - -SET client_encoding = 'UNICODE'; -SET check_function_bodies = false; - -SET SESSION AUTHORIZATION 'postgres'; - --- --- TOC entry 4 (OID 2200) --- Name: public; Type: ACL; Schema: -; Owner: postgres --- - -REVOKE ALL ON SCHEMA public FROM PUBLIC; -REVOKE ALL ON SCHEMA public FROM postgres; -GRANT ALL ON SCHEMA public TO PUBLIC; - - -SET SESSION AUTHORIZATION 'postgres'; - -SET search_path = public, pg_catalog; - --- --- TOC entry 5 (OID 39310) --- Name: valori; Type: TABLE; Schema: public; Owner: postgres --- - -CREATE TABLE valori ( - id_azioni bigint NOT NULL, - id_campi integer NOT NULL, - valore character varying DEFAULT ''::character varying -) WITHOUT OIDS; - - --- --- TOC entry 6 (OID 39315) --- Name: tabelle; Type: TABLE; Schema: public; Owner: postgres --- - -CREATE TABLE tabelle ( - id integer NOT NULL, - nome character(30) DEFAULT ''::bpchar, - status character(1) DEFAULT ''::bpchar, - id_datasources integer NOT NULL -) WITHOUT OIDS; - - --- --- TOC entry 7 (OID 39321) --- Name: campi; Type: TABLE; Schema: public; Owner: postgres --- - -CREATE TABLE campi ( - id integer NOT NULL, - id_tabelle integer NOT NULL, - nome character(30) DEFAULT ''::bpchar, - status character(1) DEFAULT ''::bpchar, - id_datasources integer NOT NULL -) WITHOUT OIDS; - - --- --- TOC entry 8 (OID 39344) --- Name: azioni; Type: TABLE; Schema: public; Owner: postgres --- - -CREATE TABLE azioni ( - id bigint NOT NULL, - tipo_azione integer, - dn character(200) DEFAULT ''::bpchar, - data timestamp without time zone, - id_tabelle integer, - id_datasources integer -) WITHOUT OIDS; - - --- --- TOC entry 9 (OID 39357) --- Name: datasources; Type: TABLE; Schema: public; Owner: postgres --- - CREATE TABLE datasources ( - id integer NOT NULL, - nome character(30) DEFAULT ''::bpchar, - cnc_string character(255) DEFAULT ''::bpchar, - status character(1) DEFAULT ''::bpchar -) WITHOUT OIDS; - - --- --- TOC entry 13 (OID 39347) --- Name: azioni_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY azioni - ADD CONSTRAINT azioni_pkey PRIMARY KEY (id); - - --- --- TOC entry 14 (OID 39360) --- Name: database_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY datasources - ADD CONSTRAINT database_pkey PRIMARY KEY (id); - - --- --- TOC entry 11 (OID 39363) --- Name: tabelle_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY tabelle - ADD CONSTRAINT tabelle_pkey PRIMARY KEY (id_datasources, id); - - --- --- TOC entry 12 (OID 39365) --- Name: campi_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY campi - ADD CONSTRAINT campi_pkey PRIMARY KEY (id_datasources, id_tabelle, id); - - --- --- TOC entry 10 (OID 39367) --- Name: valori_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY valori - ADD CONSTRAINT valori_pkey PRIMARY KEY (id_azioni, id_campi); - - --- --- TOC entry 3 (OID 2200) --- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: postgres --- - -COMMENT ON SCHEMA public IS 'Standard public namespace'; - - + id integer NOT NULL, + name character(30) DEFAULT '', + cnc_string character(255) DEFAULT '', + status character(1) DEFAULT '', + CONSTRAINT datasources_pkey PRIMARY KEY (id) +); + +CREATE TABLE tables ( + id integer NOT NULL, + name character(30) DEFAULT '', + status character(1) DEFAULT '', + id_datasources integer NOT NULL, + CONSTRAINT tables_pkey PRIMARY KEY (id) +); + +CREATE TABLE fields ( + id integer NOT NULL, + id_tables integer NOT NULL, + name character(30) DEFAULT '', + status character(1) DEFAULT '', + CONSTRAINT campi_pkey PRIMARY KEY (id) +); + +CREATE TABLE actions ( + id bigint NOT NULL, + type integer, + dn character(200) DEFAULT '', + date timestamp without time zone, + id_tables integer, + CONSTRAINT actions_pkey PRIMARY KEY (id) +); + +CREATE TABLE values ( + id bigint NOT NULL, + id_actions bigint NOT NULL, + id_fields integer NOT NULL, + value character varying DEFAULT '', + CONSTRAINT valori_pkey PRIMARY KEY (id) +); diff --git a/src/audit.c b/src/audit.c index b57d429..7984a34 100644 --- a/src/audit.c +++ b/src/audit.c @@ -116,7 +116,7 @@ load_fields (Audit *audit, AuditPrivate *priv = AUDIT_GET_PRIVATE (audit); sql = g_strdup_printf ("SELECT id, name FROM fields" - " WHERE status <> 'D' AND id_tabelle = %d", + " WHERE status <> 'D' AND id_tables = %d", table->id); dm = gdaex_query (priv->gdaex, sql); @@ -139,8 +139,8 @@ load_fields (Audit *audit, { cam = (Field *)g_malloc (sizeof (Field)); - cam->id = gdaex_data_model_get_field_value_integer_at (dm, 0, "id"); - cam->name = gdaex_data_model_get_field_value_stringify_at (dm, 1, "name"); + cam->id = gdaex_data_model_get_field_value_integer_at (dm, row, "id"); + cam->name = gdaex_data_model_get_field_value_stringify_at (dm, row, "name"); table->fields = g_list_append (table->fields, (gpointer)cam); } @@ -183,8 +183,8 @@ load_tables (Audit *audit, { tab = (Table *)g_malloc (sizeof (Table)); - tab->id = gdaex_data_model_get_field_value_integer_at (dm, 0, "id"); - tab->name = gdaex_data_model_get_field_value_stringify_at (dm, 1, "name"); + tab->id = gdaex_data_model_get_field_value_integer_at (dm, row, "id"); + tab->name = gdaex_data_model_get_field_value_stringify_at (dm, row, "name"); datasource->tables = g_list_append (datasource->tables, (gpointer)tab); @@ -321,8 +321,8 @@ insert_value (Audit *audit, } else { - sql = g_strdup_printf ("INSERT INTO valori" - " (id_azioni, id_campi, value)" + sql = g_strdup_printf ("INSERT INTO values" + " (id_actions, id_fields, value)" " VALUES (%d, %d, '%s')", id_azione, field->id, value); gdaex_execute (priv->gdaex, sql); @@ -494,8 +494,8 @@ audit_action (Audit *audit, /* salvo l'azione */ if (action != AUDIT_ACTION_BEFORE_UPDATE) { - sql = g_strdup_printf ("INSERT INTO azioni" - " (id, tipo_azione, dn, data, id_tabelle, id_datasources)" + sql = g_strdup_printf ("INSERT INTO actions" + " (id, type, dn, date, id_tables, id_datasources)" " VALUES (%d, %d, '%s', '%04d-%02d-%02d %02d:%02d:%02d', %d, %d)", id, action + 1, dn, tm_ora->tm_year + 1900, tm_ora->tm_mon + 1, tm_ora->tm_mday, @@ -678,9 +678,9 @@ audit_get_record_at (Audit *audit, return FALSE; } - sql = g_strdup_printf ("SELECT * FROM azioni" - " WHERE id_tabelle = %d AND id_datasources = %d" - " ORDER BY data)"); + sql = g_strdup_printf ("SELECT * FROM actions" + " WHERE id_tables = %d AND id_datasources = %d" + " ORDER BY date)"); return TRUE; }