Commit 1f393fc9 authored by Michael Meskes's avatar Michael Meskes

Fixed array handling in ecpg.

When ecpg was rewritten to the new protocol version not all variable types
were corrected. This patch rewrites the code for these types to fix that. It
also fixes the documentation to correctly tell the status of array handling.
parent 025c0242
...@@ -1377,10 +1377,13 @@ EXEC SQL END DECLARE SECTION; ...@@ -1377,10 +1377,13 @@ EXEC SQL END DECLARE SECTION;
<title>Arrays</title> <title>Arrays</title>
<para> <para>
SQL-level arrays are not directly supported in ECPG. It is not Multi-dimensional SQL-level arrays are not directly supported in ECPG.
possible to simply map an SQL array into a C array host variable. One-dimensional SQL-level arrays can be mapped into C array host
This will result in undefined behavior. Some workarounds exist, variables and vice-versa. However, when creating a statement ecpg does
however. not know the types of the columns, so that it cannot check if a C array
is input into a corresponding SQL-level array. When processing the
output of a SQL statement, ecpg has the necessary information and thus
checks if both are arrays.
</para> </para>
<para> <para>
......
...@@ -291,6 +291,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, ...@@ -291,6 +291,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
date ddres; date ddres;
timestamp tres; timestamp tres;
interval *ires; interval *ires;
char *endptr, endchar;
case ECPGt_short: case ECPGt_short:
case ECPGt_int: case ECPGt_int:
...@@ -564,10 +565,11 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, ...@@ -564,10 +565,11 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
case ECPGt_decimal: case ECPGt_decimal:
case ECPGt_numeric: case ECPGt_numeric:
if (isarray && *pval == '"') for (endptr = pval; *endptr && *endptr != ',' && *endptr != '}'; endptr++);
nres = PGTYPESnumeric_from_asc(pval + 1, &scan_length); endchar = *endptr;
else *endptr = '\0';
nres = PGTYPESnumeric_from_asc(pval, &scan_length); nres = PGTYPESnumeric_from_asc(pval, &scan_length);
*endptr = endchar;
/* did we get an error? */ /* did we get an error? */
if (nres == NULL) if (nres == NULL)
...@@ -600,10 +602,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, ...@@ -600,10 +602,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
} }
else else
{ {
if (isarray && *scan_length == '"') if (!isarray && garbage_left(isarray, scan_length, compat))
scan_length++;
if (garbage_left(isarray, scan_length, compat))
{ {
free(nres); free(nres);
ecpg_raise(lineno, ECPG_NUMERIC_FORMAT, ecpg_raise(lineno, ECPG_NUMERIC_FORMAT,
...@@ -622,10 +621,14 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, ...@@ -622,10 +621,14 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
break; break;
case ECPGt_interval: case ECPGt_interval:
if (isarray && *pval == '"') if (*pval == '"')
ires = PGTYPESinterval_from_asc(pval + 1, &scan_length); pval++;
else
ires = PGTYPESinterval_from_asc(pval, &scan_length); for (endptr = pval; *endptr && *endptr != ',' && *endptr != '"' && *endptr != '}'; endptr++);
endchar = *endptr;
*endptr = '\0';
ires = PGTYPESinterval_from_asc(pval, &scan_length);
*endptr = endchar;
/* did we get an error? */ /* did we get an error? */
if (ires == NULL) if (ires == NULL)
...@@ -654,10 +657,10 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, ...@@ -654,10 +657,10 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
} }
else else
{ {
if (isarray && *scan_length == '"') if (*scan_length == '"')
scan_length++; scan_length++;
if (garbage_left(isarray, scan_length, compat)) if (!isarray && garbage_left(isarray, scan_length, compat))
{ {
free(ires); free(ires);
ecpg_raise(lineno, ECPG_INTERVAL_FORMAT, ecpg_raise(lineno, ECPG_INTERVAL_FORMAT,
...@@ -672,10 +675,14 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, ...@@ -672,10 +675,14 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
break; break;
case ECPGt_date: case ECPGt_date:
if (isarray && *pval == '"') if (*pval == '"')
ddres = PGTYPESdate_from_asc(pval + 1, &scan_length); pval++;
else
ddres = PGTYPESdate_from_asc(pval, &scan_length); for (endptr = pval; *endptr && *endptr != ',' && *endptr != '"' && *endptr != '}'; endptr++);
endchar = *endptr;
*endptr = '\0';
ddres = PGTYPESdate_from_asc(pval, &scan_length);
*endptr = endchar;
/* did we get an error? */ /* did we get an error? */
if (errno != 0) if (errno != 0)
...@@ -700,10 +707,10 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, ...@@ -700,10 +707,10 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
} }
else else
{ {
if (isarray && *scan_length == '"') if (*scan_length == '"')
scan_length++; scan_length++;
if (garbage_left(isarray, scan_length, compat)) if (!isarray && garbage_left(isarray, scan_length, compat))
{ {
ecpg_raise(lineno, ECPG_DATE_FORMAT, ecpg_raise(lineno, ECPG_DATE_FORMAT,
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval); ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
...@@ -716,10 +723,14 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, ...@@ -716,10 +723,14 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
break; break;
case ECPGt_timestamp: case ECPGt_timestamp:
if (isarray && *pval == '"') if (*pval == '"')
tres = PGTYPEStimestamp_from_asc(pval + 1, &scan_length); pval++;
else
tres = PGTYPEStimestamp_from_asc(pval, &scan_length); for (endptr = pval; *endptr && *endptr != ',' && *endptr != '"' && *endptr != '}'; endptr++);
endchar = *endptr;
*endptr = '\0';
tres = PGTYPEStimestamp_from_asc(pval, &scan_length);
*endptr = endchar;
/* did we get an error? */ /* did we get an error? */
if (errno != 0) if (errno != 0)
...@@ -744,10 +755,10 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, ...@@ -744,10 +755,10 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
} }
else else
{ {
if (isarray && *scan_length == '"') if (*scan_length == '"')
scan_length++; scan_length++;
if (garbage_left(isarray, scan_length, compat)) if (!isarray && garbage_left(isarray, scan_length, compat))
{ {
ecpg_raise(lineno, ECPG_TIMESTAMP_FORMAT, ecpg_raise(lineno, ECPG_TIMESTAMP_FORMAT,
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval); ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
......
This diff is collapsed.
...@@ -11,8 +11,13 @@ ...@@ -11,8 +11,13 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <pgtypes_date.h>
#include <pgtypes_interval.h>
#include <pgtypes_numeric.h>
#include <pgtypes_timestamp.h>
/* exec sql whenever sqlerror sqlprint ; */ /* exec sql whenever sqlerror sqlprint ; */
#line 5 "array.pgc" #line 10 "array.pgc"
...@@ -84,7 +89,7 @@ struct sqlca_t *ECPGget_sqlca(void); ...@@ -84,7 +89,7 @@ struct sqlca_t *ECPGget_sqlca(void);
#endif #endif
#line 7 "array.pgc" #line 12 "array.pgc"
#line 1 "regression.h" #line 1 "regression.h"
...@@ -94,39 +99,55 @@ struct sqlca_t *ECPGget_sqlca(void); ...@@ -94,39 +99,55 @@ struct sqlca_t *ECPGget_sqlca(void);
#line 8 "array.pgc" #line 13 "array.pgc"
int int
main (void) main (void)
{ {
/* exec sql begin declare section */ /* exec sql begin declare section */
#line 14 "array.pgc" #line 19 "array.pgc"
int i = 1 ; int i = 1 , j ;
#line 15 "array.pgc" #line 20 "array.pgc"
int * did = & i ; int * did = & i ;
#line 16 "array.pgc" #line 21 "array.pgc"
int a [ 10 ] = { 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 } ; short a [ 10 ] = { 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 } ;
#line 22 "array.pgc"
timestamp ts [ 10 ] ;
#line 17 "array.pgc" #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" ; char text [ 25 ] = "klmnopqrst" ;
#line 18 "array.pgc" #line 27 "array.pgc"
char * t = ( char * ) malloc ( 11 ) ; char * t = ( char * ) malloc ( 11 ) ;
#line 19 "array.pgc" #line 28 "array.pgc"
double f ; double f ;
/* exec sql end declare section */ /* exec sql end declare section */
#line 20 "array.pgc" #line 29 "array.pgc"
strcpy(t, "0123456789"); strcpy(t, "0123456789");
...@@ -134,77 +155,124 @@ main (void) ...@@ -134,77 +155,124 @@ main (void)
ECPGdebug(1, stderr); 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, "regress1" , NULL, NULL , NULL, 0); { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0);
#line 27 "array.pgc" #line 53 "array.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 27 "array.pgc" #line 53 "array.pgc"
{ ECPGsetcommit(__LINE__, "on", NULL); { ECPGsetcommit(__LINE__, "on", NULL);
#line 29 "array.pgc" #line 55 "array.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 29 "array.pgc" #line 55 "array.pgc"
{ ECPGtrans(__LINE__, NULL, "begin work"); { ECPGtrans(__LINE__, NULL, "begin work");
#line 31 "array.pgc" #line 57 "array.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 31 "array.pgc" #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 ) )", ECPGt_EOIT, ECPGt_EORT); { 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 33 "array.pgc" #line 59 "array.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 33 "array.pgc" #line 59 "array.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( f , i , a , text ) values ( 404.90 , 3 , '{0,1,2,3,4,5,6,7,8,9}' , 'abcdefghij' )", ECPGt_EOIT, ECPGt_EORT); { 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 )",
#line 35 "array.pgc" 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();} if (sqlca.sqlcode < 0) sqlprint();}
#line 35 "array.pgc" #line 61 "array.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( f , i , a , text ) values ( 140787.0 , 2 , $1 , $2 )", { 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_int,(a),(long)1,(long)10,sizeof(int), ECPGt_short,(a),(long)1,(long)10,sizeof(short),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char), 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); ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 37 "array.pgc" #line 63 "array.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 37 "array.pgc" #line 63 "array.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( f , i , a , text ) values ( 14.07 , $1 , $2 , $3 )", { 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_int,&(did),(long)1,(long)0,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_int,(a),(long)1,(long)10,sizeof(int), ECPGt_short,(a),(long)1,(long)10,sizeof(short),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_char,&(t),(long)0,(long)1,(1)*sizeof(char), 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); ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 39 "array.pgc" #line 65 "array.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 39 "array.pgc" #line 65 "array.pgc"
{ ECPGtrans(__LINE__, NULL, "commit"); { ECPGtrans(__LINE__, NULL, "commit");
#line 41 "array.pgc" #line 67 "array.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 41 "array.pgc" #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"); { ECPGtrans(__LINE__, NULL, "begin work");
#line 43 "array.pgc" #line 75 "array.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 43 "array.pgc" #line 75 "array.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select f , text from test where i = 1", ECPGt_EOIT, { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select f , text from test where i = 1", ECPGt_EOIT,
...@@ -212,30 +280,38 @@ if (sqlca.sqlcode < 0) sqlprint();} ...@@ -212,30 +280,38 @@ if (sqlca.sqlcode < 0) sqlprint();}
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char), ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 48 "array.pgc" #line 80 "array.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 48 "array.pgc" #line 80 "array.pgc"
printf("Found f=%f text=%10.10s\n", f, text); printf("Found f=%f text=%10.10s\n", f, text);
f=140787; f=140787;
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select a , text from test where f = $1 ", { 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_double,&(f),(long)1,(long)1,sizeof(double),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
ECPGt_int,(a),(long)1,(long)10,sizeof(int), ECPGt_short,(a),(long)1,(long)10,sizeof(short),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_char,&(t),(long)0,(long)1,(1)*sizeof(char), 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); ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 56 "array.pgc" #line 88 "array.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 56 "array.pgc" #line 88 "array.pgc"
for (i = 0; i < 10; i++) for (i = 0; i < 10; i++)
printf("Found a[%d] = %d\n", i, a[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); printf("Found text=%10.10s\n", t);
...@@ -244,33 +320,33 @@ if (sqlca.sqlcode < 0) sqlprint();} ...@@ -244,33 +320,33 @@ if (sqlca.sqlcode < 0) sqlprint();}
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char), ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 66 "array.pgc" #line 98 "array.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 66 "array.pgc" #line 98 "array.pgc"
printf("Found text=%s\n", text); printf("Found text=%s\n", text);
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT); { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
#line 70 "array.pgc" #line 102 "array.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 70 "array.pgc" #line 102 "array.pgc"
{ ECPGtrans(__LINE__, NULL, "commit"); { ECPGtrans(__LINE__, NULL, "commit");
#line 72 "array.pgc" #line 104 "array.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 72 "array.pgc" #line 104 "array.pgc"
{ ECPGdisconnect(__LINE__, "CURRENT"); { ECPGdisconnect(__LINE__, "CURRENT");
#line 74 "array.pgc" #line 106 "array.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 74 "array.pgc" #line 106 "array.pgc"
free(t); free(t);
......
Found f=14.070000 text=0123456789 Found f=14.070000 text=0123456789
Found a[0] = 9 Found a[0] = 9 ts[0] = 2000-01-01 00:00:00 n[0] = 0.0 d[0] = 2000-01-10 in[0] = @ 10 hours
Found a[1] = 8 Found a[1] = 8 ts[1] = 2000-01-01 01:00:00 n[1] = 1.0 d[1] = 2000-01-11 in[1] = @ 11 hours
Found a[2] = 7 Found a[2] = 7 ts[2] = 2000-01-01 02:00:00 n[2] = 2.0 d[2] = 2000-01-12 in[2] = @ 12 hours
Found a[3] = 6 Found a[3] = 6 ts[3] = 2000-01-01 03:00:00 n[3] = 3.0 d[3] = 2000-01-13 in[3] = @ 13 hours
Found a[4] = 5 Found a[4] = 5 ts[4] = 2000-01-01 04:00:00 n[4] = 4.0 d[4] = 2000-01-14 in[4] = @ 14 hours
Found a[5] = 4 Found a[5] = 4 ts[5] = 2000-01-01 05:00:00 n[5] = 5.0 d[5] = 2000-01-15 in[5] = @ 15 hours
Found a[6] = 3 Found a[6] = 3 ts[6] = 2000-01-01 06:00:00 n[6] = 6.0 d[6] = 2000-01-16 in[6] = @ 16 hours
Found a[7] = 2 Found a[7] = 2 ts[7] = 2000-01-01 07:00:00 n[7] = 7.0 d[7] = 2000-01-17 in[7] = @ 17 hours
Found a[8] = 1 Found a[8] = 1 ts[8] = 2000-01-01 08:00:00 n[8] = 8.0 d[8] = 2000-01-18 in[8] = @ 18 hours
Found a[9] = 0 Found a[9] = 0 ts[9] = 2000-01-01 09:00:00 n[9] = 9.0 d[9] = 2000-01-19 in[9] = @ 19 hours
Found text=klmnopqrst Found text=klmnopqrst
Found text={9,8,7,6,5,4,3,2,1,0} Found text={9,8,7,6,5,4,3,2,1,0}
...@@ -64,89 +64,90 @@ main(void) ...@@ -64,89 +64,90 @@ main(void)
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 24 "oldexec.pgc" #line 24 "oldexec.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "create table test ( name char ( 8 ) , amount int , letter char ( 1 ) )", ECPGt_EOIT, ECPGt_EORT); { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "create table test ( name char ( 8 ) , amount int , letter char ( 1 ) )", ECPGt_EOIT, ECPGt_EORT);
#line 25 "oldexec.pgc" #line 26 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 25 "oldexec.pgc" #line 26 "oldexec.pgc"
{ ECPGtrans(__LINE__, NULL, "commit"); { ECPGtrans(__LINE__, NULL, "commit");
#line 26 "oldexec.pgc" #line 27 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 26 "oldexec.pgc" #line 27 "oldexec.pgc"
sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 1, 'f')"); sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 1, 'f')");
{ ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT); { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
#line 29 "oldexec.pgc" #line 30 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 29 "oldexec.pgc" #line 30 "oldexec.pgc"
sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 2, 't')"); sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 2, 't')");
{ ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT); { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
#line 32 "oldexec.pgc" #line 33 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 32 "oldexec.pgc" #line 33 "oldexec.pgc"
sprintf(command, "insert into test (name, amount, letter) select name, amount+10, letter from test"); sprintf(command, "insert into test (name, amount, letter) select name, amount+10, letter from test");
{ ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT); { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
#line 35 "oldexec.pgc" #line 36 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 35 "oldexec.pgc" #line 36 "oldexec.pgc"
printf("Inserted %ld tuples via execute immediate\n", sqlca.sqlerrd[2]); printf("Inserted %ld tuples via execute immediate\n", sqlca.sqlerrd[2]);
sprintf(command, "insert into test (name, amount, letter) select name, amount+$1, letter from test"); sprintf(command, "insert into test (name, amount, letter) select name, amount+$1, letter from test");
{ ECPGprepare(__LINE__, NULL, 1, "i", command); { ECPGprepare(__LINE__, NULL, 1, "i", command);
#line 40 "oldexec.pgc" #line 41 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 40 "oldexec.pgc" #line 41 "oldexec.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_execute, "i", { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_execute, "i",
ECPGt_int,&(increment),(long)1,(long)1,sizeof(int), ECPGt_int,&(increment),(long)1,(long)1,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT); ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 41 "oldexec.pgc" #line 42 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 41 "oldexec.pgc" #line 42 "oldexec.pgc"
printf("Inserted %ld tuples via prepared execute\n", sqlca.sqlerrd[2]); printf("Inserted %ld tuples via prepared execute\n", sqlca.sqlerrd[2]);
{ ECPGtrans(__LINE__, NULL, "commit"); { ECPGtrans(__LINE__, NULL, "commit");
#line 45 "oldexec.pgc" #line 46 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 45 "oldexec.pgc" #line 46 "oldexec.pgc"
sprintf (command, "select * from test"); sprintf (command, "select * from test");
{ ECPGprepare(__LINE__, NULL, 1, "f", command); { ECPGprepare(__LINE__, NULL, 1, "f", command);
#line 49 "oldexec.pgc" #line 50 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 49 "oldexec.pgc" #line 50 "oldexec.pgc"
/* declare CUR cursor for $1 */ /* declare CUR cursor for $1 */
#line 50 "oldexec.pgc" #line 51 "oldexec.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "declare CUR cursor for $1", { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "declare CUR cursor for $1",
ECPGt_char_variable,(ECPGprepared_statement(NULL, "f", __LINE__)),(long)1,(long)1,(1)*sizeof(char), ECPGt_char_variable,(ECPGprepared_statement(NULL, "f", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT); ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 52 "oldexec.pgc" #line 53 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 52 "oldexec.pgc" #line 53 "oldexec.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "fetch 8 in CUR", ECPGt_EOIT, { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "fetch 8 in CUR", ECPGt_EOIT,
ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char), ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char),
...@@ -155,48 +156,38 @@ if (sqlca.sqlcode < 0) sqlprint();} ...@@ -155,48 +156,38 @@ if (sqlca.sqlcode < 0) sqlprint();}
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_char,(letter),(long)1,(long)8,(1)*sizeof(char), ECPGt_char,(letter),(long)1,(long)8,(1)*sizeof(char),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 53 "oldexec.pgc" #line 54 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 53 "oldexec.pgc" #line 54 "oldexec.pgc"
for (i=0, j=sqlca.sqlerrd[2]; i<j; i++) for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
{ {
/* exec sql begin declare section */ char n[8], l = letter[i][0];
int a = amount[i];
#line 58 "oldexec.pgc"
char n [ 8 ] , l = letter [ i ] [ 0 ] ;
#line 59 "oldexec.pgc"
int a = amount [ i ] ;
/* exec sql end declare section */
#line 60 "oldexec.pgc"
strncpy(n, name[i], 8); strncpy(n, name[i], 8);
printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l); printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
} }
{ ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "close CUR", ECPGt_EOIT, ECPGt_EORT); { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "close CUR", ECPGt_EOIT, ECPGt_EORT);
#line 66 "oldexec.pgc" #line 65 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 66 "oldexec.pgc" #line 65 "oldexec.pgc"
sprintf (command, "select * from test where ? = amount"); sprintf (command, "select * from test where ? = amount");
{ ECPGprepare(__LINE__, NULL, 1, "f", command); { ECPGprepare(__LINE__, NULL, 1, "f", command);
#line 70 "oldexec.pgc" #line 69 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 70 "oldexec.pgc" #line 69 "oldexec.pgc"
/* declare CUR3 cursor for $1 */ /* declare CUR3 cursor for $1 */
#line 71 "oldexec.pgc" #line 70 "oldexec.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "declare CUR3 cursor for $1", { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "declare CUR3 cursor for $1",
...@@ -204,10 +195,10 @@ if (sqlca.sqlcode < 0) sqlprint();} ...@@ -204,10 +195,10 @@ if (sqlca.sqlcode < 0) sqlprint();}
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_const,"1",(long)1,(long)1,strlen("1"), ECPGt_const,"1",(long)1,(long)1,strlen("1"),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT); ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 73 "oldexec.pgc" #line 72 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 73 "oldexec.pgc" #line 72 "oldexec.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "fetch in CUR3", ECPGt_EOIT, { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "fetch in CUR3", ECPGt_EOIT,
ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char), ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char),
...@@ -216,54 +207,44 @@ if (sqlca.sqlcode < 0) sqlprint();} ...@@ -216,54 +207,44 @@ if (sqlca.sqlcode < 0) sqlprint();}
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_char,(letter),(long)1,(long)8,(1)*sizeof(char), ECPGt_char,(letter),(long)1,(long)8,(1)*sizeof(char),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 74 "oldexec.pgc" #line 73 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 74 "oldexec.pgc" #line 73 "oldexec.pgc"
for (i=0, j=sqlca.sqlerrd[2]; i<j; i++) for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
{ {
/* exec sql begin declare section */ char n[8], l = letter[i][0];
int a = amount[i];
#line 79 "oldexec.pgc"
char n [ 8 ] , l = letter [ i ] [ 0 ] ;
#line 80 "oldexec.pgc"
int a = amount [ i ] ;
/* exec sql end declare section */
#line 81 "oldexec.pgc"
strncpy(n, name[i], 8); strncpy(n, name[i], 8);
printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l); printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
} }
{ ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "close CUR3", ECPGt_EOIT, ECPGt_EORT); { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "close CUR3", ECPGt_EOIT, ECPGt_EORT);
#line 87 "oldexec.pgc" #line 84 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 87 "oldexec.pgc" #line 84 "oldexec.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT); { ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
#line 88 "oldexec.pgc" #line 85 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 88 "oldexec.pgc" #line 85 "oldexec.pgc"
{ ECPGtrans(__LINE__, NULL, "commit"); { ECPGtrans(__LINE__, NULL, "commit");
#line 89 "oldexec.pgc" #line 86 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 89 "oldexec.pgc" #line 86 "oldexec.pgc"
{ ECPGdisconnect(__LINE__, "CURRENT"); { ECPGdisconnect(__LINE__, "CURRENT");
#line 90 "oldexec.pgc" #line 87 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();}
#line 90 "oldexec.pgc" #line 87 "oldexec.pgc"
return (0); return (0);
......
...@@ -2,6 +2,11 @@ ...@@ -2,6 +2,11 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <pgtypes_date.h>
#include <pgtypes_interval.h>
#include <pgtypes_numeric.h>
#include <pgtypes_timestamp.h>
exec sql whenever sqlerror sqlprint; exec sql whenever sqlerror sqlprint;
exec sql include sqlca; exec sql include sqlca;
...@@ -11,9 +16,13 @@ int ...@@ -11,9 +16,13 @@ int
main (void) main (void)
{ {
EXEC SQL BEGIN DECLARE SECTION; EXEC SQL BEGIN DECLARE SECTION;
int i = 1; int i = 1, j;
int *did = &i; int *did = &i;
int a[10] = {9,8,7,6,5,4,3,2,1,0}; short a[10] = {9,8,7,6,5,4,3,2,1,0};
timestamp ts[10];
date d[10];
interval in[10];
numeric n[10];
char text[25] = "klmnopqrst"; char text[25] = "klmnopqrst";
char *t = (char *)malloc(11); char *t = (char *)malloc(11);
double f; double f;
...@@ -24,22 +33,45 @@ EXEC SQL END DECLARE SECTION; ...@@ -24,22 +33,45 @@ EXEC SQL END DECLARE SECTION;
ECPGdebug(1, stderr); 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;
}
EXEC SQL CONNECT TO REGRESSDB1; EXEC SQL CONNECT TO REGRESSDB1;
EXEC SQL SET AUTOCOMMIT = ON; EXEC SQL SET AUTOCOMMIT = ON;
EXEC SQL BEGIN WORK; EXEC SQL BEGIN WORK;
EXEC SQL CREATE TABLE test (f float, i int, a int[10], text char(10)); EXEC SQL 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]);
EXEC SQL INSERT INTO test(f,i,a,text) VALUES(404.90,3,'{0,1,2,3,4,5,6,7,8,9}','abcdefghij'); EXEC SQL 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',:ts,:n,:d,:in);
EXEC SQL INSERT INTO test(f,i,a,text) VALUES(140787.0,2,:a,:text); EXEC SQL INSERT INTO test(f,i,a,text,ts,n,d,inter) VALUES(140787.0,2,:a,:text,:ts,:n,:d,:in);
EXEC SQL INSERT INTO test(f,i,a,text) VALUES(14.07,:did,:a,:t); EXEC SQL INSERT INTO test(f,i,a,text,ts,n,d,inter) VALUES(14.07,:did,:a,:t,:ts,:n,:d,:in);
EXEC SQL COMMIT; EXEC SQL COMMIT;
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();
}
EXEC SQL BEGIN WORK; EXEC SQL BEGIN WORK;
EXEC SQL SELECT f,text EXEC SQL SELECT f,text
...@@ -50,13 +82,13 @@ EXEC SQL END DECLARE SECTION; ...@@ -50,13 +82,13 @@ EXEC SQL END DECLARE SECTION;
printf("Found f=%f text=%10.10s\n", f, text); printf("Found f=%f text=%10.10s\n", f, text);
f=140787; f=140787;
EXEC SQL SELECT a,text EXEC SQL SELECT a,text,ts,n,d,inter
INTO :a,:t INTO :a,:t,:ts,:n,:d,:in
FROM test FROM test
WHERE f = :f; WHERE f = :f;
for (i = 0; i < 10; i++) for (i = 0; i < 10; i++)
printf("Found a[%d] = %d\n", i, a[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); printf("Found text=%10.10s\n", t);
......
...@@ -22,6 +22,7 @@ exec sql end declare section; ...@@ -22,6 +22,7 @@ exec sql end declare section;
ECPGdebug(1, stderr); ECPGdebug(1, stderr);
exec sql connect to REGRESSDB1 as main; exec sql connect to REGRESSDB1 as main;
exec sql create table test (name char(8), amount int, letter char(1)); exec sql create table test (name char(8), amount int, letter char(1));
exec sql commit; exec sql commit;
...@@ -54,10 +55,8 @@ exec sql end declare section; ...@@ -54,10 +55,8 @@ exec sql end declare section;
for (i=0, j=sqlca.sqlerrd[2]; i<j; i++) for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
{ {
exec sql begin declare section;
char n[8], l = letter[i][0]; char n[8], l = letter[i][0];
int a = amount[i]; int a = amount[i];
exec sql end declare section;
strncpy(n, name[i], 8); strncpy(n, name[i], 8);
printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l); printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
...@@ -75,10 +74,8 @@ exec sql end declare section; ...@@ -75,10 +74,8 @@ exec sql end declare section;
for (i=0, j=sqlca.sqlerrd[2]; i<j; i++) for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
{ {
exec sql begin declare section;
char n[8], l = letter[i][0]; char n[8], l = letter[i][0];
int a = amount[i]; int a = amount[i];
exec sql end declare section;
strncpy(n, name[i], 8); strncpy(n, name[i], 8);
printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l); printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
......
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