]> saetta.ns0.it Git - zakaudit/gui/commitdiff
Bugfixes and adjustments.
authorAndrea Zagli <azagli@libero.it>
Wed, 1 Jun 2011 09:12:29 +0000 (11:12 +0200)
committerAndrea Zagli <azagli@libero.it>
Wed, 1 Jun 2011 09:12:29 +0000 (11:12 +0200)
data/audit-gui/gui/audit-gui.gui
src/datasources.c
src/main.c
src/table.c

index b65e125fbeee22d7523020fd0b022765bd68c25f..83ac71ff0c41d9bffc440ea6f314fa505735da50 100644 (file)
   <object class="GtkAboutDialog" id="dlg_about">
     <property name="border_width">5</property>
     <property name="type_hint">normal</property>
-    <property name="has_separator">False</property>
     <property name="program_name">Audit GUI</property>
     <property name="version">0.0.1</property>
     <property name="copyright" translatable="yes">Andrea Zagli 2010</property>
       <column type="gboolean"/>
     </columns>
   </object>
-  <object class="GtkListStore" id="lstore_tables">
-    <columns>
-      <!-- column-name name -->
-      <column type="gchararray"/>
-    </columns>
-  </object>
   <object class="GtkListStore" id="lstore_fields">
     <columns>
       <!-- column-name id -->
       <column type="gboolean"/>
     </columns>
   </object>
+  <object class="GtkListStore" id="lstore_tables">
+    <columns>
+      <!-- column-name name -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
   <object class="GtkWindow" id="w_table">
     <property name="title" translatable="yes">Table - Audit GUI</property>
     <property name="modal">True</property>
