]> saetta.ns0.it Git - libgtkform/commitdiff
Added property GtkForm::quote.
authorAndrea Zagli <azagli@libero.it>
Wed, 9 Sep 2009 11:42:00 +0000 (13:42 +0200)
committerAndrea Zagli <azagli@libero.it>
Wed, 9 Sep 2009 11:42:00 +0000 (13:42 +0200)
src/form.c

index 7e55067fdb8c9ea2da019e616d943a64be6a0006..3557b62b0d59ede4f77e491acb3557ac51b1c520 100644 (file)
@@ -47,7 +47,8 @@ enum
 {
        PROP_0,
        PROP_TABLE,
-       PROP_KEY
+       PROP_KEY,
+       PROP_QUOTE
 };
 
 static void gtk_form_class_init (GtkFormClass *class);
@@ -75,6 +76,7 @@ struct _GtkFormPrivate
                gchar *table;
                GSList *fields;
                GtkFormKey *key;
+               gchar quote;
        };
 
 G_DEFINE_TYPE (GtkForm, gtk_form, G_TYPE_OBJECT)
@@ -92,7 +94,7 @@ gtk_form_class_init (GtkFormClass *class)
                                                              "Table name",
                                                              "GtkForm's table name",
                                                              "",
-                                                             G_PARAM_READWRITE));
+                                                             G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
 
        g_object_class_install_property (object_class, PROP_KEY,
                                         g_param_spec_object ("key",
@@ -101,6 +103,13 @@ gtk_form_class_init (GtkFormClass *class)
                                                              TYPE_GTK_FORM_KEY,
                                                              G_PARAM_READWRITE));
 
+       g_object_class_install_property (object_class, PROP_QUOTE,
+                                        g_param_spec_char ("quote",
+                                                           "Quoting character",
+                                                           "Character to use to quote fields name",
+                                                           G_MININT8, G_MAXINT8, '"',
+                                                           G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
+
        g_type_class_add_private (object_class, sizeof (GtkFormPrivate));
 }
 
@@ -109,7 +118,6 @@ gtk_form_init (GtkForm *form)
 {
        GtkFormPrivate *priv = GTK_FORM_GET_PRIVATE (form);
 
-       priv->table = g_strdup ("");
        priv->fields = NULL;
        priv->key = NULL;
 }
@@ -1126,39 +1134,42 @@ gchar
 
                        field_name = gtk_form_field_get_field_name (field);
 
-                       if (field_name != NULL && g_strcmp0 (field_name, "") != 0
-                           && g_strstr_len (fields_names, -1, field_name) == NULL)
+                       if (field_name != NULL && g_strcmp0 (field_name, "") != 0)
                                {
-                                       switch (type)
+                                       field_name = g_strconcat (&priv->quote, field_name, &priv->quote, NULL);
+                                       if (g_strstr_len (fields_names, -1, field_name) == NULL)
                                                {
-                                                       case GTK_FORM_SQL_SELECT:
-                                                               fields_names = g_strconcat (fields_names, field_name, ", ", NULL);
-                                                               break;
-
-                                                       case GTK_FORM_SQL_INSERT:
-                                                               if (gtk_form_field_is_to_save (field))
-                                                                       {
-                                                                               value = gtk_form_field_get_value_sql (field);
-                                                                               if (value != NULL)
+                                                       switch (type)
+                                                               {
+                                                                       case GTK_FORM_SQL_SELECT:
+                                                                               fields_names = g_strconcat (fields_names, field_name, ", ", NULL);
+                                                                               break;
+
+                                                                       case GTK_FORM_SQL_INSERT:
+                                                                               if (gtk_form_field_is_to_save (field))
                                                                                        {
-                                                                                               fields_names = g_strconcat (fields_names, field_name, ", ", NULL);
-                                                                                               values = g_strconcat (values, value, ", ", NULL);
+                                                                                               value = gtk_form_field_get_value_sql (field);
+                                                                                               if (value != NULL)
+                                                                                                       {
+                                                                                                               fields_names = g_strconcat (fields_names, field_name, ", ", NULL);
+                                                                                                               values = g_strconcat (values, value, ", ", NULL);
+                                                                                                       }
                                                                                        }
-                                                                       }
-                                                               break;
-
-                                                       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)))
-                                                                       {
-                                                                               value = gtk_form_field_get_value_sql (field);
-                                                                               if (value != NULL)
+                                                                               break;
+
+                                                                       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)))
                                                                                        {
-                                                                                               fields_names = g_strconcat (fields_names, field_name, " = ", value, ", ", NULL);
+                                                                                               value = gtk_form_field_get_value_sql (field);
+                                                                                               if (value != NULL)
+                                                                                                       {
+                                                                                                               fields_names = g_strconcat (fields_names, field_name, " = ", value, ", ", NULL);
+                                                                                                       }
                                                                                        }
-                                                                       }
-                                                               break;
+                                                                               break;
+                                                               }
                                                }
                                }
 
@@ -1261,6 +1272,10 @@ gtk_form_set_property (GObject *object,
                                gtk_form_set_key (form, GTK_FORM_KEY (g_value_get_object (value)));
                                break;
 
+                       case PROP_QUOTE:
+                               priv->quote = g_value_get_char (value);
+                               break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
@@ -1287,6 +1302,10 @@ gtk_form_get_property (GObject *object,
                                g_value_set_object (value, gtk_form_get_key (form));
                                break;
 
+                       case PROP_QUOTE:
+                               g_value_set_char (value, priv->quote);
+                               break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;