1 /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.70 2007/09/26 10:57:00 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 *) ECPGalloc(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 ECPGfree(stmt->command);
107 ECPGfree(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(text[p+1]))
127 /* this can be either a dollar quote or a variable */
130 for (i = p + 1; isdigit(text[i]); i++);
131 if (!isalpha(text[i]) && isascii(text[i]) && text[i] != '_')
132 /* not dollar delimeted quote */
135 else if (questionmarks && text[p] == '?')
137 /* also allow old style placeholders */
147 ECPGtypeinfocache_push(struct ECPGtype_information_cache ** cache, int oid, bool isarray, int lineno)
149 struct ECPGtype_information_cache *new_entry
150 = (struct ECPGtype_information_cache *) ECPGalloc(sizeof(struct ECPGtype_information_cache), lineno);
152 if (new_entry == NULL)
155 new_entry->oid = oid;
156 new_entry->isarray = isarray;
157 new_entry->next = *cache;
162 static enum ARRAY_TYPE
163 ECPGis_type_an_array(int type, const struct statement * stmt, const struct variable * var)
166 enum ARRAY_TYPE isarray = ECPG_ARRAY_NOT_SET;
168 struct ECPGtype_information_cache *cache_entry;
170 if ((stmt->connection->cache_head) == NULL)
173 * Text like types are not an array for ecpg, but postgres counts them
174 * as an array. This define reminds you to not 'correct' these values.
176 #define not_an_array_in_ecpg ECPG_ARRAY_NONE
178 /* populate cache with well known types to speed things up */
179 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), BOOLOID, ECPG_ARRAY_NONE, stmt->lineno))
180 return (ECPG_ARRAY_ERROR);
181 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), BYTEAOID, ECPG_ARRAY_NONE, stmt->lineno))
182 return (ECPG_ARRAY_ERROR);
183 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), CHAROID, ECPG_ARRAY_NONE, stmt->lineno))
184 return (ECPG_ARRAY_ERROR);
185 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), NAMEOID, not_an_array_in_ecpg, stmt->lineno))
186 return (ECPG_ARRAY_ERROR);
187 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), INT8OID, ECPG_ARRAY_NONE, stmt->lineno))
188 return (ECPG_ARRAY_ERROR);
189 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), INT2OID, ECPG_ARRAY_NONE, stmt->lineno))
190 return (ECPG_ARRAY_ERROR);
191 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), INT2VECTOROID, ECPG_ARRAY_VECTOR, stmt->lineno))
192 return (ECPG_ARRAY_ERROR);
193 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), INT4OID, ECPG_ARRAY_NONE, stmt->lineno))
194 return (ECPG_ARRAY_ERROR);
195 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), REGPROCOID, ECPG_ARRAY_NONE, stmt->lineno))
196 return (ECPG_ARRAY_ERROR);
197 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), TEXTOID, ECPG_ARRAY_NONE, stmt->lineno))
198 return (ECPG_ARRAY_ERROR);
199 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), OIDOID, ECPG_ARRAY_NONE, stmt->lineno))
200 return (ECPG_ARRAY_ERROR);
201 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), TIDOID, ECPG_ARRAY_NONE, stmt->lineno))
202 return (ECPG_ARRAY_ERROR);
203 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), XIDOID, ECPG_ARRAY_NONE, stmt->lineno))
204 return (ECPG_ARRAY_ERROR);
205 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), CIDOID, ECPG_ARRAY_NONE, stmt->lineno))
206 return (ECPG_ARRAY_ERROR);
207 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), OIDVECTOROID, ECPG_ARRAY_VECTOR, stmt->lineno))
208 return (ECPG_ARRAY_ERROR);
209 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), POINTOID, ECPG_ARRAY_VECTOR, stmt->lineno))
210 return (ECPG_ARRAY_ERROR);
211 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), LSEGOID, ECPG_ARRAY_VECTOR, stmt->lineno))
212 return (ECPG_ARRAY_ERROR);
213 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), PATHOID, ECPG_ARRAY_NONE, stmt->lineno))
214 return (ECPG_ARRAY_ERROR);
215 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), BOXOID, ECPG_ARRAY_VECTOR, stmt->lineno))
216 return (ECPG_ARRAY_ERROR);
217 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), POLYGONOID, ECPG_ARRAY_NONE, stmt->lineno))
218 return (ECPG_ARRAY_ERROR);
219 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), LINEOID, ECPG_ARRAY_VECTOR, stmt->lineno))
220 return (ECPG_ARRAY_ERROR);
221 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), FLOAT4OID, ECPG_ARRAY_NONE, stmt->lineno))
222 return (ECPG_ARRAY_ERROR);
223 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), FLOAT8OID, ECPG_ARRAY_NONE, stmt->lineno))
224 return (ECPG_ARRAY_ERROR);
225 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), ABSTIMEOID, ECPG_ARRAY_NONE, stmt->lineno))
226 return (ECPG_ARRAY_ERROR);
227 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), RELTIMEOID, ECPG_ARRAY_NONE, stmt->lineno))
228 return (ECPG_ARRAY_ERROR);
229 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), TINTERVALOID, ECPG_ARRAY_NONE, stmt->lineno))
230 return (ECPG_ARRAY_ERROR);
231 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), UNKNOWNOID, ECPG_ARRAY_NONE, stmt->lineno))
232 return (ECPG_ARRAY_ERROR);
233 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), CIRCLEOID, ECPG_ARRAY_NONE, stmt->lineno))
234 return (ECPG_ARRAY_ERROR);
235 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), CASHOID, ECPG_ARRAY_NONE, stmt->lineno))
236 return (ECPG_ARRAY_ERROR);
237 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), INETOID, ECPG_ARRAY_NONE, stmt->lineno))
238 return (ECPG_ARRAY_ERROR);
239 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), CIDROID, ECPG_ARRAY_NONE, stmt->lineno))
240 return (ECPG_ARRAY_ERROR);
241 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), BPCHAROID, ECPG_ARRAY_NONE, stmt->lineno))
242 return (ECPG_ARRAY_ERROR);
243 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), VARCHAROID, ECPG_ARRAY_NONE, stmt->lineno))
244 return (ECPG_ARRAY_ERROR);
245 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), DATEOID, ECPG_ARRAY_NONE, stmt->lineno))
246 return (ECPG_ARRAY_ERROR);
247 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), TIMEOID, ECPG_ARRAY_NONE, stmt->lineno))
248 return (ECPG_ARRAY_ERROR);
249 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), TIMESTAMPOID, ECPG_ARRAY_NONE, stmt->lineno))
250 return (ECPG_ARRAY_ERROR);
251 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), TIMESTAMPTZOID, ECPG_ARRAY_NONE, stmt->lineno))
252 return (ECPG_ARRAY_ERROR);
253 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), INTERVALOID, ECPG_ARRAY_NONE, stmt->lineno))
254 return (ECPG_ARRAY_ERROR);
255 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), TIMETZOID, ECPG_ARRAY_NONE, stmt->lineno))
256 return (ECPG_ARRAY_ERROR);
257 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), ZPBITOID, ECPG_ARRAY_NONE, stmt->lineno))
258 return (ECPG_ARRAY_ERROR);
259 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), VARBITOID, ECPG_ARRAY_NONE, stmt->lineno))
260 return (ECPG_ARRAY_ERROR);
261 if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), NUMERICOID, ECPG_ARRAY_NONE, stmt->lineno))
262 return (ECPG_ARRAY_ERROR);
265 for (cache_entry = (stmt->connection->cache_head); cache_entry != NULL; cache_entry = cache_entry->next)
267 if (cache_entry->oid == type)
268 return cache_entry->isarray;
271 array_query = (char *) ECPGalloc(strlen("select typlen from pg_type where oid= and typelem<>0") + 11, stmt->lineno);
272 if (array_query == NULL)
273 return (ECPG_ARRAY_ERROR);
275 sprintf(array_query, "select typlen from pg_type where oid=%d and typelem<>0", type);
276 query = PQexec(stmt->connection->connection, array_query);
277 ECPGfree(array_query);
278 if (!ECPGcheck_PQresult(query, stmt->lineno, stmt->connection->connection, stmt->compat))
279 return (ECPG_ARRAY_ERROR);
280 else if (PQresultStatus(query) == PGRES_TUPLES_OK)
282 if (PQntuples(query) == 0)
283 isarray = ECPG_ARRAY_NONE;
286 isarray = (atol((char *) PQgetvalue(query, 0, 0)) == -1) ? ECPG_ARRAY_ARRAY : ECPG_ARRAY_VECTOR;
287 if (ECPGDynamicType(type) == SQL3_CHARACTER ||
288 ECPGDynamicType(type) == SQL3_CHARACTER_VARYING)
291 * arrays of character strings are not yet implemented
293 isarray = ECPG_ARRAY_NONE;
299 return (ECPG_ARRAY_ERROR);
301 ECPGtypeinfocache_push(&(stmt->connection->cache_head), type, isarray, stmt->lineno);
302 ECPGlog("ECPGis_type_an_array line %d: TYPE database: %d C: %d array: %s\n", stmt->lineno, type, var->type, isarray ? "Yes" : "No");
308 ECPGstore_result(const PGresult *results, int act_field,
309 const struct statement * stmt, struct variable * var)
311 enum ARRAY_TYPE isarray;
313 ntuples = PQntuples(results);
316 if ((isarray = ECPGis_type_an_array(PQftype(results, act_field), stmt, var)) == ECPG_ARRAY_ERROR)
318 ECPGraise(stmt->lineno, ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL);
322 if (isarray == ECPG_ARRAY_NONE)
325 * if we don't have enough space, we cannot read all tuples
327 if ((var->arrsize > 0 && ntuples > var->arrsize) || (var->ind_arrsize > 0 && ntuples > var->ind_arrsize))
329 ECPGlog("ECPGstore_result line %d: Incorrect number of matches: %d don't fit into array of %d\n",
330 stmt->lineno, ntuples, var->arrsize);
331 ECPGraise(stmt->lineno, INFORMIX_MODE(stmt->compat) ? ECPG_INFORMIX_SUBSELECT_NOT_ONE : ECPG_TOO_MANY_MATCHES, ECPG_SQLSTATE_CARDINALITY_VIOLATION, NULL);
338 * since we read an array, the variable has to be an array too
340 if (var->arrsize == 0)
342 ECPGraise(stmt->lineno, ECPG_NO_ARRAY, ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
348 * allocate memory for NULL pointers
350 if ((var->arrsize == 0 || var->varcharsize == 0) && var->value == NULL)
357 case ECPGt_unsigned_char:
358 if (!var->varcharsize && !var->arrsize)
360 /* special mode for handling char**foo=0 */
361 for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
362 len += strlen(PQgetvalue(results, act_tuple, act_field)) + 1;
363 len *= var->offset; /* should be 1, but YMNK */
364 len += (ntuples + 1) * sizeof(char *);
368 var->varcharsize = 0;
369 /* check strlen for each tuple */
370 for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
372 int len = strlen(PQgetvalue(results, act_tuple, act_field)) + 1;
374 if (len > var->varcharsize)
375 var->varcharsize = len;
377 var->offset *= var->varcharsize;
378 len = var->offset * ntuples;
382 len = ntuples * (var->varcharsize + sizeof(int));
385 len = var->offset * ntuples;
388 ECPGlog("ECPGstore_result: line %d: allocating memory for %d tuples\n", stmt->lineno, ntuples);
389 var->value = (char *) ECPGalloc(len, stmt->lineno);
392 *((char **) var->pointer) = var->value;
393 ECPGadd_mem(var->value, stmt->lineno);
396 /* allocate indicator variable if needed */
397 if ((var->ind_arrsize == 0 || var->ind_varcharsize == 0) && var->ind_value == NULL && var->ind_pointer != NULL)
399 int len = var->ind_offset * ntuples;
401 var->ind_value = (char *) ECPGalloc(len, stmt->lineno);
404 *((char **) var->ind_pointer) = var->ind_value;
405 ECPGadd_mem(var->ind_value, stmt->lineno);
408 /* fill the variable with the tuple(s) */
409 if (!var->varcharsize && !var->arrsize &&
410 (var->type == ECPGt_char || var->type == ECPGt_unsigned_char))
412 /* special mode for handling char**foo=0 */
414 /* filling the array of (char*)s */
415 char **current_string = (char **) var->value;
417 /* storing the data (after the last array element) */
418 char *current_data_location = (char *) ¤t_string[ntuples + 1];
420 for (act_tuple = 0; act_tuple < ntuples && status; act_tuple++)
422 int len = strlen(PQgetvalue(results, act_tuple, act_field)) + 1;
424 if (!ECPGget_data(results, act_tuple, act_field, stmt->lineno,
425 var->type, var->ind_type, current_data_location,
426 var->ind_value, len, 0, var->ind_offset, isarray, stmt->compat, stmt->force_indicator))
430 *current_string = current_data_location;
431 current_data_location += len;
436 /* terminate the list */
437 *current_string = NULL;
441 for (act_tuple = 0; act_tuple < ntuples && status; act_tuple++)
443 if (!ECPGget_data(results, act_tuple, act_field, stmt->lineno,
444 var->type, var->ind_type, var->value,
445 var->ind_value, var->varcharsize, var->offset, var->ind_offset, isarray, stmt->compat, stmt->force_indicator))
453 ECPGstore_input(const int lineno, const bool force_indicator, const struct variable * var,
454 const char **tobeinserted_p, bool quote)
456 char *mallocedval = NULL;
457 char *newcopy = NULL;
460 * arrays are not possible unless the attribute is an array too FIXME: we
461 * do not know if the attribute is an array here
464 if (var->arrsize > 1 &&...)
466 ECPGraise(lineno, ECPG_ARRAY_INSERT, ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
472 * Some special treatment is needed for records since we want their
473 * contents to arrive in a comma-separated list on insert (I think).
476 *tobeinserted_p = "";
478 /* check for null value and set input buffer accordingly */
479 switch (var->ind_type)
482 case ECPGt_unsigned_short:
483 if (*(short *) var->ind_value < 0)
484 *tobeinserted_p = NULL;
487 case ECPGt_unsigned_int:
488 if (*(int *) var->ind_value < 0)
489 *tobeinserted_p = NULL;
492 case ECPGt_unsigned_long:
493 if (*(long *) var->ind_value < 0L)
494 *tobeinserted_p = NULL;
496 #ifdef HAVE_LONG_LONG_INT_64
497 case ECPGt_long_long:
498 case ECPGt_unsigned_long_long:
499 if (*(long long int *) var->ind_value < (long long) 0)
500 *tobeinserted_p = NULL;
502 #endif /* HAVE_LONG_LONG_INT_64 */
503 case ECPGt_NO_INDICATOR:
504 if (force_indicator == false)
506 if (ECPGis_noind_null(var->type, var->value))
507 *tobeinserted_p = NULL;
513 if (*tobeinserted_p != NULL)
515 int asize = var->arrsize ? var->arrsize : 1;
522 if (!(mallocedval = ECPGalloc(asize * 20, lineno)))
527 strcpy(mallocedval, "array [");
529 for (element = 0; element < asize; element++)
530 sprintf(mallocedval + strlen(mallocedval), "%hd,", ((short *) var->value)[element]);
532 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
535 sprintf(mallocedval, "%hd", *((short *) var->value));
537 *tobeinserted_p = mallocedval;
541 if (!(mallocedval = ECPGalloc(asize * 20, lineno)))
546 strcpy(mallocedval, "{");
548 for (element = 0; element < asize; element++)
549 sprintf(mallocedval + strlen(mallocedval), "%d,", ((int *) var->value)[element]);
551 strcpy(mallocedval + strlen(mallocedval) - 1, "}");
554 sprintf(mallocedval, "%d", *((int *) var->value));
556 *tobeinserted_p = mallocedval;
559 case ECPGt_unsigned_short:
560 if (!(mallocedval = ECPGalloc(asize * 20, lineno)))
565 strcpy(mallocedval, "array [");
567 for (element = 0; element < asize; element++)
568 sprintf(mallocedval + strlen(mallocedval), "%hu,", ((unsigned short *) var->value)[element]);
570 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
573 sprintf(mallocedval, "%hu", *((unsigned short *) var->value));
575 *tobeinserted_p = mallocedval;
578 case ECPGt_unsigned_int:
579 if (!(mallocedval = ECPGalloc(asize * 20, lineno)))
584 strcpy(mallocedval, "array [");
586 for (element = 0; element < asize; element++)
587 sprintf(mallocedval + strlen(mallocedval), "%u,", ((unsigned int *) var->value)[element]);
589 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
592 sprintf(mallocedval, "%u", *((unsigned int *) var->value));
594 *tobeinserted_p = mallocedval;
598 if (!(mallocedval = ECPGalloc(asize * 20, lineno)))
603 strcpy(mallocedval, "array [");
605 for (element = 0; element < asize; element++)
606 sprintf(mallocedval + strlen(mallocedval), "%ld,", ((long *) var->value)[element]);
608 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
611 sprintf(mallocedval, "%ld", *((long *) var->value));
613 *tobeinserted_p = mallocedval;
616 case ECPGt_unsigned_long:
617 if (!(mallocedval = ECPGalloc(asize * 20, lineno)))
622 strcpy(mallocedval, "array [");
624 for (element = 0; element < asize; element++)
625 sprintf(mallocedval + strlen(mallocedval), "%lu,", ((unsigned long *) var->value)[element]);
627 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
630 sprintf(mallocedval, "%lu", *((unsigned long *) var->value));
632 *tobeinserted_p = mallocedval;
634 #ifdef HAVE_LONG_LONG_INT_64
635 case ECPGt_long_long:
636 if (!(mallocedval = ECPGalloc(asize * 30, lineno)))
641 strcpy(mallocedval, "array [");
643 for (element = 0; element < asize; element++)
644 sprintf(mallocedval + strlen(mallocedval), "%lld,", ((long long *) var->value)[element]);
646 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
649 sprintf(mallocedval, "%lld", *((long long *) var->value));
651 *tobeinserted_p = mallocedval;
654 case ECPGt_unsigned_long_long:
655 if (!(mallocedval = ECPGalloc(asize * 30, lineno)))
660 strcpy(mallocedval, "array [");
662 for (element = 0; element < asize; element++)
663 sprintf(mallocedval + strlen(mallocedval), "%llu,", ((unsigned long long *) var->value)[element]);
665 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
668 sprintf(mallocedval, "%llu", *((unsigned long long *) var->value));
670 *tobeinserted_p = mallocedval;
672 #endif /* HAVE_LONG_LONG_INT_64 */
674 if (!(mallocedval = ECPGalloc(asize * 25, lineno)))
679 strcpy(mallocedval, "array [");
681 for (element = 0; element < asize; element++)
682 sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((float *) var->value)[element]);
684 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
687 sprintf(mallocedval, "%.14g", *((float *) var->value));
689 *tobeinserted_p = mallocedval;
693 if (!(mallocedval = ECPGalloc(asize * 25, lineno)))
698 strcpy(mallocedval, "array [");
700 for (element = 0; element < asize; element++)
701 sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((double *) var->value)[element]);
703 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
706 sprintf(mallocedval, "%.14g", *((double *) var->value));
708 *tobeinserted_p = mallocedval;
712 if (!(mallocedval = ECPGalloc(var->arrsize + sizeof("array []"), lineno)))
715 if (var->arrsize > 1)
717 strcpy(mallocedval, "array [");
719 if (var->offset == sizeof(char))
720 for (element = 0; element < var->arrsize; element++)
721 sprintf(mallocedval + strlen(mallocedval), "%c,", (((char *) var->value)[element]) ? 't' : 'f');
724 * this is necessary since sizeof(C++'s bool)==sizeof(int)
726 else if (var->offset == sizeof(int))
727 for (element = 0; element < var->arrsize; element++)
728 sprintf(mallocedval + strlen(mallocedval), "%c,", (((int *) var->value)[element]) ? 't' : 'f');
730 ECPGraise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, "different size");
732 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
736 if (var->offset == sizeof(char))
737 sprintf(mallocedval, "%c", (*((char *) var->value)) ? 't' : 'f');
738 else if (var->offset == sizeof(int))
739 sprintf(mallocedval, "%c", (*((int *) var->value)) ? 't' : 'f');
741 ECPGraise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, "different size");
744 *tobeinserted_p = mallocedval;
748 case ECPGt_unsigned_char:
750 /* set slen to string length if type is char * */
751 int slen = (var->varcharsize == 0) ? strlen((char *) var->value) : var->varcharsize;
753 if (!(newcopy = ECPGalloc(slen + 1, lineno)))
756 strncpy(newcopy, (char *) var->value, slen);
757 newcopy[slen] = '\0';
759 mallocedval = quote_postgres(newcopy, quote, lineno);
763 *tobeinserted_p = mallocedval;
767 case ECPGt_char_variable:
769 int slen = strlen((char *) var->value);
771 if (!(mallocedval = ECPGalloc(slen + 1, lineno)))
774 strncpy(mallocedval, (char *) var->value, slen);
775 mallocedval[slen] = '\0';
777 *tobeinserted_p = mallocedval;
782 struct ECPGgeneric_varchar *variable =
783 (struct ECPGgeneric_varchar *) (var->value);
785 if (!(newcopy = (char *) ECPGalloc(variable->len + 1, lineno)))
788 strncpy(newcopy, variable->arr, variable->len);
789 newcopy[variable->len] = '\0';
791 mallocedval = quote_postgres(newcopy, quote, lineno);
795 *tobeinserted_p = mallocedval;
806 if (var->arrsize > 1)
808 for (element = 0; element < var->arrsize; element++)
810 nval = PGTYPESnumeric_new();
814 if (var->type == ECPGt_numeric)
815 PGTYPESnumeric_copy((numeric *) ((var + var->offset * element)->value), nval);
817 PGTYPESnumeric_from_decimal((decimal *) ((var + var->offset * element)->value), nval);
819 str = PGTYPESnumeric_to_asc(nval, nval->dscale);
821 PGTYPESnumeric_free(nval);
823 if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [] "), lineno)))
830 strcpy(mallocedval, "array [");
832 strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
833 strcpy(mallocedval + strlen(mallocedval), ",");
836 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
840 nval = PGTYPESnumeric_new();
844 if (var->type == ECPGt_numeric)
845 PGTYPESnumeric_copy((numeric *) (var->value), nval);
847 PGTYPESnumeric_from_decimal((decimal *) (var->value), nval);
849 str = PGTYPESnumeric_to_asc(nval, nval->dscale);
851 PGTYPESnumeric_free(nval);
853 if (!(mallocedval = ECPGalloc(slen + 1, lineno)))
859 strncpy(mallocedval, str, slen);
860 mallocedval[slen] = '\0';
864 *tobeinserted_p = mallocedval;
873 if (var->arrsize > 1)
875 for (element = 0; element < var->arrsize; element++)
877 str = quote_postgres(PGTYPESinterval_to_asc((interval *) ((var + var->offset * element)->value)), quote, lineno);
882 if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [],interval "), lineno)))
889 strcpy(mallocedval, "array [");
891 strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
892 strcpy(mallocedval + strlen(mallocedval), ",");
895 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
899 str = quote_postgres(PGTYPESinterval_to_asc((interval *) (var->value)), quote, lineno);
904 if (!(mallocedval = ECPGalloc(slen + sizeof("interval ") + 1, lineno)))
910 /* also copy trailing '\0' */
911 strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
915 *tobeinserted_p = mallocedval;
924 if (var->arrsize > 1)
926 for (element = 0; element < var->arrsize; element++)
928 str = quote_postgres(PGTYPESdate_to_asc(*(date *) ((var + var->offset * element)->value)), quote, lineno);
933 if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [],date "), lineno)))
940 strcpy(mallocedval, "array [");
942 strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
943 strcpy(mallocedval + strlen(mallocedval), ",");
946 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
950 str = quote_postgres(PGTYPESdate_to_asc(*(date *) (var->value)), quote, lineno);
955 if (!(mallocedval = ECPGalloc(slen + sizeof("date ") + 1, lineno)))
961 /* also copy trailing '\0' */
962 strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
966 *tobeinserted_p = mallocedval;
970 case ECPGt_timestamp:
975 if (var->arrsize > 1)
977 for (element = 0; element < var->arrsize; element++)
979 str = quote_postgres(PGTYPEStimestamp_to_asc(*(timestamp *) ((var + var->offset * element)->value)), quote, lineno);
985 if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [], timestamp "), lineno)))
992 strcpy(mallocedval, "array [");
994 strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
995 strcpy(mallocedval + strlen(mallocedval), ",");
998 strcpy(mallocedval + strlen(mallocedval) - 1, "]");
1002 str = quote_postgres(PGTYPEStimestamp_to_asc(*(timestamp *) (var->value)), quote, lineno);
1007 if (!(mallocedval = ECPGalloc(slen + sizeof("timestamp") + 1, lineno)))
1013 /* also copy trailing '\0' */
1014 strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
1018 *tobeinserted_p = mallocedval;
1022 case ECPGt_descriptor:
1026 /* Not implemented yet */
1027 ECPGraise(lineno, ECPG_UNSUPPORTED, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, (char *) ECPGtype_name(var->type));
1036 free_params(const char **paramValues, int nParams, bool print, int lineno)
1040 for (n = 0; n < nParams; n++)
1043 ECPGlog("ECPGexecute line %d: parameter %d = %s\n", lineno, n + 1, paramValues[n] ? paramValues[n] : "null");
1044 ECPGfree((void *)(paramValues[n]));
1046 ECPGfree(paramValues);
1050 ECPGexecute(struct statement * stmt)
1052 bool status = false;
1056 struct variable *var;
1057 int desc_counter = 0;
1058 const char * *paramValues = NULL;
1061 struct sqlca_t *sqlca = ECPGget_sqlca();
1062 bool clear_result = true;
1065 * If the type is one of the fill in types then we take the argument
1066 * and enter it to our parameter array at the first position. Then if there
1067 * are any more fill in types we add more parameters.
1072 const char *tobeinserted;
1075 tobeinserted = NULL;
1078 * A descriptor is a special case since it contains many variables but
1079 * is listed only once.
1081 if (var->type == ECPGt_descriptor)
1084 * We create an additional variable list here, so the same logic
1087 struct variable desc_inlist;
1088 struct descriptor *desc;
1089 struct descriptor_item *desc_item;
1091 for (desc = all_descriptors; desc; desc = desc->next)
1093 if (strcmp(var->pointer, desc->name) == 0)
1099 ECPGraise(stmt->lineno, ECPG_UNKNOWN_DESCRIPTOR, ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME, var->pointer);
1104 for (desc_item = desc->items; desc_item; desc_item = desc_item->next)
1106 if (desc_item->num == desc_counter)
1108 desc_inlist.type = ECPGt_char;
1109 desc_inlist.value = desc_item->data;
1110 desc_inlist.pointer = &(desc_item->data);
1111 desc_inlist.varcharsize = strlen(desc_item->data);
1112 desc_inlist.arrsize = 1;
1113 desc_inlist.offset = 0;
1114 if (!desc_item->indicator)
1116 desc_inlist.ind_type = ECPGt_NO_INDICATOR;
1117 desc_inlist.ind_value = desc_inlist.ind_pointer = NULL;
1118 desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = desc_inlist.ind_offset = 0;
1122 desc_inlist.ind_type = ECPGt_int;
1123 desc_inlist.ind_value = &(desc_item->indicator);
1124 desc_inlist.ind_pointer = &(desc_inlist.ind_value);
1125 desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = 1;
1126 desc_inlist.ind_offset = 0;
1128 if (!ECPGstore_input(stmt->lineno, stmt->force_indicator, &desc_inlist, &tobeinserted, false))
1134 if (desc->count == desc_counter)
1139 if (!ECPGstore_input(stmt->lineno, stmt->force_indicator, var, &tobeinserted, false))
1144 * now tobeinserted points to an area that contains the next parameter
1145 * if var->type=ECPGt_char_variable we have a dynamic cursor
1146 * we have to simulate a dynamic cursor because there is no backend functionality for it
1148 if (var->type != ECPGt_char_variable)
1151 if (!(paramValues = (const char **) ECPGrealloc(paramValues, sizeof(const char *) * nParams, stmt->lineno)))
1153 ECPGfree(paramValues);
1157 paramValues[nParams - 1] = tobeinserted;
1159 if ((position = next_insert(stmt->command, position, stmt->questionmarks) + 1) == 0)
1162 * We have an argument but we dont have the matched up
1163 * placeholder in the string
1165 ECPGraise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS,
1166 ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS,
1168 free_params(paramValues, nParams, false, stmt->lineno);
1172 /* let's see if this was an old style placeholder */
1173 if (stmt->command[position-1] == '?')
1175 /* yes, replace with new style */
1176 int buffersize = sizeof(int) * CHAR_BIT * 10 / 3; /* a rough guess of the size we need */
1177 char *buffer, *newcopy;
1179 if (!(buffer = (char *) ECPGalloc(buffersize, stmt->lineno)))
1181 free_params(paramValues, nParams, false, stmt->lineno);
1185 snprintf(buffer, buffersize, "$%d", counter++);
1187 if (!(newcopy = (char *) ECPGalloc(strlen(stmt->command) + strlen(buffer) + 1, stmt->lineno)))
1189 free_params(paramValues, nParams, false, stmt->lineno);
1194 strcpy(newcopy, stmt->command);
1196 /* set positional parameter */
1197 strcpy(newcopy + position - 1, buffer);
1200 * The strange thing in the second argument is the rest of the
1201 * string from the old string
1207 ECPGfree(stmt->command);
1208 stmt->command = newcopy;
1215 if (!(newcopy = (char *) ECPGalloc(strlen(stmt->command)
1216 + strlen(tobeinserted)
1217 + 1, stmt->lineno)))
1219 free_params(paramValues, nParams, false, stmt->lineno);
1223 strcpy(newcopy, stmt->command);
1224 if ((position = next_insert(stmt->command, position, stmt->questionmarks) + 1) == 0)
1227 * We have an argument but we dont have the matched up string
1230 ECPGraise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS,
1231 ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS,
1233 free_params(paramValues, nParams, false, stmt->lineno);
1239 int ph_len = (stmt->command[position] == '?') ? strlen("?") : strlen("$1");
1241 strcpy(newcopy + position - 1, tobeinserted);
1244 * The strange thing in the second argument is the rest of the
1245 * string from the old string
1253 ECPGfree(stmt->command);
1254 stmt->command = newcopy;
1256 ECPGfree((char *)tobeinserted);
1257 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 ECPGraise(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 (!ECPGcheck_PQresult(results, stmt->lineno, stmt->connection->connection, stmt->compat))
1280 free_params(paramValues, nParams, false, stmt->lineno);
1284 stmt->connection->committed = false;
1287 ECPGlog("ECPGexecute line %d: QUERY: %s with %d parameter 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 ECPGlog("ECPGexecute line %d: using PQexecPrepared for %s\n", stmt->lineno, stmt->command);
1297 results = PQexec(stmt->connection->connection, stmt->command);
1298 ECPGlog("ECPGexecute line %d: using PQexec\n", stmt->lineno);
1302 results = PQexecParams(stmt->connection->connection, stmt->command, nParams, NULL, paramValues, NULL, NULL, 0);
1303 ECPGlog("ECPGexecute line %d: using PQexecParams \n", stmt->lineno);
1307 free_params(paramValues, nParams, true, stmt->lineno);
1309 if (!ECPGcheck_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 ECPGlog("ECPGexecute line %d: Correctly got %d tuples with %d fields\n", stmt->lineno, ntuples, nfields);
1328 ECPGlog("ECPGexecute line %d: Incorrect number of matches: %d\n",
1329 stmt->lineno, ntuples);
1330 ECPGraise(stmt->lineno, ECPG_NOT_FOUND, ECPG_SQLSTATE_NO_DATA, NULL);
1335 if (var != NULL && var->type == ECPGt_descriptor)
1337 PGresult **resultpp = ECPGdescriptor_lvalue(stmt->lineno, (const char *) var->pointer);
1339 if (resultpp == NULL)
1345 *resultpp = results;
1346 clear_result = FALSE;
1347 ECPGlog("ECPGexecute putting result (%d tuples) into descriptor '%s'\n", PQntuples(results), (const char *) var->pointer);
1352 for (act_field = 0; act_field < nfields && status; act_field++)
1356 status = ECPGstore_result(results, act_field, stmt, var);
1359 else if (!INFORMIX_MODE(stmt->compat))
1361 ECPGraise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS, ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS, NULL);
1366 if (status && var != NULL)
1368 ECPGraise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS, ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS, NULL);
1373 case PGRES_COMMAND_OK:
1375 cmdstat = PQcmdStatus(results);
1376 sqlca->sqlerrd[1] = PQoidValue(results);
1377 sqlca->sqlerrd[2] = atol(PQcmdTuples(results));
1378 ECPGlog("ECPGexecute line %d Ok: %s\n", stmt->lineno, cmdstat);
1379 if (stmt->compat != ECPG_COMPAT_INFORMIX_SE &&
1380 !sqlca->sqlerrd[2] &&
1381 (!strncmp(cmdstat, "UPDATE", 6)
1382 || !strncmp(cmdstat, "INSERT", 6)
1383 || !strncmp(cmdstat, "DELETE", 6)))
1384 ECPGraise(stmt->lineno, ECPG_NOT_FOUND, ECPG_SQLSTATE_NO_DATA, NULL);
1386 case PGRES_COPY_OUT:
1391 ECPGlog("ECPGexecute line %d: Got PGRES_COPY_OUT\n", stmt->lineno);
1392 while ((res = PQgetCopyData(stmt->connection->connection,
1395 printf("%s", buffer);
1402 results = PQgetResult(stmt->connection->connection);
1403 if (PQresultStatus(results) == PGRES_COMMAND_OK)
1404 ECPGlog("ECPGexecute line %d: Got PGRES_COMMAND_OK after PGRES_COPY_OUT\n", stmt->lineno);
1406 ECPGlog("ECPGexecute line %d: Got error after PGRES_COPY_OUT: %s", PQresultErrorMessage(results));
1411 /* execution should never reach this code because it is already handled in ECPGcheck_PQresult() */
1412 ECPGlog("ECPGexecute line %d: Got something else, postgres error.\n",
1414 ECPGraise_backend(stmt->lineno, results, stmt->connection->connection, stmt->compat);
1421 /* check for asynchronous returns */
1422 notify = PQnotifies(stmt->connection->connection);
1425 ECPGlog("ECPGexecute line %d: ASYNC NOTIFY of '%s' from backend pid '%d' received\n",
1426 stmt->lineno, notify->relname, notify->be_pid);
1434 ECPGdo(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, const enum ECPG_statement_type st, const char *query,...)
1437 struct statement *stmt;
1438 struct connection *con;
1441 enum ECPGttype type;
1442 struct variable **list;
1443 enum ECPG_statement_type statement_type = st;
1448 ECPGraise(lineno, ECPG_EMPTY, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, NULL);
1452 /* Make sure we do NOT honor the locale for numeric input/output */
1453 /* since the database wants the standard decimal point */
1454 oldlocale = ECPGstrdup(setlocale(LC_NUMERIC, NULL), lineno);
1455 setlocale(LC_NUMERIC, "C");
1457 #ifdef ENABLE_THREAD_SAFETY
1458 ecpg_pthreads_init();
1461 con = ECPGget_connection(connection_name);
1463 if (!ECPGinit(con, connection_name, lineno))
1465 setlocale(LC_NUMERIC, oldlocale);
1466 ECPGfree(oldlocale);
1470 /* construct statement in our own structure */
1471 va_start(args, query);
1474 * create a list of variables
1475 * The variables are listed with input variables preceding outputvariables
1476 * The end of each group is marked by an end marker.
1477 * per variable we list:
1478 * type - as defined in ecpgtype.h
1479 * value - where to store the data
1480 * varcharsize - length of string in case we have a stringvariable, else 0
1481 * arraysize - 0 for pointer (we don't know the size of the array),
1482 * 1 for simple variable, size for arrays
1483 * offset - offset between ith and (i+1)th entry in an array,
1484 * normally that means sizeof(type)
1485 * ind_type - type of indicator variable
1486 * ind_value - pointer to indicator variable
1487 * ind_varcharsize - empty
1488 * ind_arraysize - arraysize of indicator array
1489 * ind_offset - indicator offset
1491 if (!(stmt = (struct statement *) ECPGalloc(sizeof(struct statement), lineno)))
1493 setlocale(LC_NUMERIC, oldlocale);
1494 ECPGfree(oldlocale);
1499 /* If statement type is ECPGst_prepnormal we are supposed to prepare
1500 * the statement before executing them */
1501 if (statement_type == ECPGst_prepnormal)
1503 if (!ECPGauto_prepare(lineno, connection_name, questionmarks, &prepname, query))
1506 /* statement is now prepared, so instead of the query we have to execute the name */
1507 stmt->command = prepname;
1508 statement_type = ECPGst_execute;
1511 stmt->command = ECPGstrdup(query, lineno);
1515 if (statement_type == ECPGst_execute)
1517 /* if we have an EXECUTE command, only the name is send */
1518 char *command = ECPGprepared(stmt->command, con, lineno);
1522 stmt->name = stmt->command;
1523 stmt->command = ECPGstrdup(command, lineno);
1526 ECPGraise(lineno, ECPG_INVALID_STMT, ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME, stmt->command);
1529 stmt->connection = con;
1530 stmt->lineno = lineno;
1531 stmt->compat = compat;
1532 stmt->force_indicator = force_indicator;
1533 stmt->questionmarks = questionmarks;
1534 stmt->statement_type = statement_type;
1536 list = &(stmt->inlist);
1538 type = va_arg(args, enum ECPGttype);
1540 while (type != ECPGt_EORT)
1542 if (type == ECPGt_EOIT)
1543 list = &(stmt->outlist);
1546 struct variable *var,
1549 if (!(var = (struct variable *) ECPGalloc(sizeof(struct variable), lineno)))
1551 setlocale(LC_NUMERIC, oldlocale);
1552 ECPGfree(oldlocale);
1553 free_statement(stmt);
1559 var->pointer = va_arg(args, char *);
1561 var->varcharsize = va_arg(args, long);
1562 var->arrsize = va_arg(args, long);
1563 var->offset = va_arg(args, long);
1565 if (var->arrsize == 0 || var->varcharsize == 0)
1566 var->value = *((char **) (var->pointer));
1568 var->value = var->pointer;
1571 * negative values are used to indicate an array without given bounds
1573 /* reset to zero for us */
1574 if (var->arrsize < 0)
1576 if (var->varcharsize < 0)
1577 var->varcharsize = 0;
1581 var->ind_type = va_arg(args, enum ECPGttype);
1582 var->ind_pointer = va_arg(args, char *);
1583 var->ind_varcharsize = va_arg(args, long);
1584 var->ind_arrsize = va_arg(args, long);
1585 var->ind_offset = va_arg(args, long);
1587 if (var->ind_type != ECPGt_NO_INDICATOR
1588 && (var->ind_arrsize == 0 || var->ind_varcharsize == 0))
1589 var->ind_value = *((char **) (var->ind_pointer));
1591 var->ind_value = var->ind_pointer;
1594 * negative values are used to indicate an array without given bounds
1596 /* reset to zero for us */
1597 if (var->ind_arrsize < 0)
1598 var->ind_arrsize = 0;
1599 if (var->ind_varcharsize < 0)
1600 var->ind_varcharsize = 0;
1602 /* if variable is NULL, the statement hasn't been prepared */
1603 if (var->pointer == NULL)
1605 ECPGraise(lineno, ECPG_INVALID_STMT, ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME, NULL);
1607 setlocale(LC_NUMERIC, oldlocale);
1608 ECPGfree(oldlocale);
1609 free_statement(stmt);
1614 for (ptr = *list; ptr && ptr->next; ptr = ptr->next);
1622 type = va_arg(args, enum ECPGttype);
1627 /* are we connected? */
1628 if (con == NULL || con->connection == NULL)
1630 free_statement(stmt);
1631 ECPGraise(lineno, ECPG_NOT_CONN, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, (con) ? con->name : "<empty>");
1632 setlocale(LC_NUMERIC, oldlocale);
1633 ECPGfree(oldlocale);
1637 /* initialize auto_mem struct */
1638 ECPGclear_auto_mem();
1640 status = ECPGexecute(stmt);
1641 free_statement(stmt);
1643 /* and reset locale value so our application is not affected */
1644 setlocale(LC_NUMERIC, oldlocale);
1645 ECPGfree(oldlocale);
1650 /* old descriptor interface */
1652 ECPGdo_descriptor(int line, const char *connection,
1653 const char *descriptor, const char *query)
1655 return ECPGdo(line, ECPG_COMPAT_PGSQL, true, connection, '\0', 0, (char *) query, ECPGt_EOIT,
1656 ECPGt_descriptor, descriptor, 0L, 0L, 0L,
1657 ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EORT);