index b3ed7058ddc22657ce8efa091a61407d66bbc604..fb6aa7af0604d3601a80c7deedc285a4b4dfd627 100644 (file)
@@ -1,5 +1,5 @@
 /* 
- * Copyright (C) 2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-2011 Andrea Zagli <azagli@libero.it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -316,7 +316,7 @@ datasources_edit (Datasources *datasources)
                                        Datasource *c = datasource_new (priv->commons, id);
 
                                        g_signal_connect (G_OBJECT (c), "updated",
-                                                                 G_CALLBACK (datasources_on_datasource_updated), (gpointer)datasources);
+                                                         G_CALLBACK (datasources_on_datasource_updated), (gpointer)datasources);
 
                                        w = datasource_get_widget (c);
                                        gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")));
@@ -325,14 +325,14 @@ datasources_edit (Datasources *datasources)
                        else
                                {
                                        gtk_tree_model_get (GTK_TREE_MODEL (priv->tstore_datasources), &iter,
-                                                                   COL_ID_TABLE, &id,
-                                                                   -1);
+                                                           COL_ID_TABLE, &id,
+                                                           -1);
                                        if (id != 0)
                                                {
                                                        Table *c = table_new (priv->commons, id, 0);
 
                                                        g_signal_connect (G_OBJECT (c), "updated",
-                                                                                         G_CALLBACK (datasources_on_datasource_updated), (gpointer)datasources);
+                                                                         G_CALLBACK (datasources_on_datasource_updated), (gpointer)datasources);
 
                                                        w = table_get_widget (c);
                                                        gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")));
@@ -418,6 +418,8 @@ datasources_on_btn_new_table_clicked (GtkButton *button,
        GtkTreeIter iter;
 
        guint id_ds;
+       guint depth;
+       GtkTreePath *path;
 
        Datasources *datasources = (Datasources *)user_data;
        DatasourcesPrivate *priv = DATASOURCES_GET_PRIVATE (datasources);
@@ -430,13 +432,9 @@ datasources_on_btn_new_table_clicked (GtkButton *button,
 
                        if (id_ds == 0)
                                {
-                                       GtkTreePath *path;
-
                                        path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->tstore_datasources), &iter);
                                        if (path != NULL)
                                                {
-                                                       guint depth;
-                                                       
                                                        depth = gtk_tree_path_get_depth (path);
 
                                                        if (depth >= 2) gtk_tree_path_up (path);
@@ -445,8 +443,8 @@ datasources_on_btn_new_table_clicked (GtkButton *button,
                                                        if (gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->tstore_datasources), &iter, path))
                                                                {
                                                                        gtk_tree_model_get (GTK_TREE_MODEL (priv->tstore_datasources), &iter,
-                                                                                                               COL_ID_DS, &id_ds,
-                                                                                                               -1);                                                                    
+                                                                                           COL_ID_DS, &id_ds,
+                                                                                           -1);
                                                                }
                                                }
                                }
@@ -456,7 +454,7 @@ datasources_on_btn_new_table_clicked (GtkButton *button,
                                        Table *c = table_new (priv->commons, 0, id_ds);
 
                                        g_signal_connect (G_OBJECT (c), "updated",
-                                                                         G_CALLBACK (datasources_on_datasource_updated), (gpointer)datasources);
+                                                         G_CALLBACK (datasources_on_datasource_updated), (gpointer)datasources);
 
                                        w = table_get_widget (c);
                                        gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")));
@@ -465,10 +463,10 @@ datasources_on_btn_new_table_clicked (GtkButton *button,
                        else
                                {
                                        dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")),
-                                                                                GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                                                GTK_MESSAGE_WARNING,
-                                                                                GTK_BUTTONS_OK,
-                                                                                "Select a datasource or a table.");
+                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                                        GTK_MESSAGE_WARNING,
+                                                                        GTK_BUTTONS_OK,
+                                                                        "Select a datasource or a table.");
                                        gtk_dialog_run (GTK_DIALOG (dialog));
                                        gtk_widget_destroy (dialog);
                                }
index c17075037c54ad232da2d6cea50dcf6e3a5a0512..ec52227c49c61cc5d3d990e2ece07210456095c9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Andrea Zagli <a.zagli@comune.scandicci.fi.it>
+ * Copyright (C) 2010-2011 Andrea Zagli <a.zagli@comune.scandicci.fi.it>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -60,10 +60,21 @@ main_on_ds_opened (gpointer instance, const gchar *arg1, gpointer user_data)
        GError *error;
 
        gchar *cnc;
-
        gchar *pos;
 
-       cnc = g_strdup (arg1);
+       Datasources *m;
+
+       if (arg1 == NULL)
+               {
+                       return;
+               }
+
+       cnc = g_strstrip (g_strdup (arg1));
+       if (g_strcmp0 (cnc, "") == 0)
+               {
+                       return;
+               }
+
        pos = g_strrstr (cnc, "{prefix}");
        if (pos != NULL)
                {
@@ -77,9 +88,9 @@ main_on_ds_opened (gpointer instance, const gchar *arg1, gpointer user_data)
 
        error = NULL;
        commons->gdacon = gda_connection_open_from_string (NULL, cnc, NULL,
-                                                       GDA_CONNECTION_OPTIONS_NONE,
-                                                       &error);
-       if (!commons->gdacon)
+                                                          GDA_CONNECTION_OPTIONS_NONE,
+                                                          &error);
+       if (!commons->gdacon || error != NULL)
                {
                        GtkWidget *dialog;
                        dialog = gtk_message_dialog_new (GTK_WINDOW (w),
@@ -95,15 +106,20 @@ main_on_ds_opened (gpointer instance, const gchar *arg1, gpointer user_data)
                }
 
        commons->gdaparser = gda_connection_create_parser (commons->gdacon);
-       if (!commons->gdaparser) /* @cnc doe snot provide its own parser => use default one */
-               commons->gdaparser = gda_sql_parser_new ();
+       if (!commons->gdaparser)
+               {
+                       /* @cnc doe snot provide its own parser => use default one */
+                       commons->gdaparser = gda_sql_parser_new ();
+               }
 
-       Datasources *m = datasources_new (commons);
+       m = datasources_new (commons);
 
        vbx = datasources_get_widget (m);
 
        main_set_vbx_body_child (vbx);
        gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "menuitem2")), TRUE);
+
+       g_free (cnc);
 }
 
 G_MODULE_EXPORT void
