{
if (gtk_form_field_is_auto_increment (field))
{
- gchar *sql;
- GdaDataModel *dm;
gchar *field_name;
guint new_val;
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));
}