summaryrefslogtreecommitdiff
blob: 07077e5461d8301aa43a77db38dcd5ead675810f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
From 7d7742477ad03f19a168c763b988a7807421e9ca Mon Sep 17 00:00:00 2001
From: Vivien Malerba <malerba@gnome-db.org>
Date: Sat, 17 Sep 2011 14:26:09 +0000
Subject: Fixed nasty bug introduced in commit #036420a459b0bb241716cd9a14c3dd1eb2b21f63

which "Improved statement rewriting for NULL parameters", and in other
commits for each provider
---
diff --git a/libgda/sqlite/gda-sqlite-provider.c b/libgda/sqlite/gda-sqlite-provider.c
index afeab3c..69ccd16 100644
--- a/libgda/sqlite/gda-sqlite-provider.c
+++ b/libgda/sqlite/gda-sqlite-provider.c
@@ -2935,7 +2935,33 @@ gda_sqlite_provider_statement_execute (GdaServerProvider *provider, GdaConnectio
 			else if (!rstmt)
 				return NULL;
 			else {
+				/* The strategy here is to execute @rstmt using the prepared
+				 * statement associcted to @stmt, but adapted to @rstmt, so all
+				 * the column names, etc remain the same.
+				 *
+				 * The adaptation consists to replace SQLite specific information
+				 * in the GdaSqlitePStmt object.
+				 *
+				 * The trick is to adapt @ps, then associate @ps with @rstmt, then
+				 * execute @rstmt, and then undo the trick */
 				GObject *obj;
+				GdaSqlitePStmt *tps;
+				if (!gda_sqlite_provider_statement_prepare (provider, cnc,
+									    rstmt, error))
+					return NULL;
+				tps = (GdaSqlitePStmt *)
+					gda_connection_get_prepared_statement (cnc, rstmt);
+
+				/* adapt @ps with @tps's SQLite specific information */
+				GdaSqlitePStmt hps;
+				hps.sqlite_stmt = ps->sqlite_stmt; /* save */
+				ps->sqlite_stmt = tps->sqlite_stmt; /* override */
+				hps.stmt_used = ps->stmt_used; /* save */
+				ps->stmt_used = tps->stmt_used; /* override */
+				g_object_ref (tps);
+				gda_connection_add_prepared_statement (cnc, rstmt, (GdaPStmt *) ps);
+
+				/* execute rstmt (it will use @ps) */
 				obj = gda_sqlite_provider_statement_execute (provider, cnc,
 									     rstmt, params,
 									     model_usage,
@@ -2943,15 +2969,14 @@ gda_sqlite_provider_statement_execute (GdaServerProvider *provider, GdaConnectio
 									     last_inserted_row,
 									     task_id, async_cb,
 									     cb_data, error);
+
+				/* revert adaptations */
+				ps->sqlite_stmt = hps.sqlite_stmt;
+				ps->stmt_used = hps.stmt_used;
+				gda_connection_add_prepared_statement (cnc, rstmt, (GdaPStmt *) tps);
+				g_object_unref (tps);
 				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);
-					}
-				}
+
 				if (new_ps)
 					g_object_unref (ps);
 				pending_blobs_free_list (blobs_list);
diff --git a/providers/jdbc/gda-jdbc-provider.c b/providers/jdbc/gda-jdbc-provider.c
index 164e67f..c1192fb 100644
--- a/providers/jdbc/gda-jdbc-provider.c
+++ b/providers/jdbc/gda-jdbc-provider.c
@@ -1429,9 +1429,49 @@ gda_jdbc_provider_statement_execute (GdaServerProvider *provider, GdaConnection
 			else if (!rstmt)
 				return NULL;
 			else {
-				GObject *obj;
-				g_object_unref (ps);
 				_gda_jdbc_release_jenv (jni_detach);
+
+				/* The strategy here is to execute @rstmt using the prepared
+				 * statement associcted to @stmt, but adapted to @rstmt, so all
+				 * the column names, etc remain the same.
+				 *
+				 * The adaptation consists to replace Jdbc specific information
+				 * in the GdaJdbcPStmt object.
+				 *
+				 * The trick is to adapt @ps, then associate @ps with @rstmt, then
+				 * execute @rstmt, and then undo the trick */
+				GObject *obj;
+				GdaJdbcPStmt *tps;
+				if (!gda_jdbc_provider_statement_prepare (provider, cnc,
+									    rstmt, error)) {
+					g_object_unref (ps);
+					return NULL;
+				}
+				tps = (GdaJdbcPStmt *)
+					gda_connection_get_prepared_statement (cnc, rstmt);
+
+				/* adapt @ps with @tps's Jdbc specific information */
+				GdaJdbcPStmt hps;
+				hps.pstmt_obj = ps->pstmt_obj; /* save */
+				ps->pstmt_obj = tps->pstmt_obj; /* override */
+				g_object_ref (tps);
+				gda_connection_add_prepared_statement (cnc, rstmt, (GdaPStmt *) ps);
+
+				/* execute rstmt (it will use @ps) */
+				obj = gda_jdbc_provider_statement_execute (provider, cnc,
+									     rstmt, params,
+									     model_usage,
+									     col_types,
+									     last_inserted_row,
+									     task_id, async_cb,
+									     cb_data, error);
+
+				/* revert adaptations */
+				ps->pstmt_obj = hps.pstmt_obj;
+				gda_connection_add_prepared_statement (cnc, rstmt, (GdaPStmt *) tps);
+				g_object_unref (tps);
+				g_object_unref (rstmt);
+
 				obj = gda_jdbc_provider_statement_execute (provider, cnc,
 									   rstmt, params,
 									   model_usage,
@@ -1440,14 +1480,7 @@ gda_jdbc_provider_statement_execute (GdaServerProvider *provider, GdaConnection
 									   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);
-					}
-				}
+				g_object_unref (ps);
 				return obj;
 			}
 		}
