Commit dbccdd37 authored by Tom Lane's avatar Tom Lane

Add some test coverage for ecpg's "long long" support.

This will only actually exercise the "long long" code paths on platforms
where "long" is 32 bits --- otherwise, the SQL bigint type maps to
plain "long", and we will test that code path instead.  But that's
probably sufficient coverage, and anyway we weren't testing either
code path before.

Dang Minh Huong, tweaked a bit by me

Discussion: https://postgr.es/m/151935568942.1461.14623890240535309745@wrigleys.postgresql.org
parent f586f863
......@@ -149,6 +149,14 @@ dump_sqlda(sqlda_t *sqlda)
case ECPGt_int:
printf("name sqlda descriptor: '%s' value %d\n", sqlda->sqlvar[i].sqlname.data, *(int *)sqlda->sqlvar[i].sqldata);
break;
case ECPGt_long:
printf("name sqlda descriptor: '%s' value %ld\n", sqlda->sqlvar[i].sqlname.data, *(long int *)sqlda->sqlvar[i].sqldata);
break;
#ifdef HAVE_LONG_LONG_INT
case ECPGt_long_long:
printf("name sqlda descriptor: '%s' value %lld\n", sqlda->sqlvar[i].sqlname.data, *(long long int *)sqlda->sqlvar[i].sqldata);
break;
#endif
case ECPGt_double:
printf("name sqlda descriptor: '%s' value %lf\n", sqlda->sqlvar[i].sqlname.data, *(double *)sqlda->sqlvar[i].sqldata);
break;
......@@ -174,19 +182,19 @@ main (void)
#line 59 "sqlda.pgc"
#line 67 "sqlda.pgc"
char * stmt1 = "SELECT * FROM t1" ;
#line 60 "sqlda.pgc"
#line 68 "sqlda.pgc"
char * stmt2 = "SELECT * FROM t1 WHERE id = ?" ;
#line 61 "sqlda.pgc"
#line 69 "sqlda.pgc"
int rec ;
#line 62 "sqlda.pgc"
#line 70 "sqlda.pgc"
int id ;
/* exec sql end declare section */
#line 63 "sqlda.pgc"
#line 71 "sqlda.pgc"
char msg[128];
......@@ -195,42 +203,42 @@ main (void)
strcpy(msg, "connect");
{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , "regress1", 0);
#line 70 "sqlda.pgc"
#line 78 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 70 "sqlda.pgc"
#line 78 "sqlda.pgc"
strcpy(msg, "set");
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
#line 73 "sqlda.pgc"
#line 81 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 73 "sqlda.pgc"
#line 81 "sqlda.pgc"
strcpy(msg, "create");
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table t1 ( id integer , t text , d1 numeric , d2 float8 , c char ( 10 ) )", ECPGt_EOIT, ECPGt_EORT);
#line 81 "sqlda.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table t1 ( id integer , t text , d1 numeric , d2 float8 , c char ( 10 ) , big bigint )", ECPGt_EOIT, ECPGt_EORT);
#line 91 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 81 "sqlda.pgc"
#line 91 "sqlda.pgc"
strcpy(msg, "insert");
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into t1 values ( 1 , 'a' , 1.0 , 1 , 'a' ) , ( 2 , null , null , null , null ) , ( 4 , 'd' , 4.0 , 4 , 'd' )", ECPGt_EOIT, ECPGt_EORT);
#line 87 "sqlda.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into t1 values ( 1 , 'a' , 1.0 , 1 , 'a' , 1111111111111111111 ) , ( 2 , null , null , null , null , null ) , ( 4 , 'd' , 4.0 , 4 , 'd' , 4444444444444444444 )", ECPGt_EOIT, ECPGt_EORT);
#line 97 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 87 "sqlda.pgc"
#line 97 "sqlda.pgc"
strcpy(msg, "commit");
{ ECPGtrans(__LINE__, NULL, "commit");
#line 90 "sqlda.pgc"
#line 100 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 90 "sqlda.pgc"
#line 100 "sqlda.pgc"
/* SQLDA test for getting all records from a table */
......@@ -239,29 +247,29 @@ if (sqlca.sqlcode < 0) exit (1);}
strcpy(msg, "prepare");
{ ECPGprepare(__LINE__, NULL, 0, "st_id1", stmt1);
#line 97 "sqlda.pgc"
#line 107 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 97 "sqlda.pgc"
#line 107 "sqlda.pgc"
strcpy(msg, "declare");
/* declare mycur1 cursor for $1 */
#line 100 "sqlda.pgc"
#line 110 "sqlda.pgc"
strcpy(msg, "open");
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur1 cursor for $1",
ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id1", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 103 "sqlda.pgc"
#line 113 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 103 "sqlda.pgc"
#line 113 "sqlda.pgc"
/* exec sql whenever not found break ; */
#line 105 "sqlda.pgc"
#line 115 "sqlda.pgc"
rec = 0;
......@@ -271,13 +279,13 @@ if (sqlca.sqlcode < 0) exit (1);}
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 from mycur1", ECPGt_EOIT,
ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 111 "sqlda.pgc"
#line 121 "sqlda.pgc"
if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
#line 111 "sqlda.pgc"
#line 121 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 111 "sqlda.pgc"
#line 121 "sqlda.pgc"
printf("FETCH RECORD %d\n", ++rec);
......@@ -285,23 +293,23 @@ if (sqlca.sqlcode < 0) exit (1);}
}
/* exec sql whenever not found continue ; */
#line 117 "sqlda.pgc"
#line 127 "sqlda.pgc"
strcpy(msg, "close");
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close mycur1", ECPGt_EOIT, ECPGt_EORT);
#line 120 "sqlda.pgc"
#line 130 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 120 "sqlda.pgc"
#line 130 "sqlda.pgc"
strcpy(msg, "deallocate");
{ ECPGdeallocate(__LINE__, 0, NULL, "st_id1");
#line 123 "sqlda.pgc"
#line 133 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 123 "sqlda.pgc"
#line 133 "sqlda.pgc"
free(outp_sqlda);
......@@ -312,35 +320,35 @@ if (sqlca.sqlcode < 0) exit (1);}
strcpy(msg, "prepare");
{ ECPGprepare(__LINE__, NULL, 0, "st_id2", stmt1);
#line 132 "sqlda.pgc"
#line 142 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 132 "sqlda.pgc"
#line 142 "sqlda.pgc"
strcpy(msg, "declare");
/* declare mycur2 cursor for $1 */
#line 135 "sqlda.pgc"
#line 145 "sqlda.pgc"
strcpy(msg, "open");
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur2 cursor for $1",
ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id2", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 138 "sqlda.pgc"
#line 148 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 138 "sqlda.pgc"
#line 148 "sqlda.pgc"
strcpy(msg, "fetch");
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch all from mycur2", ECPGt_EOIT,
ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 141 "sqlda.pgc"
#line 151 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 141 "sqlda.pgc"
#line 151 "sqlda.pgc"
outp_sqlda1 = outp_sqlda;
......@@ -358,18 +366,18 @@ if (sqlca.sqlcode < 0) exit (1);}
strcpy(msg, "close");
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close mycur2", ECPGt_EOIT, ECPGt_EORT);
#line 157 "sqlda.pgc"
#line 167 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 157 "sqlda.pgc"
#line 167 "sqlda.pgc"
strcpy(msg, "deallocate");
{ ECPGdeallocate(__LINE__, 0, NULL, "st_id2");
#line 160 "sqlda.pgc"
#line 170 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 160 "sqlda.pgc"
#line 170 "sqlda.pgc"
/* SQLDA test for getting one record using an input descriptor */
......@@ -393,10 +401,10 @@ if (sqlca.sqlcode < 0) exit (1);}
strcpy(msg, "prepare");
{ ECPGprepare(__LINE__, NULL, 0, "st_id3", stmt2);
#line 182 "sqlda.pgc"
#line 192 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 182 "sqlda.pgc"
#line 192 "sqlda.pgc"
strcpy(msg, "execute");
......@@ -405,20 +413,20 @@ if (sqlca.sqlcode < 0) exit (1);}
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 185 "sqlda.pgc"
#line 195 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 185 "sqlda.pgc"
#line 195 "sqlda.pgc"
dump_sqlda(outp_sqlda);
strcpy(msg, "deallocate");
{ ECPGdeallocate(__LINE__, 0, NULL, "st_id3");
#line 190 "sqlda.pgc"
#line 200 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 190 "sqlda.pgc"
#line 200 "sqlda.pgc"
free(inp_sqlda);
......@@ -429,10 +437,10 @@ if (sqlca.sqlcode < 0) exit (1);}
*/
{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , "con2", 0);
#line 199 "sqlda.pgc"
#line 209 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 199 "sqlda.pgc"
#line 209 "sqlda.pgc"
/*
......@@ -454,10 +462,10 @@ if (sqlca.sqlcode < 0) exit (1);}
strcpy(msg, "prepare");
{ ECPGprepare(__LINE__, "con2", 0, "st_id4", stmt2);
#line 219 "sqlda.pgc"
#line 229 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 219 "sqlda.pgc"
#line 229 "sqlda.pgc"
strcpy(msg, "execute");
......@@ -466,28 +474,28 @@ if (sqlca.sqlcode < 0) exit (1);}
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 222 "sqlda.pgc"
#line 232 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 222 "sqlda.pgc"
#line 232 "sqlda.pgc"
dump_sqlda(outp_sqlda);
strcpy(msg, "commit");
{ ECPGtrans(__LINE__, "con2", "commit");
#line 227 "sqlda.pgc"
#line 237 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 227 "sqlda.pgc"
#line 237 "sqlda.pgc"
strcpy(msg, "deallocate");
{ ECPGdeallocate(__LINE__, 0, NULL, "st_id4");
#line 230 "sqlda.pgc"
#line 240 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 230 "sqlda.pgc"
#line 240 "sqlda.pgc"
free(inp_sqlda);
......@@ -495,36 +503,36 @@ if (sqlca.sqlcode < 0) exit (1);}
strcpy(msg, "disconnect");
{ ECPGdisconnect(__LINE__, "con2");
#line 236 "sqlda.pgc"
#line 246 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 236 "sqlda.pgc"
#line 246 "sqlda.pgc"
/* End test */
strcpy(msg, "drop");
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table t1", ECPGt_EOIT, ECPGt_EORT);
#line 241 "sqlda.pgc"
#line 251 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 241 "sqlda.pgc"
#line 251 "sqlda.pgc"
strcpy(msg, "commit");
{ ECPGtrans(__LINE__, NULL, "commit");
#line 244 "sqlda.pgc"
#line 254 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 244 "sqlda.pgc"
#line 254 "sqlda.pgc"
strcpy(msg, "disconnect");
{ ECPGdisconnect(__LINE__, "CURRENT");
#line 247 "sqlda.pgc"
#line 257 "sqlda.pgc"
if (sqlca.sqlcode < 0) exit (1);}
#line 247 "sqlda.pgc"
#line 257 "sqlda.pgc"
return 0;
......
......@@ -4,45 +4,53 @@ name sqlda descriptor: 't' value 'a'
name sqlda descriptor: 'd1' value NUMERIC '1.0'
name sqlda descriptor: 'd2' value 1.000000
name sqlda descriptor: 'c' value 'a '
name sqlda descriptor: 'big' value 1111111111111111111
FETCH RECORD 2
name sqlda descriptor: 'id' value 2
name sqlda descriptor: 't' value NULL'
name sqlda descriptor: 'd1' value NULL'
name sqlda descriptor: 'd2' value NULL'
name sqlda descriptor: 'c' value NULL'
name sqlda descriptor: 'big' value NULL'
FETCH RECORD 3
name sqlda descriptor: 'id' value 4
name sqlda descriptor: 't' value 'd'
name sqlda descriptor: 'd1' value NUMERIC '4.0'
name sqlda descriptor: 'd2' value 4.000000
name sqlda descriptor: 'c' value 'd '
name sqlda descriptor: 'big' value 4444444444444444444
FETCH RECORD 1
name sqlda descriptor: 'id' value 1
name sqlda descriptor: 't' value 'a'
name sqlda descriptor: 'd1' value NUMERIC '1.0'
name sqlda descriptor: 'd2' value 1.000000
name sqlda descriptor: 'c' value 'a '
name sqlda descriptor: 'big' value 1111111111111111111
FETCH RECORD 2
name sqlda descriptor: 'id' value 2
name sqlda descriptor: 't' value NULL'
name sqlda descriptor: 'd1' value NULL'
name sqlda descriptor: 'd2' value NULL'
name sqlda descriptor: 'c' value NULL'
name sqlda descriptor: 'big' value NULL'
FETCH RECORD 3
name sqlda descriptor: 'id' value 4
name sqlda descriptor: 't' value 'd'
name sqlda descriptor: 'd1' value NUMERIC '4.0'
name sqlda descriptor: 'd2' value 4.000000
name sqlda descriptor: 'c' value 'd '
name sqlda descriptor: 'big' value 4444444444444444444
EXECUTE RECORD 4
name sqlda descriptor: 'id' value 4
name sqlda descriptor: 't' value 'd'
name sqlda descriptor: 'd1' value NUMERIC '4.0'
name sqlda descriptor: 'd2' value 4.000000
name sqlda descriptor: 'c' value 'd '
name sqlda descriptor: 'big' value 4444444444444444444
EXECUTE RECORD 4
name sqlda descriptor: 'id' value 4
name sqlda descriptor: 't' value 'd'
name sqlda descriptor: 'd1' value NUMERIC '4.0'
name sqlda descriptor: 'd2' value 4.000000
name sqlda descriptor: 'c' value 'd '
name sqlda descriptor: 'big' value 4444444444444444444
......@@ -36,6 +36,14 @@ dump_sqlda(sqlda_t *sqlda)
case ECPGt_int:
printf("name sqlda descriptor: '%s' value %d\n", sqlda->sqlvar[i].sqlname.data, *(int *)sqlda->sqlvar[i].sqldata);
break;
case ECPGt_long:
printf("name sqlda descriptor: '%s' value %ld\n", sqlda->sqlvar[i].sqlname.data, *(long int *)sqlda->sqlvar[i].sqldata);
break;
#ifdef HAVE_LONG_LONG_INT
case ECPGt_long_long:
printf("name sqlda descriptor: '%s' value %lld\n", sqlda->sqlvar[i].sqlname.data, *(long long int *)sqlda->sqlvar[i].sqldata);
break;
#endif
case ECPGt_double:
printf("name sqlda descriptor: '%s' value %lf\n", sqlda->sqlvar[i].sqlname.data, *(double *)sqlda->sqlvar[i].sqldata);
break;
......@@ -78,13 +86,15 @@ exec sql end declare section;
t text,
d1 numeric,
d2 float8,
c char(10));
c char(10),
big bigint
);
strcpy(msg, "insert");
exec sql insert into t1 values
(1, 'a', 1.0, 1, 'a'),
(2, null, null, null, null),
(4, 'd', 4.0, 4, 'd');
(1, 'a', 1.0, 1, 'a',1111111111111111111),
(2, null, null, null, null,null),
(4, 'd', 4.0, 4, 'd',4444444444444444444);
strcpy(msg, "commit");
exec sql commit;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment