From 4e7092cfca2fa6dca5d6bd154475a1ad429234c5 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 6 Jun 2010 11:24:16 +0200 Subject: [PATCH] Check the structure of the db monitored against that declared on libaudit tables. --- src/audit.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/audit.c b/src/audit.c index 446c0a5..fee5ae9 100644 --- a/src/audit.c +++ b/src/audit.c @@ -55,6 +55,7 @@ static void audit_init (Audit *audit); static Audit *audit_new_ (void); static gboolean load_fields (Audit *audit, + Datasource *datasource, Table *table); static gboolean load_tables (Audit *audit, Datasource *datasource); @@ -130,15 +131,28 @@ static Audit static gboolean load_fields (Audit *audit, + Datasource *datasource, Table *table) { GdaDataModel *dm; + GdaDataModel *dm_table; + gchar *sql; gint rows, row; + Field *cam; AuditPrivate *priv = AUDIT_GET_PRIVATE (audit); + /* check if table exists */ + dm_table = gdaex_query (datasource->gdaex, + g_strdup_printf ("SELECT * FROM %s", table->name)); + if (dm_table == NULL) + { + g_warning ("The table «%s» doesn't exist on db.", table->name); + return FALSE; + } + sql = g_strdup_printf ("SELECT id, name FROM fields" " WHERE status <> 'D' AND id_tables = %d", table->id); @@ -166,6 +180,13 @@ load_fields (Audit *audit, 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"); + if (gda_data_model_get_column_index (dm_table, cam->name) < 0) + { + g_warning ("The field «%s» doesn't exists on table «%s».", + cam->name, table->name); + return FALSE; + } + table->fields = g_list_append (table->fields, (gpointer)cam); } @@ -174,7 +195,7 @@ load_fields (Audit *audit, static gboolean load_tables (Audit *audit, - Datasource *datasource) + Datasource *datasource) { GdaDataModel *dm; gchar *sql; @@ -210,14 +231,14 @@ load_tables (Audit *audit, 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); - /* for each table must be loaded fields */ tab->fields = NULL; - if (!load_fields (audit, tab)) + if (!load_fields (audit, datasource, tab)) { return FALSE; } + + datasource->tables = g_list_append (datasource->tables, (gpointer)tab); } return TRUE; -- 2.49.0