index 09a67a2c875d3c417e03c29bedf27299be8f1ba0..e21f0b13398faefe2e4d540d86819c174c2b64bd 100644 (file)
@@ -1,5 +1,5 @@
 /* 
- * Copyright (C) 2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-2011 Andrea Zagli <azagli@libero.it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -62,6 +62,8 @@ struct _TablePrivate
        {
                Commons *commons;
 
+               GdaConnection *gdacon;
+
                GtkWidget *w;
                GtkListStore *lstore_fields;
 
@@ -151,13 +153,14 @@ Table
        g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button6"),
                          "clicked", G_CALLBACK (table_on_btn_save_clicked), (gpointer *)a);
 
-       table_load_db_tables (a);
-
        priv->id = id;
+
        if (priv->id == 0)
                {
                        gtk_label_set_text (GTK_LABEL (gtk_builder_get_object (priv->commons->gtkbuilder, "label7")), "");
                        gtk_label_set_text (GTK_LABEL (gtk_builder_get_object (priv->commons->gtkbuilder, "label8")), g_strdup_printf ("%d", id_datasources));
+
+                       table_load_db_tables (a);
                }
        else
                {
@@ -207,10 +210,12 @@ table_is_a_system_table (Table *table, const gchar *table_name)
 static void
 table_load_db_tables (Table *table)
 {
+       GtkWidget *dialog;
        GError *error;
 
        GdaMetaContext mcontext = {"_tables", 0, NULL, NULL};
 
+       GdaStatement *stmt;
        GdaDataModel *dm;
 
        GtkTreeModel *model;
@@ -221,33 +226,95 @@ table_load_db_tables (Table *table)
 
        gchar *table_name;
 
+       gchar *sql;
+       gchar *cnc;
+
        TablePrivate *priv = TABLE_GET_PRIVATE (table);
 
+       model = gtk_combo_box_get_model (GTK_COMBO_BOX (gtk_builder_get_object (priv->commons->gtkbuilder, "combobox1")));
+
+       gtk_list_store_clear (GTK_LIST_STORE (model));
+
+       /* open connection to the db to inspect */
+       sql = g_strdup_printf ("SELECT cnc_string"
+                              " FROM %sdatasources"
+                              " WHERE id = %d AND status <> 'D'",
+                              priv->commons->prefix,
+                              strtol (gtk_label_get_text (GTK_LABEL (gtk_builder_get_object (priv->commons->gtkbuilder, "label8"))), NULL, 10));
+
        error = NULL;
-       if (!gda_connection_update_meta_store (priv->commons->gdacon, &mcontext, &error))
+       stmt = gda_sql_parser_parse_string (priv->commons->gdaparser, sql, NULL, &error);
+       if (stmt == NULL || error != NULL)
                {
-                       GtkWidget *dialog;
                        dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
-                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                                                        GTK_MESSAGE_WARNING,
-                                                                                        GTK_BUTTONS_OK,
-                                                                                        "Unable to get tables list.\n\n",
-                                                                                        (error != NULL && error->message != NULL ? error->message : "No details."));
+                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                        GTK_MESSAGE_WARNING,
+                                                        GTK_BUTTONS_OK,
+                                                        "Unable to get tables list.\n%s",
+                                                        (error != NULL && error->message != NULL ? error->message : "No details."));
                        gtk_dialog_run (GTK_DIALOG (dialog));
                        gtk_widget_destroy (dialog);
                        return;
                }
 
-       model = gtk_combo_box_get_model (GTK_COMBO_BOX (gtk_builder_get_object (priv->commons->gtkbuilder, "combobox1")));
+       error = NULL;
+       dm = gda_connection_statement_execute_select (priv->commons->gdacon, stmt, NULL, &error);
+       g_object_unref (stmt);
+       if (dm != NULL && error == NULL && gda_data_model_get_n_rows (dm) > 0)
+               {
+                       cnc = gda_value_stringify (gda_data_model_get_value_at (dm, 0, 0, NULL));
+                       g_object_unref (dm);
+               }
+       else
+               {
+                       dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                        GTK_MESSAGE_WARNING,
+                                                        GTK_BUTTONS_OK,
+                                                        "Unable to get tables list.\n%s",
+                                                        (error != NULL && error->message != NULL ? error->message : "No details."));
+                       gtk_dialog_run (GTK_DIALOG (dialog));
+                       gtk_widget_destroy (dialog);
+                       return;
+               }
 
