]> saetta.ns0.it Git - libgtkform/commitdiff
Multifields key (closes #797).
authorAndrea Zagli <azagli@libero.it>
Sat, 16 Nov 2013 16:13:46 +0000 (17:13 +0100)
committerAndrea Zagli <azagli@libero.it>
Sat, 16 Nov 2013 16:13:46 +0000 (17:13 +0100)
.anjuta/default.profile [new file with mode: 0644]
.anjuta_sym_db.db [new file with mode: 0644]
libgtkform.anjuta [new file with mode: 0644]
libgtkform/form.c
libgtkform/key.c
libgtkform/key.h

diff --git a/.anjuta/default.profile b/.anjuta/default.profile
new file mode 100644 (file)
index 0000000..054294f
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<anjuta>
+    <plugin name="Git" mandatory="no">
+        <require group="Anjuta Plugin"
+                 attribute="Location"
+                 value="anjuta-git:Git"/>
+    </plugin>
+</anjuta>
diff --git a/.anjuta_sym_db.db b/.anjuta_sym_db.db
new file mode 100644 (file)
index 0000000..99d8107
Binary files /dev/null and b/.anjuta_sym_db.db differ
diff --git a/libgtkform.anjuta b/libgtkform.anjuta
new file mode 100644 (file)
index 0000000..793b25e
--- /dev/null
@@ -0,0 +1,50 @@
+<?xml version="1.0"?>
+<anjuta>
+       <plugin name="GBF Project Manager"
+            url="http://anjuta.org/plugins/"
+            mandatory="yes">
+               <require group="Anjuta Plugin"
+                 attribute="Interfaces"
+                 value="IAnjutaProjectManager"/>
+       </plugin>
+       <plugin name= "Autotools backend"
+            mandatory="yes">
+         <require group="Anjuta Plugin"
+                  attribute="Location"
+                  value="am-project:AmpPlugin"/>
+         <require group="Anjuta Plugin"
+                  attribute="Interfaces"
+                  value="IAnjutaProjectBackend"/>
+    </plugin>
+       <plugin name="Symbol Browser"
+            url="http://anjuta.org/plugins/"
+            mandatory="yes">
+               <require group="Anjuta Plugin"
+                 attribute="Interfaces"
+                 value="IAnjutaSymbolManager"/>
+       </plugin>
+       <plugin name="Make Build System"
+            url="http://anjuta.org/plugins/"
+            mandatory="yes">
+               <require group="Anjuta Plugin"
+                 attribute="Interfaces"
+                 value="IAnjutaBuildable"/>
+               <require group="Build"
+                 attribute="Supported-Build-Types"
+                 value="make"/>
+       </plugin>
+       <plugin name="Task Manager"
+            url="http://anjuta.org/plugins/"
+            mandatory="no">
+               <require group="Anjuta Plugin"
+                 attribute="Interfaces"
+                 value="IAnjutaTodo"/>
+       </plugin>
+       <plugin name="Debug Manager"
+            url="http://anjuta.org/plugins/"
+            mandatory="no">
+               <require group="Anjuta Plugin"
+                 attribute="Interfaces"
+                 value="IAnjutaDebugManager"/>
+       </plugin>
+</anjuta>
index e35669d8caafc19486cec4a7b3ab11beec6a8558..9ed93f06cfbaf1a59deab95f7f354ddf360636f8 100644 (file)
@@ -2056,17 +2056,52 @@ gchar
                                                                                                if (gtk_form_field_is_auto_increment (field))
                                                                                                        {
                                                                                                                gchar *field_name;
+                                                                                                               GString *key_where;
                                                                                                                guint new_val;
 
                                                                                                                g_return_val_if_fail (IS_GDAEX (priv->gdaex), NULL);
 
-                                                                                                               g_object_get (field, "field", &field_name, NULL);
+                                                                                                               where = NULL;
+                                                                                                               if (IS_GTK_FORM_KEY (priv->key)
+                                                                                                                   && gtk_form_key_field_is_key (priv->key, field))
+                                                                                                                       {
+                                                                                                                               /* it depends on other key fields value */
+                                                                                                                               GSList *key_fields;
+                                                                                                                               GtkFormField *kffield;
+
+                                                                                                                               key_fields = gtk_form_key_get_fields (priv->key);
+                                                                                                                               if (key_fields != NULL)
+                                                                                                                                       {
+                                                                                                                                               key_where = g_string_new ("");
+                                                                                                                                       }
+                                                                                                                               while (key_fields)
+                                                                                                                                       {
+                                                                                                                                               kffield = (GtkFormField *)key_fields->data;
+                                                                                                                                               if (g_strcmp0 (gtk_form_field_get_field_name (field),
+                                                                                                                                                              gtk_form_field_get_field_name (kffield)) != 0)
+                                                                                                                                                       {
+                                                                                                                                                               g_string_append (key_where,
+                                                                                                                                                                                gtk_form_key_get_field_sql (priv->key, kffield));
+                                                                                                                                                       }
+
+                                                                                                                                               key_fields = g_slist_next (key_fields);
+                                                                                                                                       }
+                                                                                                                       }
+
+                                                                                                               if (g_strcmp0 (key_where->str, "") != 0)
+                                                                                                                       {
+                                                                                                                               g_string_erase (key_where, 0, 5);
+                                                                                                                       }
+
+                                                                                                               g_object_get (field, "field", &field_name, key_where->str);
 
                                                                                                                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));
