]> saetta.ns0.it Git - libgtkform/commitdiff
Use of GdaEx::get_new_id in GtkForm::get_sql.
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Fri, 15 Nov 2013 08:22:44 +0000 (09:22 +0100)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Fri, 15 Nov 2013 08:22:44 +0000 (09:22 +0100)
libgtkform/form.c

index 02bf80a5842af0e413a0ecbb17ad6fed998b5c9e..e35669d8caafc19486cec4a7b3ab11beec6a8558 100644 (file)
@@ -2055,8 +2055,6 @@ gchar
                                                                                        {
                                                                                                if (gtk_form_field_is_auto_increment (field))
                                                                                                        {
-                                                                                                               gchar *sql;
-                                                                                                               GdaDataModel *dm;
                                                                                                                gchar *field_name;
                                                                                                                guint new_val;
 
@@ -2064,20 +2062,7 @@ gchar
 
                                                                                                                g_object_get (field, "field", &field_name, NULL);
 
-                                                                                                               new_val = 1;
-                                                                                                               sql = g_strdup_printf ("SELECT COALESCE (MAX (%s), 0) + 1 FROM %s",
-                                                                                                                                      field_name,
-                                                                                                                                      priv->table);
-                                                                                                               dm = gdaex_query (priv->gdaex, sql);
-                                                                                                               g_free (sql);
-                                                                                                               if (dm != NULL && gda_data_model_get_n_rows (dm) > 0)
-                                                                                                                       {
-                                                                                                                               new_val = gdaex_data_model_get_value_integer_at (dm, 0, 0);
-                                                                                                                       }
-                                                                                                               if (dm != NULL)
-                                                                                                                       {
-                                                                                                                               g_object_unref (dm);
-                                                                                                                       }
+                                                                                                               new_val = gdaex_get_new_id (priv->gdaex, priv->table, field_name, NULL);
 
                                                                                                                gtk_form_widget_set_value_stringify (gtk_form_field_get_form_widget (field), g_strdup_printf ("%d", new_val));
                                                                                                        }