int main(void) { decimal *dec, *din; char buf[BUFSIZE]; long l; int i, j, k, q, r, count = 0; double dbl; decimal **decarr = (decimal **) calloc(1, sizeof(decimal)); ECPGdebug(1, stderr); for (i = 0; decs[i]; i++) { dec = PGTYPESdecimal_new(); r = deccvasc(decs[i], strlen(decs[i]), dec); if (r) { check_errno(); printf("dec[%d,0]: r: %d\n", i, r); PGTYPESdecimal_free(dec); continue; } decarr = realloc(decarr, sizeof(decimal *) * (count + 1)); decarr[count++] = dec; r = dectoasc(dec, buf, BUFSIZE-1, -1); if (r < 0) check_errno(); printf("dec[%d,1]: r: %d, %s\n", i, r, buf); r = dectoasc(dec, buf, BUFSIZE-1, 0); if (r < 0) check_errno(); printf("dec[%d,2]: r: %d, %s\n", i, r, buf); r = dectoasc(dec, buf, BUFSIZE-1, 1); if (r < 0) check_errno(); printf("dec[%d,3]: r: %d, %s\n", i, r, buf); r = dectoasc(dec, buf, BUFSIZE-1, 2); if (r < 0) check_errno(); printf("dec[%d,4]: r: %d, %s\n", i, r, buf); din = PGTYPESdecimal_new(); r = dectoasc(din, buf, BUFSIZE-1, 2); if (r < 0) check_errno(); printf("dec[%d,5]: r: %d, %s\n", i, r, buf); r = dectolong(dec, &l); if (r) check_errno(); printf("dec[%d,6]: %ld (r: %d)\n", i, r?0L:l, r); if (r == 0) { r = deccvlong(l, din); if (r) check_errno(); dectoasc(din, buf, BUFSIZE-1, 2); q = deccmp(dec, din); printf("dec[%d,7]: %s (r: %d - cmp: %d)\n", i, buf, r, q); } r = dectoint(dec, &k); if (r) check_errno(); printf("dec[%d,8]: %d (r: %d)\n", i, r?0:k, r); if (r == 0) { r = deccvint(k, din); if (r) check_errno(); dectoasc(din, buf, BUFSIZE-1, 2); q = deccmp(dec, din); printf("dec[%d,9]: %s (r: %d - cmp: %d)\n", i, buf, r, q); } if (i != 6) { /* underflow does not work reliable on several archs, so not testing it here */ /* this is a libc problem since we only call strtod() */ r = dectodbl(dec, &dbl); if (r) check_errno(); printf("dec[%d,10]: %g (r: %d)\n", i, r?0.0:dbl, r); } PGTYPESdecimal_free(din); printf("\n"); } /* add a NULL value */ dec = PGTYPESdecimal_new(); decarr = realloc(decarr, sizeof(decimal *) * (count + 1)); decarr[count++] = dec; rsetnull(CDECIMALTYPE, (char *) decarr[count-1]); printf("dec[%d]: %sNULL\n", count-1, risnull(CDECIMALTYPE, (char *) decarr[count-1]) ? "" : "NOT "); printf("dec[0]: %sNULL\n", risnull(CDECIMALTYPE, (char *) decarr[0]) ? "" : "NOT "); r = dectoasc(decarr[3], buf, -1, -1); check_errno(); printf("dectoasc with len == -1: r: %d\n", r); r = dectoasc(decarr[3], buf, 0, -1); check_errno(); printf("dectoasc with len == 0: r: %d\n", r); for (i = 0; i < count; i++) { for (j = 0; j < count; j++) { decimal a, s, m, d; int c; c = deccmp(decarr[i], decarr[j]); printf("dec[c,%d,%d]: %d\n", i, j, c); r = decadd(decarr[i], decarr[j], &a); if (r) { check_errno(); printf("r: %d\n", r); } else { dectoasc(&a, buf, BUFSIZE-1, -1); printf("dec[a,%d,%d]: %s\n", i, j, buf); } r = decsub(decarr[i], decarr[j], &s); if (r) { check_errno(); printf("r: %d\n", r); } else { dectoasc(&s, buf, BUFSIZE-1, -1); printf("dec[s,%d,%d]: %s\n", i, j, buf); } r = decmul(decarr[i], decarr[j], &m); if (r) { check_errno(); printf("r: %d\n", r); } else { dectoasc(&m, buf, BUFSIZE-1, -1); printf("dec[m,%d,%d]: %s\n", i, j, buf); } r = decdiv(decarr[i], decarr[j], &d); if (r) { check_errno(); printf("r: %d\n", r); } else { dectoasc(&d, buf, BUFSIZE-1, -1); printf("dec[d,%d,%d]: %s\n", i, j, buf); } } } for (i = 0; i < count; i++) { dectoasc(decarr[i], buf, BUFSIZE-1, -1); printf("%d: %s\n", i, buf); PGTYPESdecimal_free(decarr[i]); } free(decarr); return 0; }
int main(void) { #line 14 "test_informix.pgc" int i = 14 ; #line 14 "test_informix.pgc" #line 15 "test_informix.pgc" decimal j , m , n ; #line 15 "test_informix.pgc" #line 16 "test_informix.pgc" char c [ 10 ] ; #line 16 "test_informix.pgc" ECPGdebug(1, stderr); /* exec sql whenever sqlerror do dosqlprint ( ) ; */ #line 19 "test_informix.pgc" { ECPGconnect(__LINE__, 1, "ecpg1_regression" , NULL, NULL , NULL, 0); #line 21 "test_informix.pgc" if (sqlca.sqlcode < 0) dosqlprint ( );} #line 21 "test_informix.pgc" if (sqlca.sqlcode != 0) exit(1); { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "create table test ( i int primary key , j int , c text )", ECPGt_EOIT, ECPGt_EORT); #line 24 "test_informix.pgc" if (sqlca.sqlcode < 0) dosqlprint ( );} #line 24 "test_informix.pgc" /* this INSERT works */ rsetnull(CDECIMALTYPE, (char *)&j); { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into test ( i , j , c ) values ( 7 , $1 , 'test ' )", ECPGt_decimal,&(j),(long)1,(long)1,sizeof(decimal), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT); #line 28 "test_informix.pgc" if (sqlca.sqlcode < 0) dosqlprint ( );} #line 28 "test_informix.pgc" { ECPGtrans(__LINE__, NULL, "commit"); #line 29 "test_informix.pgc" if (sqlca.sqlcode < 0) dosqlprint ( );} #line 29 "test_informix.pgc" /* this INSERT should fail because i is a unique column */ { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into test ( i , j , c ) values ( 7 , 12 , 'a' )", ECPGt_EOIT, ECPGt_EORT); #line 32 "test_informix.pgc" if (sqlca.sqlcode < 0) dosqlprint ( );} #line 32 "test_informix.pgc" printf("INSERT: %ld=%s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); if (sqlca.sqlcode != 0) { ECPGtrans(__LINE__, NULL, "rollback"); #line 34 "test_informix.pgc" if (sqlca.sqlcode < 0) dosqlprint ( );} #line 34 "test_informix.pgc" { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into test ( i , j , c ) values ( $1 , 1 , 'a ' )", ECPGt_int,&(i),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT); #line 36 "test_informix.pgc" if (sqlca.sqlcode < 0) dosqlprint ( );} #line 36 "test_informix.pgc" { ECPGtrans(__LINE__, NULL, "commit"); #line 37 "test_informix.pgc" if (sqlca.sqlcode < 0) dosqlprint ( );} #line 37 "test_informix.pgc" /* this will fail (more than one row in subquery) */ { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select i from test where j = ( select j from test )", ECPGt_EOIT, ECPGt_EORT); #line 40 "test_informix.pgc" if (sqlca.sqlcode < 0) dosqlprint ( );} #line 40 "test_informix.pgc" { ECPGtrans(__LINE__, NULL, "rollback"); #line 41 "test_informix.pgc" if (sqlca.sqlcode < 0) dosqlprint ( );} #line 41 "test_informix.pgc" /* this however should be ok */ { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select i from test where j = ( select j from test order by i limit 1 )", ECPGt_EOIT, ECPGt_EORT); #line 44 "test_informix.pgc" if (sqlca.sqlcode < 0) dosqlprint ( );} #line 44 "test_informix.pgc" printf("SELECT: %ld=%s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); if (sqlca.sqlcode != 0) { ECPGtrans(__LINE__, NULL, "rollback"); #line 46 "test_informix.pgc" if (sqlca.sqlcode < 0) dosqlprint ( );} #line 46 "test_informix.pgc" sqlca.sqlcode = 100; ECPGset_var( 0, &( i ), __LINE__);\ ECPG_informix_reset_sqlca(); /* declare c cursor for select * from test where i <= $1 */ #line 49 "test_informix.pgc" printf ("%ld\n", sqlca.sqlcode); openit(); deccvint(0, &j); while (1) { { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "fetch forward c", ECPGt_EOIT, ECPGt_int,&(i),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_decimal,&(j),(long)1,(long)1,sizeof(decimal), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_string,(c),(long)10,(long)1,(10)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); #line 57 "test_informix.pgc" if (sqlca.sqlcode < 0) dosqlprint ( );} #line 57 "test_informix.pgc" if (sqlca.sqlcode == 100) break; else if (sqlca.sqlcode != 0) printf ("Error: %ld\n", sqlca.sqlcode); if (risnull(CDECIMALTYPE, (char *)&j)) printf("%d NULL\n", i); else { int a; dectoint(&j, &a); printf("%d %d \"%s\"\n", i, a, c); } } deccvint(7, &j); deccvint(14, &m); decadd(&j, &m, &n); { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "delete from test where i = $1 :: decimal", ECPGt_decimal,&(n),(long)1,(long)1,sizeof(decimal), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT); #line 75 "test_informix.pgc" if (sqlca.sqlcode < 0) dosqlprint ( );} #line 75 "test_informix.pgc" printf("DELETE: %ld\n", sqlca.sqlcode); { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select 1 from test where i = 14", ECPGt_EOIT, ECPGt_EORT); #line 78 "test_informix.pgc" if (sqlca.sqlcode < 0) dosqlprint ( );} #line 78 "test_informix.pgc" printf("Exists: %ld\n", sqlca.sqlcode); { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select 1 from test where i = 147", ECPGt_EOIT, ECPGt_EORT); #line 81 "test_informix.pgc" if (sqlca.sqlcode < 0) dosqlprint ( );} #line 81 "test_informix.pgc" printf("Does not exist: %ld\n", sqlca.sqlcode); { ECPGtrans(__LINE__, NULL, "commit"); #line 84 "test_informix.pgc" if (sqlca.sqlcode < 0) dosqlprint ( );} #line 84 "test_informix.pgc" { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT); #line 85 "test_informix.pgc" if (sqlca.sqlcode < 0) dosqlprint ( );} #line 85 "test_informix.pgc" { ECPGtrans(__LINE__, NULL, "commit"); #line 86 "test_informix.pgc" if (sqlca.sqlcode < 0) dosqlprint ( );} #line 86 "test_informix.pgc" { ECPGdisconnect(__LINE__, "CURRENT"); #line 88 "test_informix.pgc" if (sqlca.sqlcode < 0) dosqlprint ( );} #line 88 "test_informix.pgc" return 0; }
int main(void) { #line 15 "rnull.pgc" char c [] = "abc " ; #line 15 "rnull.pgc" #line 16 "rnull.pgc" short s = 17 ; #line 16 "rnull.pgc" #line 17 "rnull.pgc" int i = - 74874 ; #line 17 "rnull.pgc" #line 18 "rnull.pgc" bool b = 1 ; #line 18 "rnull.pgc" #line 19 "rnull.pgc" float f = 3.71 ; #line 19 "rnull.pgc" #line 20 "rnull.pgc" long l = 487444 ; #line 20 "rnull.pgc" #line 21 "rnull.pgc" double dbl = 404.404 ; #line 21 "rnull.pgc" #line 22 "rnull.pgc" decimal dec ; #line 22 "rnull.pgc" #line 23 "rnull.pgc" date dat ; #line 23 "rnull.pgc" #line 24 "rnull.pgc" timestamp tmp ; #line 24 "rnull.pgc" ECPGdebug(1, stderr); /* exec sql whenever sqlerror do sqlprint ( ) ; */ #line 27 "rnull.pgc" { ECPGconnect(__LINE__, 1, "regress1" , NULL,NULL , NULL, 0); #line 29 "rnull.pgc" if (sqlca.sqlcode < 0) sqlprint ( );} #line 29 "rnull.pgc" { ECPGdo(__LINE__, 1, 0, NULL, "create table test ( id int , c char ( 10 ) , s smallint , i int , b bool , f float , l bigint , dbl double precision , dec decimal , dat date , tmp timestamptz ) ", ECPGt_EOIT, ECPGt_EORT); #line 33 "rnull.pgc" if (sqlca.sqlcode < 0) sqlprint ( );} #line 33 "rnull.pgc" { ECPGtrans(__LINE__, NULL, "commit"); #line 34 "rnull.pgc" if (sqlca.sqlcode < 0) sqlprint ( );} #line 34 "rnull.pgc" { ECPGdo(__LINE__, 1, 0, NULL, "insert into test ( id , c , s , i , b , f , l , dbl ) values ( 1 , ? , ? , ? , ? , ? , ? , ? ) ", ECPGt_char,(c),(long)sizeof("abc "),(long)1,(sizeof("abc "))*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_short,&(s),(long)1,(long)1,sizeof(short), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_int,&(i),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_bool,&(b),(long)1,(long)1,sizeof(bool), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_float,&(f),(long)1,(long)1,sizeof(float), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_long,&(l),(long)1,(long)1,sizeof(long), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_double,&(dbl),(long)1,(long)1,sizeof(double), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT); #line 38 "rnull.pgc" if (sqlca.sqlcode < 0) sqlprint ( );} #line 38 "rnull.pgc" { ECPGtrans(__LINE__, NULL, "commit"); #line 39 "rnull.pgc" if (sqlca.sqlcode < 0) sqlprint ( );} #line 39 "rnull.pgc" rsetnull(CCHARTYPE, (char *) c); rsetnull(CSHORTTYPE, (char *) &s); rsetnull(CINTTYPE, (char *) &i); rsetnull(CBOOLTYPE, (char *) &b); rsetnull(CFLOATTYPE, (char *) &f); rsetnull(CLONGTYPE, (char *) &l); rsetnull(CDOUBLETYPE, (char *) &dbl); rsetnull(CDECIMALTYPE, (char *) &dec); rsetnull(CDATETYPE, (char *) &dat); rsetnull(CDTIMETYPE, (char *) &tmp); { ECPGdo(__LINE__, 1, 0, NULL, "insert into test ( id , c , s , i , b , f , l , dbl , dec , dat , tmp ) values ( 2 , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) ", ECPGt_char,(c),(long)sizeof("abc "),(long)1,(sizeof("abc "))*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_short,&(s),(long)1,(long)1,sizeof(short), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_int,&(i),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_bool,&(b),(long)1,(long)1,sizeof(bool), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_float,&(f),(long)1,(long)1,sizeof(float), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_long,&(l),(long)1,(long)1,sizeof(long), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_double,&(dbl),(long)1,(long)1,sizeof(double), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_decimal,&(dec),(long)1,(long)1,sizeof(decimal), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_date,&(dat),(long)1,(long)1,sizeof(date), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_timestamp,&(tmp),(long)1,(long)1,sizeof(timestamp), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT); #line 54 "rnull.pgc" if (sqlca.sqlcode < 0) sqlprint ( );} #line 54 "rnull.pgc" { ECPGtrans(__LINE__, NULL, "commit"); #line 55 "rnull.pgc" if (sqlca.sqlcode < 0) sqlprint ( );} #line 55 "rnull.pgc" printf("first select\n"); { ECPGdo(__LINE__, 1, 0, NULL, "select c , s , i , b , f , l , dbl , dec , dat , tmp from test where id = 1 ", ECPGt_EOIT, ECPGt_char,(c),(long)sizeof("abc "),(long)1,(sizeof("abc "))*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_short,&(s),(long)1,(long)1,sizeof(short), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_int,&(i),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_bool,&(b),(long)1,(long)1,sizeof(bool), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_float,&(f),(long)1,(long)1,sizeof(float), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_long,&(l),(long)1,(long)1,sizeof(long), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_double,&(dbl),(long)1,(long)1,sizeof(double), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_decimal,&(dec),(long)1,(long)1,sizeof(decimal), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_date,&(dat),(long)1,(long)1,sizeof(date), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_timestamp,&(tmp),(long)1,(long)1,sizeof(timestamp), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); #line 61 "rnull.pgc" if (sqlca.sqlcode < 0) sqlprint ( );} #line 61 "rnull.pgc" test_null(CCHARTYPE, (char *) c); test_null(CSHORTTYPE, (char *) &s); test_null(CINTTYPE, (char *) &i); test_null(CBOOLTYPE, (char *) &b); test_null(CFLOATTYPE, (char *) &f); test_null(CLONGTYPE, (char *) &l); test_null(CDOUBLETYPE, (char *) &dbl); test_null(CDECIMALTYPE, (char *) &dec); test_null(CDATETYPE, (char *) &dat); test_null(CDTIMETYPE, (char *) &tmp); printf("second select\n"); { ECPGdo(__LINE__, 1, 0, NULL, "select c , s , i , b , f , l , dbl , dec , dat , tmp from test where id = 2 ", ECPGt_EOIT, ECPGt_char,(c),(long)sizeof("abc "),(long)1,(sizeof("abc "))*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_short,&(s),(long)1,(long)1,sizeof(short), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_int,&(i),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_bool,&(b),(long)1,(long)1,sizeof(bool), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_float,&(f),(long)1,(long)1,sizeof(float), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_long,&(l),(long)1,(long)1,sizeof(long), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_double,&(dbl),(long)1,(long)1,sizeof(double), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_decimal,&(dec),(long)1,(long)1,sizeof(decimal), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_date,&(dat),(long)1,(long)1,sizeof(date), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_timestamp,&(tmp),(long)1,(long)1,sizeof(timestamp), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); #line 78 "rnull.pgc" if (sqlca.sqlcode < 0) sqlprint ( );} #line 78 "rnull.pgc" test_null(CCHARTYPE, (char *) c); test_null(CSHORTTYPE, (char *) &s); test_null(CINTTYPE, (char *) &i); test_null(CBOOLTYPE, (char *) &b); test_null(CFLOATTYPE, (char *) &f); test_null(CLONGTYPE, (char *) &l); test_null(CDOUBLETYPE, (char *) &dbl); test_null(CDECIMALTYPE, (char *) &dec); test_null(CDATETYPE, (char *) &dat); test_null(CDTIMETYPE, (char *) &tmp); { ECPGdo(__LINE__, 1, 0, NULL, "drop table test ", ECPGt_EOIT, ECPGt_EORT); #line 91 "rnull.pgc" if (sqlca.sqlcode < 0) sqlprint ( );} #line 91 "rnull.pgc" { ECPGtrans(__LINE__, NULL, "commit"); #line 92 "rnull.pgc" if (sqlca.sqlcode < 0) sqlprint ( );} #line 92 "rnull.pgc" { ECPGdisconnect(__LINE__, "CURRENT"); #line 94 "rnull.pgc" if (sqlca.sqlcode < 0) sqlprint ( );} #line 94 "rnull.pgc" return 0; }