]> saetta.ns0.it Git - zakaudit/libzakaudit/commitdiff
Some little changes before start coding.
authorAndrea Zagli <azagli@libero.it>
Mon, 31 May 2010 14:41:16 +0000 (16:41 +0200)
committerAndrea Zagli <azagli@libero.it>
Mon, 31 May 2010 14:41:16 +0000 (16:41 +0200)
doc/sql/audit.sql
src/audit.c

index 6da6866ac5b51bf65588095e82ec553cfe081e3f..ad93857aa542da224e6313cb60e1f7ff57d9824c 100644 (file)
@@ -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;
 
index d52c46060c6356861fbe4e6d05bd831cbdca7a1d..b57d42948c623e863c95ffde80f0a7d4d2d3cfc6 100644 (file)
@@ -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;