From: Andrea Zagli Date: Sun, 2 Dec 2012 18:23:32 +0000 (+0100) Subject: Bugfixes on deleting records. X-Git-Tag: v0.0.1~11 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=b6968107ee586b42439112c75d0fb0c2934d5e88;p=zakautho%2Fgui Bugfixes on deleting records. Some adjustments. --- diff --git a/data/autoz-gui/gui/autoz-gui.ui b/data/autoz-gui/gui/autoz-gui.ui index ad20781..f95ae13 100644 --- a/data/autoz-gui/gui/autoz-gui.ui +++ b/data/autoz-gui/gui/autoz-gui.ui @@ -157,7 +157,7 @@ True Autoz GUI 0.0.1 - Andrea Zagli 2011 + Andrea Zagli 2011-2012 Andrea Zagli <azagli@libero.it> True diff --git a/src/resource.c b/src/resource.c index 5561d57..01e5896 100644 --- a/src/resource.c +++ b/src/resource.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 Andrea Zagli + * Copyright (C) 2011-2012 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -216,9 +216,10 @@ resource_save (Resource *resource) new_id = g_value_get_int (gda_data_model_get_value_at (dm, 0, 0, NULL)); } new_id++; + g_object_unref (dm); sql = g_strdup_printf ("INSERT INTO %sresources (id, resource_id)" - " VALUES (%d, '%s',)", + " VALUES (%d, '%s')", priv->commons->prefix, new_id, gtk_entry_get_text (GTK_ENTRY (gtk_builder_get_object (priv->commons->gtkbuilder, "entry2")))); diff --git a/src/resources.c b/src/resources.c index 94e028b..91acabb 100644 --- a/src/resources.c +++ b/src/resources.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 Andrea Zagli + * Copyright (C) 2011-2012 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -328,6 +328,7 @@ resources_on_btn_delete_clicked (GtkButton *button, GTK_BUTTONS_YES_NO, "Are you sure to want to delete the selected resource?"); risp = gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); if (risp == GTK_RESPONSE_YES) { GError *error; @@ -339,19 +340,23 @@ resources_on_btn_delete_clicked (GtkButton *button, error = NULL; stmt = gda_sql_parser_parse_string (priv->commons->gdaparser, - g_strdup_printf ("DELETE %sresources WHERE id = %d", priv->commons->prefix, id), - NULL, NULL); + g_strdup_printf ("DELETE FROM %sresources WHERE id = %d", priv->commons->prefix, id), + NULL, &error); - if (stmt != NULL) + if (stmt == NULL || error != NULL) { 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, - "You must select a resource."); + "You must select a resource.%s", + error != NULL && error->message != NULL ? g_strdup_printf ("\n\n", error->message) : ""); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); return; } + error = NULL; if (gda_connection_statement_execute_non_select (priv->commons->gdacon, stmt, NULL, NULL, &error) <= 0) { dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")), @@ -360,11 +365,12 @@ resources_on_btn_delete_clicked (GtkButton *button, 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); } resources_load (resources); } - gtk_widget_destroy (dialog); } else { diff --git a/src/role.c b/src/role.c index 77c962a..0622996 100644 --- a/src/role.c +++ b/src/role.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 Andrea Zagli + * Copyright (C) 2011-2012 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -184,6 +184,7 @@ role_load (Role *role) gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); } + g_object_unref (dm); } static void @@ -216,9 +217,10 @@ role_save (Role *role) new_id = g_value_get_int (gda_data_model_get_value_at (dm, 0, 0, NULL)); } new_id++; + g_object_unref (dm); sql = g_strdup_printf ("INSERT INTO %sroles (id, role_id)" - " VALUES (%d, '%s',)", + " VALUES (%d, '%s')", priv->commons->prefix, new_id, gtk_entry_get_text (GTK_ENTRY (gtk_builder_get_object (priv->commons->gtkbuilder, "entry1")))); diff --git a/src/roles.c b/src/roles.c index c8ac30b..d2e9136 100644 --- a/src/roles.c +++ b/src/roles.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 Andrea Zagli + * Copyright (C) 2011-2012 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -328,6 +328,7 @@ roles_on_btn_delete_clicked (GtkButton *button, GTK_BUTTONS_YES_NO, "Are you sure to want to delete the selected role?"); risp = gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); if (risp == GTK_RESPONSE_YES) { GError *error; @@ -339,19 +340,23 @@ roles_on_btn_delete_clicked (GtkButton *button, error = NULL; stmt = gda_sql_parser_parse_string (priv->commons->gdaparser, - g_strdup_printf ("DELETE %sroles WHERE id = %d", priv->commons->prefix, id), - NULL, NULL); + g_strdup_printf ("DELETE FROM %sroles WHERE id = %d", priv->commons->prefix, id), + NULL, &error); - if (stmt != NULL) + if (stmt == NULL || error != NULL) { 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, - "You must select a role."); + "You must select a role.%s", + error != NULL && error->message != NULL ? g_strdup_printf ("\n\n%s", error->message) : ""); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); return; } + error = NULL; if (gda_connection_statement_execute_non_select (priv->commons->gdacon, stmt, NULL, NULL, &error) <= 0) { dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")), @@ -360,11 +365,12 @@ roles_on_btn_delete_clicked (GtkButton *button, 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); } roles_load (roles); } - gtk_widget_destroy (dialog); } else { diff --git a/tests/db.db b/tests/db.db index cde3c51..5ac3002 100644 Binary files a/tests/db.db and b/tests/db.db differ