From f0c09a8e30b20b066f1d6f671245dca7d2d447a6 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Thu, 3 Dec 2015 16:58:01 +0100 Subject: [PATCH] Implemented ZakFormGdaexProvider::update. --- src/form.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/form.c b/src/form.c index 899bb81..9d024af 100644 --- a/src/form.c +++ b/src/form.c @@ -323,7 +323,59 @@ zak_form_gdaex_provider_insert (ZakFormIProvider *provider, GPtrArray *elements) static gboolean zak_form_gdaex_provider_update (ZakFormIProvider *provider, GPtrArray *elements) { + gboolean ret; + + guint i; + + GdaExSqlBuilder *sqlb; + gboolean with_key; + + GdaDataModel *dm; + + ZakFormGdaexProviderPrivate *priv = ZAK_FORM_GDAEX_PROVIDER_GET_PRIVATE (provider); + + g_return_val_if_fail (IS_GDAEX (priv->gdaex), FALSE); + + ret = TRUE; + + sqlb = gdaex_sql_builder_new (GDA_SQL_STATEMENT_UPDATE); + + gdaex_sql_builder_from (sqlb, priv->table, NULL); + /* first round to make sql statement */ + with_key = FALSE; + for (i = 0; i < elements->len; i++) + { + ZakFormElement *element = (ZakFormElement *)g_ptr_array_index (elements, i); + if (zak_form_element_get_to_save (element)) + { + gdaex_sql_builder_field (sqlb, + priv->table, + zak_form_element_get_name (element), + "", + zak_form_gdaex_provider_new_gvalue_from_str_type (zak_form_element_get_provider_type (element), zak_form_element_get_value (element))); + + } + + if (zak_form_element_get_is_key (element)) + { + gdaex_sql_builder_where (sqlb, (with_key ? GDA_SQL_OPERATOR_TYPE_AND : 0), + priv->table, + zak_form_element_get_name (element), + "", + GDA_SQL_OPERATOR_TYPE_EQ, + zak_form_gdaex_provider_new_gvalue_from_str_type (zak_form_element_get_provider_type (element), zak_form_element_get_value (element)), + NULL); + with_key = TRUE; + } + } + + if (gdaex_sql_builder_execute (sqlb, priv->gdaex, NULL) <= 0) + { + ret = FALSE; + } + + return ret; } static gboolean -- 2.49.0