]> saetta.ns0.it Git - zakaudit/gui/commitdiff
Logically deleting fields and tables on autofill.
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Fri, 14 Dec 2012 08:56:55 +0000 (09:56 +0100)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Fri, 14 Dec 2012 08:56:55 +0000 (09:56 +0100)
src/datasources.c

index 3477784ce68c56efb4f04e831a17c6d8b9100f01..98571edb3ca0304954a1491ac77a0513fb8febc3 100644 (file)
@@ -482,6 +482,46 @@ datasources_add_all_tables (Datasources *datasources)
                                                                                                {
                                                                                                        error = NULL;
                                                                                                        new_id = g_value_get_int (gda_data_model_get_value_at (dm, 0, 0, &error));
+
+                                                                                                       /* updating status */
+                                                                                                       sql = g_strdup_printf ("UPDATE %stables"
+                                                                                                                              " SET status = ''"
+                                                                                                                              " WHERE id = %d",
+                                                                                                                              priv->commons->prefix,
+                                                                                                                              new_id);
+                                                                                                       error = NULL;
+                                                                                                       stmt = gda_sql_parser_parse_string (priv->commons->gdaparser, sql, NULL, &error);
+                                                                                                       if (stmt == NULL || error != NULL)
+                                                                                                               {
+                                                                                                                       gtk_widget_hide_all (dialog);
+                                                                                                                       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,
+                                                                                                                                                        "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);
+                                                                                                                       break;
+                                                                                                               }
+
+                                                                                                       g_free (sql);
+
+                                                                                                       error = NULL;
+                                                                                                       if (gda_connection_statement_execute_non_select (priv->commons->gdacon, stmt, NULL, NULL, &error) != 1
+                                                                                                           || error != NULL)
+                                                                                                               {
+                                                                                                                       gtk_widget_hide_all (dialog);
+                                                                                                                       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,
+                                                                                                                                                        "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);
+                                                                                                                       break;
+                                                                                                               }
                                                                                                }
                                                                                        g_object_unref (stmt);
                                                                                        g_object_unref (dm);
@@ -660,7 +700,8 @@ datasources_add_all_tables (Datasources *datasources)
                                        if (g_strcmp0 (ids_fields_saved, "") != 0)
                                                {
                                                        ids_fields_saved[strlen (ids_fields_saved) - 1] = '\0';
-                                                       sql = g_strdup_printf ("DELETE FROM %sfields AS f"
+                                                       sql = g_strdup_printf ("UPDATE %sfields AS f"
+                                                                              " SET status = 'D'"
                                                                               " WHERE f.id NOT IN (%s)"
                                                                               " AND EXISTS (SELECT id FROM %stables AS t"
                                                                               " WHERE f.id_tables = t.id"
@@ -679,7 +720,9 @@ datasources_add_all_tables (Datasources *datasources)
                                        if (g_strcmp0 (ids_tables_saved, "") != 0)
                                                {
                                                        ids_tables_saved[strlen (ids_tables_saved) - 1] = '\0';
-                                                       sql = g_strdup_printf ("DELETE FROM %stables WHERE id NOT IN (%s)"
+                                                       sql = g_strdup_printf ("UPDATE %stables "
+                                                                              " SET status = 'D'"
+                                                                              " WHERE id NOT IN (%s)"
                                                                               " AND id_datasources = %d",
                                                                               priv->commons->prefix,
                                                                               ids_tables_saved,