[libgda] Skel provider implementation: added statement rewriting for NULL parameters



commit 68dfa1c73aea68f4260ceb6f9e4d7bc85b2cc976
Author: Vivien Malerba <malerba gnome-db org>
Date:   Fri Aug 19 17:11:13 2011 +0200

    Skel provider implementation: added statement rewriting for NULL parameters

 .../skel-implementation/capi/gda-capi-provider.c   |   62 +++++++++++++++-----
 1 files changed, 46 insertions(+), 16 deletions(-)
---
diff --git a/providers/skel-implementation/capi/gda-capi-provider.c b/providers/skel-implementation/capi/gda-capi-provider.c
index c5f3e30..653f9ea 100644
--- a/providers/skel-implementation/capi/gda-capi-provider.c
+++ b/providers/skel-implementation/capi/gda-capi-provider.c
@@ -1101,7 +1101,13 @@ gda_capi_provider_statement_execute (GdaServerProvider *provider, GdaConnection
 			}
 		}
 		if (!h) {
-			if (! allow_noparam) {
+			if (allow_noparam) {
+                                /* bind param to NULL */
+                                TO_IMPLEMENT;
+                                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);
@@ -1110,17 +1116,17 @@ gda_capi_provider_statement_execute (GdaServerProvider *provider, GdaConnection
 					     GDA_SERVER_PROVIDER_MISSING_PARAM_ERROR, "%s", str);
 				g_free (str);
 				break;
-			}
-			else {
-                                /* bind param to NULL */
-                                TO_IMPLEMENT;
-                                empty_rs = TRUE;
-                                continue;
                         }
 
 		}
 		if (!gda_holder_is_valid (h)) {
-			if (! allow_noparam) {
+			if (allow_noparam) {
+                                /* bind param to NULL */
+				TO_IMPLEMENT;
+                                empty_rs = TRUE;
+                                continue;
+			}
+			else {
 				gchar *str;
 				str = g_strdup_printf (_("Parameter '%s' is invalid"), pname);
 				event = gda_connection_point_available_event (cnc, GDA_CONNECTION_EVENT_ERROR);
@@ -1129,12 +1135,6 @@ gda_capi_provider_statement_execute (GdaServerProvider *provider, GdaConnection
 					     GDA_SERVER_PROVIDER_MISSING_PARAM_ERROR, "%s", str);
 				g_free (str);
 				break;
-			}
-			else {
-                                /* bind param to NULL */
-				TO_IMPLEMENT;
-                                empty_rs = TRUE;
-                                continue;
                         }
 		}
 		else if (gda_holder_value_is_default (h) && !gda_holder_get_value (h)) {
@@ -1172,8 +1172,38 @@ gda_capi_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); */
-		TO_IMPLEMENT;
+		const GValue *value = gda_holder_get_value (h);
+		if (!value || gda_value_is_null (value)) {
+			GdaStatement *rstmt;
+			if (! gda_rewrite_statement_for_null_parameters (stmt, params, &rstmt, error)) {
+				TO_IMPLEMENT; /* bind to NULL */
+			}
+			else if (!rstmt)
+				return NULL;
+			else {
+				GObject *obj;
+				obj = gda_capi_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 {
+			TO_IMPLEMENT;
+		}
 	}
 		
 	if (event) {



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