From: Andrea Zagli Date: Fri, 14 Dec 2012 08:56:55 +0000 (+0100) Subject: Logically deleting fields and tables on autofill. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=03c9df150ec9f42e53f090b66c8fa2c8d3fe94ff;p=zakaudit%2Fgui Logically deleting fields and tables on autofill. --- diff --git a/src/datasources.c b/src/datasources.c index 3477784..98571ed 100644 --- a/src/datasources.c +++ b/src/datasources.c @@ -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,