1 /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.84 2009/05/20 16:49:23 meskes Exp $ */
4 * The aim is to get a simpler inteface to the database routines.
5 * All the tidieous messing around with tuples is supposed to be hidden
9 (actually most if the code is "borrowed" from the distribution and just
13 /* Taken over as part of PostgreSQL by Michael Meskes <meskes@postgresql.org>
16 #define POSTGRES_ECPG_INTERNAL
17 #include "postgres_fe.h"
25 #include "ecpgerrno.h"
28 #include "sql3types.h"
29 #include "pgtypes_numeric.h"
30 #include "pgtypes_date.h"
31 #include "pgtypes_timestamp.h"
32 #include "pgtypes_interval.h"
35 * This function returns a newly malloced string that has ' and \
39 quote_postgres(char *arg, bool quote, int lineno)
47 * if quote is false we just need to store things in a descriptor they
48 * will be quoted once they are inserted in a statement
55 buffer_len = 2 * length + 1;
56 res = (char *) ecpg_alloc(buffer_len + 3, lineno);
59 escaped_len = PQescapeString(res + 1, arg, buffer_len);
60 if (length == escaped_len)
62 res[0] = res[escaped_len + 1] = '\'';
63 res[escaped_len + 2] = '\0';
68 * We don't know if the target database is using
69 * standard_conforming_strings, so we always use E'' strings.
71 memmove(res + 2, res + 1, escaped_len);
72 res[0] = ESCAPE_STRING_SYNTAX;
73 res[1] = res[escaped_len + 2] = '\'';
74 res[escaped_len + 3] = '\0';
82 free_variable(struct variable * var)
84 struct variable *var_next;
100 free_statement(struct statement * stmt)
104 free_variable(stmt->inlist);
105 free_variable(stmt->outlist);
106 ecpg_free(stmt->command);
107 ecpg_free(stmt->name);
112 next_insert(char *text, int pos, bool questionmarks)
117 for (; text[p] != '\0'; p++)
119 if (text[p] == '\\') /* escape character */
121 else if (text[p] == '\'')
122 string = string ? false : true;
125 if (text[p] == '$' && isdigit((unsigned char) text[p + 1]))
127 /* this can be either a dollar quote or a variable */
130 for (i = p + 1; isdigit((unsigned char) text[i]); i++)
131 /* empty loop body */ ;
132 if (!isalpha((unsigned char) text[i]) &&
133 isascii((unsigned char) text[i]) && text[i] != '_')
134 /* not dollar delimited quote */
137 else if (questionmarks && text[p] == '?')
139 /* also allow old style placeholders */
149 ecpg_type_infocache_push(struct ECPGtype_information_cache ** cache, int oid, bool isarray, int lineno)
151 struct ECPGtype_information_cache *new_entry
152 = (struct ECPGtype_information_cache *) ecpg_alloc(sizeof(struct ECPGtype_information_cache), lineno);
154 if (new_entry == NULL)
157 new_entry->oid = oid;
158 new_entry->isarray = isarray;
159 new_entry->next = *cache;
164 static enum ARRAY_TYPE
165 ecpg_is_type_an_array(int type, const struct statement * stmt, const struct variable * var)
168 enum ARRAY_TYPE isarray = ECPG_ARRAY_NOT_SET;
170 struct ECPGtype_information_cache *cache_entry;
172 if ((stmt->connection->cache_head) == NULL)
175 * Text like types are not an array for ecpg, but postgres counts them
176 * as an array. This define reminds you to not 'correct' these values.
178 #define not_an_array_in_ecpg ECPG_ARRAY_NONE
180 /* populate cache with well known types to speed things up */
181 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), BOOLOID, ECPG_ARRAY_NONE, stmt->lineno))
182 return (ECPG_ARRAY_ERROR);
183 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), BYTEAOID, ECPG_ARRAY_NONE, stmt->lineno))
184 return (ECPG_ARRAY_ERROR);
185 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), CHAROID, ECPG_ARRAY_NONE, stmt->lineno))
186 return (ECPG_ARRAY_ERROR);
187 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), NAMEOID, not_an_array_in_ecpg, stmt->lineno))
188 return (ECPG_ARRAY_ERROR);
189 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), INT8OID, ECPG_ARRAY_NONE, stmt->lineno))
190 return (ECPG_ARRAY_ERROR);
191 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), INT2OID, ECPG_ARRAY_NONE, stmt->lineno))
192 return (ECPG_ARRAY_ERROR);
193 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), INT2VECTOROID, ECPG_ARRAY_VECTOR, stmt->lineno))
194 return (ECPG_ARRAY_ERROR);
195 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), INT4OID, ECPG_ARRAY_NONE, stmt->lineno))
196 return (ECPG_ARRAY_ERROR);
197 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), REGPROCOID, ECPG_ARRAY_NONE, stmt->lineno))
198 return (ECPG_ARRAY_ERROR);
199 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), TEXTOID, ECPG_ARRAY_NONE, stmt->lineno))
200 return (ECPG_ARRAY_ERROR);
201 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), OIDOID, ECPG_ARRAY_NONE, stmt->lineno))
202 return (ECPG_ARRAY_ERROR);
203 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), TIDOID, ECPG_ARRAY_NONE, stmt->lineno))
204 return (ECPG_ARRAY_ERROR);
205 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), XIDOID, ECPG_ARRAY_NONE, stmt->lineno))
206 return (ECPG_ARRAY_ERROR);
207 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), CIDOID, ECPG_ARRAY_NONE, stmt->lineno))
208 return (ECPG_ARRAY_ERROR);
209 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), OIDVECTOROID, ECPG_ARRAY_VECTOR, stmt->lineno))
210 return (ECPG_ARRAY_ERROR);
211 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), POINTOID, ECPG_ARRAY_VECTOR, stmt->lineno))
212 return (ECPG_ARRAY_ERROR);
213 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), LSEGOID, ECPG_ARRAY_VECTOR, stmt->lineno))
214 return (ECPG_ARRAY_ERROR);
215 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), PATHOID, ECPG_ARRAY_NONE, stmt->lineno))
216 return (ECPG_ARRAY_ERROR);
217 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), BOXOID, ECPG_ARRAY_VECTOR, stmt->lineno))
218 return (ECPG_ARRAY_ERROR);
219 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), POLYGONOID, ECPG_ARRAY_NONE, stmt->lineno))
220 return (ECPG_ARRAY_ERROR);
221 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), LINEOID, ECPG_ARRAY_VECTOR, stmt->lineno))
222 return (ECPG_ARRAY_ERROR);
223 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), FLOAT4OID, ECPG_ARRAY_NONE, stmt->lineno))
224 return (ECPG_ARRAY_ERROR);
225 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), FLOAT8OID, ECPG_ARRAY_NONE, stmt->lineno))
226 return (ECPG_ARRAY_ERROR);
227 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), ABSTIMEOID, ECPG_ARRAY_NONE, stmt->lineno))
228 return (ECPG_ARRAY_ERROR);
229 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), RELTIMEOID, ECPG_ARRAY_NONE, stmt->lineno))
230 return (ECPG_ARRAY_ERROR);
231 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), TINTERVALOID, ECPG_ARRAY_NONE, stmt->lineno))
232 return (ECPG_ARRAY_ERROR);
233 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), UNKNOWNOID, ECPG_ARRAY_NONE, stmt->lineno))
234 return (ECPG_ARRAY_ERROR);
235 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), CIRCLEOID, ECPG_ARRAY_NONE, stmt->lineno))
236 return (ECPG_ARRAY_ERROR);
237 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), CASHOID, ECPG_ARRAY_NONE, stmt->lineno))
238 return (ECPG_ARRAY_ERROR);
239 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), INETOID, ECPG_ARRAY_NONE, stmt->lineno))
240 return (ECPG_ARRAY_ERROR);
241 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), CIDROID, ECPG_ARRAY_NONE, stmt->lineno))
242 return (ECPG_ARRAY_ERROR);
243 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), BPCHAROID, ECPG_ARRAY_NONE, stmt->lineno))
244 return (ECPG_ARRAY_ERROR);
245 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), VARCHAROID, ECPG_ARRAY_NONE, stmt->lineno))
246 return (ECPG_ARRAY_ERROR);
247 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), DATEOID, ECPG_ARRAY_NONE, stmt->lineno))
248 return (ECPG_ARRAY_ERROR);
249 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), TIMEOID, ECPG_ARRAY_NONE, stmt->lineno))
250 return (ECPG_ARRAY_ERROR);
251 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), TIMESTAMPOID, ECPG_ARRAY_NONE, stmt->lineno))
252 return (ECPG_ARRAY_ERROR);
253 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), TIMESTAMPTZOID, ECPG_ARRAY_NONE, stmt->lineno))
254 return (ECPG_ARRAY_ERROR);
255 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), INTERVALOID, ECPG_ARRAY_NONE, stmt->lineno))
256 return (ECPG_ARRAY_ERROR);
257 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), TIMETZOID, ECPG_ARRAY_NONE, stmt->lineno))
258 return (ECPG_ARRAY_ERROR);
259 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), ZPBITOID, ECPG_ARRAY_NONE, stmt->lineno))
260 return (ECPG_ARRAY_ERROR);
261 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), VARBITOID, ECPG_ARRAY_NONE, stmt->lineno))
262 return (ECPG_ARRAY_ERROR);
263 if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), NUMERICOID, ECPG_ARRAY_NONE, stmt->lineno))
264 return (ECPG_ARRAY_ERROR);
267 for (cache_entry = (stmt->connection->cache_head); cache_entry != NULL; cache_entry = cache_entry->next)
269 if (cache_entry->oid == type)
270 return cache_entry->isarray;
273 array_query = (char *) ecpg_alloc(strlen("select typlen from pg_type where oid= and typelem<>0") + 11, stmt->lineno);
274 if (array_query == NULL)
275 return (ECPG_ARRAY_ERROR);
277 sprintf(array_query, "select typlen from pg_type where oid=%d and typelem<>0", type);
278 query = PQexec(stmt->connection->connection, array_query);
279 ecpg_free(array_query);
280 if (!ecpg_check_PQresult(query, stmt->lineno, stmt->connection->connection, stmt->compat))
281 return (ECPG_ARRAY_ERROR);
282 else if (PQresultStatus(query) == PGRES_TUPLES_OK)
284 if (PQntuples(query) == 0)
285 isarray = ECPG_ARRAY_NONE;
288 isarray = (atol((char *) PQgetvalue(query, 0, 0)) == -1) ? ECPG_ARRAY_ARRAY : ECPG_ARRAY_VECTOR;
289 if (ecpg_dynamic_type(type) == SQL3_CHARACTER ||
290 ecpg_dynamic_type(type) == SQL3_CHARACTER_VARYING)
293 * arrays of character strings are not yet implemented
295 isarray = ECPG_ARRAY_NONE;
301 return (ECPG_ARRAY_ERROR);
303 ecpg_type_infocache_push(&(stmt->connection->cache_head), type, isarray, stmt->lineno);
304 ecpg_log("ecpg_is_type_an_array on line %d: type (%d); C (%d); array (%s)\n", stmt->lineno, type, var->type, isarray ? "yes" : "no");
310 ecpg_store_result(const PGresult *results, int act_field,
311 const struct statement * stmt, struct variable * var)
313 enum ARRAY_TYPE isarray;
315 ntuples = PQntuples(results);
318 if ((isarray = ecpg_is_type_an_array(PQftype(results, act_field), stmt, var)) == ECPG_ARRAY_ERROR)
320 ecpg_raise(stmt->lineno, ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL);
324 if (isarray == ECPG_ARRAY_NONE)
327 * if we don't have enough space, we cannot read all tuples
329 if ((var->arrsize > 0 && ntuples > var->arrsize) || (var->ind_arrsize > 0 && ntuples > var->ind_arrsize))
331 ecpg_log("ecpg_store_result on line %d: incorrect number of matches; %d don't fit into array of %d\n",
332 stmt->lineno, ntuples, var->arrsize);
333 ecpg_raise(stmt->lineno, INFORMIX_MODE(stmt->compat) ? ECPG_INFORMIX_SUBSELECT_NOT_ONE : ECPG_TOO_MANY_MATCHES, ECPG_SQLSTATE_CARDINALITY_VIOLATION, NULL);
340 * since we read an array, the variable has to be an array too
342 if (var->arrsize == 0)
344 ecpg_raise(stmt->lineno, ECPG_NO_ARRAY, ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
350 * allocate memory for NULL pointers
352 if ((var->arrsize == 0 || var->varcharsize == 0) && var->value == NULL)
356 if (!PQfformat(results, act_field))
361 case ECPGt_unsigned_char:
362 if (!var->varcharsize && !var->arrsize)
364 /* special mode for handling char**foo=0 */
365 for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
366 len += strlen(PQgetvalue(results, act_tuple, act_field)) + 1;
367 len *= var->offset; /* should be 1, but YMNK */
368 len += (ntuples + 1) * sizeof(char *);
372 var->varcharsize = 0;
373 /* check strlen for each tuple */
374 for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
376 int len = strlen(PQgetvalue(results, act_tuple, act_field)) + 1;
378 if (len > var->varcharsize)
379 var->varcharsize = len;
381 var->offset *= var->varcharsize;
382 len = var->offset * ntuples;
386 len = ntuples * (var->varcharsize + sizeof(int));
389 len = var->offset * ntuples;
395 for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
396 len += PQgetlength(results, act_tuple, act_field);
399 ecpg_log("ecpg_store_result on line %d: allocating memory for %d tuples\n", stmt->lineno, ntuples);
400 var->value = (char *) ecpg_alloc(len, stmt->lineno);
403 *((char **) var->pointer) = var->value;
404 ecpg_add_mem(var->value, stmt->lineno);
407 /* allocate indicator variable if needed */
408 if ((var->ind_arrsize == 0 || var->ind_varcharsize == 0) && var->ind_value == NULL && var->ind_pointer != NULL)
410 int len = var->ind_offset * ntuples;
412 var->ind_value = (char *) ecpg_alloc(len, stmt->lineno);
415 *((char **) var->ind_pointer) = var->ind_value;
416 ecpg_add_mem(var->ind_value, stmt->lineno);
419 /* fill the variable with the tuple(s) */
420 if (!var->varcharsize && !var->arrsize &&
421 (var->type == ECPGt_char || var->type == ECPGt_unsigned_char))
423 /* special mode for handling char**foo=0 */
425 /* filling the array of (char*)s */
426 char **current_string = (char **) var->value;
428 /* storing the data (after the last array element) */
429 char *current_data_location = (char *) ¤t_string[ntuples + 1];
431 for (act_tuple = 0; act_tuple < ntuples && status; act_tuple++)
433 int len = strlen(PQgetvalue(results, act_tuple, act_field)) + 1;
435 if (!ecpg_get_data(results, act_tuple, act_field, stmt->lineno,
436 var->type, var->ind_type, current_data_location,
437 var->ind_value, len, 0, var->ind_offset, isarray, stmt->compat, stmt->force_indicator))
441 *current_string = current_data_location;
442 current_data_location += len;
447 /* terminate the list */
448 *current_string = NULL;
452 for (act_tuple = 0; act_tuple < ntuples && status; act_tuple++)
454 if (!ecpg_get_data(results, act_tuple, act_field, stmt->lineno,
455 var->type, var->ind_type, var->value,
456 var->ind_value, var->varcharsize, var->offset, var->ind_offset, isarray, stmt->compat, stmt->force_indicator))
464 ecpg_store_input(const int lineno, const bool force_indicator, const struct variable * var,
465 char **tobeinserted_p, bool quote)
467 char *mallocedval = NULL;
468 char *newcopy = NULL;
471 * arrays are not possible unless the attribute is an array too FIXME: we
472 * do not know if the attribute is an array here
475 if (var->arrsize > 1 &&...)
477 ecpg_raise(lineno, ECPG_ARRAY_INSERT, ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
483 * Some special treatment is needed for records since we want their
484 * contents to arrive in a comma-separated list on insert (I think).
487 *tobeinserted_p = "";
489 /* check for null value and set input buffer accordingly */
490 switch (var->ind_type)
493 case ECPGt_unsigned_short:
494 if (*(short *) var->ind_value < 0)
495 *tobeinserted_p = NULL;
498 case ECPGt_unsigned_int:
499 if (*(int *) var->ind_value < 0)
500 *tobeinserted_p = NULL;
503 case ECPGt_unsigned_long:
504 if (*(long *) var->ind_value < 0L)
505 *tobeinserted_p = NULL;
507 #ifdef HAVE_LONG_LONG_INT_64
508 case ECPGt_long_long:
509 case ECPGt_unsigned_long_long:
510 if (*(long long int *) var->ind_value < (long long) 0)
511 *tobeinserted_p = NULL;
513 #endif /* HAVE_LONG_LONG_INT_64 */
514 case ECPGt_NO_INDICATOR:
515 if (force_indicator == false)
517 if (ECPGis_noind_null(var->type, var->value))
518 *tobeinserted_p = NULL;
524 if (*tobeinserted_p != NULL)
526 int asize = var->arrsize ? var->arrsize : 1;
533 if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
538 strcpy(mallocedval, "array [");
540 for (element = 0; element < asize; element++)
541 sprintf(mallocedval + strlen(mallocedval), "%hd,", ((short *) var->value)[element]);
543 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
546 sprintf(mallocedval, "%hd", *((short *) var->value));
548 *tobeinserted_p = mallocedval;
552 if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
557 strcpy(mallocedval, "{");
559 for (element = 0; element < asize; element++)
560 sprintf(mallocedval + strlen(mallocedval), "%d,", ((int *) var->value)[element]);
562 strcpy(mallocedval + strlen(mallocedval) - 1, "}");
565 sprintf(mallocedval, "%d", *((int *) var->value));
567 *tobeinserted_p = mallocedval;
570 case ECPGt_unsigned_short:
571 if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
576 strcpy(mallocedval, "array [");
578 for (element = 0; element < asize; element++)
579 sprintf(mallocedval + strlen(mallocedval), "%hu,", ((unsigned short *) var->value)[element]);
581 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
584 sprintf(mallocedval, "%hu", *((unsigned short *) var->value));
586 *tobeinserted_p = mallocedval;
589 case ECPGt_unsigned_int:
590 if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
595 strcpy(mallocedval, "array [");
597 for (element = 0; element < asize; element++)
598 sprintf(mallocedval + strlen(mallocedval), "%u,", ((unsigned int *) var->value)[element]);
600 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
603 sprintf(mallocedval, "%u", *((unsigned int *) var->value));
605 *tobeinserted_p = mallocedval;
609 if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
614 strcpy(mallocedval, "array [");
616 for (element = 0; element < asize; element++)
617 sprintf(mallocedval + strlen(mallocedval), "%ld,", ((long *) var->value)[element]);
619 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
622 sprintf(mallocedval, "%ld", *((long *) var->value));
624 *tobeinserted_p = mallocedval;
627 case ECPGt_unsigned_long:
628 if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
633 strcpy(mallocedval, "array [");
635 for (element = 0; element < asize; element++)
636 sprintf(mallocedval + strlen(mallocedval), "%lu,", ((unsigned long *) var->value)[element]);
638 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
641 sprintf(mallocedval, "%lu", *((unsigned long *) var->value));
643 *tobeinserted_p = mallocedval;
645 #ifdef HAVE_LONG_LONG_INT_64
646 case ECPGt_long_long:
647 if (!(mallocedval = ecpg_alloc(asize * 30, lineno)))
652 strcpy(mallocedval, "array [");
654 for (element = 0; element < asize; element++)
655 sprintf(mallocedval + strlen(mallocedval), "%lld,", ((long long *) var->value)[element]);
657 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
660 sprintf(mallocedval, "%lld", *((long long *) var->value));
662 *tobeinserted_p = mallocedval;
665 case ECPGt_unsigned_long_long:
666 if (!(mallocedval = ecpg_alloc(asize * 30, lineno)))
671 strcpy(mallocedval, "array [");
673 for (element = 0; element < asize; element++)
674 sprintf(mallocedval + strlen(mallocedval), "%llu,", ((unsigned long long *) var->value)[element]);
676 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
679 sprintf(mallocedval, "%llu", *((unsigned long long *) var->value));
681 *tobeinserted_p = mallocedval;
683 #endif /* HAVE_LONG_LONG_INT_64 */
685 if (!(mallocedval = ecpg_alloc(asize * 25, lineno)))
690 strcpy(mallocedval, "array [");
692 for (element = 0; element < asize; element++)
693 sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((float *) var->value)[element]);
695 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
698 sprintf(mallocedval, "%.14g", *((float *) var->value));
700 *tobeinserted_p = mallocedval;
704 if (!(mallocedval = ecpg_alloc(asize * 25, lineno)))
709 strcpy(mallocedval, "array [");
711 for (element = 0; element < asize; element++)
712 sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((double *) var->value)[element]);
714 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
717 sprintf(mallocedval, "%.14g", *((double *) var->value));
719 *tobeinserted_p = mallocedval;
723 if (!(mallocedval = ecpg_alloc(var->arrsize + sizeof("array []"), lineno)))
726 if (var->arrsize > 1)
728 strcpy(mallocedval, "array [");
730 if (var->offset == sizeof(char))
731 for (element = 0; element < var->arrsize; element++)
732 sprintf(mallocedval + strlen(mallocedval), "%c,", (((char *) var->value)[element]) ? 't' : 'f');
735 * this is necessary since sizeof(C++'s bool)==sizeof(int)
737 else if (var->offset == sizeof(int))
738 for (element = 0; element < var->arrsize; element++)
739 sprintf(mallocedval + strlen(mallocedval), "%c,", (((int *) var->value)[element]) ? 't' : 'f');
741 ecpg_raise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
743 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
747 if (var->offset == sizeof(char))
748 sprintf(mallocedval, "%c", (*((char *) var->value)) ? 't' : 'f');
749 else if (var->offset == sizeof(int))
750 sprintf(mallocedval, "%c", (*((int *) var->value)) ? 't' : 'f');
752 ecpg_raise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
755 *tobeinserted_p = mallocedval;
759 case ECPGt_unsigned_char:
761 /* set slen to string length if type is char * */
762 int slen = (var->varcharsize == 0) ? strlen((char *) var->value) : (unsigned int)var->varcharsize;
764 if (!(newcopy = ecpg_alloc(slen + 1, lineno)))
767 strncpy(newcopy, (char *) var->value, slen);
768 newcopy[slen] = '\0';
770 mallocedval = quote_postgres(newcopy, quote, lineno);
774 *tobeinserted_p = mallocedval;
778 case ECPGt_char_variable:
780 int slen = strlen((char *) var->value);
782 if (!(mallocedval = ecpg_alloc(slen + 1, lineno)))
785 strncpy(mallocedval, (char *) var->value, slen);
786 mallocedval[slen] = '\0';
788 *tobeinserted_p = mallocedval;
793 struct ECPGgeneric_varchar *variable =
794 (struct ECPGgeneric_varchar *) (var->value);
796 if (!(newcopy = (char *) ecpg_alloc(variable->len + 1, lineno)))
799 strncpy(newcopy, variable->arr, variable->len);
800 newcopy[variable->len] = '\0';
802 mallocedval = quote_postgres(newcopy, quote, lineno);
806 *tobeinserted_p = mallocedval;
817 if (var->arrsize > 1)
819 for (element = 0; element < var->arrsize; element++)
821 nval = PGTYPESnumeric_new();
825 if (var->type == ECPGt_numeric)
826 PGTYPESnumeric_copy((numeric *) ((var + var->offset * element)->value), nval);
828 PGTYPESnumeric_from_decimal((decimal *) ((var + var->offset * element)->value), nval);
830 str = PGTYPESnumeric_to_asc(nval, nval->dscale);
832 PGTYPESnumeric_free(nval);
834 if (!(mallocedval = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [] "), lineno)))
841 strcpy(mallocedval, "array [");
843 strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
844 strcpy(mallocedval + strlen(mallocedval), ",");
847 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
851 nval = PGTYPESnumeric_new();
855 if (var->type == ECPGt_numeric)
856 PGTYPESnumeric_copy((numeric *) (var->value), nval);
858 PGTYPESnumeric_from_decimal((decimal *) (var->value), nval);
860 str = PGTYPESnumeric_to_asc(nval, nval->dscale);
862 PGTYPESnumeric_free(nval);
864 if (!(mallocedval = ecpg_alloc(slen + 1, lineno)))
870 strncpy(mallocedval, str, slen);
871 mallocedval[slen] = '\0';
875 *tobeinserted_p = mallocedval;
884 if (var->arrsize > 1)
886 for (element = 0; element < var->arrsize; element++)
888 str = quote_postgres(PGTYPESinterval_to_asc((interval *) ((var + var->offset * element)->value)), quote, lineno);
893 if (!(mallocedval = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [],interval "), lineno)))
900 strcpy(mallocedval, "array [");
902 strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
903 strcpy(mallocedval + strlen(mallocedval), ",");
906 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
910 str = quote_postgres(PGTYPESinterval_to_asc((interval *) (var->value)), quote, lineno);
915 if (!(mallocedval = ecpg_alloc(slen + sizeof("interval ") + 1, lineno)))
921 /* also copy trailing '\0' */
922 strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
926 *tobeinserted_p = mallocedval;
935 if (var->arrsize > 1)
937 for (element = 0; element < var->arrsize; element++)
939 str = quote_postgres(PGTYPESdate_to_asc(*(date *) ((var + var->offset * element)->value)), quote, lineno);
944 if (!(mallocedval = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [],date "), lineno)))
951 strcpy(mallocedval, "array [");
953 strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
954 strcpy(mallocedval + strlen(mallocedval), ",");
957 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
961 str = quote_postgres(PGTYPESdate_to_asc(*(date *) (var->value)), quote, lineno);
966 if (!(mallocedval = ecpg_alloc(slen + sizeof("date ") + 1, lineno)))
972 /* also copy trailing '\0' */
973 strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
977 *tobeinserted_p = mallocedval;
981 case ECPGt_timestamp:
986 if (var->arrsize > 1)
988 for (element = 0; element < var->arrsize; element++)
990 str = quote_postgres(PGTYPEStimestamp_to_asc(*(timestamp *) ((var + var->offset * element)->value)), quote, lineno);
996 if (!(mallocedval = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [], timestamp "), lineno)))
1003 strcpy(mallocedval, "array [");
1005 strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
1006 strcpy(mallocedval + strlen(mallocedval), ",");
1009 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
1013 str = quote_postgres(PGTYPEStimestamp_to_asc(*(timestamp *) (var->value)), quote, lineno);
1018 if (!(mallocedval = ecpg_alloc(slen + sizeof("timestamp") + 1, lineno)))
1024 /* also copy trailing '\0' */
1025 strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
1029 *tobeinserted_p = mallocedval;
1033 case ECPGt_descriptor:
1037 /* Not implemented yet */
1038 ecpg_raise(lineno, ECPG_UNSUPPORTED, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, (char *) ecpg_type_name(var->type));
1047 free_params(const char **paramValues, int nParams, bool print, int lineno)
1051 for (n = 0; n < nParams; n++)
1054 ecpg_log("free_params on line %d: parameter %d = %s\n", lineno, n + 1, paramValues[n] ? paramValues[n] : "null");
1055 ecpg_free((void *) (paramValues[n]));
1057 ecpg_free(paramValues);
1062 insert_tobeinserted(int position, int ph_len, struct statement * stmt, char *tobeinserted)
1066 if (!(newcopy = (char *) ecpg_alloc(strlen(stmt->command)
1067 + strlen(tobeinserted)
1068 + 1, stmt->lineno)))
1070 ecpg_free(tobeinserted);
1074 strcpy(newcopy, stmt->command);
1075 strcpy(newcopy + position - 1, tobeinserted);
1078 * The strange thing in the second argument is the rest of the
1079 * string from the old string
1086 ecpg_free(stmt->command);
1087 stmt->command = newcopy;
1089 ecpg_free((char *) tobeinserted);
1094 ecpg_execute(struct statement * stmt)
1096 bool status = false;
1100 struct variable *var;
1101 int desc_counter = 0;
1102 const char **paramValues = NULL;
1105 struct sqlca_t *sqlca = ECPGget_sqlca();
1106 bool clear_result = true;
1109 * If the type is one of the fill in types then we take the argument and
1110 * enter it to our parameter array at the first position. Then if there
1111 * are any more fill in types we add more parameters.
1119 tobeinserted = NULL;
1122 * A descriptor is a special case since it contains many variables but
1123 * is listed only once.
1125 if (var->type == ECPGt_descriptor)
1128 * We create an additional variable list here, so the same logic
1131 struct variable desc_inlist;
1132 struct descriptor *desc;
1133 struct descriptor_item *desc_item;
1135 desc = ecpg_find_desc(stmt->lineno, var->pointer);
1140 for (desc_item = desc->items; desc_item; desc_item = desc_item->next)
1142 if (desc_item->num == desc_counter)
1144 desc_inlist.type = ECPGt_char;
1145 desc_inlist.value = desc_item->data;
1146 desc_inlist.pointer = &(desc_item->data);
1147 desc_inlist.varcharsize = strlen(desc_item->data);
1148 desc_inlist.arrsize = 1;
1149 desc_inlist.offset = 0;
1150 if (!desc_item->indicator)
1152 desc_inlist.ind_type = ECPGt_NO_INDICATOR;
1153 desc_inlist.ind_value = desc_inlist.ind_pointer = NULL;
1154 desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = desc_inlist.ind_offset = 0;
1158 desc_inlist.ind_type = ECPGt_int;
1159 desc_inlist.ind_value = &(desc_item->indicator);
1160 desc_inlist.ind_pointer = &(desc_inlist.ind_value);
1161 desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = 1;
1162 desc_inlist.ind_offset = 0;
1164 if (!ecpg_store_input(stmt->lineno, stmt->force_indicator, &desc_inlist, &tobeinserted, false))
1170 if (desc->count == desc_counter)
1175 if (!ecpg_store_input(stmt->lineno, stmt->force_indicator, var, &tobeinserted, false))
1180 * now tobeinserted points to an area that contains the next parameter
1181 * now find the positin in the string where it belongs
1183 if ((position = next_insert(stmt->command, position, stmt->questionmarks) + 1) == 0)
1186 * We have an argument but we dont have the matched up
1187 * placeholder in the string
1189 ecpg_raise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS,
1190 ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS,
1192 free_params(paramValues, nParams, false, stmt->lineno);
1197 * if var->type=ECPGt_char_variable we have a dynamic cursor we have
1198 * to simulate a dynamic cursor because there is no backend
1199 * functionality for it
1201 if (var->type == ECPGt_char_variable)
1203 int ph_len = (stmt->command[position] == '?') ? strlen("?") : strlen("$1");
1205 if (!insert_tobeinserted(position, ph_len, stmt, tobeinserted))
1207 free_params(paramValues, nParams, false, stmt->lineno);
1210 tobeinserted = NULL;
1213 * if the placeholder is '$0' we have to replace it on the client side
1214 * this is for places we want to support variables at that are not supported in the backend
1216 else if (stmt->command[position] == '0' )
1218 if (!insert_tobeinserted(position, 2, stmt, tobeinserted))
1220 free_params(paramValues, nParams, false, stmt->lineno);
1223 tobeinserted = NULL;
1228 if (!(paramValues = (const char **) ecpg_realloc(paramValues, sizeof(const char *) * nParams, stmt->lineno)))
1230 ecpg_free(paramValues);
1234 paramValues[nParams - 1] = tobeinserted;
1236 /* let's see if this was an old style placeholder */
1237 if (stmt->command[position] == '?')
1239 /* yes, replace with new style */
1240 int buffersize = sizeof(int) * CHAR_BIT * 10 / 3; /* a rough guess of the
1243 if (!(tobeinserted = (char *) ecpg_alloc(buffersize, stmt->lineno)))
1245 free_params(paramValues, nParams, false, stmt->lineno);
1249 snprintf(tobeinserted, buffersize, "$%d", counter++);
1251 if (!insert_tobeinserted(position, 2, stmt, tobeinserted))
1253 free_params(paramValues, nParams, false, stmt->lineno);
1256 tobeinserted = NULL;
1260 if (desc_counter == 0)
1264 /* Check if there are unmatched things left. */
1265 if (next_insert(stmt->command, position, stmt->questionmarks) >= 0)
1267 ecpg_raise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS,
1268 ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS, NULL);
1269 free_params(paramValues, nParams, false, stmt->lineno);
1273 /* The request has been build. */
1275 if (stmt->connection->committed && !stmt->connection->autocommit)
1277 results = PQexec(stmt->connection->connection, "begin transaction");
1278 if (!ecpg_check_PQresult(results, stmt->lineno, stmt->connection->connection, stmt->compat))
1280 free_params(paramValues, nParams, false, stmt->lineno);
1284 stmt->connection->committed = false;
1287 ecpg_log("ecpg_execute on line %d: query: %s; with %d parameter(s) on connection %s\n", stmt->lineno, stmt->command, nParams, stmt->connection->name);
1288 if (stmt->statement_type == ECPGst_execute)
1290 results = PQexecPrepared(stmt->connection->connection, stmt->name, nParams, paramValues, NULL, NULL, 0);
1291 ecpg_log("ecpg_execute on line %d: using PQexecPrepared for \"%s\"\n", stmt->lineno, stmt->command);
1297 results = PQexec(stmt->connection->connection, stmt->command);
1298 ecpg_log("ecpg_execute on line %d: using PQexec\n", stmt->lineno);
1302 results = PQexecParams(stmt->connection->connection, stmt->command, nParams, NULL, paramValues, NULL, NULL, 0);
1303 ecpg_log("ecpg_execute on line %d: using PQexecParams\n", stmt->lineno);
1307 free_params(paramValues, nParams, true, stmt->lineno);
1309 if (!ecpg_check_PQresult(results, stmt->lineno, stmt->connection->connection, stmt->compat))
1312 var = stmt->outlist;
1313 switch (PQresultStatus(results))
1319 case PGRES_TUPLES_OK:
1320 nfields = PQnfields(results);
1321 sqlca->sqlerrd[2] = ntuples = PQntuples(results);
1322 ecpg_log("ecpg_execute on line %d: correctly got %d tuples with %d fields\n", stmt->lineno, ntuples, nfields);
1328 ecpg_log("ecpg_execute on line %d: incorrect number of matches (%d)\n",
1329 stmt->lineno, ntuples);
1330 ecpg_raise(stmt->lineno, ECPG_NOT_FOUND, ECPG_SQLSTATE_NO_DATA, NULL);
1335 if (var != NULL && var->type == ECPGt_descriptor)
1337 struct descriptor *desc = ecpg_find_desc(stmt->lineno, var->pointer);
1344 PQclear(desc->result);
1345 desc->result = results;
1346 clear_result = false;
1347 ecpg_log("ecpg_execute on line %d: putting result (%d tuples) into descriptor %s\n",
1348 stmt->lineno, PQntuples(results), (const char *) var->pointer);
1353 for (act_field = 0; act_field < nfields && status; act_field++)
1357 status = ecpg_store_result(results, act_field, stmt, var);
1360 else if (!INFORMIX_MODE(stmt->compat))
1362 ecpg_raise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS, ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS, NULL);
1367 if (status && var != NULL)
1369 ecpg_raise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS, ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS, NULL);
1374 case PGRES_COMMAND_OK:
1376 cmdstat = PQcmdStatus(results);
1377 sqlca->sqlerrd[1] = PQoidValue(results);
1378 sqlca->sqlerrd[2] = atol(PQcmdTuples(results));
1379 ecpg_log("ecpg_execute on line %d: OK: %s\n", stmt->lineno, cmdstat);
1380 if (stmt->compat != ECPG_COMPAT_INFORMIX_SE &&
1381 !sqlca->sqlerrd[2] &&
1382 (!strncmp(cmdstat, "UPDATE", 6)
1383 || !strncmp(cmdstat, "INSERT", 6)
1384 || !strncmp(cmdstat, "DELETE", 6)))
1385 ecpg_raise(stmt->lineno, ECPG_NOT_FOUND, ECPG_SQLSTATE_NO_DATA, NULL);
1387 case PGRES_COPY_OUT:
1392 ecpg_log("ecpg_execute on line %d: COPY OUT data transfer in progress\n", stmt->lineno);
1393 while ((res = PQgetCopyData(stmt->connection->connection,
1396 printf("%s", buffer);
1403 results = PQgetResult(stmt->connection->connection);
1404 if (PQresultStatus(results) == PGRES_COMMAND_OK)
1405 ecpg_log("ecpg_execute on line %d: got PGRES_COMMAND_OK after PGRES_COPY_OUT\n", stmt->lineno);
1407 ecpg_log("ecpg_execute on line %d: got error after PGRES_COPY_OUT: %s", PQresultErrorMessage(results));
1414 * execution should never reach this code because it is already
1415 * handled in ECPGcheck_PQresult()
1417 ecpg_log("ecpg_execute on line %d: unknown execution status type\n",
1419 ecpg_raise_backend(stmt->lineno, results, stmt->connection->connection, stmt->compat);
1426 /* check for asynchronous returns */
1427 notify = PQnotifies(stmt->connection->connection);
1430 ecpg_log("ecpg_execute on line %d: asynchronous notification of \"%s\" from backend pid %d received\n",
1431 stmt->lineno, notify->relname, notify->be_pid);
1439 ECPGdo(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, const int st, const char *query,...)
1442 struct statement *stmt;
1443 struct connection *con;
1446 enum ECPGttype type;
1447 struct variable **list;
1448 enum ECPG_statement_type statement_type = (enum ECPG_statement_type) st;
1453 ecpg_raise(lineno, ECPG_EMPTY, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, NULL);
1457 /* Make sure we do NOT honor the locale for numeric input/output */
1458 /* since the database wants the standard decimal point */
1459 oldlocale = ecpg_strdup(setlocale(LC_NUMERIC, NULL), lineno);
1460 setlocale(LC_NUMERIC, "C");
1462 #ifdef ENABLE_THREAD_SAFETY
1463 ecpg_pthreads_init();
1466 con = ecpg_get_connection(connection_name);
1468 if (!ecpg_init(con, connection_name, lineno))
1470 setlocale(LC_NUMERIC, oldlocale);
1471 ecpg_free(oldlocale);
1475 /* construct statement in our own structure */
1476 va_start(args, query);
1479 * create a list of variables The variables are listed with input
1480 * variables preceding outputvariables The end of each group is marked by
1481 * an end marker. per variable we list: type - as defined in ecpgtype.h
1482 * value - where to store the data varcharsize - length of string in case
1483 * we have a stringvariable, else 0 arraysize - 0 for pointer (we don't
1484 * know the size of the array), 1 for simple variable, size for arrays
1485 * offset - offset between ith and (i+1)th entry in an array, normally
1486 * that means sizeof(type) ind_type - type of indicator variable ind_value
1487 * - pointer to indicator variable ind_varcharsize - empty ind_arraysize -
1488 * arraysize of indicator array ind_offset - indicator offset
1490 if (!(stmt = (struct statement *) ecpg_alloc(sizeof(struct statement), lineno)))
1492 setlocale(LC_NUMERIC, oldlocale);
1493 ecpg_free(oldlocale);
1499 * If statement type is ECPGst_prepnormal we are supposed to prepare the
1500 * statement before executing them
1502 if (statement_type == ECPGst_prepnormal)
1504 if (!ecpg_auto_prepare(lineno, connection_name, compat, &prepname, query))
1508 * statement is now prepared, so instead of the query we have to
1511 stmt->command = prepname;
1512 statement_type = ECPGst_execute;
1515 stmt->command = ecpg_strdup(query, lineno);
1519 if (statement_type == ECPGst_execute)
1521 /* if we have an EXECUTE command, only the name is send */
1522 char *command = ecpg_prepared(stmt->command, con);
1526 stmt->name = stmt->command;
1527 stmt->command = ecpg_strdup(command, lineno);
1530 ecpg_raise(lineno, ECPG_INVALID_STMT, ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME, stmt->command);
1533 stmt->connection = con;
1534 stmt->lineno = lineno;
1535 stmt->compat = compat;
1536 stmt->force_indicator = force_indicator;
1537 stmt->questionmarks = questionmarks;
1538 stmt->statement_type = statement_type;
1540 list = &(stmt->inlist);
1542 type = va_arg(args, enum ECPGttype);
1544 while (type != ECPGt_EORT)
1546 if (type == ECPGt_EOIT)
1547 list = &(stmt->outlist);
1550 struct variable *var,
1553 if (!(var = (struct variable *) ecpg_alloc(sizeof(struct variable), lineno)))
1555 setlocale(LC_NUMERIC, oldlocale);
1556 ecpg_free(oldlocale);
1557 free_statement(stmt);
1563 var->pointer = va_arg(args, char *);
1565 var->varcharsize = va_arg(args, long);
1566 var->arrsize = va_arg(args, long);
1567 var->offset = va_arg(args, long);
1569 if (var->arrsize == 0 || var->varcharsize == 0)
1570 var->value = *((char **) (var->pointer));
1572 var->value = var->pointer;
1575 * negative values are used to indicate an array without given
1578 /* reset to zero for us */
1579 if (var->arrsize < 0)
1581 if (var->varcharsize < 0)
1582 var->varcharsize = 0;
1586 var->ind_type = va_arg(args, enum ECPGttype);
1587 var->ind_pointer = va_arg(args, char *);
1588 var->ind_varcharsize = va_arg(args, long);
1589 var->ind_arrsize = va_arg(args, long);
1590 var->ind_offset = va_arg(args, long);
1592 if (var->ind_type != ECPGt_NO_INDICATOR
1593 && (var->ind_arrsize == 0 || var->ind_varcharsize == 0))
1594 var->ind_value = *((char **) (var->ind_pointer));
1596 var->ind_value = var->ind_pointer;
1599 * negative values are used to indicate an array without given
1602 /* reset to zero for us */
1603 if (var->ind_arrsize < 0)
1604 var->ind_arrsize = 0;
1605 if (var->ind_varcharsize < 0)
1606 var->ind_varcharsize = 0;
1608 /* if variable is NULL, the statement hasn't been prepared */
1609 if (var->pointer == NULL)
1611 ecpg_raise(lineno, ECPG_INVALID_STMT, ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME, NULL);
1613 setlocale(LC_NUMERIC, oldlocale);
1614 ecpg_free(oldlocale);
1615 free_statement(stmt);
1620 for (ptr = *list; ptr && ptr->next; ptr = ptr->next);
1628 type = va_arg(args, enum ECPGttype);
1633 /* are we connected? */
1634 if (con == NULL || con->connection == NULL)
1636 free_statement(stmt);
1637 ecpg_raise(lineno, ECPG_NOT_CONN, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, (con) ? con->name : ecpg_gettext("<empty>"));
1638 setlocale(LC_NUMERIC, oldlocale);
1639 ecpg_free(oldlocale);
1643 /* initialize auto_mem struct */
1644 ecpg_clear_auto_mem();
1646 status = ecpg_execute(stmt);
1647 free_statement(stmt);
1649 /* and reset locale value so our application is not affected */
1650 setlocale(LC_NUMERIC, oldlocale);
1651 ecpg_free(oldlocale);
1656 /* old descriptor interface */
1658 ECPGdo_descriptor(int line, const char *connection,
1659 const char *descriptor, const char *query)
1661 return ECPGdo(line, ECPG_COMPAT_PGSQL, true, connection, '\0', 0, (char *) query, ECPGt_EOIT,
1662 ECPGt_descriptor, descriptor, 0L, 0L, 0L,
1663 ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EORT);