PostgreSQL Source Code git master
Loading...
Searching...
No Matches
descriptor.c
Go to the documentation of this file.
1/*
2 * dynamic SQL support routines
3 *
4 * src/interfaces/ecpg/ecpglib/descriptor.c
5 */
6
7#define POSTGRES_ECPG_INTERNAL
8#include "postgres_fe.h"
9
10#include "catalog/pg_type_d.h"
11#include "ecpg-pthread-win32.h"
12#include "ecpgerrno.h"
13#include "ecpglib.h"
14#include "ecpglib_extern.h"
15#include "ecpgtype.h"
16#include "sql3types.h"
17#include "sqlca.h"
18#include "sqlda.h"
19
20static void descriptor_free(struct descriptor *desc);
21
22/* We manage descriptors separately for each thread. */
25
26static void descriptor_deallocate_all(struct descriptor *list);
27
28static void
33
34static void
39
40static struct descriptor *
46
47static void
52
53/* old internal convenience function that might go away later */
54static PGresult *
55ecpg_result_by_descriptor(int line, const char *name)
56{
57 struct descriptor *desc = ecpg_find_desc(line, name);
58
59 if (desc == NULL)
60 return NULL;
61 return desc->result;
62}
63
64static unsigned int
66{
67 switch (type)
68 {
69 case DATEOID:
70 return SQL3_DDT_DATE;
71 case TIMEOID:
72 return SQL3_DDT_TIME;
73 case TIMESTAMPOID:
74 return SQL3_DDT_TIMESTAMP;
75 case TIMESTAMPTZOID:
77 case TIMETZOID:
79 default:
80 return SQL3_DDT_ILLEGAL;
81 }
82}
83
84bool
85ECPGget_desc_header(int lineno, const char *desc_name, int *count)
86{
88 struct sqlca_t *sqlca = ECPGget_sqlca();
89
90 if (sqlca == NULL)
91 {
94 return false;
95 }
96
98 ECPGresult = ecpg_result_by_descriptor(lineno, desc_name);
99 if (!ECPGresult)
100 return false;
101
102 *count = PQnfields(ECPGresult);
103 sqlca->sqlerrd[2] = 1;
104 ecpg_log("ECPGget_desc_header: found %d attributes\n", *count);
105 return true;
106}
107
108static bool
109get_int_item(int lineno, void *var, enum ECPGttype vartype, int value)
110{
111 switch (vartype)
112 {
113 case ECPGt_short:
114 *(short *) var = (short) value;
115 break;
116 case ECPGt_int:
117 *(int *) var = value;
118 break;
119 case ECPGt_long:
120 *(long *) var = (long) value;
121 break;
123 *(unsigned short *) var = (unsigned short) value;
124 break;
126 *(unsigned int *) var = (unsigned int) value;
127 break;
129 *(unsigned long *) var = (unsigned long) value;
130 break;
131 case ECPGt_long_long:
132 *(long long int *) var = (long long int) value;
133 break;
135 *(unsigned long long int *) var = (unsigned long long int) value;
136 break;
137 case ECPGt_float:
138 *(float *) var = (float) value;
139 break;
140 case ECPGt_double:
141 *(double *) var = (double) value;
142 break;
143 default:
145 return false;
146 }
147
148 return true;
149}
150
151static bool
152set_int_item(int lineno, int *target, const void *var, enum ECPGttype vartype)
153{
154 switch (vartype)
155 {
156 case ECPGt_short:
157 *target = *(const short *) var;
158 break;
159 case ECPGt_int:
160 *target = *(const int *) var;
161 break;
162 case ECPGt_long:
163 *target = *(const long *) var;
164 break;
166 *target = *(const unsigned short *) var;
167 break;
169 *target = *(const unsigned int *) var;
170 break;
172 *target = *(const unsigned long *) var;
173 break;
174 case ECPGt_long_long:
175 *target = *(const long long int *) var;
176 break;
178 *target = *(const unsigned long long int *) var;
179 break;
180 case ECPGt_float:
181 *target = *(const float *) var;
182 break;
183 case ECPGt_double:
184 *target = *(const double *) var;
185 break;
186 default:
188 return false;
189 }
190
191 return true;
192}
193
194static bool
195get_char_item(int lineno, void *var, enum ECPGttype vartype, char *value, int varcharsize)
196{
197 switch (vartype)
198 {
199 case ECPGt_char:
201 case ECPGt_string:
202 strncpy(var, value, varcharsize);
203 break;
204 case ECPGt_varchar:
205 {
207 (struct ECPGgeneric_varchar *) var;
208
209 if (varcharsize == 0)
211 else
212 strncpy(variable->arr, value, varcharsize);
213
214 variable->len = strlen(value);
215 if (varcharsize > 0 && variable->len > varcharsize)
216 variable->len = varcharsize;
217 }
218 break;
219 default:
221 return false;
222 }
223
224 return true;
225}
226
227#define RETURN_IF_NO_DATA if (ntuples < 1) \
228 { \
229 va_end(args); \
230 ecpg_raise(lineno, ECPG_NOT_FOUND, ECPG_SQLSTATE_NO_DATA, NULL); \
231 return false; \
232 }
233
234bool
235ECPGget_desc(int lineno, const char *desc_name, int index, ...)
236{
237 va_list args;
239 enum ECPGdtype type;
240 int ntuples,
241 act_tuple;
242 struct variable data_var;
243 struct sqlca_t *sqlca = ECPGget_sqlca();
244 bool alloc_failed = (sqlca == NULL);
245
246 if (alloc_failed)
247 {
250 return false;
251 }
252
253 va_start(args, index);
255 ECPGresult = ecpg_result_by_descriptor(lineno, desc_name);
256 if (!ECPGresult)
257 {
258 va_end(args);
259 return false;
260 }
261
262 ntuples = PQntuples(ECPGresult);
263
265 {
267 va_end(args);
268 return false;
269 }
270
271 ecpg_log("ECPGget_desc: reading items for tuple %d\n", index);
272 --index;
273
274 type = va_arg(args, enum ECPGdtype);
275
276 memset(&data_var, 0, sizeof data_var);
277 data_var.type = ECPGt_EORT;
278 data_var.ind_type = ECPGt_NO_INDICATOR;
279
280 while (type != ECPGd_EODT)
281 {
282 char type_str[20];
283 long varcharsize;
284 long offset;
285 long arrsize;
286 enum ECPGttype vartype;
287 void *var;
288
289 vartype = va_arg(args, enum ECPGttype);
290 var = va_arg(args, void *);
291 varcharsize = va_arg(args, long);
292 arrsize = va_arg(args, long);
293 offset = va_arg(args, long);
294
295 switch (type)
296 {
297 case (ECPGd_indicator):
299 data_var.ind_type = vartype;
300 data_var.ind_pointer = var;
301 data_var.ind_varcharsize = varcharsize;
302 data_var.ind_arrsize = arrsize;
303 data_var.ind_offset = offset;
304 if (data_var.ind_arrsize == 0 || data_var.ind_varcharsize == 0)
305 data_var.ind_value = *((void **) (data_var.ind_pointer));
306 else
307 data_var.ind_value = data_var.ind_pointer;
308 break;
309
310 case ECPGd_data:
312 data_var.type = vartype;
313 data_var.pointer = var;
314 data_var.varcharsize = varcharsize;
315 data_var.arrsize = arrsize;
316 data_var.offset = offset;
317 if (data_var.arrsize == 0 || data_var.varcharsize == 0)
318 data_var.value = *((void **) (data_var.pointer));
319 else
320 data_var.value = data_var.pointer;
321 break;
322
323 case ECPGd_name:
324 if (!get_char_item(lineno, var, vartype, PQfname(ECPGresult, index), varcharsize))
325 {
326 va_end(args);
327 return false;
328 }
329
330 ecpg_log("ECPGget_desc: NAME = %s\n", PQfname(ECPGresult, index));
331 break;
332
333 case ECPGd_nullable:
334 if (!get_int_item(lineno, var, vartype, 1))
335 {
336 va_end(args);
337 return false;
338 }
339
340 break;
341
342 case ECPGd_key_member:
343 if (!get_int_item(lineno, var, vartype, 0))
344 {
345 va_end(args);
346 return false;
347 }
348
349 break;
350
351 case ECPGd_scale:
352 if (!get_int_item(lineno, var, vartype, (PQfmod(ECPGresult, index) - VARHDRSZ) & 0xffff))
353 {
354 va_end(args);
355 return false;
356 }
357
358 ecpg_log("ECPGget_desc: SCALE = %d\n", (PQfmod(ECPGresult, index) - VARHDRSZ) & 0xffff);
359 break;
360
361 case ECPGd_precision:
362 if (!get_int_item(lineno, var, vartype, PQfmod(ECPGresult, index) >> 16))
363 {
364 va_end(args);
365 return false;
366 }
367
368 ecpg_log("ECPGget_desc: PRECISION = %d\n", PQfmod(ECPGresult, index) >> 16);
369 break;
370
371 case ECPGd_octet:
372 if (!get_int_item(lineno, var, vartype, PQfsize(ECPGresult, index)))
373 {
374 va_end(args);
375 return false;
376 }
377
378 ecpg_log("ECPGget_desc: OCTET_LENGTH = %d\n", PQfsize(ECPGresult, index));
379 break;
380
381 case ECPGd_length:
382 if (!get_int_item(lineno, var, vartype, PQfmod(ECPGresult, index) - VARHDRSZ))
383 {
384 va_end(args);
385 return false;
386 }
387
388 ecpg_log("ECPGget_desc: LENGTH = %d\n", PQfmod(ECPGresult, index) - VARHDRSZ);
389 break;
390
391 case ECPGd_type:
392 if (!get_int_item(lineno, var, vartype, ecpg_dynamic_type(PQftype(ECPGresult, index))))
393 {
394 va_end(args);
395 return false;
396 }
397
398 ecpg_log("ECPGget_desc: TYPE = %d\n", ecpg_dynamic_type(PQftype(ECPGresult, index)));
399 break;
400
401 case ECPGd_di_code:
402 if (!get_int_item(lineno, var, vartype, ecpg_dynamic_type_DDT(PQftype(ECPGresult, index))))
403 {
404 va_end(args);
405 return false;
406 }
407
408 ecpg_log("ECPGget_desc: TYPE = %d\n", ecpg_dynamic_type_DDT(PQftype(ECPGresult, index)));
409 break;
410
412 if (!get_int_item(lineno, var, vartype, PQntuples(ECPGresult)))
413 {
414 va_end(args);
415 return false;
416 }
417
418 ecpg_log("ECPGget_desc: CARDINALITY = %d\n", PQntuples(ECPGresult));
419 break;
420
421 case ECPGd_ret_length:
422 case ECPGd_ret_octet:
423
425
426 /*
427 * this is like ECPGstore_result
428 */
429 if (arrsize > 0 && ntuples > arrsize)
430 {
431 ecpg_log("ECPGget_desc on line %d: incorrect number of matches; %d don't fit into array of %ld\n",
432 lineno, ntuples, arrsize);
434 va_end(args);
435 return false;
436 }
437 /* allocate storage if needed */
438 if (arrsize == 0 && *(void **) var == NULL)
439 {
440 void *mem = ecpg_auto_alloc(offset * ntuples, lineno);
441
442 if (!mem)
443 {
444 va_end(args);
445 return false;
446 }
447 *(void **) var = mem;
448 var = mem;
449 }
450
451 for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
452 {
453 if (!get_int_item(lineno, var, vartype, PQgetlength(ECPGresult, act_tuple, index)))
454 {
455 va_end(args);
456 return false;
457 }
458 var = (char *) var + offset;
459 ecpg_log("ECPGget_desc: RETURNED[%d] = %d\n", act_tuple, PQgetlength(ECPGresult, act_tuple, index));
460 }
461 break;
462
463 default:
464 snprintf(type_str, sizeof(type_str), "%d", type);
466 va_end(args);
467 return false;
468 }
469
470 type = va_arg(args, enum ECPGdtype);
471 }
472
473 if (data_var.type != ECPGt_EORT)
474 {
475 struct statement stmt;
476
477 memset(&stmt, 0, sizeof stmt);
478 stmt.lineno = lineno;
479
480 /* desperate try to guess something sensible */
481 stmt.connection = ecpg_get_connection(NULL);
482 if (stmt.connection == NULL)
483 {
485 ecpg_gettext("NULL"));
486 va_end(args);
487 return false;
488 }
489
490 /* Make sure we do NOT honor the locale for numeric input */
491 /* since the database gives the standard decimal point */
492 /* (see comments in execute.c) */
493#ifdef HAVE_USELOCALE
494
495 /*
496 * To get here, the above PQnfields() test must have found nonzero
497 * fields. One needs a connection to create such a descriptor. (EXEC
498 * SQL SET DESCRIPTOR can populate the descriptor's "items", but it
499 * can't change the descriptor's PQnfields().) Any successful
500 * connection initializes ecpg_clocale.
501 */
503 stmt.oldlocale = uselocale(ecpg_clocale);
504#else
505#ifdef WIN32
507#endif
510 if (alloc_failed)
511 {
512 va_end(args);
513 return false;
514 }
515
516 setlocale(LC_NUMERIC, "C");
517#endif
518
520
521#ifdef HAVE_USELOCALE
522 if (stmt.oldlocale != (locale_t) 0)
523 uselocale(stmt.oldlocale);
524#else
525 if (stmt.oldlocale)
526 {
527 setlocale(LC_NUMERIC, stmt.oldlocale);
528 ecpg_free(stmt.oldlocale);
529 }
530#ifdef WIN32
531 if (stmt.oldthreadlocale != -1)
532 _configthreadlocale(stmt.oldthreadlocale);
533#endif
534#endif
535 }
536 else if (data_var.ind_type != ECPGt_NO_INDICATOR && data_var.ind_pointer != NULL)
537
538 /*
539 * ind_type != NO_INDICATOR should always have ind_pointer != NULL but
540 * since this might be changed manually in the .c file let's play it
541 * safe
542 */
543 {
544 /*
545 * this is like ECPGstore_result but since we don't have a data
546 * variable at hand, we can't call it
547 */
548 if (data_var.ind_arrsize > 0 && ntuples > data_var.ind_arrsize)
549 {
550 ecpg_log("ECPGget_desc on line %d: incorrect number of matches (indicator); %d don't fit into array of %ld\n",
551 lineno, ntuples, data_var.ind_arrsize);
553 va_end(args);
554 return false;
555 }
556
557 /* allocate storage if needed */
558 if (data_var.ind_arrsize == 0 && data_var.ind_value == NULL)
559 {
560 void *mem = ecpg_auto_alloc(data_var.ind_offset * ntuples, lineno);
561
562 if (!mem)
563 {
564 va_end(args);
565 return false;
566 }
567 *(void **) data_var.ind_pointer = mem;
568 data_var.ind_value = mem;
569 }
570
571 for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
572 {
574 {
575 va_end(args);
576 return false;
577 }
578 data_var.ind_value = (char *) data_var.ind_value + data_var.ind_offset;
579 ecpg_log("ECPGget_desc: INDICATOR[%d] = %d\n", act_tuple, -PQgetisnull(ECPGresult, act_tuple, index));
580 }
581 }
582 sqlca->sqlerrd[2] = ntuples;
583 va_end(args);
584 return true;
585}
586
587#undef RETURN_IF_NO_DATA
588
589bool
590ECPGset_desc_header(int lineno, const char *desc_name, int count)
591{
592 struct descriptor *desc = ecpg_find_desc(lineno, desc_name);
593
594 if (desc == NULL)
595 return false;
596 desc->count = count;
597 return true;
598}
599
600static void
602 char *tobeinserted)
603{
604 if (var->type != ECPGt_bytea)
605 desc_item->is_binary = false;
606
607 else
608 {
610 (struct ECPGgeneric_bytea *) (var->value);
611
612 desc_item->is_binary = true;
613 desc_item->data_len = variable->len;
614 }
615
616 ecpg_free(desc_item->data); /* free() takes care of a potential NULL value */
617 desc_item->data = tobeinserted;
618}
619
620
621bool
622ECPGset_desc(int lineno, const char *desc_name, int index, ...)
623{
624 va_list args;
625 struct descriptor *desc;
627 struct variable *var;
628
629 desc = ecpg_find_desc(lineno, desc_name);
630 if (desc == NULL)
631 return false;
632
633 for (desc_item = desc->items; desc_item; desc_item = desc_item->next)
634 {
635 if (desc_item->num == index)
636 break;
637 }
638
639 if (desc_item == NULL)
640 {
641 desc_item = (struct descriptor_item *) ecpg_alloc(sizeof(*desc_item), lineno);
642 if (!desc_item)
643 return false;
644 desc_item->num = index;
645 if (desc->count < index)
646 desc->count = index;
647 desc_item->next = desc->items;
648 desc->items = desc_item;
649 }
650
651 if (!(var = (struct variable *) ecpg_alloc(sizeof(struct variable), lineno)))
652 return false;
653
654 va_start(args, index);
655
656 for (;;)
657 {
658 enum ECPGdtype itemtype;
659 char *tobeinserted = NULL;
660
661 itemtype = va_arg(args, enum ECPGdtype);
662
663 if (itemtype == ECPGd_EODT)
664 break;
665
666 var->type = va_arg(args, enum ECPGttype);
667 var->pointer = va_arg(args, char *);
668
669 var->varcharsize = va_arg(args, long);
670 var->arrsize = va_arg(args, long);
671 var->offset = va_arg(args, long);
672
673 if (var->arrsize == 0 || var->varcharsize == 0)
674 var->value = *((char **) (var->pointer));
675 else
676 var->value = var->pointer;
677
678 /*
679 * negative values are used to indicate an array without given bounds
680 */
681 /* reset to zero for us */
682 if (var->arrsize < 0)
683 var->arrsize = 0;
684 if (var->varcharsize < 0)
685 var->varcharsize = 0;
686
687 var->next = NULL;
688
689 switch (itemtype)
690 {
691 case ECPGd_data:
692 {
693 if (!ecpg_store_input(lineno, true, var, &tobeinserted, false))
694 {
695 ecpg_free(var);
696 va_end(args);
697 return false;
698 }
699
702 break;
703 }
704
705 case ECPGd_indicator:
706 set_int_item(lineno, &desc_item->indicator, var->pointer, var->type);
707 break;
708
709 case ECPGd_length:
710 set_int_item(lineno, &desc_item->length, var->pointer, var->type);
711 break;
712
713 case ECPGd_precision:
714 set_int_item(lineno, &desc_item->precision, var->pointer, var->type);
715 break;
716
717 case ECPGd_scale:
718 set_int_item(lineno, &desc_item->scale, var->pointer, var->type);
719 break;
720
721 case ECPGd_type:
722 set_int_item(lineno, &desc_item->type, var->pointer, var->type);
723 break;
724
725 default:
726 {
727 char type_str[20];
728
729 snprintf(type_str, sizeof(type_str), "%d", itemtype);
731 ecpg_free(var);
732 va_end(args);
733 return false;
734 }
735 }
736 }
737 ecpg_free(var);
738 va_end(args);
739
740 return true;
741}
742
743/* Free the descriptor and items in it. */
744static void
746{
748
749 for (desc_item = desc->items; desc_item;)
750 {
751 struct descriptor_item *di;
752
753 ecpg_free(desc_item->data);
754 di = desc_item;
755 desc_item = desc_item->next;
756 ecpg_free(di);
757 }
758
759 ecpg_free(desc->name);
760 PQclear(desc->result);
761 ecpg_free(desc);
762}
763
764bool
765ECPGdeallocate_desc(int line, const char *name)
766{
767 struct descriptor *desc;
768 struct descriptor *prev;
769 struct sqlca_t *sqlca = ECPGget_sqlca();
770
771 if (sqlca == NULL)
772 {
775 return false;
776 }
777
779 for (desc = get_descriptors(), prev = NULL; desc; prev = desc, desc = desc->next)
780 {
781 if (strcmp(name, desc->name) == 0)
782 {
783 if (prev)
784 prev->next = desc->next;
785 else
786 set_descriptors(desc->next);
787 descriptor_free(desc);
788 return true;
789 }
790 }
792 return false;
793}
794
795/* Deallocate all descriptors in the list */
796static void
798{
799 while (list)
800 {
801 struct descriptor *next = list->next;
802
803 descriptor_free(list);
804 list = next;
805 }
806}
807
808bool
809ECPGallocate_desc(int line, const char *name)
810{
811 struct descriptor *new;
812 struct sqlca_t *sqlca = ECPGget_sqlca();
813
814 if (sqlca == NULL)
815 {
818 return false;
819 }
820
822 new = (struct descriptor *) ecpg_alloc(sizeof(struct descriptor), line);
823 if (!new)
824 return false;
825 new->next = get_descriptors();
826 new->name = ecpg_alloc(strlen(name) + 1, line);
827 if (!new->name)
828 {
829 ecpg_free(new);
830 return false;
831 }
832 new->count = -1;
833 new->items = NULL;
834 new->result = PQmakeEmptyPGresult(NULL, 0);
835 if (!new->result)
836 {
837 ecpg_free(new->name);
838 ecpg_free(new);
840 return false;
841 }
842 strcpy(new->name, name);
843 set_descriptors(new);
844 return true;
845}
846
847/* Find descriptor with name in the connection. */
848struct descriptor *
849ecpg_find_desc(int line, const char *name)
850{
851 struct descriptor *desc;
852
853 for (desc = get_descriptors(); desc; desc = desc->next)
854 {
855 if (strcmp(name, desc->name) == 0)
856 return desc;
857 }
858
860 return NULL; /* not found */
861}
862
863bool
864ECPGdescribe(int line, int compat, bool input, const char *connection_name, const char *stmt_name, ...)
865{
866 bool ret = false;
867 struct connection *con;
868 struct prepared_statement *prep;
869 PGresult *res;
870 va_list args;
871
872 /* DESCRIBE INPUT is not yet supported */
873 if (input)
874 {
876 return ret;
877 }
878
880 if (!con)
881 {
884 return ret;
885 }
886 prep = ecpg_find_prepared_statement(stmt_name, con, NULL);
887 if (!prep)
888 {
890 return ret;
891 }
892
893 va_start(args, stmt_name);
894
895 for (;;)
896 {
897 enum ECPGttype type;
898 void *ptr;
899
900 /* variable type */
901 type = va_arg(args, enum ECPGttype);
902
903 if (type == ECPGt_EORT)
904 break;
905
906 /* rest of variable parameters */
907 ptr = va_arg(args, void *);
908 (void) va_arg(args, long); /* skip args */
909 (void) va_arg(args, long);
910 (void) va_arg(args, long);
911
912 /* variable indicator */
913 (void) va_arg(args, enum ECPGttype);
914 (void) va_arg(args, void *); /* skip args */
915 (void) va_arg(args, long);
916 (void) va_arg(args, long);
917 (void) va_arg(args, long);
918
919 switch (type)
920 {
921 case ECPGt_descriptor:
922 {
923 char *name = ptr;
924 struct descriptor *desc = ecpg_find_desc(line, name);
925
926 if (desc == NULL)
927 break;
928
929 res = PQdescribePrepared(con->connection, stmt_name);
930 if (!ecpg_check_PQresult(res, line, con->connection, compat))
931 break;
932
933 PQclear(desc->result);
934
935 desc->result = res;
936 ret = true;
937 break;
938 }
939 case ECPGt_sqlda:
940 {
942 {
943 struct sqlda_compat **_sqlda = ptr;
944 struct sqlda_compat *sqlda;
945
946 res = PQdescribePrepared(con->connection, stmt_name);
947 if (!ecpg_check_PQresult(res, line, con->connection, compat))
948 break;
949
950 sqlda = ecpg_build_compat_sqlda(line, res, -1, compat);
951 if (sqlda)
952 {
953 struct sqlda_compat *sqlda_old = *_sqlda;
954 struct sqlda_compat *sqlda_old1;
955
956 while (sqlda_old)
957 {
961 }
962
963 *_sqlda = sqlda;
964 ret = true;
965 }
966
967 PQclear(res);
968 }
969 else
970 {
971 struct sqlda_struct **_sqlda = ptr;
972 struct sqlda_struct *sqlda;
973
974 res = PQdescribePrepared(con->connection, stmt_name);
975 if (!ecpg_check_PQresult(res, line, con->connection, compat))
976 break;
977
978 sqlda = ecpg_build_native_sqlda(line, res, -1, compat);
979 if (sqlda)
980 {
981 struct sqlda_struct *sqlda_old = *_sqlda;
982 struct sqlda_struct *sqlda_old1;
983
984 while (sqlda_old)
985 {
989 }
990
991 *_sqlda = sqlda;
992 ret = true;
993 }
994
995 PQclear(res);
996 }
997 break;
998 }
999 default:
1000 /* nothing else may come */
1001 ;
1002 }
1003 }
1004
1005 va_end(args);
1006
1007 return ret;
1008}
static int32 next
Definition blutils.c:225
#define VARHDRSZ
Definition c.h:781
#define Assert(condition)
Definition c.h:943
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
struct connection * ecpg_get_connection(const char *connection_name)
Definition connect.c:76
enum COMPAT_MODE compat
Definition ecpg.c:26
#define ECPG_UNKNOWN_DESCRIPTOR
Definition ecpgerrno.h:43
#define ECPG_UNSUPPORTED
Definition ecpgerrno.h:19
#define ECPG_UNKNOWN_DESCRIPTOR_ITEM
Definition ecpgerrno.h:45
#define ECPG_INVALID_DESCRIPTOR_INDEX
Definition ecpgerrno.h:44
#define ECPG_INVALID_STMT
Definition ecpgerrno.h:40
#define ECPG_VAR_NOT_NUMERIC
Definition ecpgerrno.h:46
#define ECPG_VAR_NOT_CHAR
Definition ecpgerrno.h:47
#define ECPG_TOO_MANY_MATCHES
Definition ecpgerrno.h:22
#define ECPG_OUT_OF_MEMORY
Definition ecpgerrno.h:16
#define ECPG_NO_CONN
Definition ecpgerrno.h:37
bool ECPGdeallocate_desc(int line, const char *name)
Definition descriptor.c:765
bool ECPGget_desc(int lineno, const char *desc_name, int index,...)
Definition descriptor.c:235
struct descriptor * ecpg_find_desc(int line, const char *name)
Definition descriptor.c:849
static pthread_key_t descriptor_key
Definition descriptor.c:23
bool ECPGallocate_desc(int line, const char *name)
Definition descriptor.c:809
static bool get_char_item(int lineno, void *var, enum ECPGttype vartype, char *value, int varcharsize)
Definition descriptor.c:195
#define RETURN_IF_NO_DATA
Definition descriptor.c:227
static void set_descriptors(struct descriptor *value)
Definition descriptor.c:48
bool ECPGset_desc_header(int lineno, const char *desc_name, int count)
Definition descriptor.c:590
static void descriptor_free(struct descriptor *desc)
Definition descriptor.c:745
static PGresult * ecpg_result_by_descriptor(int line, const char *name)
Definition descriptor.c:55
static void descriptor_destructor(void *arg)
Definition descriptor.c:29
static void descriptor_key_init(void)
Definition descriptor.c:35
static bool get_int_item(int lineno, void *var, enum ECPGttype vartype, int value)
Definition descriptor.c:109
bool ECPGdescribe(int line, int compat, bool input, const char *connection_name, const char *stmt_name,...)
Definition descriptor.c:864
static struct descriptor * get_descriptors(void)
Definition descriptor.c:41
bool ECPGset_desc(int lineno, const char *desc_name, int index,...)
Definition descriptor.c:622
static void descriptor_deallocate_all(struct descriptor *list)
Definition descriptor.c:797
static unsigned int ecpg_dynamic_type_DDT(Oid type)
Definition descriptor.c:65
static pthread_once_t descriptor_once
Definition descriptor.c:24
bool ECPGget_desc_header(int lineno, const char *desc_name, int *count)
Definition descriptor.c:85
static bool set_int_item(int lineno, int *target, const void *var, enum ECPGttype vartype)
Definition descriptor.c:152
static void set_desc_attr(struct descriptor_item *desc_item, struct variable *var, char *tobeinserted)
Definition descriptor.c:601
bool ecpg_store_result(const PGresult *results, int act_field, const struct statement *stmt, struct variable *var)
Definition execute.c:307
bool ecpg_check_PQresult(PGresult *results, int lineno, PGconn *connection, enum COMPAT_MODE compat)
Definition error.c:281
#define ecpg_gettext(x)
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
char * ecpg_strdup(const char *string, int lineno, bool *alloc_failed)
Definition memory.c:54
#define ECPG_SQLSTATE_RESTRICTED_DATA_TYPE_ATTRIBUTE_VIOLATION
char * ecpg_alloc(long size, int lineno)
Definition memory.c:19
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR
struct sqlda_struct * ecpg_build_native_sqlda(int line, PGresult *res, int row, enum COMPAT_MODE compat)
Definition sqlda.c:412
char * ecpg_auto_alloc(long size, int lineno)
Definition memory.c:110
bool ecpg_store_input(const int lineno, const bool force_indicator, const struct variable *var, char **tobeinserted_p, bool quote)
Definition execute.c:510
void ecpg_log(const char *format,...) pg_attribute_printf(1
struct sqlda_compat * ecpg_build_compat_sqlda(int line, PGresult *res, int row, enum COMPAT_MODE compat)
Definition sqlda.c:205
#define ECPG_SQLSTATE_CARDINALITY_VIOLATION
#define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME
#define INFORMIX_MODE(X)
#define ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX
struct prepared_statement * ecpg_find_prepared_statement(const char *name, struct connection *con, struct prepared_statement **prev_)
Definition prepare.c:271
int ecpg_dynamic_type(Oid type)
Definition typename.c:73
#define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition error.c:13
void ecpg_free(void *ptr)
Definition memory.c:13
void ecpg_init_sqlca(struct sqlca_t *sqlca_p)
Definition misc.c:67
#define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME
ECPGttype
Definition ecpgtype.h:42
@ ECPGt_float
Definition ecpgtype.h:47
@ ECPGt_long_long
Definition ecpgtype.h:45
@ ECPGt_sqlda
Definition ecpgtype.h:66
@ ECPGt_short
Definition ecpgtype.h:43
@ ECPGt_bytea
Definition ecpgtype.h:67
@ ECPGt_varchar
Definition ecpgtype.h:48
@ ECPGt_unsigned_short
Definition ecpgtype.h:43
@ ECPGt_int
Definition ecpgtype.h:44
@ ECPGt_long
Definition ecpgtype.h:44
@ ECPGt_unsigned_char
Definition ecpgtype.h:43
@ ECPGt_double
Definition ecpgtype.h:47
@ ECPGt_NO_INDICATOR
Definition ecpgtype.h:64
@ ECPGt_EORT
Definition ecpgtype.h:63
@ ECPGt_unsigned_long
Definition ecpgtype.h:44
@ ECPGt_unsigned_long_long
Definition ecpgtype.h:45
@ ECPGt_unsigned_int
Definition ecpgtype.h:44
@ ECPGt_descriptor
Definition ecpgtype.h:59
@ ECPGt_char
Definition ecpgtype.h:43
@ ECPGt_string
Definition ecpgtype.h:65
ECPGdtype
Definition ecpgtype.h:72
@ ECPGd_scale
Definition ecpgtype.h:86
@ ECPGd_precision
Definition ecpgtype.h:83
@ ECPGd_length
Definition ecpgtype.h:79
@ ECPGd_nullable
Definition ecpgtype.h:81
@ ECPGd_type
Definition ecpgtype.h:87
@ ECPGd_cardinality
Definition ecpgtype.h:89
@ ECPGd_indicator
Definition ecpgtype.h:77
@ ECPGd_ret_length
Definition ecpgtype.h:84
@ ECPGd_di_code
Definition ecpgtype.h:75
@ ECPGd_name
Definition ecpgtype.h:80
@ ECPGd_key_member
Definition ecpgtype.h:78
@ ECPGd_EODT
Definition ecpgtype.h:88
@ ECPGd_octet
Definition ecpgtype.h:82
@ ECPGd_ret_octet
Definition ecpgtype.h:85
@ ECPGd_data
Definition ecpgtype.h:74
Datum arg
Definition elog.c:1323
Oid PQftype(const PGresult *res, int field_num)
Definition fe-exec.c:3750
PGresult * PQdescribePrepared(PGconn *conn, const char *stmt)
Definition fe-exec.c:2472
PGresult * PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status)
Definition fe-exec.c:160
int PQfmod(const PGresult *res, int field_num)
Definition fe-exec.c:3772
int PQfsize(const PGresult *res, int field_num)
Definition fe-exec.c:3761
#define stmt
FILE * input
static struct @177 value
struct sqlca_t * ECPGget_sqlca(void)
Definition misc.c:108
#define PQgetlength
#define PQclear
#define PQnfields
#define PQgetisnull
#define PQfname
#define PQntuples
#define snprintf
Definition port.h:261
unsigned int Oid
static int fb(int x)
void pthread_setspecific(pthread_key_t key, void *val)
void * pthread_getspecific(pthread_key_t key)
ULONG pthread_key_t
int pthread_once_t
#define free(a)
@ SQL3_DDT_TIME_WITH_TIME_ZONE
Definition sql3types.h:36
@ SQL3_DDT_DATE
Definition sql3types.h:33
@ SQL3_DDT_TIMESTAMP
Definition sql3types.h:35
@ SQL3_DDT_ILLEGAL
Definition sql3types.h:39
@ SQL3_DDT_TIMESTAMP_WITH_TIME_ZONE
Definition sql3types.h:37
@ SQL3_DDT_TIME
Definition sql3types.h:34
#define sqlca
Definition sqlca.h:59
PGconn * connection
struct descriptor * next
struct descriptor_item * items
PGresult * result
Definition type.h:97
Definition type.h:110
struct sqlda_compat * desc_next
struct sqlda_struct * desc_next
struct variable * next
enum ECPGttype type
void * pointer
const char * type
const char * name
#define locale_t
Definition win32_port.h:429
#define setlocale(a, b)
Definition win32_port.h:472