diff --git a/providers/mysql/gda-mysql-provider.c b/providers/mysql/gda-mysql-provider.c
index d581828..8baf0a3 100644
--- a/providers/mysql/gda-mysql-provider.c
+++ b/providers/mysql/gda-mysql-provider.c
@@ -2304,8 +2304,35 @@ gda_mysql_provider_statement_execute (GdaServerProvider               *provider,
 			else if (!rstmt)
 				return NULL;
 			else {
-				GObject *obj;
 				free_bind_param_data (mem_to_free);
+
+				/* The strategy here is to execute @rstmt using the prepared
+				 * statement associcted to @stmt, but adapted to @rstmt, so all
+				 * the column names, etc remain the same.
+				 *
+				 * The adaptation consists to replace MySQL specific information
+				 * in the GdaMysqlPStmt object.
+				 *
+				 * The trick is to adapt @ps, then associate @ps with @rstmt, then
+				 * execute @rstmt, and then undo the trick */
+				GObject *obj;
+				GdaMysqlPStmt *tps;
+				if (!gda_mysql_provider_statement_prepare (provider, cnc,
+									    rstmt, error))
+					return NULL;
+				tps = (GdaMysqlPStmt *)
+					gda_connection_get_prepared_statement (cnc, rstmt);
+
+				/* adapt @ps with @tps's Mysql specific information */
+				GdaMysqlPStmt hps;
+				hps.mysql_stmt = ps->mysql_stmt; /* save */
+				ps->mysql_stmt = tps->mysql_stmt; /* override */
+				hps.stmt_used = ps->stmt_used; /* save */
+				ps->stmt_used = tps->stmt_used; /* override */
+				g_object_ref (tps);
+				gda_connection_add_prepared_statement (cnc, rstmt, (GdaPStmt *) ps);
+
+				/* execute rstmt (it will use @ps) */
 				obj = gda_mysql_provider_statement_execute (provider, cnc,
 									    rstmt, params,
 									    model_usage,
@@ -2313,15 +2340,13 @@ gda_mysql_provider_statement_execute (GdaServerProvider               *provider,
 									    last_inserted_row,
 									    task_id, async_cb,
 									    cb_data, error);
+
+				/* revert adaptations */
+				ps->mysql_stmt = hps.mysql_stmt;
+				ps->stmt_used = hps.stmt_used;
+				gda_connection_add_prepared_statement (cnc, rstmt, (GdaPStmt *) tps);
+				g_object_unref (tps);
 				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;
 			}
 		}
diff --git a/providers/oracle/gda-oracle-provider.c b/providers/oracle/gda-oracle-provider.c
index 1d40105..9d0f485 100644
--- a/providers/oracle/gda-oracle-provider.c
+++ b/providers/oracle/gda-oracle-provider.c
@@ -1931,8 +1931,35 @@ gda_oracle_provider_statement_execute (GdaServerProvider *provider, GdaConnectio
 			else if (!rstmt)
 				return NULL;
 			else {
+				/* The strategy here is to execute @rstmt using the prepared
+				 * statement associcted to @stmt, but adapted to @rstmt, so all
+				 * the column names, etc remain the same.
+				 *
+				 * The adaptation consists to replace Oracle specific information
+				 * in the GdaOraclePStmt object.
+				 *
+				 * The trick is to adapt @ps, then associate @ps with @rstmt, then
+				 * execute @rstmt, and then undo the trick */
 				GObject *obj;
-				g_object_unref (ps);
+				GdaOraclePStmt *tps;
+				if (!gda_oracle_provider_statement_prepare (provider, cnc,
+									    rstmt, error)) {
+					g_object_unref (ps);
+					return NULL;
+				}
+				tps = (GdaOraclePStmt *)
+					gda_connection_get_prepared_statement (cnc, rstmt);
+
+				/* adapt @ps with @tps's Oracle specific information */
+				GdaOraclePStmt hps;
+				hps.hstmt = ps->hstmt; /* save */
+				ps->hstmt = tps->hstmt; /* override */
+				hps.ora_values = ps->ora_values; /* save */
+				ps->ora_values = tps->ora_values; /* override */
+				g_object_ref (tps);
+				gda_connection_add_prepared_statement (cnc, rstmt, (GdaPStmt *) ps);
+
+				/* execute rstmt (it will use @ps) */
 				obj = gda_oracle_provider_statement_execute (provider, cnc,
 									     rstmt, params,
 									     model_usage,
@@ -1940,15 +1967,14 @@ gda_oracle_provider_statement_execute (GdaServerProvider *provider, GdaConnectio
 									     last_inserted_row,
 									     task_id, async_cb,
 									     cb_data, error);
+				
+				/* revert adaptations */
+				ps->hstmt = hps.hstmt;
+				ps->ora_values = hps.ora_values;
+				gda_connection_add_prepared_statement (cnc, rstmt, (GdaPStmt *) tps);
+				g_object_unref (tps);
 				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);
-					}
-				}
+				g_object_unref (ps);
 				return obj;
 			}
 		}