-       gtk_list_store_clear (GTK_LIST_STORE (model));
+       error = NULL;
+       priv->gdacon = gda_connection_open_from_string (NULL, cnc, NULL,
+                                                       GDA_CONNECTION_OPTIONS_NONE,
+                                                       &error);
+       if (priv->gdacon == NULL || error != NULL)
+               {
+                       dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                        GTK_MESSAGE_WARNING,
+                                                        GTK_BUTTONS_OK,
+                                                        "Unable to get tables list.\n%s",
+                                                        (error != NULL && error->message != NULL ? error->message : "No details."));
+                       gtk_dialog_run (GTK_DIALOG (dialog));
+                       gtk_widget_destroy (dialog);
+                       return;
+               }
 
        error = NULL;
-       dm = gda_connection_get_meta_store_data (priv->commons->gdacon,
-                                           GDA_CONNECTION_META_TABLES,
-                                           &error,
-                                           0);
-       if (dm != NULL)
+       if (!gda_connection_update_meta_store (priv->gdacon, &mcontext, &error))
+               {
+                       dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                        GTK_MESSAGE_WARNING,
+                                                        GTK_BUTTONS_OK,
+                                                        "Unable to get tables list.\n%s",
+                                                        (error != NULL && error->message != NULL ? error->message : "No details."));
+                       gtk_dialog_run (GTK_DIALOG (dialog));
+                       gtk_widget_destroy (dialog);
+                       return;
+               }
+
+       error = NULL;
+       dm = gda_connection_get_meta_store_data (priv->gdacon,
+                                                GDA_CONNECTION_META_TABLES,
+                                                &error,
+                                                0);
+       if (dm != NULL && error == NULL)
                {
                        rows = gda_data_model_get_n_rows (dm);
                        for (row = 0; row < rows; row++)
@@ -258,10 +325,23 @@ table_load_db_tables (Table *table)
                                                {
                                                        gtk_list_store_append (GTK_LIST_STORE (model), &iter);
                                                        gtk_list_store_set (GTK_LIST_STORE (model), &iter,
-                                                                                   0, table_name,
-                                                                                   -1);
+                                                                           0, table_name,
+                                                                           -1);
                                                }
                                }
+                       g_object_unref (dm);
+               }
+       else
+               {
+                       dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                        GTK_MESSAGE_WARNING,
+                                                        GTK_BUTTONS_OK,
+                                                        "Unable to get tables list.\n%s",
+                                                        (error != NULL && error->message != NULL ? error->message : "No details."));
+                       gtk_dialog_run (GTK_DIALOG (dialog));
+                       gtk_widget_destroy (dialog);
+                       return;
                }
 }
 
@@ -295,6 +375,8 @@ table_set_table (Table *table, const gchar *table_name)
 static void
 table_load (Table *table)
 {
+       GtkWidget *dialog;
+
        TablePrivate *priv = TABLE_GET_PRIVATE (table);
 
        GError *error;
@@ -302,24 +384,30 @@ table_load (Table *table)
        GdaStatement *stmt;
        GdaDataModel *dm;
 
-       sql = g_strdup_printf ("SELECT name FROM %stables WHERE id = %d",
+       sql = g_strdup_printf ("SELECT id_datasources, name FROM %stables WHERE id = %d",
                               priv->commons->prefix,
                               priv->id);
        stmt = gda_sql_parser_parse_string (priv->commons->gdaparser, sql, NULL, NULL);
        dm = gda_connection_statement_execute_select (priv->commons->gdacon, stmt, NULL, &error);
        g_object_unref (stmt);
+       g_free (sql);
        if (dm != NULL && gda_data_model_get_n_rows (dm) == 1)
                {
-                       table_set_table (table, gda_value_stringify (gda_data_model_get_value_at (dm, 0, 0, NULL)));
+                       gtk_label_set_text (GTK_LABEL (gtk_builder_get_object (priv->commons->gtkbuilder, "label8")),
+                                           g_strdup_printf ("%d", g_value_get_int (gda_data_model_get_value_at (dm, 0, 0, NULL))));
+                       table_load_db_tables (table);
+
+                       table_set_table (table, gda_value_stringify (gda_data_model_get_value_at (dm, 1, 0, NULL)));
+                       g_object_unref (dm);
                }
        else
                {
-                       GtkWidget *dialog;
                        dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
-                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                                                        GTK_MESSAGE_WARNING,
-                                                                                        GTK_BUTTONS_OK,
-                                                                                        "Record %d doesn't exist.", priv->id);
+                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                        GTK_MESSAGE_WARNING,
+                                                        GTK_BUTTONS_OK,
+                                                        "Record %d doesn't exist.",
+                                                        priv->id);
                        gtk_dialog_run (GTK_DIALOG (dialog));
                        gtk_widget_destroy (dialog);
                }
