PostgreSQL Source Code: src/interfaces/ecpg/compatlib/informix.c Source File (original) (raw)
1
2
3#define POSTGRES_ECPG_INTERNAL
5
6#include <math.h>
7#include <ctype.h>
8#include <limits.h>
9
18
19
20
22{
23 {
24 'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '
25 },
27 0,
28 {
29 0,
30 {
31 0
32 }
33 },
34 {
35 'N', 'O', 'T', ' ', 'S', 'E', 'T', ' '
36 },
37 {
38 0, 0, 0, 0, 0, 0
39 },
40 {
41 0, 0, 0, 0, 0, 0, 0, 0
42 },
43 {
44 '0', '0', '0', '0', '0'
45 }
46};
47static int
49{
52 int i;
53
56
58 {
61 }
62
64 {
68 }
69
71 {
75 }
76
78
81
82 return i;
83}
84
85static int
87{
90 *nres;
91 int i;
92
93
94
95
96
98 return 0;
99
102
104 {
107 }
108
110 {
114 }
115
117 {
122 }
123
125 {
130 }
131
132 i = (*ptr) (a1, a2, nres);
133
134 if (i == 0)
135 {
136
137
140 }
141
145
146 return i;
147}
148
149
150int
152{
153 errno = 0;
155
160 else if (errno != 0)
161 return -1;
162 else
163 return 0;
164}
165
166int
168{
170}
171
172void
174{
175 memcpy(target, src, sizeof(decimal));
176}
177
178static char *
180{
181 size_t real_len = strlen(str);
182 int use_len = (int) ((real_len > len) ? len : real_len);
183
184 char *new = malloc(use_len + 1);
185
186 if (new)
187 {
188 memcpy(new, str, use_len);
189 new[use_len] = '\0';
190 }
191 else
192 errno = ENOMEM;
193
194 return new;
195}
196
197int
199{
200 char *str;
201 int ret = 0;
203
206 return 0;
207
208 str = ecpg_strndup(cp, len);
209
210 if ()
212 else
213 {
214 errno = 0;
216 if (!result)
217 {
218 switch (errno)
219 {
222 break;
225 break;
226 default:
228 break;
229 }
230 }
231 else
232 {
234
236 if (i != 0)
238 }
239 }
240
242 return ret;
243}
244
245int
247{
249 int result = 1;
250
253 return 0;
254
256 if (nres == NULL)
258
260 if (result == 0)
262
264 return result;
265}
266
267int
269{
271 int result = 1;
272
275 return 0;
276
278 if (nres == NULL)
280
282 if (result == 0)
284
286 return result;
287}
288
289int
291{
293 int result = 1;
294
297 return 0;
298
300 if (nres == NULL)
302
304 if (result == 0)
306
308 return result;
309}
310
311int
313{
314 int i;
315
316 errno = 0;
318
319 if (i != 0)
320 switch (errno)
321 {
324 break;
327 break;
328 default:
330 break;
331 }
332
333 return 0;
334}
335
336int
338{
339 int i;
340
341 errno = 0;
343
344 if (i != 0)
345 switch (errno)
346 {
349 break;
350 default:
352 break;
353 }
354
355 return 0;
356}
357
358int
360{
361 int i;
362
363 errno = 0;
365
366 if (i != 0)
367 switch (errno)
368 {
371 break;
372 default:
374 break;
375 }
376
377 return 0;
378}
379
380int
382{
383 char *str;
385
388 return 0;
389
391 if (nres == NULL)
393
395 {
398 }
399
400 if (right >= 0)
402 else
404
406 if ()
407 return -1;
408
409
410
411
412
413 if ((int) (strlen(str) + 1) > len)
414 {
415 if (len > 1)
416 {
417 cp[0] = '*';
418 cp[1] = '\0';
419 }
421 return -1;
422 }
423 else
424 {
425 strcpy(cp, str);
427 return 0;
428 }
429}
430
431int
433{
434 int i;
436
437 if (nres == NULL)
439
441 {
444 }
445
448
449 return i;
450}
451
452int
454{
455 int ret;
457 int errnum;
458
459 if (nres == NULL)
461
463 {
466 }
467
468 errno = 0;
470 errnum = errno;
472
475
476 return ret;
477}
478
479int
481{
482 int ret;
484 int errnum;
485
486 if (nres == NULL)
488
490 {
493 }
494
495 errno = 0;
497 errnum = errno;
499
502
503 return ret;
504}
505
506
507int
509{
511
512 if (!tmp)
514
515
516 strcpy(str, tmp);
518
519 return 0;
520}
521
522
523
524
525
526
527
528int
530{
532}
533
534void
536{
538}
539
540int
542{
543 int mdy_int[3];
544
546 mdy[0] = (short) mdy_int[0];
547 mdy[1] = (short) mdy_int[1];
548 mdy[2] = (short) mdy_int[2];
549 return 0;
550}
551
552int
554{
555
556
557
558 errno = 0;
560 return 0;
561
562 switch (errno)
563 {
573 default:
575 }
576}
577
578int
580{
581 errno = 0;
583 return 0;
584
585 if (errno == ENOMEM)
587
589}
590
591int
593{
594 int mdy_int[3];
595
596 mdy_int[0] = mdy[0];
597 mdy_int[1] = mdy[1];
598 mdy_int[2] = mdy[2];
600 return 0;
601}
602
603int
605{
607}
608
609
610
611void
613{
615}
616
617int
619{
621 int i;
622 char **endptr = &str;
623
624 errno = 0;
626 i = errno;
627 if (i)
628
629 return i;
630 if (**endptr)
631 {
632
634 }
635
636
637
638 *ts = ts_tmp;
639
640 return 0;
641}
642
643int
645{
647}
648
649int
651{
653}
654
655int
657{
659
660 strcpy(output, asctime);
661 free(asctime);
662 return 0;
663}
664
665int
667{
669}
670
671int
673{
674 char *tmp;
675
676 errno = 0;
678
679 if (!tmp)
680 return -errno;
681
682 strcpy(str, tmp);
684 return 0;
685}
686
687static struct
688{
696
701static int
703{
704 int i,
705 j;
706 long l,
707 dig;
708
709
710 value.val = lng_val >= 0 ? lng_val : lng_val * (-1);
711 value.sign = lng_val >= 0 ? '+' : '-';
712 value.maxdigits = log10(2) * (8 * sizeof(long) - 1);
713
714
715 i = 0;
716 l = 1;
717 do
718 {
719 i++;
720 l *= 10;
721 }
722 while ((l - 1) < value.val && l <= LONG_MAX / 10);
723
724 if (l <= LONG_MAX / 10)
725 {
727 l /= 10;
728 }
729 else
731
733
734
735 if ((value.val_string = (char *) malloc(value.digits + 1)) == NULL)
736 return -1;
738 for (i = value.digits, j = 0; i > 0; i--, j++)
739 {
740 value.val_string[j] = dig / l + '0';
741 dig = dig % l;
742 l /= 10;
743 }
744 value.val_string[value.digits] = '\0';
745 return 0;
746}
747
748
749static int
751{
753 int i,
754 j;
755
756 j = 0;
757 for (i = len - 1; i >= 0; i--)
758 {
761 j++;
762 }
763 return -1;
764}
765
766
767int
768rfmtlong(long lng_val, const char *fmt, char *outbuf)
769{
770 size_t fmt_len = strlen(fmt);
771 size_t temp_len;
772 int i,
773 j,
774 k,
775 dotpos;
776 int leftalign = 0,
777 blank = 0,
779 entitydone = 0,
780 signdone = 0,
781 brackets_ok = 0;
782 char *temp;
783 char tmp[2] = " ";
784 char lastfmt = ' ',
786
787 temp = (char *) malloc(fmt_len + 1);
788 if (!temp)
789 {
790 errno = ENOMEM;
791 return -1;
792 }
793
794
796 {
798 errno = ENOMEM;
799 return -1;
800 }
801
802
803 if (strchr(fmt, (int) '<'))
804 leftalign = 1;
805
806
807 if (strchr(fmt, (int) '(') && strchr(fmt, (int) ')'))
808 brackets_ok = 1;
809
810
811
812
813
815
816
817 temp[0] = '\0';
818 k = value.digits - 1;
819 for (i = fmt_len - 1, j = 0; i >= 0; i--, j++)
820 {
821
822 if (k < 0)
823 {
824 blank = 1;
825 if (k == -1)
827 if (leftalign)
828 {
829
831 if (signdone)
832 {
833 temp[j] = '\0';
834 break;
835 }
836 }
837 }
838
839 if (dotpos >= 0 && dotpos <= i)
840 {
841 if (dotpos < i)
842 {
843 if (fmt[i] == ')')
844 tmp[0] = value.sign == '-' ? ')' : ' ';
845 else
846 tmp[0] = '0';
847 }
848 else
849 tmp[0] = '.';
850 strcat(temp, tmp);
851 continue;
852 }
853
854 if (blank && fmt[i] == ',')
856 else
858
859 if (k < 0 && leftalign && sign && !signdone && fmtchar != '+' && fmtchar != '-')
860 continue;
861
863 {
864 case ',':
865 tmp[0] = ',';
866 k++;
867 break;
868 case '*':
869 if (blank)
870 tmp[0] = '*';
871 else
872 tmp[0] = value.val_string[k];
873 break;
874 case '&':
875 if (blank)
876 tmp[0] = '0';
877 else
878 tmp[0] = value.val_string[k];
879 break;
880 case '#':
881 if (blank)
882 tmp[0] = ' ';
883 else
884 tmp[0] = value.val_string[k];
885 break;
886 case '-':
887 if (sign && value.sign == '-' && !signdone)
888 {
889 tmp[0] = '-';
890 signdone = 1;
891 }
892 else if (blank)
893 tmp[0] = ' ';
894 else
895 tmp[0] = value.val_string[k];
896 break;
897 case '+':
898 if (sign && !signdone)
899 {
900 tmp[0] = value.sign;
901 signdone = 1;
902 }
903 else if (blank)
904 tmp[0] = ' ';
905 else
906 tmp[0] = value.val_string[k];
907 break;
908 case '(':
909 if (sign && brackets_ok && value.sign == '-')
910 tmp[0] = '(';
911 else if (blank)
912 tmp[0] = ' ';
913 else
914 tmp[0] = value.val_string[k];
915 break;
916 case ')':
917 if (brackets_ok && value.sign == '-')
918 tmp[0] = ')';
919 else
920 tmp[0] = ' ';
921 break;
922 case '$':
923 if (blank && !entitydone)
924 {
925 tmp[0] = '$';
926 entitydone = 1;
927 }
928 else if (blank)
929 tmp[0] = ' ';
930 else
931 tmp[0] = value.val_string[k];
932 break;
933 case '<':
934 tmp[0] = value.val_string[k];
935 break;
936 default:
937 tmp[0] = fmt[i];
938 }
939 strcat(temp, tmp);
940 lastfmt = fmt[i];
941 k--;
942 }
943
944 temp[fmt_len] = '\0';
945
946
947 temp_len = strlen(temp);
948 outbuf[0] = '\0';
949 for (i = temp_len - 1; i >= 0; i--)
950 {
951 tmp[0] = temp[i];
952 strcat(outbuf, tmp);
953 }
954 outbuf[temp_len] = '\0';
955
956
959
960 return 0;
961}
962
963void
965{
966 for (; *str != '\0'; str++)
967 if (islower((unsigned char) *str))
968 *str = toupper((unsigned char) *str);
969}
970
971int
973{
975 return (len + 1);
976}
977
978void
980{
982
983 memmove(dest, src, dlen);
984 dest[dlen] = '\0';
985}
986
987int
988rgetmsg(int msgnum, char *s, int maxsize)
989{
990 (void) msgnum;
991 (void) s;
992 (void) maxsize;
993 return 0;
994}
995
996int
998{
999 (void) offset;
1000 (void) type;
1001 return 0;
1002}
1003
1004int
1006{
1007 (void) type;
1008 (void) len;
1009 return 0;
1010}
1011
1012int
1014{
1015 (void) sqltype;
1016 (void) sqllen;
1017 return 0;
1018}
1019
1020void
1022{
1024}
1025
1026void *
1028{
1030}
1031
1032void
1034{
1036
1037 if (sqlca == NULL)
1038 return;
1039
1041}
1042
1043int
1045{
1047 return 0;
1048}
1049
1050int
1052{
1054}
#define ECPG_INFORMIX_ENOTDMY
#define ECPG_INFORMIX_BAD_DAY
#define ECPG_INFORMIX_NUM_OVERFLOW
#define ECPG_INFORMIX_BAD_NUMERIC
#define ECPG_INFORMIX_BAD_MONTH
#define ECPG_INFORMIX_ENOSHORTDATE
#define ECPG_INFORMIX_OUT_OF_MEMORY
#define ECPG_INFORMIX_EXTRA_CHARS
#define ECPG_INFORMIX_NUM_UNDERFLOW
#define ECPG_INFORMIX_BAD_EXPONENT
#define ECPG_INFORMIX_DATE_CONVERT
#define ECPG_INFORMIX_BAD_YEAR
#define ECPG_INFORMIX_DIVIDE_ZERO
static const FormData_pg_attribute a1
static const FormData_pg_attribute a2
int deccvasc(const char *cp, int len, decimal *np)
int rstrdate(const char *str, date *d)
static int getRightMostDot(const char *str)
static int initValue(long lng_val)
int dttofmtasc(timestamp *ts, char *output, int str_len, char *fmtstr)
int decadd(decimal *arg1, decimal *arg2, decimal *sum)
int rtypwidth(int sqltype, int sqllen)
void ldchar(char *src, int len, char *dest)
int rdatestr(date d, char *str)
static int deccall2(decimal *arg1, decimal *arg2, int(*ptr)(numeric *, numeric *))
int dtsub(timestamp *ts1, timestamp *ts2, interval *iv)
int rfmtlong(long lng_val, const char *fmt, char *outbuf)
int deccvlong(long lng, decimal *np)
int rtypalign(int offset, int type)
static struct sqlca_t sqlca_init
int deccvint(int in, decimal *np)
int rjulmdy(date d, short *mdy)
int dectoasc(decimal *np, char *cp, int len, int right)
int dectoint(decimal *np, int *ip)
static char * ecpg_strndup(const char *str, size_t len)
int dtcvfmtasc(char *inbuf, char *fmtstr, timestamp *dtvalue)
void * ECPG_informix_get_var(int number)
int dtcvasc(char *str, timestamp *ts)
int decmul(decimal *n1, decimal *n2, decimal *result)
static int deccall3(decimal *arg1, decimal *arg2, decimal *result, int(*ptr)(numeric *, numeric *, numeric *))
int risnull(int t, const char *ptr)
int byleng(char *str, int len)
void ECPG_informix_reset_sqlca(void)
int rmdyjul(short *mdy, date *d)
void ECPG_informix_set_var(int number, void *pointer, int lineno)
int rfmtdate(date d, const char *fmt, char *str)
int decsub(decimal *n1, decimal *n2, decimal *result)
int dectolong(decimal *np, long *lngp)
int deccvdbl(double dbl, decimal *np)
int rtypmsize(int type, int len)
int deccmp(decimal *arg1, decimal *arg2)
int decdiv(decimal *n1, decimal *n2, decimal *result)
int dttoasc(timestamp *ts, char *output)
int rsetnull(int t, char *ptr)
int rgetmsg(int msgnum, char *s, int maxsize)
void dtcurrent(timestamp *ts)
int rdefmtdate(date *d, const char *fmt, const char *str)
int dectodbl(decimal *np, double *dblp)
void deccopy(decimal *src, decimal *target)
int intoasc(interval *i, char *str)
void ECPGset_var(int number, void *pointer, int lineno)
struct sqlca_t * ECPGget_sqlca(void)
void ECPGset_noind_null(enum ECPGttype type, void *ptr)
bool ECPGis_noind_null(enum ECPGttype type, const void *ptr)
void * ECPGget_var(int number)
int PGTYPESdate_dayofweek(date dDate)
char * PGTYPESdate_to_asc(date dDate)
void PGTYPESdate_today(date *d)
int PGTYPESdate_fmt_asc(date dDate, const char *fmtstring, char *outbuf)
int PGTYPESdate_defmt_asc(date *d, const char *fmt, const char *str)
void PGTYPESdate_julmdy(date jd, int *mdy)
void PGTYPESdate_mdyjul(int *mdy, date *jdate)
#define PGTYPES_DATE_ERR_ENOTDMY
#define PGTYPES_NUM_BAD_NUMERIC
#define PGTYPES_DATE_BAD_DAY
#define PGTYPES_NUM_OVERFLOW
#define PGTYPES_DATE_ERR_ENOSHORTDATE
#define PGTYPES_NUM_UNDERFLOW
#define PGTYPES_NUM_DIVIDE_ZERO
#define PGTYPES_DATE_ERR_EARGS
#define PGTYPES_DATE_BAD_MONTH
char * PGTYPESinterval_to_asc(interval *span)
int PGTYPESnumeric_from_double(double d, numeric *dst)
int PGTYPESnumeric_from_decimal(decimal *src, numeric *dst)
numeric * PGTYPESnumeric_new(void)
int PGTYPESnumeric_to_decimal(numeric *src, decimal *dst)
char * PGTYPESnumeric_to_asc(numeric *num, int dscale)
int PGTYPESnumeric_mul(numeric *var1, numeric *var2, numeric *result)
int PGTYPESnumeric_to_long(numeric *nv, long *lp)
int PGTYPESnumeric_to_double(numeric *nv, double *dp)
int PGTYPESnumeric_from_long(signed long int long_val, numeric *var)
int PGTYPESnumeric_to_int(numeric *nv, int *ip)
int PGTYPESnumeric_from_int(signed int int_val, numeric *var)
int PGTYPESnumeric_sub(numeric *var1, numeric *var2, numeric *result)
void PGTYPESnumeric_free(numeric *var)
int PGTYPESnumeric_cmp(numeric *var1, numeric *var2)
int PGTYPESnumeric_div(numeric *var1, numeric *var2, numeric *result)
int PGTYPESnumeric_add(numeric *var1, numeric *var2, numeric *result)
numeric * PGTYPESnumeric_from_asc(char *str, char **endptr)
timestamp PGTYPEStimestamp_from_asc(char *str, char **endptr)
int PGTYPEStimestamp_sub(timestamp *ts1, timestamp *ts2, interval *iv)
char * PGTYPEStimestamp_to_asc(timestamp tstamp)
void PGTYPEStimestamp_current(timestamp *ts)
int PGTYPEStimestamp_fmt_asc(timestamp *ts, char *output, int str_len, const char *fmtstr)
int PGTYPEStimestamp_defmt_asc(const char *str, const char *fmt, timestamp *d)
static void fmtchar(int value, int leftjust, int minlen, PrintfTarget *target)
static void fmtstr(const char *value, int leftjust, int minlen, int maxwidth, int pointflag, PrintfTarget *target)