diff --git a/providers/postgres/gda-postgres-provider.c b/providers/postgres/gda-postgres-provider.c
index 6adca14..85db58e 100644
--- a/providers/postgres/gda-postgres-provider.c
+++ b/providers/postgres/gda-postgres-provider.c
@@ -2017,13 +2017,39 @@ gda_postgres_provider_statement_execute (GdaServerProvider *provider, GdaConnect
 			else if (!rstmt)
 				return NULL;
 			else {
-				GObject *obj;
 				params_freev (param_values, param_mem, nb_params);
 				g_free (param_lengths);
 				g_free (param_formats);
 				if (transaction_started)
 					gda_connection_rollback_transaction (cnc, NULL, NULL);
 
+				/* The strategy here is to execute @rstmt using the prepared
+				 * statement associcted to @stmt, but adapted to @rstmt, so all
+				 * the column names, etc remain the same.
+				 *
+				 * The adaptation consists to replace Postgresql specific information
+				 * in the GdaPostgresPStmt object.
+				 *
+				 * The trick is to adapt @ps, then associate @ps with @rstmt, then
+				 * execute @rstmt, and then undo the trick */
+				GObject *obj;
+				GdaPostgresPStmt *tps;
+				if (!gda_postgres_provider_statement_prepare (provider, cnc,
+									      rstmt, error))
+					return NULL;
+				tps = (GdaPostgresPStmt *)
+					gda_connection_get_prepared_statement (cnc, rstmt);
+
+				/* adapt @ps with @tps's SQLite specific information */
+				GdaPostgresPStmt hps;
+				hps.pconn = ps->pconn; /* save */
+				ps->pconn = tps->pconn; /* override */
+				hps.prep_name = ps->prep_name; /* save */
+				ps->prep_name = tps->prep_name; /* override */
+				g_object_ref (tps);
+				gda_connection_add_prepared_statement (cnc, rstmt, (GdaPStmt *) ps);
+
+				/* execute rstmt (it will use @ps) */
 				obj = gda_postgres_provider_statement_execute (provider, cnc,
 									       rstmt, params,
 									       model_usage,
@@ -2031,15 +2057,13 @@ gda_postgres_provider_statement_execute (GdaServerProvider *provider, GdaConnect
 									       last_inserted_row,
 									       task_id, async_cb,
 									       cb_data, error);
+
+				/* revert adaptations */
+				ps->pconn = hps.pconn;
+				ps->prep_name = hps.prep_name;
+				gda_connection_add_prepared_statement (cnc, rstmt, (GdaPStmt *) tps);
+				g_object_unref (tps);
 				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;
 			}
 		}
diff --git a/providers/skel-implementation/capi/gda-capi-provider.c b/providers/skel-implementation/capi/gda-capi-provider.c
index 653f9ea..764d027 100644
--- a/providers/skel-implementation/capi/gda-capi-provider.c
+++ b/providers/skel-implementation/capi/gda-capi-provider.c
@@ -1181,7 +1181,31 @@ gda_capi_provider_statement_execute (GdaServerProvider *provider, GdaConnection
 			else if (!rstmt)
 				return NULL;
 			else {
+				/* The strategy here is to execute @rstmt using the prepared
+				 * statement associcted to @stmt, but adapted to @rstmt, so all
+				 * the column names, etc remain the same.
+				 *
+				 * The adaptation consists to replace Capi specific information
+				 * in the GdaCapiPStmt object.
+				 *
+				 * The trick is to adapt @ps, then associate @ps with @rstmt, then
+				 * execute @rstmt, and then undo the trick */
 				GObject *obj;
+				GdaCapiPStmt *tps;
+				if (!gda_capi_provider_statement_prepare (provider, cnc,
+									    rstmt, error))
+					return NULL;
+				tps = (GdaCapiPStmt *)
+					gda_connection_get_prepared_statement (cnc, rstmt);
+
+				/* adapt @ps with @tps's Capi specific information */
+				GdaCapiPStmt hps;
+				/* TO ADD: hps.capi_stmt = ps->capi_stmt;*/ /* save */
+				/* TO_ADD: ps->capi_stmt = tps->capi_stmt;*/ /* override */
+				g_object_ref (tps);
+				gda_connection_add_prepared_statement (cnc, rstmt, (GdaPStmt *) ps);
+
+				/* execute rstmt (it will use @ps) */
 				obj = gda_capi_provider_statement_execute (provider, cnc,
 									   rstmt, params,
 									   model_usage,
@@ -1189,15 +1213,13 @@ gda_capi_provider_statement_execute (GdaServerProvider *provider, GdaConnection
 									   last_inserted_row,
 									   task_id, async_cb,
 									   cb_data, error);
+
+				/* revert adaptations */
+				/* TO_ADD: ps->capi_stmt = hps.capi_stmt; */
+
+				gda_connection_add_prepared_statement (cnc, rstmt, (GdaPStmt *) tps);
+				g_object_unref (tps);
 				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;
 			}
 		}
diff --git a/providers/web/gda-web-provider.c b/providers/web/gda-web-provider.c
index 4500f01..9061126 100644
--- a/providers/web/gda-web-provider.c
+++ b/providers/web/gda-web-provider.c
@@ -1572,25 +1572,49 @@ gda_web_provider_statement_execute (GdaServerProvider *provider, GdaConnection *
 			else if (!rstmt)
 				return NULL;
 			else {
-				GObject *obj;
-				g_object_unref (ps);
 				xmlFreeDoc (doc);
+
+				/* The strategy here is to execute @rstmt using the prepared
+				 * statement associcted to @stmt, but adapted to @rstmt, so all
+				 * the column names, etc remain the same.
+				 *
+				 * The adaptation consists to replace Web specific information
+				 * in the GdaWebPStmt object.
+				 *
+				 * The trick is to adapt @ps, then associate @ps with @rstmt, then
+				 * execute @rstmt, and then undo the trick */
+				GObject *obj;
+				GdaWebPStmt *tps;
+				if (!gda_web_provider_statement_prepare (provider, cnc,
+									 rstmt, error)) {
+					g_object_unref (ps);
+					return NULL;
+				}
+				tps = (GdaWebPStmt *)
+					gda_connection_get_prepared_statement (cnc, rstmt);
+
+				/* adapt @ps with @tps's Web specific information */
+				GdaWebPStmt hps;
+				hps.pstmt_hash = ps->pstmt_hash; /* save */
+				ps->pstmt_hash = tps->pstmt_hash; /* override */
+				g_object_ref (tps);
+				gda_connection_add_prepared_statement (cnc, rstmt, (GdaPStmt *) ps);
+
+				/* execute rstmt (it will use @ps) */
 				obj = gda_web_provider_statement_execute (provider, cnc,
-									  rstmt, params,
-									  model_usage,
-									  col_types,
-									  last_inserted_row,
-									  task_id, async_cb,
-									  cb_data, error);
+									     rstmt, params,
+									     model_usage,
+									     col_types,
+									     last_inserted_row,
+									     task_id, async_cb,
+									     cb_data, error);
+
+				/* revert adaptations */
+				ps->pstmt_hash = hps.pstmt_hash;
+				gda_connection_add_prepared_statement (cnc, rstmt, (GdaPStmt *) tps);
+				g_object_unref (tps);
 				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);
-					}
-				}
+				g_object_unref (ps);
 				return obj;
 			}
 		}
--
cgit v0.9.0.2