@@ -357,10 +445,10 @@ table_save (Table *table)
        else
                {
                        dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
-                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                                                        GTK_MESSAGE_WARNING,
-                                                                                        GTK_BUTTONS_OK,
-                                                                                        "You must select a table.");
+                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                        GTK_MESSAGE_WARNING,
+                                                        GTK_BUTTONS_OK,
+                                                        "You must select a table.");
                        gtk_dialog_run (GTK_DIALOG (dialog));
                        gtk_widget_destroy (dialog);
                        return;
@@ -449,11 +537,11 @@ table_save (Table *table)
                                                                                        error = NULL;
                                                                                        sql = g_strdup_printf ("INSERT INTO %sfields"
                                                                                                               " (id, id_tables, name)"
-                                                                                                                      " VALUES (%d, %d, '%s')",
+                                                                                                             " VALUES (%d, %d, '%s')",
                                                                                                               priv->commons->prefix,
-                                                                                                                      id_field,
+                                                                                                              id_field,
                                                                                                               priv->id,
-                                                                                                                      field_name);
+                                                                                                              field_name);
                                                                                        stmt = gda_sql_parser_parse_string (priv->commons->gdaparser, sql, NULL, NULL);
                                                                                        gda_connection_statement_execute_non_select (priv->commons->gdacon, stmt, NULL, NULL, &error);
                                                                                        if (error != NULL)
@@ -472,27 +560,27 @@ table_save (Table *table)
                        error = NULL;
                        id_saved[strlen (id_saved) - 1] = '\0';
                        sql = g_strdup_printf ("DELETE FROM %sfields"
-                                                      " WHERE id_tables = %d"
-                                                      "%s",
-                                                      priv->commons->prefix,
-                                                      priv->id,
-                                                      (g_strcmp0 (id_saved, "") != 0 ? g_strdup_printf (" AND id NOT IN (%s)", id_saved) : ""));
+                                              " WHERE id_tables = %d"
+                                              "%s",
+                                              priv->commons->prefix,
+                                              priv->id,
+                                              (g_strcmp0 (id_saved, "") != 0 ? g_strdup_printf (" AND id NOT IN (%s)", id_saved) : ""));
                        stmt = gda_sql_parser_parse_string (priv->commons->gdaparser, sql, NULL, NULL);
                        gda_connection_statement_execute_non_select (priv->commons->gdacon, stmt, NULL, NULL, &error);
                        if (error != NULL)
                                {
                                        g_warning ("Error removing old fields: %s",
-                                                      (error->message != NULL ? error->message : "No details."));
+                                                  (error->message != NULL ? error->message : "No details."));
                                }
                        g_object_unref (stmt);
 
                        g_signal_emit (table, klass->updated_signal_id, 0);
 
                        dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
-                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                                                        GTK_MESSAGE_INFO,
-                                                                                        GTK_BUTTONS_OK,
-                                                                                        "Saved with success.");
+                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                        GTK_MESSAGE_INFO,
+                                                        GTK_BUTTONS_OK,
+                                                        "Saved with success.");
                        gtk_dialog_run (GTK_DIALOG (dialog));
                        gtk_widget_destroy (dialog);
                }
@@ -504,11 +592,11 @@ table_save (Table *table)
                                }
 
                        dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
