]> saetta.ns0.it Git - zakautho/gui/commitdiff
Bugfixes on deleting records.
authorAndrea Zagli <azagli@libero.it>
Sun, 2 Dec 2012 18:23:32 +0000 (19:23 +0100)
committerAndrea Zagli <azagli@libero.it>
Sun, 2 Dec 2012 18:23:32 +0000 (19:23 +0100)
Some adjustments.

data/autoz-gui/gui/autoz-gui.ui
src/resource.c
src/resources.c
src/role.c
src/roles.c
tests/db.db

index ad20781f033a6f755f95493587a99b158188336d..f95ae135266ad1359e8cfda0f25c2ac9663bdf7b 100644 (file)
     <property name="has_separator">True</property>
     <property name="program_name">Autoz GUI</property>
     <property name="version">0.0.1</property>
-    <property name="copyright" translatable="yes">Andrea Zagli 2011</property>
+    <property name="copyright" translatable="yes">Andrea Zagli 2011-2012</property>
     <property name="authors">Andrea Zagli &lt;azagli@libero.it&gt;</property>
     <property name="wrap_license">True</property>
     <child internal-child="vbox">
index 5561d57eefd25be77c5d3187c07f1bdd72ff07c3..01e58963a18a47348c3c4085ed431c569285c5dc 100644 (file)
@@ -1,5 +1,5 @@
 /* 
- * Copyright (C) 2011 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2011-2012 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
@@ -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"))));
index 94e028bf71c064b2cf009dc10370977d8f50948e..91acabb9044a795345f7f63f93464be665f9c927 100644 (file)
@@ -1,5 +1,5 @@
 /* 
- * Copyright (C) 2011 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2011-2012 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
@@ -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
                {
index 77c962a9a008eb1bad3065a5a0397d0bf8c9c63f..0622996dce18b023beb3a7b85ba7af8743c8d66e 100644 (file)
@@ -1,5 +1,5 @@
 /* 
- * Copyright (C) 2011 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2011-2012 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
@@ -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"))));
index c8ac30ba1936047253fb4c886169d0dfe25172bb..d2e91367a1573e44bde25e843d75219095bbc950 100644 (file)
@@ -1,5 +1,5 @@
 /* 
- * Copyright (C) 2011 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2011-2012 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
@@ -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
                {
index cde3c51f4e560e2c109d87225955cb25bfef8073..5ac3002335eb3b0b7349734ef59edecaec3ecabb 100644 (file)
Binary files a/tests/db.db and b/tests/db.db differ