int main (void) { /* exec sql begin declare section */ #line 19 "array.pgc" int i = 1 , j ; #line 20 "array.pgc" int * did = & i ; #line 21 "array.pgc" short a [ 10 ] = { 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 } ; #line 22 "array.pgc" timestamp ts [ 10 ] ; #line 23 "array.pgc" date d [ 10 ] ; #line 24 "array.pgc" interval in [ 10 ] ; #line 25 "array.pgc" numeric n [ 10 ] ; #line 26 "array.pgc" char text [ 25 ] = "klmnopqrst" ; #line 27 "array.pgc" char * t = ( char * ) malloc ( 11 ) ; #line 28 "array.pgc" double f ; /* exec sql end declare section */ #line 29 "array.pgc" strcpy(t, "0123456789"); setlocale(LC_ALL, "C"); ECPGdebug(1, stderr); for (j = 0; j < 10; j++) { char str[20]; numeric *value; interval *inter; sprintf(str, "2000-1-1 0%d:00:00", j); ts[j] = PGTYPEStimestamp_from_asc(str, NULL); sprintf(str, "2000-1-1%d\n", j); d[j] = PGTYPESdate_from_asc(str, NULL); sprintf(str, "%d hours", j+10); inter = PGTYPESinterval_from_asc(str, NULL); in[j] = *inter; value = PGTYPESnumeric_new(); PGTYPESnumeric_from_int(j, value); n[j] = *value; } { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0); #line 53 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 53 "array.pgc" { ECPGsetcommit(__LINE__, "on", NULL); #line 55 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 55 "array.pgc" { ECPGtrans(__LINE__, NULL, "begin work"); #line 57 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 57 "array.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test ( f float , i int , a int [ 10 ] , text char ( 10 ) , ts timestamp [ 10 ] , n numeric [ 10 ] , d date [ 10 ] , inter interval [ 10 ] )", ECPGt_EOIT, ECPGt_EORT); #line 59 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 59 "array.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( f , i , a , text , ts , n , d , inter ) values ( 404.90 , 3 , '{0,1,2,3,4,5,6,7,8,9}' , 'abcdefghij' , $1 , $2 , $3 , $4 )", ECPGt_timestamp,&(ts),(long)1,(long)10,sizeof(timestamp), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_numeric,&(n),(long)1,(long)10,sizeof(numeric), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_date,&(d),(long)1,(long)10,sizeof(date), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_interval,&(in),(long)1,(long)10,sizeof(interval), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT); #line 61 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 61 "array.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( f , i , a , text , ts , n , d , inter ) values ( 140787.0 , 2 , $1 , $2 , $3 , $4 , $5 , $6 )", ECPGt_short,(a),(long)1,(long)10,sizeof(short), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_timestamp,&(ts),(long)1,(long)10,sizeof(timestamp), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_numeric,&(n),(long)1,(long)10,sizeof(numeric), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_date,&(d),(long)1,(long)10,sizeof(date), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_interval,&(in),(long)1,(long)10,sizeof(interval), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT); #line 63 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 63 "array.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( f , i , a , text , ts , n , d , inter ) values ( 14.07 , $1 , $2 , $3 , $4 , $5 , $6 , $7 )", ECPGt_int,&(did),(long)1,(long)0,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_short,(a),(long)1,(long)10,sizeof(short), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_char,&(t),(long)0,(long)1,(1)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_timestamp,&(ts),(long)1,(long)10,sizeof(timestamp), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_numeric,&(n),(long)1,(long)10,sizeof(numeric), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_date,&(d),(long)1,(long)10,sizeof(date), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_interval,&(in),(long)1,(long)10,sizeof(interval), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT); #line 65 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 65 "array.pgc" { ECPGtrans(__LINE__, NULL, "commit"); #line 67 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 67 "array.pgc" for (j = 0; j < 10; j++) { ts[j] = PGTYPEStimestamp_from_asc("1900-01-01 00:00:00", NULL); d[j] = PGTYPESdate_from_asc("1900-01-01", NULL); in[j] = *PGTYPESinterval_new(); n[j] = *PGTYPESnumeric_new(); } { ECPGtrans(__LINE__, NULL, "begin work"); #line 75 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 75 "array.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select f , text from test where i = 1", ECPGt_EOIT, ECPGt_double,&(f),(long)1,(long)1,sizeof(double), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); #line 80 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 80 "array.pgc" printf("Found f=%f text=%10.10s\n", f, text); f=140787; { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select a , text , ts , n , d , inter from test where f = $1 ", ECPGt_double,&(f),(long)1,(long)1,sizeof(double), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_short,(a),(long)1,(long)10,sizeof(short), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_char,&(t),(long)0,(long)1,(1)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_timestamp,&(ts),(long)1,(long)10,sizeof(timestamp), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_numeric,&(n),(long)1,(long)10,sizeof(numeric), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_date,&(d),(long)1,(long)10,sizeof(date), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_interval,&(in),(long)1,(long)10,sizeof(interval), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); #line 88 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 88 "array.pgc" for (i = 0; i < 10; i++) printf("Found a[%d] = %d ts[%d] = %s n[%d] = %s d[%d] = %s in[%d] = %s\n", i, a[i], i, PGTYPEStimestamp_to_asc(ts[i]), i, PGTYPESnumeric_to_asc(&(n[i]), -1), i, PGTYPESdate_to_asc(d[i]), i, PGTYPESinterval_to_asc(&(in[i]))); printf("Found text=%10.10s\n", t); { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select a from test where f = $1 ", ECPGt_double,&(f),(long)1,(long)1,sizeof(double), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); #line 98 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 98 "array.pgc" printf("Found text=%s\n", text); { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT); #line 102 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 102 "array.pgc" { ECPGtrans(__LINE__, NULL, "commit"); #line 104 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 104 "array.pgc" { ECPGdisconnect(__LINE__, "CURRENT"); #line 106 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 106 "array.pgc" free(t); return 0; }
int main(void) { char *text="error\n"; char *endptr; numeric *num, *nin; decimal *dec; long l; int i, j, k, q, r, count = 0; double d; numeric **numarr = (numeric **) calloc(1, sizeof(numeric)); ECPGdebug(1, stderr); for (i = 0; nums[i]; i++) { num = PGTYPESnumeric_from_asc(nums[i], &endptr); if (!num) check_errno(); if (endptr != NULL) { printf("endptr of %d is not NULL\n", i); if (*endptr != '\0') printf("*endptr of %d is not \\0\n", i); } if (!num) continue; numarr = realloc(numarr, sizeof(numeric *) * (count + 1)); numarr[count++] = num; text = PGTYPESnumeric_to_asc(num, -1); if (!text) check_errno(); printf("num[%d,1]: %s\n", i, text); free(text); text = PGTYPESnumeric_to_asc(num, 0); if (!text) check_errno(); printf("num[%d,2]: %s\n", i, text); free(text); text = PGTYPESnumeric_to_asc(num, 1); if (!text) check_errno(); printf("num[%d,3]: %s\n", i, text); free(text); text = PGTYPESnumeric_to_asc(num, 2); if (!text) check_errno(); printf("num[%d,4]: %s\n", i, text); free(text); nin = PGTYPESnumeric_new(); text = PGTYPESnumeric_to_asc(nin, 2); if (!text) check_errno(); printf("num[%d,5]: %s\n", i, text); free(text); r = PGTYPESnumeric_to_long(num, &l); if (r) check_errno(); printf("num[%d,6]: %ld (r: %d)\n", i, r?0L:l, r); if (r == 0) { r = PGTYPESnumeric_from_long(l, nin); if (r) check_errno(); text = PGTYPESnumeric_to_asc(nin, 2); q = PGTYPESnumeric_cmp(num, nin); printf("num[%d,7]: %s (r: %d - cmp: %d)\n", i, text, r, q); free(text); } r = PGTYPESnumeric_to_int(num, &k); if (r) check_errno(); printf("num[%d,8]: %d (r: %d)\n", i, r?0:k, r); if (r == 0) { r = PGTYPESnumeric_from_int(k, nin); if (r) check_errno(); text = PGTYPESnumeric_to_asc(nin, 2); q = PGTYPESnumeric_cmp(num, nin); printf("num[%d,9]: %s (r: %d - cmp: %d)\n", i, text, r, q); free(text); } r = PGTYPESnumeric_to_double(num, &d); if (r) check_errno(); printf("num[%d,10]: %g (r: %d)\n", i, r?0.0:d, r); /* do not test double to numeric because * - extra digits are different on different architectures * - PGTYPESnumeric_from_double internally calls PGTYPESnumeric_from_asc anyway */ dec = PGTYPESdecimal_new(); r = PGTYPESnumeric_to_decimal(num, dec); if (r) check_errno(); /* we have no special routine for outputting decimal, it would * convert to a numeric anyway */ printf("num[%d,11]: - (r: %d)\n", i, r); if (r == 0) { r = PGTYPESnumeric_from_decimal(dec, nin); if (r) check_errno(); text = PGTYPESnumeric_to_asc(nin, 2); q = PGTYPESnumeric_cmp(num, nin); printf("num[%d,12]: %s (r: %d - cmp: %d)\n", i, text, r, q); free(text); } PGTYPESdecimal_free(dec); PGTYPESnumeric_free(nin); printf("\n"); } for (i = 0; i < count; i++) { for (j = 0; j < count; j++) { numeric* a = PGTYPESnumeric_new(); numeric* s = PGTYPESnumeric_new(); numeric* m = PGTYPESnumeric_new(); numeric* d = PGTYPESnumeric_new(); r = PGTYPESnumeric_add(numarr[i], numarr[j], a); if (r) { check_errno(); printf("r: %d\n", r); } else { text = PGTYPESnumeric_to_asc(a, 10); printf("num[a,%d,%d]: %s\n", i, j, text); free(text); } r = PGTYPESnumeric_sub(numarr[i], numarr[j], s); if (r) { check_errno(); printf("r: %d\n", r); } else { text = PGTYPESnumeric_to_asc(s, 10); printf("num[s,%d,%d]: %s\n", i, j, text); free(text); } r = PGTYPESnumeric_mul(numarr[i], numarr[j], m); if (r) { check_errno(); printf("r: %d\n", r); } else { text = PGTYPESnumeric_to_asc(m, 10); printf("num[m,%d,%d]: %s\n", i, j, text); free(text); } r = PGTYPESnumeric_div(numarr[i], numarr[j], d); if (r) { check_errno(); printf("r: %d\n", r); } else { text = PGTYPESnumeric_to_asc(d, 10); printf("num[d,%d,%d]: %s\n", i, j, text); free(text); } } } for (i = 0; i < count; i++) { text = PGTYPESnumeric_to_asc(numarr[i], -1); printf("%d: %s\n", i, text); free(text); } return (0); }