-                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                                                        GTK_MESSAGE_WARNING,
-                                                                                        GTK_BUTTONS_OK,
-                                                                                        "Error on saving.\n\n%s",
-                                                                                        (error != NULL && error->message != NULL ? error->message : "No details."));
+                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                        GTK_MESSAGE_WARNING,
+                                                        GTK_BUTTONS_OK,
+                                                        "Error on saving.\n\n%s",
+                                                        (error != NULL && error->message != NULL ? error->message : "No details."));
                        gtk_dialog_run (GTK_DIALOG (dialog));
                        gtk_widget_destroy (dialog);
                }
@@ -574,10 +662,13 @@ table_on_cb_tables_changed (GtkComboBox *widget,
                             gpointer user_data)
 {
        GError *error;
+       GtkWidget *dialog;
 
        GdaMetaContext mcontext = {"_columns", 1, NULL, NULL};
 
+       guint id_tables;
        gchar *table_name;
+
        GdaDataModel *dm;
        GdaStatement *stmt;
        GdaDataModel *dm_fields;
@@ -601,7 +692,9 @@ table_on_cb_tables_changed (GtkComboBox *widget,
                        return;
                }
 
-       gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (gtk_builder_get_object (priv->commons->gtkbuilder, "combobox1"))), &iter, 0, &table_name, -1);
+       gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (gtk_builder_get_object (priv->commons->gtkbuilder, "combobox1"))), &iter,
+                           0, &table_name,
+                           -1);
 
        error = NULL;
        mcontext.column_names = g_new (gchar *, 1);
@@ -609,16 +702,15 @@ table_on_cb_tables_changed (GtkComboBox *widget,
        mcontext.column_values = g_new (GValue *, 1);
        mcontext.column_values[0] = gda_value_new (G_TYPE_STRING);
        g_value_take_string (mcontext.column_values[0],
-                            gda_sql_identifier_quote (table_name, priv->commons->gdacon, NULL, FALSE, FALSE));
-       if (!gda_connection_update_meta_store (priv->commons->gdacon, &mcontext, &error))
+                            gda_sql_identifier_quote (table_name, priv->gdacon, NULL, FALSE, FALSE));
+       if (!gda_connection_update_meta_store (priv->gdacon, &mcontext, &error))
                {
-                       GtkWidget *dialog;
                        dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
-                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                                                        GTK_MESSAGE_WARNING,
-                                                                                        GTK_BUTTONS_OK,
-                                                                                        "Unable to get fields list.\n\n%s",
-                                                                                        (error != NULL && error->message != NULL ? error->message : "No details."));
+                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                        GTK_MESSAGE_WARNING,
+                                                        GTK_BUTTONS_OK,
+                                                        "Unable to get fields list.\n\n%s",
+                                                        (error != NULL && error->message != NULL ? error->message : "No details."));
                        gtk_dialog_run (GTK_DIALOG (dialog));
                        gtk_widget_destroy (dialog);
                        return;
@@ -627,7 +719,7 @@ table_on_cb_tables_changed (GtkComboBox *widget,
        error = NULL;
        gval = gda_value_new (G_TYPE_STRING);
        g_value_take_string (gval, table_name);
-       dm = gda_connection_get_meta_store_data (priv->commons->gdacon,
+       dm = gda_connection_get_meta_store_data (priv->gdacon,
                                            GDA_CONNECTION_META_FIELDS,
                                            &error,
                                            1,
@@ -645,8 +737,16 @@ table_on_cb_tables_changed (GtkComboBox *widget,
 
                                        /* check if field is choosen for libaudit */
                                        error = NULL;
-                                       sql = g_strdup_printf ("SELECT id FROM %sfields WHERE name = '%s' AND status <> 'D'",
+                                       sql = g_strdup_printf ("SELECT f.id"
+                                                              " FROM %sfields AS f INNER JOIN %stables AS t ON f.id_tables = t.id"
+                                                              " WHERE f.id_tables = %d"
+                                                              " AND t.name = '%s'"
+                                                              " AND f.name = '%s'"
+                                                              " AND f.status <> 'D'",
+                                                              priv->commons->prefix,
                                                               priv->commons->prefix,
+                                                              priv->id,
+                                                              table_name,
                                                               field_name);
                                        stmt = gda_sql_parser_parse_string (priv->commons->gdaparser, sql, NULL, NULL);
                                        dm_fields = gda_connection_statement_execute_select (priv->commons->gdacon, stmt, NULL, &error);