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
813
814
815 temp[0] = '\0';
816 k = value.digits - 1;
817 for (i = fmt_len - 1, j = 0; i >= 0; i--, j++)
818 {
819
820 if (k < 0)
821 {
822 blank = 1;
823 if (k == -1)
825 if (leftalign)
826 {
827
829 if (signdone)
830 {
831 temp[j] = '\0';
832 break;
833 }
834 }
835 }
836
837 if (dotpos >= 0 && dotpos <= i)
838 {
839 if (dotpos < i)
840 {
841 if (fmt[i] == ')')
842 tmp[0] = value.sign == '-' ? ')' : ' ';
843 else
844 tmp[0] = '0';
845 }
846 else
847 tmp[0] = '.';
848 strcat(temp, tmp);
849 continue;
850 }
851
852 if (blank && fmt[i] == ',')
854 else
856
857 if (k < 0 && leftalign && sign && !signdone && fmtchar != '+' && fmtchar != '-')
858 continue;
859
861 {
862 case ',':
863 tmp[0] = ',';
864 k++;
865 break;
866 case '*':
867 if (blank)
868 tmp[0] = '*';
869 else
870 tmp[0] = value.val_string[k];
871 break;
872 case '&':
873 if (blank)
874 tmp[0] = '0';
875 else
876 tmp[0] = value.val_string[k];
877 break;
878 case '#':
879 if (blank)
880 tmp[0] = ' ';
881 else
882 tmp[0] = value.val_string[k];
883 break;
884 case '-':
885 if (sign && value.sign == '-' && !signdone)
886 {
887 tmp[0] = '-';
888 signdone = 1;
889 }
890 else if (blank)
891 tmp[0] = ' ';
892 else
893 tmp[0] = value.val_string[k];
894 break;
895 case '+':
896 if (sign && !signdone)
897 {
898 tmp[0] = value.sign;
899 signdone = 1;
900 }
901 else if (blank)
902 tmp[0] = ' ';
903 else
904 tmp[0] = value.val_string[k];
905 break;
906 case '(':
907 if (sign && brackets_ok && value.sign == '-')
908 tmp[0] = '(';
909 else if (blank)
910 tmp[0] = ' ';
911 else
912 tmp[0] = value.val_string[k];
913 break;
914 case ')':
915 if (brackets_ok && value.sign == '-')
916 tmp[0] = ')';
917 else
918 tmp[0] = ' ';
919 break;
920 case '$':
921 if (blank && !entitydone)
922 {
923 tmp[0] = '$';
924 entitydone = 1;
925 }
926 else if (blank)
927 tmp[0] = ' ';
928 else
929 tmp[0] = value.val_string[k];
930 break;
931 case '<':
932 tmp[0] = value.val_string[k];
933 break;
934 default:
935 tmp[0] = fmt[i];
936 }
937 strcat(temp, tmp);
938 lastfmt = fmt[i];
939 k--;
940 }
941
942 temp[fmt_len] = '\0';
943
944
945 temp_len = strlen(temp);
946 outbuf[0] = '\0';
947 for (i = temp_len - 1; i >= 0; i--)
948 {
949 tmp[0] = temp[i];
950 strcat(outbuf, tmp);
951 }
952 outbuf[temp_len] = '\0';
953
954
957
958 return 0;
959}
960
961void
963{
964 for (; *str != '\0'; str++)
965 if (islower((unsigned char) *str))
966 *str = toupper((unsigned char) *str);
967}
968
969int
971{
973 return (len + 1);
974}
975
976void
978{
980
981 memmove(dest, src, dlen);
982 dest[dlen] = '\0';
983}
984
985int
986rgetmsg(int msgnum, char *s, int maxsize)
987{
988 (void) msgnum;
989 (void) s;
990 (void) maxsize;
991 return 0;
992}
993
994int
996{
997 (void) offset;
998 (void) type;
999 return 0;
1000}
1001
1002int
1004{
1005 (void) type;
1006 (void) len;
1007 return 0;
1008}
1009
1010int
1012{
1013 (void) sqltype;
1014 (void) sqllen;
1015 return 0;
1016}
1017
1018void
1020{
1022}
1023
1024void *
1026{
1028}
1029
1030void
1032{
1034
1035 if (sqlca == NULL)
1036 return;
1037
1039}
1040
1041int
1043{
1045 return 0;
1046}
1047
1048int
1050{
1052}
#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)