<!ELEMENT column-field (#PCDATA)>
-<!ELEMENT field (obligatory?, default?, is-key?, type?, display-format?)>
+<!ELEMENT field (no-save?, obligatory?, default?, is-key?, type?, display-format?)>
<!ATTLIST field
type (boolean | datetime | float | integer | text) #REQUIRED
name CDATA #REQUIRED
>
+<!ELEMENT to-save (y | n)>
<!ELEMENT obligatory (#PCDATA)>
<!ELEMENT default (#PCDATA)>
<!ELEMENT is-key (#PCDATA)>
{
PROP_0,
PROP_FIELD,
+ PROP_TO_SAVE,
PROP_OBLIGATORY,
PROP_DATAMODEL,
PROP_WIDGET
{
gchar *field;
gboolean is_key;
+ gboolean to_save;
gboolean obligatory;
GdaDataModel *dm;
"",
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class, PROP_TO_SAVE,
+ g_param_spec_boolean ("to-save",
+ "Whether save the field or not",
+ "Whether the field should be included or not on sql INSERT INTO and UPDATE",
+ TRUE,
+ G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
+
g_object_class_install_property (object_class, PROP_OBLIGATORY,
g_param_spec_boolean ("obligatory",
"Obligatory",
return ret;
}
+/**
+ * gtk_form_field_is_to_save:
+ * @field: a #GtkFormField object.
+ *
+ */
+gboolean
+gtk_form_field_is_to_save (GtkFormField *field)
+{
+ GtkFormFieldPrivate *priv;
+
+ g_return_val_if_fail (IS_GTK_FORM_FIELD (field), FALSE);
+
+ priv = GTK_FORM_FIELD_GET_PRIVATE (field);
+
+ return priv->to_save;
+}
+
/**
* gtk_form_field_is_empty:
* @field: a #GtkFormField object.
priv->field = g_strstrip (g_value_dup_string (value));
break;
+ case PROP_TO_SAVE:
+ priv->to_save = g_value_get_boolean (value);
+ break;
+
case PROP_OBLIGATORY:
priv->obligatory = g_value_get_boolean (value);
break;
g_value_set_string (value, gtk_form_field_get_field_name (field));
break;
+ case PROP_TO_SAVE:
+ g_value_set_boolean (value, priv->to_save);
+ break;
+
case PROP_OBLIGATORY:
g_value_set_boolean (value, priv->obligatory);
break;
while (node_field != NULL)
{
prop = (gchar *)xmlNodeGetContent (node_field);
- if (xmlStrcmp (node_field->name, (const xmlChar *)"obligatory") == 0)
+ if (xmlStrcmp (node_field->name, (const xmlChar *)"to-save") == 0)
+ {
+ g_object_set (G_OBJECT (field),
+ "to-save", gtk_form_field_boolean_str_to_boolean (prop),
+ NULL);
+ }
+ else if (xmlStrcmp (node_field->name, (const xmlChar *)"obligatory") == 0)
{
g_object_set (G_OBJECT (field),
"obligatory", gtk_form_field_boolean_str_to_boolean (prop),
GtkWidget *widget;
gboolean ret = TRUE;
- gboolean obl = FALSE;
+ gboolean to_save;
+ gboolean obl;
g_return_val_if_fail (IS_GTK_FORM (form), FALSE);
field = (GtkFormField *)fields->data;
g_object_get (G_OBJECT (field),
+ "to-save", &to_save,
"obligatory", &obl,
NULL);
- if (obl && gtk_form_field_is_empty (field))
+ if (to_save && obl && gtk_form_field_is_empty (field))
{
ret = FALSE;
field_name = gtk_form_field_get_field_name (field);
- if (field_name != NULL && g_strcmp0 (field_name, "") != 0)
+ if (field_name != NULL && g_strcmp0 (field_name, "") != 0
+ && g_strstr_len (fields_names, -1, field_name) == NULL)
{
switch (type)
{
break;
case GTK_FORM_SQL_INSERT:
- value = gtk_form_field_get_value_sql (field);
- if (value != NULL)
+ 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 (!IS_GTK_FORM_KEY (priv->key) ||
- !gtk_form_key_field_is_key (priv->key, field))
+ 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;
}
- if (IS_GTK_FORM_KEY (priv->key))
+ if (IS_GTK_FORM_KEY (priv->key)
+ && (type == GTK_FORM_SQL_SELECT || type == GTK_FORM_SQL_UPDATE || type == GTK_FORM_SQL_DELETE))
{
where = gtk_form_key_get_sql (priv->key);
- if ((type == GTK_FORM_SQL_SELECT || type == GTK_FORM_SQL_UPDATE || type == GTK_FORM_SQL_DELETE)
- && where != NULL && g_strcmp0 (where, "") != 0)
+ if (where != NULL && g_strcmp0 (where, "") != 0)
{
sql = g_strconcat (sql, where, NULL);
}