[libgda] Web provider: added statement rewriting for NULL parameters



commit c5e3bdac67ebef0dc0cc12e9743da692c5afc73d
Author: Vivien Malerba <malerba gnome-db org>
Date:   Fri Aug 19 17:10:53 2011 +0200

    Web provider: added statement rewriting for NULL parameters

 providers/web/gda-web-provider.c |   79 ++++++++++++++++++++++++++++----------
 1 files changed, 58 insertions(+), 21 deletions(-)
---
diff --git a/providers/web/gda-web-provider.c b/providers/web/gda-web-provider.c
index bf7fd8d..4500f01 100644
--- a/providers/web/gda-web-provider.c
+++ b/providers/web/gda-web-provider.c
@@ -1485,7 +1485,15 @@ gda_web_provider_statement_execute (GdaServerProvider *provider, GdaConnection *
 			}
 		}
 		if (!h) {
-			if (! allow_noparam) {
+			if (allow_noparam) {
+                                /* bind param to NULL */
+				node = xmlNewChild (argsnode, NULL, BAD_CAST "arg", NULL);
+				xmlSetProp (node, BAD_CAST "type", BAD_CAST "NULL");
+                                empty_rs = TRUE;
+                                continue;
+			}
+			else {
+
 				gchar *str;
 				str = g_strdup_printf (_("Missing parameter '%s' to execute query"), pname);
 				event = gda_connection_point_available_event (cnc, GDA_CONNECTION_EVENT_ERROR);
@@ -1494,18 +1502,16 @@ gda_web_provider_statement_execute (GdaServerProvider *provider, GdaConnection *
 					     GDA_SERVER_PROVIDER_MISSING_PARAM_ERROR, "%s", str);
 				g_free (str);
 				break;
-			}
-			else {
+                        }
+		}
+		if (!gda_holder_is_valid (h)) {
+			if (allow_noparam) {
                                 /* bind param to NULL */
-				node = xmlNewChild (argsnode, NULL, BAD_CAST "arg", NULL);
 				xmlSetProp (node, BAD_CAST "type", BAD_CAST "NULL");
                                 empty_rs = TRUE;
                                 continue;
-                        }
-
-		}
-		if (!gda_holder_is_valid (h)) {
-			if (! allow_noparam) {
+			}
+			else {
 				gchar *str;
 				str = g_strdup_printf (_("Parameter '%s' is invalid"), pname);
 				event = gda_connection_point_available_event (cnc, GDA_CONNECTION_EVENT_ERROR);
@@ -1514,12 +1520,6 @@ gda_web_provider_statement_execute (GdaServerProvider *provider, GdaConnection *
 					     GDA_SERVER_PROVIDER_MISSING_PARAM_ERROR, "%s", str);
 				g_free (str);
 				break;
-			}
-			else {
-                                /* bind param to NULL */
-				xmlSetProp (node, BAD_CAST "type", BAD_CAST "NULL");
-                                empty_rs = TRUE;
-                                continue;
                         }
 		}
 		else if (gda_holder_value_is_default (h) && !gda_holder_get_value (h)) {
@@ -1559,12 +1559,49 @@ gda_web_provider_statement_execute (GdaServerProvider *provider, GdaConnection *
 
 		/* actual binding using the C API, for parameter at position @i */
 		const GValue *value = gda_holder_get_value (h);
-		gchar *tmp;
-		tmp = gda_value_stringify (value);
-		node = xmlNewTextChild (argsnode, NULL, BAD_CAST "arg", BAD_CAST tmp);
-		g_free (tmp);
-		xmlSetProp (node, BAD_CAST "type",
-			    BAD_CAST gtype_to_webtype (gda_holder_get_g_type (h)));
+		if (!value || gda_value_is_null (value)) {
+			GdaStatement *rstmt;
+			if (! gda_rewrite_statement_for_null_parameters (stmt, params, &rstmt, error)) {
+				gchar *tmp;
+				tmp = gda_value_stringify (value);
+				node = xmlNewTextChild (argsnode, NULL, BAD_CAST "arg", BAD_CAST tmp);
+				g_free (tmp);
+				xmlSetProp (node, BAD_CAST "type",
+					    BAD_CAST gtype_to_webtype (gda_holder_get_g_type (h)));
+			}
+			else if (!rstmt)
+				return NULL;
+			else {
+				GObject *obj;
+				g_object_unref (ps);
+				xmlFreeDoc (doc);
+				obj = gda_web_provider_statement_execute (provider, cnc,
+									  rstmt, params,
+									  model_usage,
+									  col_types,
+									  last_inserted_row,
+									  task_id, async_cb,
+									  cb_data, error);
+				g_object_unref (rstmt);
+				if (GDA_IS_DATA_SELECT (obj)) {
+					GdaPStmt *pstmt;
+					g_object_get (obj, "prepared-stmt", &pstmt, NULL);
+					if (pstmt) {
+						gda_pstmt_set_gda_statement (pstmt, stmt);
+						g_object_unref (pstmt);
+					}
+				}
+				return obj;
+			}
+		}
+		else {
+			gchar *tmp;
+			tmp = gda_value_stringify (value);
+			node = xmlNewTextChild (argsnode, NULL, BAD_CAST "arg", BAD_CAST tmp);
+			g_free (tmp);
+			xmlSetProp (node, BAD_CAST "type",
+				    BAD_CAST gtype_to_webtype (gda_holder_get_g_type (h)));
+		}
 	}
 		
 	if (event) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]