From: Andrea Zagli <azagli@libero.it>
Date: Mon, 31 May 2010 14:41:16 +0000 (+0200)
Subject: Some little changes before start coding.
X-Git-Tag: 0.5.0~20
X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=4386a1115bd462c3794b9375ac46fd9521c7111d;p=zakaudit%2Flibzakaudit

Some little changes before start coding.
---

diff --git a/doc/sql/audit.sql b/doc/sql/audit.sql
index 6da6866..ad93857 100644
--- a/doc/sql/audit.sql
+++ b/doc/sql/audit.sql
@@ -83,6 +83,7 @@ CREATE TABLE azioni (
 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;
 
diff --git a/src/audit.c b/src/audit.c
index d52c460..b57d429 100644
--- a/src/audit.c
+++ b/src/audit.c
@@ -65,6 +65,7 @@ typedef struct
 typedef struct
 {
 	gint id;
+	gchar *name;
 	gchar *cnc_string;
 	GdaEx *gdaex;
 	GList *tables;
@@ -114,9 +115,9 @@ 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",
-                         table->id);
+	sql = g_strdup_printf ("SELECT id, name FROM fields"
+	                       " WHERE status <> 'D' AND id_tabelle = %d",
+	                       table->id);
 	dm = gdaex_query (priv->gdaex, sql);
 
 	if (dm == NULL)
@@ -158,23 +159,23 @@ load_tables (Audit *audit,
 
 	AuditPrivate *priv = AUDIT_GET_PRIVATE (audit);
 
-	sql = g_strdup_printf ("SELECT id, name FROM tables "
-                         "WHERE status <> 'D' AND id_datasources = %d",
-                         datasource->id);
+	sql = g_strdup_printf ("SELECT id, name FROM tables"
+	                       " WHERE status <> 'D' AND id_datasources = %d",
+	                       datasource->id);
 	dm = gdaex_query (priv->gdaex, sql);
 
 	if (dm == NULL)
-    {
-      g_warning ("Per il datasource \"%d\" non sono state configurate le tables.",
-                 datasource->id);
-      return FALSE;
-    }
+		{
+			g_warning ("Per il datasource \"%d\" non sono state configurate le tables.",
+			           datasource->id);
+			return FALSE;
+		}
 
 	rows = gda_data_model_get_n_rows (dm);
 	if (rows == 0)
 		{
 			g_warning ("Per il datasource \"%d\" non sono state configurate le tables.",
-								 datasource->id);
+			           datasource->id);
 			return FALSE;
 		}
 
@@ -206,7 +207,7 @@ load_datasources (Audit *audit)
 	AuditPrivate *priv = AUDIT_GET_PRIVATE (audit);
 
 	/* per ogni datasource nella table datasources devo aprire una connessione */
-	dm = gdaex_query (priv->gdaex, "SELECT id, cnc_string"
+	dm = gdaex_query (priv->gdaex, "SELECT id, name, cnc_string"
 	                                " FROM datasources"
 	                                " WHERE status <> 'D'");
 	if (dm == NULL)
@@ -226,8 +227,9 @@ load_datasources (Audit *audit)
 		{
 			datas = (Datasource *)g_malloc (sizeof (Datasource));
 
-			datas->id = gdaex_data_model_get_field_value_integer_at (dm, 0, "id");
-			datas->cnc_string = gdaex_data_model_get_field_value_stringify_at (dm, 1, "cnc_string");
+			datas->id = gdaex_data_model_get_field_value_integer_at (dm, row, "id");
+			datas->name = gdaex_data_model_get_field_value_stringify_at (dm, row, "name");
+			datas->cnc_string = gdaex_data_model_get_field_value_stringify_at (dm, row, "cnc_string");
 
 			datas->gdaex = gdaex_new_from_string (datas->cnc_string);
 	
@@ -285,7 +287,7 @@ static Datasource
 *get_datasource_from_nome (Audit *audit,
                            const char *datasource)
 {
-	/*GList *f = g_list_first (audit->datasources);
+	GList *f = g_list_first (audit->datasources);
 
 	while (f != NULL)
 		{
@@ -295,7 +297,7 @@ static Datasource
 				}
 
 			f = g_list_next (f);
-		}*/
+		}
 
 	return NULL;
 }
@@ -315,14 +317,14 @@ insert_value (Audit *audit,
 	if (field == NULL)
 		{
 			g_warning ("Impossibile trovare il field \"%s\" nei fields caricati",
-								 nome_campo);
+			           nome_campo);
 		}
 	else
 		{
-			sql = g_strdup_printf ("INSERT INTO valori "
-														 "(id_azioni, id_campi, value) "
-														 "VALUES (%d, %d, '%s')",
-														 id_azione, field->id, value);
+			sql = g_strdup_printf ("INSERT INTO valori"
+			                       " (id_azioni, id_campi, value)"
+			                       " VALUES (%d, %d, '%s')",
+			                       id_azione, field->id, value);
 			gdaex_execute (priv->gdaex, sql);
 		}
 
@@ -463,13 +465,13 @@ audit_action (Audit *audit,
 
 	if (dm != NULL && gda_data_model_get_n_rows (dm) == 1)
 		{
-			id = atol (gdaex_data_model_get_value_stringify_at (dm, 0, 0));
+			id = gdaex_data_model_get_value_integer_at (dm, 0, 0);
 		}
 	id++;
 
 	/* trovo il timestamp dell'operazione */
-	t = time(NULL);
-	tm_ora = localtime(&t);
+	t = time (NULL);
+	tm_ora = localtime (&t);
 
 	/* trovo il datasource */
 	datasource = get_datasource_from_nome (audit, nome_datasource);
@@ -509,20 +511,20 @@ audit_action (Audit *audit,
 		{
 			case AUDIT_ACTION_INSERT:
 				/* salvo tutti i fields */
-				sql = g_strdup_printf ("SELECT * FROM %s ",
+				sql = g_strdup_printf ("SELECT * FROM %s",
 				                       nome_tabella);
 
-				sql_where = g_strdup ("WHERE TRUE");
+				sql_where = g_strdup (" WHERE TRUE");
 				nome_campo = va_arg (vargs, gchar *);
 				while (nome_campo != NULL)
 					{
 						value = va_arg (vargs, gchar *);
 						if (value == NULL) break;
 
-						sql_where = g_strjoin (NULL, sql_where, " AND ", nome_campo, "='", value, "'", NULL);
+						sql_where = g_strconcat (sql_where, " AND ", nome_campo, "='", value, "'", NULL);
 						nome_campo = va_arg (vargs, gchar *);
 					}
-				sql = g_strjoin (NULL, sql, sql_where, NULL);
+				sql = g_strconcat (sql, sql_where, NULL);
 				dm = gdaex_query (datasource->gdaex, sql);
 
 				if (dm == NULL) return FALSE;
@@ -541,20 +543,20 @@ audit_action (Audit *audit,
 
 			case AUDIT_ACTION_BEFORE_UPDATE:
 				/* memorizzo tutta la table che sta per essere modificata */
-				sql = g_strdup_printf ("SELECT * FROM %s ",
+				sql = g_strdup_printf ("SELECT * FROM %s",
 				                       nome_tabella);
 
-				sql_where = g_strdup ("WHERE TRUE");
+				sql_where = g_strdup (" WHERE TRUE");
 				nome_campo = va_arg (vargs, gchar *);
 				while (nome_campo != NULL)
 					{
 						value = va_arg (vargs, gchar *);
 						if (value == NULL) break;
 
-						sql_where = g_strjoin (NULL, sql_where, " AND ", nome_campo, "='", value, "'", NULL);
+						sql_where = g_strconcat (sql_where, " AND ", nome_campo, "='", value, "'", NULL);
 						nome_campo = va_arg (vargs, gchar *);
 					}
-				sql = g_strjoin (NULL, sql, sql_where, NULL);
+				sql = g_strconcat (sql, sql_where, NULL);
 				dm = gdaex_query (datasource->gdaex, sql);
 
 				if (dm == NULL) return FALSE;
@@ -574,20 +576,20 @@ audit_action (Audit *audit,
 
 			case AUDIT_ACTION_AFTER_UPDATE:
 				/* salvo i fields modificati */
-				sql = g_strdup_printf ("SELECT * FROM %s ",
+				sql = g_strdup_printf ("SELECT * FROM %s",
 				                       nome_tabella);
 
-				sql_where = g_strdup ("WHERE TRUE");
+				sql_where = g_strdup (" WHERE TRUE");
 				nome_campo = va_arg (vargs, gchar *);
 				while (nome_campo != NULL)
 					{
 						value = va_arg (vargs, gchar *);
 						if (value == NULL) break;
 
-						sql_where = g_strjoin (NULL, sql_where, " AND ", nome_campo, "='", value, "'", NULL);
+						sql_where = g_strconcat (sql_where, " AND ", nome_campo, "='", value, "'", NULL);
 						nome_campo = va_arg (vargs, gchar *);
 					}
-				sql = g_strjoin (NULL, sql, sql_where, NULL);
+				sql = g_strconcat (sql, sql_where, NULL);
 				dm = gdaex_query (datasource->gdaex, sql);
 
 				if (dm == NULL) return FALSE;