+                                                                                                               
+                                                                                                               g_string_free (key_where, TRUE);
                                                                                                        }
-                                                                                       
+
                                                                                                value = gtk_form_field_get_value_sql (field);
                                                                                                if (value != NULL)
                                                                                                        {
@@ -2078,8 +2113,8 @@ gchar
 
                                                                        case GTK_FORM_SQL_UPDATE:
                                                                                if (gtk_form_field_is_to_save (field)
-                                                                                       && (!IS_GTK_FORM_KEY (priv->key) ||
-                                                                                       !gtk_form_key_field_is_key (priv->key, field)))
+                                                                                       && (!IS_GTK_FORM_KEY (priv->key)
+                                                                                           || !gtk_form_key_field_is_key (priv->key, field)))
                                                                                        {
                                                                                                value = gtk_form_field_get_value_sql (field);
                                                                                                if (value != NULL)
@@ -2133,6 +2168,10 @@ gchar
                                {
                                        sql = g_strconcat (sql, where, NULL);
                                }
+                       if (where != NULL)
+                               {
+                                       g_free (where);
+                               }
                }
 
        g_string_free (fields_names, TRUE);
index bdd83320a53b6b2eea4b76cca872c659b4c042e7..a10eafb453c1e514d40c4a3aed32214b0a14f99a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2009 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2013 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
@@ -72,17 +72,14 @@ GtkFormKey
 gboolean
 gtk_form_key_add_field (GtkFormKey *gtk_form_key, GtkFormField *field)
 {
-       gboolean ret = FALSE;
-
-       GtkFormKeyPrivate *priv = GTK_FORM_KEY_GET_PRIVATE (gtk_form_key);
+       GtkFormKeyPrivate *priv;
 
        g_return_val_if_fail (IS_GTK_FORM_FIELD (field), FALSE);
 
+       priv = GTK_FORM_KEY_GET_PRIVATE (gtk_form_key);
        priv->fields = g_slist_append (priv->fields, field);
 
-       ret = TRUE;
-
-       return ret;
+       return TRUE;
 }
 
 /**
@@ -94,17 +91,14 @@ gtk_form_key_add_field (GtkFormKey *gtk_form_key, GtkFormField *field)
 gboolean
 gtk_form_key_remove_field (GtkFormKey *gtk_form_key, GtkFormField *field)
 {
-       gboolean ret = FALSE;
-
-       GtkFormKeyPrivate *priv = GTK_FORM_KEY_GET_PRIVATE (gtk_form_key);
+       GtkFormKeyPrivate *priv;
 
        g_return_val_if_fail (IS_GTK_FORM_FIELD (field), FALSE);
 
+       priv = GTK_FORM_KEY_GET_PRIVATE (gtk_form_key);
        priv->fields = g_slist_remove (priv->fields, field);
 
-       ret = TRUE;
-
-       return ret;
+       return TRUE;
 }
 
 /**
@@ -117,6 +111,8 @@ gtk_form_key_add_fields (GtkFormKey *gtk_form_key, ...)
 {
        GtkFormField *field;
 
+       g_return_val_if_fail (IS_GTK_FORM_KEY (gtk_form_key), FALSE);
+
        va_list vargs;
 
        va_start (vargs, gtk_form_key);
@@ -127,6 +123,25 @@ gtk_form_key_add_fields (GtkFormKey *gtk_form_key, ...)
                }
 
        va_end (vargs);
+
+       return TRUE;
+}
+
+/**
+ * gtk_form_key_get_fields:
+ * @gtk_form_key: a #GtkFormKey object.
+ * 
+ */
+GSList
+*gtk_form_key_get_fields (GtkFormKey *gtk_form_key)
+{
+       GtkFormKeyPrivate *priv;
+
+       g_return_val_if_fail (IS_GTK_FORM_KEY (gtk_form_key), NULL);
+
+       priv = GTK_FORM_KEY_GET_PRIVATE (gtk_form_key);
+
+       return priv->fields;
 }
 
 /**
@@ -177,6 +192,33 @@ gtk_form_key_check (GtkFormKey *gtk_form_key, GtkFormWidget **form_widget)
        return ret;
 }
 
+/**
+ * gtk_form_key_get_field_sql:
+ * @gtk_form_key:
+ * @gtk_form_field:
+ *
+ */
+gchar
+*gtk_form_key_get_field_sql (GtkFormKey *gtk_form_key, GtkFormField *gtk_form_field)
+{
+       gchar *ret;
+
+       gchar *field_name;
+
+       g_return_val_if_fail (IS_GTK_FORM_KEY (gtk_form_key), "");
+       g_return_val_if_fail (IS_GTK_FORM_FIELD (gtk_form_field), "");
+
+       g_object_get (G_OBJECT (gtk_form_field),
+                     "field", &field_name,
+                     NULL);
+
+       ret = g_strdup_printf (" AND %s = %s",
+                              field_name,
+                              gtk_form_field_get_value_sql (gtk_form_field));
+
+       return ret;
+}
+
 /**
  * gtk_form_key_get_sql:
  * @gtk_form_key: a #GtkFormKey object.
@@ -186,40 +228,34 @@ gchar
 *gtk_form_key_get_sql (GtkFormKey *gtk_form_key)
 {
        GtkFormField *field;
-       gchar *sql = "";
-       gchar *field_name;
+       GString *sql;
 
        GtkFormKeyPrivate *priv;
        GSList *fields;
 
-       g_return_val_if_fail (IS_GTK_FORM_KEY (gtk_form_key), sql);
+       g_return_val_if_fail (IS_GTK_FORM_KEY (gtk_form_key), "");
 
        priv = GTK_FORM_KEY_GET_PRIVATE (gtk_form_key);
 
        fields = priv->fields;
 
+       sql = g_string_new ("");
        while (fields != NULL)
                {
                        field = (GtkFormField *)fields->data;
 
-                       g_object_get (G_OBJECT (field),
-                                     "field", &field_name,
-                                     NULL);
-
-                       sql = g_strconcat (sql, " AND ", field_name, " = ",
-                                          gtk_form_field_get_value_sql (field), NULL);
+                       g_string_append (sql, gtk_form_key_get_field_sql (gtk_form_key, field));
 
                        fields = g_slist_next (fields);
                }
 
-       if (strcmp (sql, "") != 0)
+       if (g_strcmp0 (sql->str, "") != 0)
                {
-                       sql = g_strconcat (" WHERE ", g_strdup (sql + 5), NULL);
+                       g_string_erase (sql, 0, 5);
+                       g_string_printf (sql, " WHERE %s", sql->str);
                }
 
-       g_free (field_name);
-
-       return sql;
+       return sql->str;
 }
 
 /**
index 636b5e261961f4108f4feb0bea54eac68abe6416..d6fd775128dbafbe4e5bdd79db2210481392c099 100644 (file)
@@ -59,8 +59,11 @@ gboolean gtk_form_key_remove_field (GtkFormKey *gtk_form_key, GtkFormField *fiel
 
 gboolean gtk_form_key_add_fields (GtkFormKey *gtk_form_key, ...);
 
+GSList *gtk_form_key_get_fields (GtkFormKey *gtk_form_key);
+
 gboolean gtk_form_key_check (GtkFormKey *gtk_form_key, GtkFormWidget **form_widget);
 
+gchar *gtk_form_key_get_field_sql (GtkFormKey *gtk_form_key, GtkFormField *gtk_form_field);
 gchar *gtk_form_key_get_sql (GtkFormKey *gtk_form_key);
 
 GHashTable *gtk_form_key_get_values_as_hashtable (GtkFormKey *gtk_form_key);