From c9970d5948b0ffcf771eef8499c9d3e7a57f4952 Mon Sep 17 00:00:00 2001 From: Michael Meskes Date: Tue, 5 Sep 2006 12:11:03 +0000 Subject: Started to cleanup complex tests. Added some interval checks to regression suite. --- src/interfaces/ecpg/test/Makefile | 6 +- src/interfaces/ecpg/test/complex/Makefile | 7 +- src/interfaces/ecpg/test/complex/test4.pgc | 95 ------- src/interfaces/ecpg/test/complex/test5.pgc | 105 ------- src/interfaces/ecpg/test/expected/complex-test4.c | 308 --------------------- .../ecpg/test/expected/complex-test4.stderr | 62 ----- .../ecpg/test/expected/complex-test4.stdout | 13 - src/interfaces/ecpg/test/expected/complex-test5.c | 215 -------------- .../ecpg/test/expected/complex-test5.stderr | 56 ---- .../ecpg/test/expected/complex-test5.stdout | 3 - src/interfaces/ecpg/test/expected/errors-init.c | 261 ----------------- .../ecpg/test/expected/errors-init.stderr | 14 - .../ecpg/test/expected/errors-init.stdout | 10 - .../ecpg/test/expected/pgtypeslib-dt_test2.c | 109 +++++++- .../ecpg/test/expected/pgtypeslib-dt_test2.stdout | 95 +++++++ src/interfaces/ecpg/test/expected/preproc-define.c | 127 +++++++++ .../ecpg/test/expected/preproc-define.stderr | 24 ++ .../ecpg/test/expected/preproc-define.stdout | 1 + src/interfaces/ecpg/test/expected/preproc-init.c | 261 +++++++++++++++++ .../ecpg/test/expected/preproc-init.stderr | 14 + .../ecpg/test/expected/preproc-init.stdout | 10 + src/interfaces/ecpg/test/expected/sql-array.c | 277 ++++++++++++++++++ src/interfaces/ecpg/test/expected/sql-array.stderr | 60 ++++ src/interfaces/ecpg/test/expected/sql-array.stdout | 13 + src/interfaces/ecpg/test/expected/sql-binary.c | 164 +++++++++++ .../ecpg/test/expected/sql-binary.stderr | 46 +++ .../ecpg/test/expected/sql-binary.stdout | 2 + src/interfaces/ecpg/test/pgtypeslib/dt_test2.pgc | 98 ++++++- src/interfaces/ecpg/test/preproc/Makefile | 11 + src/interfaces/ecpg/test/preproc/define.pgc | 64 +++++ src/interfaces/ecpg/test/preproc/init.pgc | 100 +++++++ src/interfaces/ecpg/test/sql/Makefile | 16 +- src/interfaces/ecpg/test/sql/array.pgc | 77 ++++++ src/interfaces/ecpg/test/sql/binary.pgc | 85 ++++++ 34 files changed, 1645 insertions(+), 1164 deletions(-) delete mode 100644 src/interfaces/ecpg/test/complex/test4.pgc delete mode 100644 src/interfaces/ecpg/test/complex/test5.pgc delete mode 100644 src/interfaces/ecpg/test/expected/complex-test4.c delete mode 100644 src/interfaces/ecpg/test/expected/complex-test4.stderr delete mode 100644 src/interfaces/ecpg/test/expected/complex-test4.stdout delete mode 100644 src/interfaces/ecpg/test/expected/complex-test5.c delete mode 100644 src/interfaces/ecpg/test/expected/complex-test5.stderr delete mode 100644 src/interfaces/ecpg/test/expected/complex-test5.stdout delete mode 100644 src/interfaces/ecpg/test/expected/errors-init.c delete mode 100644 src/interfaces/ecpg/test/expected/errors-init.stderr delete mode 100644 src/interfaces/ecpg/test/expected/errors-init.stdout create mode 100644 src/interfaces/ecpg/test/expected/preproc-define.c create mode 100644 src/interfaces/ecpg/test/expected/preproc-define.stderr create mode 100644 src/interfaces/ecpg/test/expected/preproc-define.stdout create mode 100644 src/interfaces/ecpg/test/expected/preproc-init.c create mode 100644 src/interfaces/ecpg/test/expected/preproc-init.stderr create mode 100644 src/interfaces/ecpg/test/expected/preproc-init.stdout create mode 100644 src/interfaces/ecpg/test/expected/sql-array.c create mode 100644 src/interfaces/ecpg/test/expected/sql-array.stderr create mode 100644 src/interfaces/ecpg/test/expected/sql-array.stdout create mode 100644 src/interfaces/ecpg/test/expected/sql-binary.c create mode 100644 src/interfaces/ecpg/test/expected/sql-binary.stderr create mode 100644 src/interfaces/ecpg/test/expected/sql-binary.stdout create mode 100644 src/interfaces/ecpg/test/preproc/Makefile create mode 100644 src/interfaces/ecpg/test/preproc/define.pgc create mode 100644 src/interfaces/ecpg/test/preproc/init.pgc create mode 100644 src/interfaces/ecpg/test/sql/array.pgc create mode 100644 src/interfaces/ecpg/test/sql/binary.pgc (limited to 'src') diff --git a/src/interfaces/ecpg/test/Makefile b/src/interfaces/ecpg/test/Makefile index 9147b7d71e4..5ed4622cabf 100644 --- a/src/interfaces/ecpg/test/Makefile +++ b/src/interfaces/ecpg/test/Makefile @@ -1,4 +1,4 @@ -# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.60 2006/08/29 12:33:45 meskes Exp $ +# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.61 2006/09/05 12:11:01 meskes Exp $ subdir = src/interfaces/ecpg/test top_builddir = ../../../.. @@ -27,7 +27,7 @@ all install installdirs uninstall dep depend distprep: $(MAKE) -C connect $@ $(MAKE) -C sql $@ $(MAKE) -C pgtypeslib $@ - $(MAKE) -C errors $@ + $(MAKE) -C preproc $@ $(MAKE) -C compat_informix $@ $(MAKE) -C complex $@ $(MAKE) -C thread $@ @@ -37,7 +37,7 @@ clean distclean maintainer-clean: $(MAKE) -C connect extraclean $(MAKE) -C sql $@ $(MAKE) -C pgtypeslib $@ - $(MAKE) -C errors $@ + $(MAKE) -C preproc $@ $(MAKE) -C compat_informix $@ $(MAKE) -C complex $@ $(MAKE) -C thread $@ diff --git a/src/interfaces/ecpg/test/complex/Makefile b/src/interfaces/ecpg/test/complex/Makefile index 0883341f0a7..5cd59f20ca5 100644 --- a/src/interfaces/ecpg/test/complex/Makefile +++ b/src/interfaces/ecpg/test/complex/Makefile @@ -6,12 +6,7 @@ include $(top_srcdir)/$(subdir)/../Makefile.regress TESTS = test1 test1.c \ test2 test2.c \ - test3 test3.c \ - test4 test4.c \ - test5 test5.c + test3 test3.c all: $(TESTS) -# test4 needs the -c option for the "EXEC SQL TYPE" construct -test4.c: test4.pgc ../regression.h - $(ECPG) -c -o $@ -I$(srcdir) $< diff --git a/src/interfaces/ecpg/test/complex/test4.pgc b/src/interfaces/ecpg/test/complex/test4.pgc deleted file mode 100644 index 4be713b2fda..00000000000 --- a/src/interfaces/ecpg/test/complex/test4.pgc +++ /dev/null @@ -1,95 +0,0 @@ -#include -#include -#include - -exec sql whenever sqlerror sqlprint; - -exec sql include sqlca; -exec sql include ../regression; - -EXEC SQL type errtype is enum -{ - OK = 0, - ERR = 1, - WARN = 2 -}; - -int -main (void) -{ -EXEC SQL BEGIN DECLARE SECTION; - struct - { - errtype e :2; - int code :14; - } error = {1, 147}; - int i = 1; - int *did = &i; - int a[10] = {9,8,7,6,5,4,3,2,1,0}; - char text[25] = "klmnopqrst"; - char *t = (char *)malloc(11); - double f; - bool b = true; -EXEC SQL END DECLARE SECTION; - - strcpy(t, "0123456789"); - setlocale(LC_ALL, "C"); - - ECPGdebug(1, stderr); - - EXEC SQL CONNECT TO REGRESSDB1; - - EXEC SQL SET AUTOCOMMIT = ON; - - EXEC SQL BEGIN WORK; - - EXEC SQL CREATE TABLE test (f float, i int, a int[10], text char(10), b bool, t int, err int); - - EXEC SQL INSERT INTO test(f,i,a,text,b,t,err) VALUES(404.90,3,'{0,1,2,3,4,5,6,7,8,9}','abcdefghij','f',0,0); - - EXEC SQL INSERT INTO test(f,i,a,text,b,t,err) VALUES(140787.0,2,:a,:text,'t',2,14); - -EXEC SQL IFDEF BIT_FIELD_IS_NOT_ACCESSIBLE; - EXEC SQL INSERT INTO test(f,i,a,text,b,t,err) VALUES(14.07,:did,:a,:t,:b,:error); -EXEC SQL ELSE; - EXEC SQL INSERT INTO test(f,i,a,text,b,t,err) VALUES(14.07,:did,:a,:t,:b,1,147); - error.code=0; -EXEC SQL ENDIF; - - EXEC SQL COMMIT; - - EXEC SQL BEGIN WORK; - - EXEC SQL SELECT f,text,b - INTO :f,:text,:b - FROM test - WHERE i = 1; - - printf("Found f=%f text=%10.10s b=%d\n", f, text, b); - - f=140787; - EXEC SQL SELECT a,text - INTO :a,:t - FROM test - WHERE f = :f; - - for (i = 0; i < 10; i++) - printf("Found a[%d] = %d\n", i, a[i]); - - printf("Found text=%10.10s\n", t); - - EXEC SQL SELECT a - INTO :text - FROM test - WHERE f = :f; - - printf("Found text=%s\n", text); - - EXEC SQL DROP TABLE test; - - EXEC SQL COMMIT; - - EXEC SQL DISCONNECT; - - return (0); -} diff --git a/src/interfaces/ecpg/test/complex/test5.pgc b/src/interfaces/ecpg/test/complex/test5.pgc deleted file mode 100644 index fa759c0ea25..00000000000 --- a/src/interfaces/ecpg/test/complex/test5.pgc +++ /dev/null @@ -1,105 +0,0 @@ -#include -#include - -EXEC SQL include ../regression; - -EXEC SQL typedef long mmInteger; -EXEC SQL typedef char mmChar; -EXEC SQL typedef short mmSmallInt; - -EXEC SQL BEGIN DECLARE SECTION; -struct TBempl -{ - mmInteger idnum; - mmChar name[21]; - mmSmallInt accs; - mmChar byte[20]; -}; -EXEC SQL END DECLARE SECTION; - -int -main (void) -{ - EXEC SQL BEGIN DECLARE SECTION; - struct TBempl empl; - char *data = "\\001\\155\\000\\212"; - union - { - mmSmallInt accs; - char t[2]; - } a; - EXEC SQL END DECLARE SECTION; - int i; - - ECPGdebug (1, stderr); - - empl.idnum = 1; - EXEC SQL connect to REGRESSDB1; - if (sqlca.sqlcode) - { - printf ("connect error = %ld\n", sqlca.sqlcode); - exit (sqlca.sqlcode); - } - - EXEC SQL create table empl - (idnum integer, name char (20), accs smallint, byte bytea); - if (sqlca.sqlcode) - { - printf ("create error = %ld\n", sqlca.sqlcode); - exit (sqlca.sqlcode); - } - - EXEC SQL insert into empl values (1, 'first user', 320,:data); - if (sqlca.sqlcode) - { - printf ("insert error = %ld\n", sqlca.sqlcode); - exit (sqlca.sqlcode); - } - - EXEC SQL select name, accs, byte - into :empl.name, :empl.accs, :empl.byte - from empl - where idnum =:empl.idnum; - if (sqlca.sqlcode) - { - printf ("select error = %ld\n", sqlca.sqlcode); - exit (sqlca.sqlcode); - } - printf ("name=%s, accs=%d byte=%s\n", empl.name, empl.accs, empl.byte); - - EXEC SQL DECLARE C CURSOR FOR select name, accs, byte from empl where idnum =:empl.idnum; - EXEC SQL OPEN C; - EXEC SQL FETCH C INTO:empl.name,:empl.accs,:empl.byte; - if (sqlca.sqlcode) - { - printf ("fetch error = %ld\n", sqlca.sqlcode); - exit (sqlca.sqlcode); - } - - printf ("name=%s, accs=%d byte=%s\n", empl.name, empl.accs, empl.byte); - - memset(empl.name, 0, 21L); - memset(empl.byte, '#', 20L); - EXEC SQL DECLARE B BINARY CURSOR FOR select name, accs, byte from empl where idnum =:empl.idnum; - EXEC SQL OPEN B; - EXEC SQL FETCH B INTO :empl.name,:a.accs,:empl.byte; - if (sqlca.sqlcode) - { - printf ("fetch error = %ld\n", sqlca.sqlcode); - exit (sqlca.sqlcode); - } - - EXEC SQL CLOSE B; - - /* do not print a.accs because big/little endian will have different outputs here */ - printf ("name=%s, byte=", empl.name); - for (i=0; i<20; i++) - { - if (empl.byte[i] == '#') - break; - printf("(%o)", (unsigned char)empl.byte[i]); - } - printf("\n"); - EXEC SQL disconnect; - exit (0); -} diff --git a/src/interfaces/ecpg/test/expected/complex-test4.c b/src/interfaces/ecpg/test/expected/complex-test4.c deleted file mode 100644 index d56b1954c7c..00000000000 --- a/src/interfaces/ecpg/test/expected/complex-test4.c +++ /dev/null @@ -1,308 +0,0 @@ -/* Processed by ecpg (4.2.1) */ -/* These include files are added by the preprocessor */ -#include -#include -#include -#include -/* End of automatic include section */ - -#line 1 "test4.pgc" -#include -#include -#include - -/* exec sql whenever sqlerror sqlprint ; */ -#line 5 "test4.pgc" - - - -#line 1 "sqlca.h" -#ifndef POSTGRES_SQLCA_H -#define POSTGRES_SQLCA_H - -#ifndef DLLIMPORT -#if defined(WIN32) || defined(__CYGWIN__) -#define DLLIMPORT __declspec (dllimport) -#else -#define DLLIMPORT -#endif /* __CYGWIN__ */ -#endif /* DLLIMPORT */ - -#define SQLERRMC_LEN 150 - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct sqlca_t -{ - char sqlcaid[8]; - long sqlabc; - long sqlcode; - struct - { - int sqlerrml; - char sqlerrmc[SQLERRMC_LEN]; - } sqlerrm; - char sqlerrp[8]; - long sqlerrd[6]; - /* Element 0: empty */ - /* 1: OID of processed tuple if applicable */ - /* 2: number of rows processed */ - /* after an INSERT, UPDATE or */ - /* DELETE statement */ - /* 3: empty */ - /* 4: empty */ - /* 5: empty */ - char sqlwarn[8]; - /* Element 0: set to 'W' if at least one other is 'W' */ - /* 1: if 'W' at least one character string */ - /* value was truncated when it was */ - /* stored into a host variable. */ - - /* - * 2: if 'W' a (hopefully) non-fatal notice occurred - */ /* 3: empty */ - /* 4: empty */ - /* 5: empty */ - /* 6: empty */ - /* 7: empty */ - - char sqlstate[5]; -}; - -struct sqlca_t *ECPGget_sqlca(void); - -#ifndef POSTGRES_ECPG_INTERNAL -#define sqlca (*ECPGget_sqlca()) -#endif - -#ifdef __cplusplus -} -#endif - -#endif - -#line 7 "test4.pgc" - - -#line 1 "regression.h" - - - - - - -#line 8 "test4.pgc" - - -typedef enum { OK = 0 , ERR = 1 , WARN = 2 } errtype ; -#line 15 "test4.pgc" - - -int -main (void) -{ -/* exec sql begin declare section */ - - - - - - - - - - - - - -#line 25 "test4.pgc" - struct { -#line 23 "test4.pgc" - errtype e : 2 ; - -#line 24 "test4.pgc" - int code : 14 ; - } error = { 1 , 147 } ; - -#line 26 "test4.pgc" - int i = 1 ; - -#line 27 "test4.pgc" - int * did = & i ; - -#line 28 "test4.pgc" - int a [ 10 ] = { 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 } ; - -#line 29 "test4.pgc" - char text [ 25 ] = "klmnopqrst" ; - -#line 30 "test4.pgc" - char * t = ( char * ) malloc ( 11 ) ; - -#line 31 "test4.pgc" - double f ; - -#line 32 "test4.pgc" - bool b = true ; -/* exec sql end declare section */ -#line 33 "test4.pgc" - - - strcpy(t, "0123456789"); - setlocale(LC_ALL, "C"); - - ECPGdebug(1, stderr); - - { ECPGconnect(__LINE__, 0, "regress1" , NULL,NULL , NULL, 0); -#line 40 "test4.pgc" - -if (sqlca.sqlcode < 0) sqlprint();} -#line 40 "test4.pgc" - - - { ECPGsetcommit(__LINE__, "on", NULL); -#line 42 "test4.pgc" - -if (sqlca.sqlcode < 0) sqlprint();} -#line 42 "test4.pgc" - - - { ECPGtrans(__LINE__, NULL, "begin transaction "); -#line 44 "test4.pgc" - -if (sqlca.sqlcode < 0) sqlprint();} -#line 44 "test4.pgc" - - - { ECPGdo(__LINE__, 0, 1, NULL, "create table test ( f float , i int , a int [ 10 ] , text char ( 10 ) , b bool , t int , err int ) ", ECPGt_EOIT, ECPGt_EORT); -#line 46 "test4.pgc" - -if (sqlca.sqlcode < 0) sqlprint();} -#line 46 "test4.pgc" - - - { ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( f , i , a , text , b , t , err ) values( 404.90 , 3 , '{0,1,2,3,4,5,6,7,8,9}' , 'abcdefghij' , 'f' , 0 , 0 ) ", ECPGt_EOIT, ECPGt_EORT); -#line 48 "test4.pgc" - -if (sqlca.sqlcode < 0) sqlprint();} -#line 48 "test4.pgc" - - - { ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( f , i , a , text , b , t , err ) values( 140787.0 , 2 , ? , ? , 't' , 2 , 14 ) ", - ECPGt_int,(a),(long)1,(long)10,sizeof(int), - 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_EOIT, ECPGt_EORT); -#line 50 "test4.pgc" - -if (sqlca.sqlcode < 0) sqlprint();} -#line 50 "test4.pgc" - - - - - - { ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( f , i , a , text , b , t , err ) values( 14.07 , ? , ? , ? , ? , 1 , 147 ) ", - ECPGt_int,&(did),(long)1,(long)0,sizeof(int), - ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_int,(a),(long)1,(long)10,sizeof(int), - 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_bool,&(b),(long)1,(long)1,sizeof(bool), - ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT); -#line 55 "test4.pgc" - -if (sqlca.sqlcode < 0) sqlprint();} -#line 55 "test4.pgc" - - error.code=0; - - - { ECPGtrans(__LINE__, NULL, "commit"); -#line 59 "test4.pgc" - -if (sqlca.sqlcode < 0) sqlprint();} -#line 59 "test4.pgc" - - - { ECPGtrans(__LINE__, NULL, "begin transaction "); -#line 61 "test4.pgc" - -if (sqlca.sqlcode < 0) sqlprint();} -#line 61 "test4.pgc" - - - { ECPGdo(__LINE__, 0, 1, NULL, "select f , text , b 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_bool,&(b),(long)1,(long)1,sizeof(bool), - ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); -#line 66 "test4.pgc" - -if (sqlca.sqlcode < 0) sqlprint();} -#line 66 "test4.pgc" - - - printf("Found f=%f text=%10.10s b=%d\n", f, text, b); - - f=140787; - { ECPGdo(__LINE__, 0, 1, NULL, "select a , text from test where f = ? ", - ECPGt_double,&(f),(long)1,(long)1,sizeof(double), - ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, - ECPGt_int,(a),(long)1,(long)10,sizeof(int), - 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_EORT); -#line 74 "test4.pgc" - -if (sqlca.sqlcode < 0) sqlprint();} -#line 74 "test4.pgc" - - - for (i = 0; i < 10; i++) - printf("Found a[%d] = %d\n", i, a[i]); - - printf("Found text=%10.10s\n", t); - - { ECPGdo(__LINE__, 0, 1, NULL, "select a from test where f = ? ", - 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 84 "test4.pgc" - -if (sqlca.sqlcode < 0) sqlprint();} -#line 84 "test4.pgc" - - - printf("Found text=%s\n", text); - - { ECPGdo(__LINE__, 0, 1, NULL, "drop table test ", ECPGt_EOIT, ECPGt_EORT); -#line 88 "test4.pgc" - -if (sqlca.sqlcode < 0) sqlprint();} -#line 88 "test4.pgc" - - - { ECPGtrans(__LINE__, NULL, "commit"); -#line 90 "test4.pgc" - -if (sqlca.sqlcode < 0) sqlprint();} -#line 90 "test4.pgc" - - - { ECPGdisconnect(__LINE__, "CURRENT"); -#line 92 "test4.pgc" - -if (sqlca.sqlcode < 0) sqlprint();} -#line 92 "test4.pgc" - - - return (0); -} diff --git a/src/interfaces/ecpg/test/expected/complex-test4.stderr b/src/interfaces/ecpg/test/expected/complex-test4.stderr deleted file mode 100644 index e9924b1a6a4..00000000000 --- a/src/interfaces/ecpg/test/expected/complex-test4.stderr +++ /dev/null @@ -1,62 +0,0 @@ -[NO_PID]: ECPGdebug: set to 1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGconnect: opening database regress1 on port -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGsetcommit line 42 action = on connection = regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGtrans line 44 action = begin transaction connection = regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 46: QUERY: create table test ( f float , i int , a int [ 10 ] , text char ( 10 ) , b bool , t int , err int ) on connection regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 46 Ok: CREATE TABLE -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 48: QUERY: insert into test ( f , i , a , text , b , t , err ) values( 404.90 , 3 , '{0,1,2,3,4,5,6,7,8,9}' , 'abcdefghij' , 'f' , 0 , 0 ) on connection regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 48 Ok: INSERT 0 1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 50: QUERY: insert into test ( f , i , a , text , b , t , err ) values( 140787.0 , 2 , array [9,8,7,6,5,4,3,2,1,0] , 'klmnopqrst' , 't' , 2 , 14 ) on connection regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 50 Ok: INSERT 0 1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 55: QUERY: insert into test ( f , i , a , text , b , t , err ) values( 14.07 , 1 , array [9,8,7,6,5,4,3,2,1,0] , '0123456789' , 't' , 1 , 147 ) on connection regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 55 Ok: INSERT 0 1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGtrans line 59 action = commit connection = regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGtrans line 61 action = begin transaction connection = regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 63: QUERY: select f , text , b from test where i = 1 on connection regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 63: Correctly got 1 tuples with 3 fields -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGget_data line 63: RESULT: 14.07 offset: -1 array: Yes -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGget_data line 63: RESULT: 0123456789 offset: -1 array: Yes -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGget_data line 63: RESULT: t offset: -1 array: Yes -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 71: QUERY: select a , text from test where f = 140787 on connection regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 71: Correctly got 1 tuples with 2 fields -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGis_type_an_array line 71: TYPE database: 1007 C: 5 array: Yes -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGget_data line 71: RESULT: {9,8,7,6,5,4,3,2,1,0} offset: -1 array: Yes -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGget_data line 71: RESULT: klmnopqrst offset: -1 array: Yes -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 81: QUERY: select a from test where f = 140787 on connection regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 81: Correctly got 1 tuples with 1 fields -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGget_data line 81: RESULT: {9,8,7,6,5,4,3,2,1,0} offset: -1 array: Yes -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 88: QUERY: drop table test on connection regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 88 Ok: DROP TABLE -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGtrans line 90 action = commit connection = regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_finish: Connection regress1 closed. -[NO_PID]: sqlca: code: 0, state: 00000 diff --git a/src/interfaces/ecpg/test/expected/complex-test4.stdout b/src/interfaces/ecpg/test/expected/complex-test4.stdout deleted file mode 100644 index 7e8a326fa11..00000000000 --- a/src/interfaces/ecpg/test/expected/complex-test4.stdout +++ /dev/null @@ -1,13 +0,0 @@ -Found f=14.070000 text=0123456789 b=1 -Found a[0] = 9 -Found a[1] = 8 -Found a[2] = 7 -Found a[3] = 6 -Found a[4] = 5 -Found a[5] = 4 -Found a[6] = 3 -Found a[7] = 2 -Found a[8] = 1 -Found a[9] = 0 -Found text=klmnopqrst -Found text={9,8,7,6,5,4,3,2,1,0} diff --git a/src/interfaces/ecpg/test/expected/complex-test5.c b/src/interfaces/ecpg/test/expected/complex-test5.c deleted file mode 100644 index 337a5d8984b..00000000000 --- a/src/interfaces/ecpg/test/expected/complex-test5.c +++ /dev/null @@ -1,215 +0,0 @@ -/* Processed by ecpg (4.2.1) */ -/* These include files are added by the preprocessor */ -#include -#include -#include -#include -/* End of automatic include section */ - -#line 1 "test5.pgc" -#include -#include - - -#line 1 "regression.h" - - - - - - -#line 4 "test5.pgc" - - -typedef long mmInteger ; - -#line 6 "test5.pgc" - -#line 6 "test5.pgc" - -typedef char mmChar ; - -#line 7 "test5.pgc" - -#line 7 "test5.pgc" - -typedef short mmSmallInt ; - -#line 8 "test5.pgc" - -#line 8 "test5.pgc" - - -/* exec sql begin declare section */ - - - - - - - -struct TBempl { -#line 13 "test5.pgc" - mmInteger idnum ; - -#line 14 "test5.pgc" - mmChar name [ 21 ] ; - -#line 15 "test5.pgc" - mmSmallInt accs ; - -#line 16 "test5.pgc" - mmChar byte [ 20 ] ; - } ;/* exec sql end declare section */ -#line 18 "test5.pgc" - - -int -main (void) -{ - /* exec sql begin declare section */ - - - - - - - - -#line 24 "test5.pgc" - struct TBempl empl ; - -#line 25 "test5.pgc" - char * data = "\\001\\155\\000\\212" ; - -#line 30 "test5.pgc" - union { -#line 28 "test5.pgc" - mmSmallInt accs ; - -#line 29 "test5.pgc" - char t [ 2 ] ; - } a ; -/* exec sql end declare section */ -#line 31 "test5.pgc" - - int i; - - ECPGdebug (1, stderr); - - empl.idnum = 1; - { ECPGconnect(__LINE__, 0, "regress1" , NULL,NULL , NULL, 0); } -#line 37 "test5.pgc" - - if (sqlca.sqlcode) - { - printf ("connect error = %ld\n", sqlca.sqlcode); - exit (sqlca.sqlcode); - } - - { ECPGdo(__LINE__, 0, 1, NULL, "create table empl ( idnum integer , name char ( 20 ) , accs smallint , byte bytea ) ", ECPGt_EOIT, ECPGt_EORT);} -#line 45 "test5.pgc" - - if (sqlca.sqlcode) - { - printf ("create error = %ld\n", sqlca.sqlcode); - exit (sqlca.sqlcode); - } - - { ECPGdo(__LINE__, 0, 1, NULL, "insert into empl values( 1 , 'first user' , 320 , ? ) ", - ECPGt_char,&(data),(long)0,(long)1,(1)*sizeof(char), - ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} -#line 52 "test5.pgc" - - if (sqlca.sqlcode) - { - printf ("insert error = %ld\n", sqlca.sqlcode); - exit (sqlca.sqlcode); - } - - { ECPGdo(__LINE__, 0, 1, NULL, "select name , accs , byte from empl where idnum = ? ", - ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long), - ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, - ECPGt_char,(empl.name),(long)21,(long)1,(21)*sizeof(char), - ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_short,&(empl.accs),(long)1,(long)1,sizeof(short), - ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(empl.byte),(long)20,(long)1,(20)*sizeof(char), - ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} -#line 62 "test5.pgc" - - if (sqlca.sqlcode) - { - printf ("select error = %ld\n", sqlca.sqlcode); - exit (sqlca.sqlcode); - } - printf ("name=%s, accs=%d byte=%s\n", empl.name, empl.accs, empl.byte); - - /* declare C cursor for select name , accs , byte from empl where idnum = ? */ -#line 70 "test5.pgc" - - { ECPGdo(__LINE__, 0, 1, NULL, "declare C cursor for select name , accs , byte from empl where idnum = ? ", - ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long), - ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} -#line 71 "test5.pgc" - - { ECPGdo(__LINE__, 0, 1, NULL, "fetch C", ECPGt_EOIT, - ECPGt_char,(empl.name),(long)21,(long)1,(21)*sizeof(char), - ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_short,&(empl.accs),(long)1,(long)1,sizeof(short), - ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(empl.byte),(long)20,(long)1,(20)*sizeof(char), - ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} -#line 72 "test5.pgc" - - if (sqlca.sqlcode) - { - printf ("fetch error = %ld\n", sqlca.sqlcode); - exit (sqlca.sqlcode); - } - - printf ("name=%s, accs=%d byte=%s\n", empl.name, empl.accs, empl.byte); - - memset(empl.name, 0, 21L); - memset(empl.byte, '#', 20L); - /* declare B binary cursor for select name , accs , byte from empl where idnum = ? */ -#line 83 "test5.pgc" - - { ECPGdo(__LINE__, 0, 1, NULL, "declare B binary cursor for select name , accs , byte from empl where idnum = ? ", - ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long), - ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} -#line 84 "test5.pgc" - - { ECPGdo(__LINE__, 0, 1, NULL, "fetch B", ECPGt_EOIT, - ECPGt_char,(empl.name),(long)21,(long)1,(21)*sizeof(char), - ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_short,&(a.accs),(long)1,(long)1,sizeof(short), - ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(empl.byte),(long)20,(long)1,(20)*sizeof(char), - ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} -#line 85 "test5.pgc" - - if (sqlca.sqlcode) - { - printf ("fetch error = %ld\n", sqlca.sqlcode); - exit (sqlca.sqlcode); - } - - { ECPGdo(__LINE__, 0, 1, NULL, "close B", ECPGt_EOIT, ECPGt_EORT);} -#line 92 "test5.pgc" - - - /* do not print a.accs because big/little endian will have different outputs here */ - printf ("name=%s, byte=", empl.name); - for (i=0; i<20; i++) - { - if (empl.byte[i] == '#') - break; - printf("(%o)", (unsigned char)empl.byte[i]); - } - printf("\n"); - { ECPGdisconnect(__LINE__, "CURRENT");} -#line 103 "test5.pgc" - - exit (0); -} diff --git a/src/interfaces/ecpg/test/expected/complex-test5.stderr b/src/interfaces/ecpg/test/expected/complex-test5.stderr deleted file mode 100644 index 164d09b55a0..00000000000 --- a/src/interfaces/ecpg/test/expected/complex-test5.stderr +++ /dev/null @@ -1,56 +0,0 @@ -[NO_PID]: ECPGdebug: set to 1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGconnect: opening database regress1 on port -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 44: QUERY: create table empl ( idnum integer , name char ( 20 ) , accs smallint , byte bytea ) on connection regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 44 Ok: CREATE TABLE -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 52: QUERY: insert into empl values( 1 , 'first user' , 320 , E'\\001\\155\\000\\212' ) on connection regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 52 Ok: INSERT 0 1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 59: QUERY: select name , accs , byte from empl where idnum = 1 on connection regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 59: Correctly got 1 tuples with 3 fields -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGget_data line 59: RESULT: first user offset: -1 array: Yes -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGget_data line 59: RESULT: 320 offset: -1 array: Yes -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGget_data line 59: RESULT: \001m\000\212 offset: -1 array: Yes -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 71: QUERY: declare C cursor for select name , accs , byte from empl where idnum = 1 on connection regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 71 Ok: DECLARE CURSOR -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 72: QUERY: fetch C on connection regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 72: Correctly got 1 tuples with 3 fields -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGget_data line 72: RESULT: first user offset: -1 array: Yes -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGget_data line 72: RESULT: 320 offset: -1 array: Yes -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGget_data line 72: RESULT: \001m\000\212 offset: -1 array: Yes -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 84: QUERY: declare B binary cursor for select name , accs , byte from empl where idnum = 1 on connection regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 84 Ok: DECLARE CURSOR -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 85: QUERY: fetch B on connection regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 85: Correctly got 1 tuples with 3 fields -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGget_data line 85: RESULT: BINARY offset: -1 array: Yes -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGget_data line 85: RESULT: BINARY offset: -1 array: Yes -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGget_data line 85: RESULT: BINARY offset: -1 array: Yes -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 92: QUERY: close B on connection regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ECPGexecute line 92 Ok: CLOSE CURSOR -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_finish: Connection regress1 closed. -[NO_PID]: sqlca: code: 0, state: 00000 diff --git a/src/interfaces/ecpg/test/expected/complex-test5.stdout b/src/interfaces/ecpg/test/expected/complex-test5.stdout deleted file mode 100644 index 745889b486c..00000000000 --- a/src/interfaces/ecpg/test/expected/complex-test5.stdout +++ /dev/null @@ -1,3 +0,0 @@ -name=first user , accs=320 byte=\001m\000\212 -name=first user , accs=320 byte=\001m\000\212 -name=first user , byte=(1)(155)(0)(212) diff --git a/src/interfaces/ecpg/test/expected/errors-init.c b/src/interfaces/ecpg/test/expected/errors-init.c deleted file mode 100644 index 0d085b140dd..00000000000 --- a/src/interfaces/ecpg/test/expected/errors-init.c +++ /dev/null @@ -1,261 +0,0 @@ -/* Processed by ecpg (4.2.1) */ -/* These include files are added by the preprocessor */ -#include -#include -#include -#include -/* End of automatic include section */ - -#line 1 "init.pgc" - -#line 1 "sqlca.h" -#ifndef POSTGRES_SQLCA_H -#define POSTGRES_SQLCA_H - -#ifndef DLLIMPORT -#if defined(WIN32) || defined(__CYGWIN__) -#define DLLIMPORT __declspec (dllimport) -#else -#define DLLIMPORT -#endif /* __CYGWIN__ */ -#endif /* DLLIMPORT */ - -#define SQLERRMC_LEN 150 - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct sqlca_t -{ - char sqlcaid[8]; - long sqlabc; - long sqlcode; - struct - { - int sqlerrml; - char sqlerrmc[SQLERRMC_LEN]; - } sqlerrm; - char sqlerrp[8]; - long sqlerrd[6]; - /* Element 0: empty */ - /* 1: OID of processed tuple if applicable */ - /* 2: number of rows processed */ - /* after an INSERT, UPDATE or */ - /* DELETE statement */ - /* 3: empty */ - /* 4: empty */ - /* 5: empty */ - char sqlwarn[8]; - /* Element 0: set to 'W' if at least one other is 'W' */ - /* 1: if 'W' at least one character string */ - /* value was truncated when it was */ - /* stored into a host variable. */ - - /* - * 2: if 'W' a (hopefully) non-fatal notice occurred - */ /* 3: empty */ - /* 4: empty */ - /* 5: empty */ - /* 6: empty */ - /* 7: empty */ - - char sqlstate[5]; -}; - -struct sqlca_t *ECPGget_sqlca(void); - -#ifndef POSTGRES_ECPG_INTERNAL -#define sqlca (*ECPGget_sqlca()) -#endif - -#ifdef __cplusplus -} -#endif - -#endif - -#line 1 "init.pgc" - - -enum e { ENUM0, ENUM1 }; -struct sa { int member; }; - -static int fa(void) -{ - printf("in fa\n"); - return 2; -} - -static int -fb(int x) -{ - printf("in fb (%d)\n", x); - return x; -} - -static int -fc(const char *x) -{ - printf("in fc (%s)\n", x); - return *x; -} - -static int fd(const char *x,int i) -{ - printf("in fd (%s, %d)\n", x, i); - return (*x)*i; -} - -static int fe(enum e x) -{ - printf("in fe (%d)\n", (int) x); - return (int)x; -} - -static void sqlnotice(char *notice, short trans) -{ - if (!notice) - notice = "-empty-"; - printf("in sqlnotice (%s, %d)\n", notice, trans); -} - - - -#define YES 1 - -#ifdef _cplusplus -namespace N -{ - static const int i=2; -}; -#endif - -int main(void) -{ - struct sa x = { 14 },*y = &x; - /* exec sql begin declare section */ - - - - - - - - - - - - /* = 1L */ - -#line 60 "init.pgc" - int a = ( int ) 2 ; - -#line 61 "init.pgc" - int b = 2 + 2 ; - -#line 62 "init.pgc" - int b2 = ( 14 * 7 ) ; - -#line 63 "init.pgc" - int d = x . member ; - -#line 64 "init.pgc" - int g = fb ( 2 ) ; - -#line 65 "init.pgc" - int i = 3 ^ 1 ; - -#line 66 "init.pgc" - int j = 1 ? 1 : 2 ; - -#line 68 "init.pgc" - int e = y -> member ; - -#line 69 "init.pgc" - int c = 10 >> 2 ; - -#line 70 "init.pgc" - bool h = 2 || 1 ; - -#line 71 "init.pgc" - long iay ; -/* exec sql end declare section */ -#line 72 "init.pgc" - - - int f=fa(); - -#ifdef _cplusplus - /* exec sql begin declare section */ - /* compile error */ - -#line 78 "init.pgc" - int k = N : : i ; -/* exec sql end declare section */ -#line 79 "init.pgc" - -#endif - - ECPGdebug(1, stderr); - - printf("%d %d %d %d %d %d %d %d %d %d %d\n", a, b, b2, c, d, e, f, g, h, i, j); - iay = 0; - printf("%ld\n", iay); - /* exec sql whenever sqlerror do fa ( ) ; */ -#line 87 "init.pgc" - - { ECPGdo(__LINE__, 0, 1, NULL, "select now () ", ECPGt_EOIT, ECPGt_EORT); -#line 88 "init.pgc" - -if (sqlca.sqlcode < 0) fa ( );} -#line 88 "init.pgc" - - /* exec sql whenever sqlerror do fb ( 20 ) ; */ -#line 89 "init.pgc" - - { ECPGdo(__LINE__, 0, 1, NULL, "select now () ", ECPGt_EOIT, ECPGt_EORT); -#line 90 "init.pgc" - -if (sqlca.sqlcode < 0) fb ( 20 );} -#line 90 "init.pgc" - - /* exec sql whenever sqlerror do fc ( \"50\" ) ; */ -#line 91 "init.pgc" - - { ECPGdo(__LINE__, 0, 1, NULL, "select now () ", ECPGt_EOIT, ECPGt_EORT); -#line 92 "init.pgc" - -if (sqlca.sqlcode < 0) fc ( "50" );} -#line 92 "init.pgc" - - /* exec sql whenever sqlerror do fd ( \"50\" , 1 ) ; */ -#line 93 "init.pgc" - - { ECPGdo(__LINE__, 0, 1, NULL, "select now () ", ECPGt_EOIT, ECPGt_EORT); -#line 94 "init.pgc" - -if (sqlca.sqlcode < 0) fd ( "50" , 1 );} -#line 94 "init.pgc" - - /* exec sql whenever sqlerror do fe ( ENUM0 ) ; */ -#line 95 "init.pgc" - - { ECPGdo(__LINE__, 0, 1, NULL, "select now () ", ECPGt_EOIT, ECPGt_EORT); -#line 96 "init.pgc" - -if (sqlca.sqlcode < 0) fe ( ENUM0 );} -#line 96 "init.pgc" - - /* exec sql whenever sqlerror do sqlnotice ( NULL , 0 ) ; */ -#line 97 "init.pgc" - - { ECPGdo(__LINE__, 0, 1, NULL, "select now () ", ECPGt_EOIT, ECPGt_EORT); -#line 98 "init.pgc" - -if (sqlca.sqlcode < 0) sqlnotice ( NULL , 0 );} -#line 98 "init.pgc" - - return 0; -} diff --git a/src/interfaces/ecpg/test/expected/errors-init.stderr b/src/interfaces/ecpg/test/expected/errors-init.stderr deleted file mode 100644 index c85fce83dc8..00000000000 --- a/src/interfaces/ecpg/test/expected/errors-init.stderr +++ /dev/null @@ -1,14 +0,0 @@ -[NO_PID]: ECPGdebug: set to 1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: raising sqlcode -220 in line 88, 'No such connection NULL in line 88.'. -[NO_PID]: sqlca: code: -220, state: 08003 -[NO_PID]: raising sqlcode -220 in line 90, 'No such connection NULL in line 90.'. -[NO_PID]: sqlca: code: -220, state: 08003 -[NO_PID]: raising sqlcode -220 in line 92, 'No such connection NULL in line 92.'. -[NO_PID]: sqlca: code: -220, state: 08003 -[NO_PID]: raising sqlcode -220 in line 94, 'No such connection NULL in line 94.'. -[NO_PID]: sqlca: code: -220, state: 08003 -[NO_PID]: raising sqlcode -220 in line 96, 'No such connection NULL in line 96.'. -[NO_PID]: sqlca: code: -220, state: 08003 -[NO_PID]: raising sqlcode -220 in line 98, 'No such connection NULL in line 98.'. -[NO_PID]: sqlca: code: -220, state: 08003 diff --git a/src/interfaces/ecpg/test/expected/errors-init.stdout b/src/interfaces/ecpg/test/expected/errors-init.stdout deleted file mode 100644 index 4738d795aac..00000000000 --- a/src/interfaces/ecpg/test/expected/errors-init.stdout +++ /dev/null @@ -1,10 +0,0 @@ -in fb (2) -in fa -2 4 98 2 14 14 2 2 1 2 1 -0 -in fa -in fb (20) -in fc (50) -in fd (50, 1) -in fe (0) -in sqlnotice (-empty-, 0) diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.c b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.c index 805f50f7e81..4a30736e780 100644 --- a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.c +++ b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -21,28 +22,72 @@ -#line 7 "dt_test2.pgc" +#line 8 "dt_test2.pgc" +char *dates[] = { "19990108foobar", + "19990108 foobar", + "1999-01-08 foobar", + "January 8, 1999", + "1999-01-08", + "1/8/1999", + "1/18/1999", + "01/02/03", + "1999-Jan-08", + "Jan-08-1999", + "08-Jan-1999", + "99-Jan-08", + "08-Jan-99", + "08-Jan-06", + "Jan-08-99", + "19990108", + "990108", + "1999.008", + "J2451187", + "January 8, 99 BC", + NULL }; + +char *times[] = { "0:04", + "1:59 PDT", + "13:24:40 -8:00", + "13:24:40.495+3", + NULL }; + +char *intervals[] = { "1 minute", + "1 12:59:10", + "2 day 12 hour 59 minute 10 second", + "1 days 12 hrs 59 mins 10 secs", + "1 days 1 hours 1 minutes 1 seconds", + "1 year 59 mins", + "1 year 59 mins foobar", + NULL }; + int main(void) { /* exec sql begin declare section */ + -#line 13 "dt_test2.pgc" +#line 51 "dt_test2.pgc" date date1 ; -#line 14 "dt_test2.pgc" - timestamp ts1 ; +#line 52 "dt_test2.pgc" + timestamp ts1 , ts2 ; -#line 15 "dt_test2.pgc" +#line 53 "dt_test2.pgc" char * text ; + +#line 54 "dt_test2.pgc" + interval * i1 ; /* exec sql end declare section */ -#line 16 "dt_test2.pgc" +#line 55 "dt_test2.pgc" + + int i, j; + char *endptr; ECPGdebug(1, stderr); @@ -57,6 +102,58 @@ main(void) printf("Date of timestamp: %s\n", text); free(text); + for (i = 0; dates[i]; i++) + { + bool err = false; + date1 = PGTYPESdate_from_asc(dates[i], &endptr); + if (date1 == INT_MIN) { + err = true; + } + text = PGTYPESdate_to_asc(date1); + printf("Date[%d]: %s (%c - %c)\n", + i, err ? "-" : text, + endptr ? 'N' : 'Y', + err ? 'T' : 'F'); + free(text); + if (!err) + { + for (j = 0; times[j]; j++) + { + int length = strlen(dates[i]) + + 1 + + strlen(times[j]) + + 1; + char* t = malloc(length); + sprintf(t, "%s %s", dates[i], times[j]); + ts1 = PGTYPEStimestamp_from_asc(t, NULL); + text = PGTYPEStimestamp_to_asc(ts1); + printf("TS[%d,%d]: %s\n", + i, j, errno ? "-" : text); + free(text); + } + } + } + + ts1 = PGTYPEStimestamp_from_asc("2004-04-04 23:23:23", NULL); + + for (i = 0; intervals[i]; i++) + { + i1 = PGTYPESinterval_from_asc(intervals[i], &endptr); + if (*endptr) + printf("endptr set to %s\n", endptr); + if (!i1) + { + printf("Error parsing interval %d\n", i); + continue; + } + j = PGTYPEStimestamp_add_interval(&ts1, i1, &ts2); + if (j < 0) + continue; + text = PGTYPESinterval_to_asc(i1); + printf("interval[%d]: %s\n", i, text ? text : "-"); + free(text); + } + return (0); } diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.stdout b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.stdout index d4c783887b0..d52555f510a 100644 --- a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.stdout +++ b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.stdout @@ -1,2 +1,97 @@ timestamp: 2003-12-04 17:34:29 Date of timestamp: 2003-12-04 +Date[0]: - (N - T) +Date[1]: - (N - T) +Date[2]: - (N - T) +Date[3]: 1999-01-08 (N - F) +TS[3,0]: 1999-01-08 00:04:00 +TS[3,1]: 1999-01-08 01:59:00 +TS[3,2]: 1999-01-08 13:24:40 +TS[3,3]: 1999-01-08 13:24:40.495 +Date[4]: 1999-01-08 (N - F) +TS[4,0]: 1999-01-08 00:04:00 +TS[4,1]: 1999-01-08 01:59:00 +TS[4,2]: 1999-01-08 13:24:40 +TS[4,3]: 1999-01-08 13:24:40.495 +Date[5]: 1999-01-08 (N - F) +TS[5,0]: 1999-01-08 00:04:00 +TS[5,1]: 1999-01-08 01:59:00 +TS[5,2]: 1999-01-08 13:24:40 +TS[5,3]: 1999-01-08 13:24:40.495 +Date[6]: 1999-01-18 (N - F) +TS[6,0]: 1999-01-18 00:04:00 +TS[6,1]: 1999-01-18 01:59:00 +TS[6,2]: 1999-01-18 13:24:40 +TS[6,3]: 1999-01-18 13:24:40.495 +Date[7]: 2003-01-02 (N - F) +TS[7,0]: 2003-01-02 00:04:00 +TS[7,1]: 2003-01-02 01:59:00 +TS[7,2]: 2003-01-02 13:24:40 +TS[7,3]: 2003-01-02 13:24:40.495 +Date[8]: 1999-01-08 (N - F) +TS[8,0]: 1999-01-08 00:04:00 +TS[8,1]: 1999-01-08 01:59:00 +TS[8,2]: 1999-01-08 13:24:40 +TS[8,3]: 1999-01-08 13:24:40.495 +Date[9]: 1999-01-08 (N - F) +TS[9,0]: 1999-01-08 00:04:00 +TS[9,1]: 1999-01-08 01:59:00 +TS[9,2]: 1999-01-08 13:24:40 +TS[9,3]: 1999-01-08 13:24:40.495 +Date[10]: 1999-01-08 (N - F) +TS[10,0]: 1999-01-08 00:04:00 +TS[10,1]: 1999-01-08 01:59:00 +TS[10,2]: 1999-01-08 13:24:40 +TS[10,3]: 1999-01-08 13:24:40.495 +Date[11]: 1999-01-08 (N - F) +TS[11,0]: 1999-01-08 00:04:00 +TS[11,1]: 1999-01-08 01:59:00 +TS[11,2]: 1999-01-08 13:24:40 +TS[11,3]: 1999-01-08 13:24:40.495 +Date[12]: 1999-01-08 (N - F) +TS[12,0]: 1999-01-08 00:04:00 +TS[12,1]: 1999-01-08 01:59:00 +TS[12,2]: 1999-01-08 13:24:40 +TS[12,3]: 1999-01-08 13:24:40.495 +Date[13]: 2006-01-08 (N - F) +TS[13,0]: 2006-01-08 00:04:00 +TS[13,1]: 2006-01-08 01:59:00 +TS[13,2]: 2006-01-08 13:24:40 +TS[13,3]: 2006-01-08 13:24:40.495 +Date[14]: 1999-01-08 (N - F) +TS[14,0]: 1999-01-08 00:04:00 +TS[14,1]: 1999-01-08 01:59:00 +TS[14,2]: 1999-01-08 13:24:40 +TS[14,3]: 1999-01-08 13:24:40.495 +Date[15]: 1999-01-08 (N - F) +TS[15,0]: 1999-01-08 00:04:00 +TS[15,1]: 1999-01-08 01:59:00 +TS[15,2]: 1999-01-08 13:24:40 +TS[15,3]: 1999-01-08 13:24:40.495 +Date[16]: 1999-01-08 (N - F) +TS[16,0]: 1999-01-08 00:04:00 +TS[16,1]: 1999-01-08 01:59:00 +TS[16,2]: 1999-01-08 13:24:40 +TS[16,3]: 1999-01-08 13:24:40.495 +Date[17]: 1999-01-08 (N - F) +TS[17,0]: 1999-01-08 00:04:00 +TS[17,1]: 1999-01-08 01:59:00 +TS[17,2]: 1999-01-08 13:24:40 +TS[17,3]: 1999-01-08 13:24:40.495 +Date[18]: 1999-01-08 (N - F) +TS[18,0]: 1999-01-08 00:04:00 +TS[18,1]: 1999-01-08 01:59:00 +TS[18,2]: 1999-01-08 13:24:40 +TS[18,3]: 1999-01-08 13:24:40.495 +Date[19]: 0099-01-08 BC (N - F) +TS[19,0]: 0099-01-08 00:04:00 BC +TS[19,1]: 0099-01-08 01:59:00 BC +TS[19,2]: 0099-01-08 13:24:40 BC +TS[19,3]: 0099-01-08 13:24:40.495 BC +interval[0]: @ 1 min +interval[1]: @ 1 day 12 hours 59 mins 10 secs +interval[2]: @ 2 days 12 hours 59 mins 10 secs +interval[3]: @ 1 day 12 hours 59 mins 10 secs +interval[4]: @ 1 day 1 hour 1 min 1 sec +interval[5]: @ 1 year 59 mins +Error parsing interval 6 diff --git a/src/interfaces/ecpg/test/expected/preproc-define.c b/src/interfaces/ecpg/test/expected/preproc-define.c new file mode 100644 index 00000000000..b5d01a94035 --- /dev/null +++ b/src/interfaces/ecpg/test/expected/preproc-define.c @@ -0,0 +1,127 @@ +/* Processed by ecpg (4.2.1) */ +/* These include files are added by the preprocessor */ +#include +#include +#include +#include +/* End of automatic include section */ + +#line 1 "define.pgc" +#include +#include + + +#line 1 "regression.h" + + + + + + +#line 4 "define.pgc" + + +typedef long mmInteger ; + +#line 6 "define.pgc" + +#line 6 "define.pgc" + +typedef char mmChar ; + +#line 7 "define.pgc" + +#line 7 "define.pgc" + +typedef short mmSmallInt ; + +#line 8 "define.pgc" + +#line 8 "define.pgc" + + +/* exec sql begin declare section */ + + + + + + +struct TBempl { +#line 13 "define.pgc" + mmInteger idnum ; + +#line 14 "define.pgc" + mmChar name [ 21 ] ; + +#line 15 "define.pgc" + mmSmallInt accs ; + } ;/* exec sql end declare section */ +#line 17 "define.pgc" + + +int +main (void) +{ + /* exec sql begin declare section */ + + +#line 23 "define.pgc" + struct TBempl empl ; +/* exec sql end declare section */ +#line 24 "define.pgc" + + + ECPGdebug (1, stderr); + + empl.idnum = 1; + { ECPGconnect(__LINE__, 0, "regress1" , NULL,NULL , NULL, 0); } +#line 29 "define.pgc" + + if (sqlca.sqlcode) + { + printf ("connect error = %ld\n", sqlca.sqlcode); + exit (sqlca.sqlcode); + } + + { ECPGdo(__LINE__, 0, 1, NULL, "create table empl ( idnum integer , name char ( 20 ) , accs smallint ) ", ECPGt_EOIT, ECPGt_EORT);} +#line 37 "define.pgc" + + if (sqlca.sqlcode) + { + printf ("create error = %ld\n", sqlca.sqlcode); + exit (sqlca.sqlcode); + } + + { ECPGdo(__LINE__, 0, 1, NULL, "insert into empl values ( 1 , 'first user' , 320 ) ", ECPGt_EOIT, ECPGt_EORT);} +#line 44 "define.pgc" + + if (sqlca.sqlcode) + { + printf ("insert error = %ld\n", sqlca.sqlcode); + exit (sqlca.sqlcode); + } + + { ECPGdo(__LINE__, 0, 1, NULL, "select idnum , name , accs from empl where idnum = ? ", + ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, + ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, + ECPGt_char,&(empl.name),(long)21,(long)1,(21)*sizeof(char), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, + ECPGt_short,&(empl.accs),(long)1,(long)1,sizeof(short), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} +#line 54 "define.pgc" + + if (sqlca.sqlcode) + { + printf ("select error = %ld\n", sqlca.sqlcode); + exit (sqlca.sqlcode); + } + printf ("id=%ld name=%s, accs=%d\n", empl.idnum, empl.name, empl.accs); + + { ECPGdisconnect(__LINE__, "CURRENT");} +#line 62 "define.pgc" + + exit (0); +} diff --git a/src/interfaces/ecpg/test/expected/preproc-define.stderr b/src/interfaces/ecpg/test/expected/preproc-define.stderr new file mode 100644 index 00000000000..34610cb50f8 --- /dev/null +++ b/src/interfaces/ecpg/test/expected/preproc-define.stderr @@ -0,0 +1,24 @@ +[NO_PID]: ECPGdebug: set to 1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGconnect: opening database regress1 on port +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 36: QUERY: create table empl ( idnum integer , name char ( 20 ) , accs smallint ) on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 36 Ok: CREATE TABLE +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 44: QUERY: insert into empl values ( 1 , 'first user' , 320 ) on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 44 Ok: INSERT 0 1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 51: QUERY: select idnum , name , accs from empl where idnum = 1 on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 51: Correctly got 1 tuples with 3 fields +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGget_data line 51: RESULT: 1 offset: -1 array: Yes +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGget_data line 51: RESULT: first user offset: -1 array: Yes +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGget_data line 51: RESULT: 320 offset: -1 array: Yes +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_finish: Connection regress1 closed. +[NO_PID]: sqlca: code: 0, state: 00000 diff --git a/src/interfaces/ecpg/test/expected/preproc-define.stdout b/src/interfaces/ecpg/test/expected/preproc-define.stdout new file mode 100644 index 00000000000..63c2bbbc0df --- /dev/null +++ b/src/interfaces/ecpg/test/expected/preproc-define.stdout @@ -0,0 +1 @@ +id=1 name=first user , accs=320 diff --git a/src/interfaces/ecpg/test/expected/preproc-init.c b/src/interfaces/ecpg/test/expected/preproc-init.c new file mode 100644 index 00000000000..0d085b140dd --- /dev/null +++ b/src/interfaces/ecpg/test/expected/preproc-init.c @@ -0,0 +1,261 @@ +/* Processed by ecpg (4.2.1) */ +/* These include files are added by the preprocessor */ +#include +#include +#include +#include +/* End of automatic include section */ + +#line 1 "init.pgc" + +#line 1 "sqlca.h" +#ifndef POSTGRES_SQLCA_H +#define POSTGRES_SQLCA_H + +#ifndef DLLIMPORT +#if defined(WIN32) || defined(__CYGWIN__) +#define DLLIMPORT __declspec (dllimport) +#else +#define DLLIMPORT +#endif /* __CYGWIN__ */ +#endif /* DLLIMPORT */ + +#define SQLERRMC_LEN 150 + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct sqlca_t +{ + char sqlcaid[8]; + long sqlabc; + long sqlcode; + struct + { + int sqlerrml; + char sqlerrmc[SQLERRMC_LEN]; + } sqlerrm; + char sqlerrp[8]; + long sqlerrd[6]; + /* Element 0: empty */ + /* 1: OID of processed tuple if applicable */ + /* 2: number of rows processed */ + /* after an INSERT, UPDATE or */ + /* DELETE statement */ + /* 3: empty */ + /* 4: empty */ + /* 5: empty */ + char sqlwarn[8]; + /* Element 0: set to 'W' if at least one other is 'W' */ + /* 1: if 'W' at least one character string */ + /* value was truncated when it was */ + /* stored into a host variable. */ + + /* + * 2: if 'W' a (hopefully) non-fatal notice occurred + */ /* 3: empty */ + /* 4: empty */ + /* 5: empty */ + /* 6: empty */ + /* 7: empty */ + + char sqlstate[5]; +}; + +struct sqlca_t *ECPGget_sqlca(void); + +#ifndef POSTGRES_ECPG_INTERNAL +#define sqlca (*ECPGget_sqlca()) +#endif + +#ifdef __cplusplus +} +#endif + +#endif + +#line 1 "init.pgc" + + +enum e { ENUM0, ENUM1 }; +struct sa { int member; }; + +static int fa(void) +{ + printf("in fa\n"); + return 2; +} + +static int +fb(int x) +{ + printf("in fb (%d)\n", x); + return x; +} + +static int +fc(const char *x) +{ + printf("in fc (%s)\n", x); + return *x; +} + +static int fd(const char *x,int i) +{ + printf("in fd (%s, %d)\n", x, i); + return (*x)*i; +} + +static int fe(enum e x) +{ + printf("in fe (%d)\n", (int) x); + return (int)x; +} + +static void sqlnotice(char *notice, short trans) +{ + if (!notice) + notice = "-empty-"; + printf("in sqlnotice (%s, %d)\n", notice, trans); +} + + + +#define YES 1 + +#ifdef _cplusplus +namespace N +{ + static const int i=2; +}; +#endif + +int main(void) +{ + struct sa x = { 14 },*y = &x; + /* exec sql begin declare section */ + + + + + + + + + + + + /* = 1L */ + +#line 60 "init.pgc" + int a = ( int ) 2 ; + +#line 61 "init.pgc" + int b = 2 + 2 ; + +#line 62 "init.pgc" + int b2 = ( 14 * 7 ) ; + +#line 63 "init.pgc" + int d = x . member ; + +#line 64 "init.pgc" + int g = fb ( 2 ) ; + +#line 65 "init.pgc" + int i = 3 ^ 1 ; + +#line 66 "init.pgc" + int j = 1 ? 1 : 2 ; + +#line 68 "init.pgc" + int e = y -> member ; + +#line 69 "init.pgc" + int c = 10 >> 2 ; + +#line 70 "init.pgc" + bool h = 2 || 1 ; + +#line 71 "init.pgc" + long iay ; +/* exec sql end declare section */ +#line 72 "init.pgc" + + + int f=fa(); + +#ifdef _cplusplus + /* exec sql begin declare section */ + /* compile error */ + +#line 78 "init.pgc" + int k = N : : i ; +/* exec sql end declare section */ +#line 79 "init.pgc" + +#endif + + ECPGdebug(1, stderr); + + printf("%d %d %d %d %d %d %d %d %d %d %d\n", a, b, b2, c, d, e, f, g, h, i, j); + iay = 0; + printf("%ld\n", iay); + /* exec sql whenever sqlerror do fa ( ) ; */ +#line 87 "init.pgc" + + { ECPGdo(__LINE__, 0, 1, NULL, "select now () ", ECPGt_EOIT, ECPGt_EORT); +#line 88 "init.pgc" + +if (sqlca.sqlcode < 0) fa ( );} +#line 88 "init.pgc" + + /* exec sql whenever sqlerror do fb ( 20 ) ; */ +#line 89 "init.pgc" + + { ECPGdo(__LINE__, 0, 1, NULL, "select now () ", ECPGt_EOIT, ECPGt_EORT); +#line 90 "init.pgc" + +if (sqlca.sqlcode < 0) fb ( 20 );} +#line 90 "init.pgc" + + /* exec sql whenever sqlerror do fc ( \"50\" ) ; */ +#line 91 "init.pgc" + + { ECPGdo(__LINE__, 0, 1, NULL, "select now () ", ECPGt_EOIT, ECPGt_EORT); +#line 92 "init.pgc" + +if (sqlca.sqlcode < 0) fc ( "50" );} +#line 92 "init.pgc" + + /* exec sql whenever sqlerror do fd ( \"50\" , 1 ) ; */ +#line 93 "init.pgc" + + { ECPGdo(__LINE__, 0, 1, NULL, "select now () ", ECPGt_EOIT, ECPGt_EORT); +#line 94 "init.pgc" + +if (sqlca.sqlcode < 0) fd ( "50" , 1 );} +#line 94 "init.pgc" + + /* exec sql whenever sqlerror do fe ( ENUM0 ) ; */ +#line 95 "init.pgc" + + { ECPGdo(__LINE__, 0, 1, NULL, "select now () ", ECPGt_EOIT, ECPGt_EORT); +#line 96 "init.pgc" + +if (sqlca.sqlcode < 0) fe ( ENUM0 );} +#line 96 "init.pgc" + + /* exec sql whenever sqlerror do sqlnotice ( NULL , 0 ) ; */ +#line 97 "init.pgc" + + { ECPGdo(__LINE__, 0, 1, NULL, "select now () ", ECPGt_EOIT, ECPGt_EORT); +#line 98 "init.pgc" + +if (sqlca.sqlcode < 0) sqlnotice ( NULL , 0 );} +#line 98 "init.pgc" + + return 0; +} diff --git a/src/interfaces/ecpg/test/expected/preproc-init.stderr b/src/interfaces/ecpg/test/expected/preproc-init.stderr new file mode 100644 index 00000000000..c85fce83dc8 --- /dev/null +++ b/src/interfaces/ecpg/test/expected/preproc-init.stderr @@ -0,0 +1,14 @@ +[NO_PID]: ECPGdebug: set to 1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: raising sqlcode -220 in line 88, 'No such connection NULL in line 88.'. +[NO_PID]: sqlca: code: -220, state: 08003 +[NO_PID]: raising sqlcode -220 in line 90, 'No such connection NULL in line 90.'. +[NO_PID]: sqlca: code: -220, state: 08003 +[NO_PID]: raising sqlcode -220 in line 92, 'No such connection NULL in line 92.'. +[NO_PID]: sqlca: code: -220, state: 08003 +[NO_PID]: raising sqlcode -220 in line 94, 'No such connection NULL in line 94.'. +[NO_PID]: sqlca: code: -220, state: 08003 +[NO_PID]: raising sqlcode -220 in line 96, 'No such connection NULL in line 96.'. +[NO_PID]: sqlca: code: -220, state: 08003 +[NO_PID]: raising sqlcode -220 in line 98, 'No such connection NULL in line 98.'. +[NO_PID]: sqlca: code: -220, state: 08003 diff --git a/src/interfaces/ecpg/test/expected/preproc-init.stdout b/src/interfaces/ecpg/test/expected/preproc-init.stdout new file mode 100644 index 00000000000..4738d795aac --- /dev/null +++ b/src/interfaces/ecpg/test/expected/preproc-init.stdout @@ -0,0 +1,10 @@ +in fb (2) +in fa +2 4 98 2 14 14 2 2 1 2 1 +0 +in fa +in fb (20) +in fc (50) +in fd (50, 1) +in fe (0) +in sqlnotice (-empty-, 0) diff --git a/src/interfaces/ecpg/test/expected/sql-array.c b/src/interfaces/ecpg/test/expected/sql-array.c new file mode 100644 index 00000000000..87ec88f985a --- /dev/null +++ b/src/interfaces/ecpg/test/expected/sql-array.c @@ -0,0 +1,277 @@ +/* Processed by ecpg (4.2.1) */ +/* These include files are added by the preprocessor */ +#include +#include +#include +#include +/* End of automatic include section */ + +#line 1 "array.pgc" +#include +#include +#include + +/* exec sql whenever sqlerror sqlprint ; */ +#line 5 "array.pgc" + + + +#line 1 "sqlca.h" +#ifndef POSTGRES_SQLCA_H +#define POSTGRES_SQLCA_H + +#ifndef DLLIMPORT +#if defined(WIN32) || defined(__CYGWIN__) +#define DLLIMPORT __declspec (dllimport) +#else +#define DLLIMPORT +#endif /* __CYGWIN__ */ +#endif /* DLLIMPORT */ + +#define SQLERRMC_LEN 150 + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct sqlca_t +{ + char sqlcaid[8]; + long sqlabc; + long sqlcode; + struct + { + int sqlerrml; + char sqlerrmc[SQLERRMC_LEN]; + } sqlerrm; + char sqlerrp[8]; + long sqlerrd[6]; + /* Element 0: empty */ + /* 1: OID of processed tuple if applicable */ + /* 2: number of rows processed */ + /* after an INSERT, UPDATE or */ + /* DELETE statement */ + /* 3: empty */ + /* 4: empty */ + /* 5: empty */ + char sqlwarn[8]; + /* Element 0: set to 'W' if at least one other is 'W' */ + /* 1: if 'W' at least one character string */ + /* value was truncated when it was */ + /* stored into a host variable. */ + + /* + * 2: if 'W' a (hopefully) non-fatal notice occurred + */ /* 3: empty */ + /* 4: empty */ + /* 5: empty */ + /* 6: empty */ + /* 7: empty */ + + char sqlstate[5]; +}; + +struct sqlca_t *ECPGget_sqlca(void); + +#ifndef POSTGRES_ECPG_INTERNAL +#define sqlca (*ECPGget_sqlca()) +#endif + +#ifdef __cplusplus +} +#endif + +#endif + +#line 7 "array.pgc" + + +#line 1 "regression.h" + + + + + + +#line 8 "array.pgc" + + +int +main (void) +{ +/* exec sql begin declare section */ + + + + + + + +#line 14 "array.pgc" + int i = 1 ; + +#line 15 "array.pgc" + int * did = & i ; + +#line 16 "array.pgc" + int a [ 10 ] = { 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 } ; + +#line 17 "array.pgc" + char text [ 25 ] = "klmnopqrst" ; + +#line 18 "array.pgc" + char * t = ( char * ) malloc ( 11 ) ; + +#line 19 "array.pgc" + double f ; +/* exec sql end declare section */ +#line 20 "array.pgc" + + + strcpy(t, "0123456789"); + setlocale(LC_ALL, "C"); + + ECPGdebug(1, stderr); + + { ECPGconnect(__LINE__, 0, "regress1" , NULL,NULL , NULL, 0); +#line 27 "array.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 27 "array.pgc" + + + { ECPGsetcommit(__LINE__, "on", NULL); +#line 29 "array.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 29 "array.pgc" + + + { ECPGtrans(__LINE__, NULL, "begin transaction "); +#line 31 "array.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 31 "array.pgc" + + + { ECPGdo(__LINE__, 0, 1, NULL, "create table test ( f float , i int , a int [ 10 ] , text char ( 10 ) ) ", ECPGt_EOIT, ECPGt_EORT); +#line 33 "array.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 33 "array.pgc" + + + { ECPGdo(__LINE__, 0, 1, NULL, "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); +#line 35 "array.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 35 "array.pgc" + + + { ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( f , i , a , text ) values ( 140787.0 , 2 , ? , ? ) ", + ECPGt_int,(a),(long)1,(long)10,sizeof(int), + 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_EOIT, ECPGt_EORT); +#line 37 "array.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 37 "array.pgc" + + + { ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( f , i , a , text ) values ( 14.07 , ? , ? , ? ) ", + ECPGt_int,&(did),(long)1,(long)0,sizeof(int), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, + ECPGt_int,(a),(long)1,(long)10,sizeof(int), + 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_EOIT, ECPGt_EORT); +#line 39 "array.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 39 "array.pgc" + + + { ECPGtrans(__LINE__, NULL, "commit"); +#line 41 "array.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 41 "array.pgc" + + + { ECPGtrans(__LINE__, NULL, "begin transaction "); +#line 43 "array.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 43 "array.pgc" + + + { ECPGdo(__LINE__, 0, 1, NULL, "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 48 "array.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 48 "array.pgc" + + + printf("Found f=%f text=%10.10s\n", f, text); + + f=140787; + { ECPGdo(__LINE__, 0, 1, NULL, "select a , text from test where f = ? ", + ECPGt_double,&(f),(long)1,(long)1,sizeof(double), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, + ECPGt_int,(a),(long)1,(long)10,sizeof(int), + 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_EORT); +#line 56 "array.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 56 "array.pgc" + + + for (i = 0; i < 10; i++) + printf("Found a[%d] = %d\n", i, a[i]); + + printf("Found text=%10.10s\n", t); + + { ECPGdo(__LINE__, 0, 1, NULL, "select a from test where f = ? ", + 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 66 "array.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 66 "array.pgc" + + + printf("Found text=%s\n", text); + + { ECPGdo(__LINE__, 0, 1, NULL, "drop table test ", ECPGt_EOIT, ECPGt_EORT); +#line 70 "array.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 70 "array.pgc" + + + { ECPGtrans(__LINE__, NULL, "commit"); +#line 72 "array.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 72 "array.pgc" + + + { ECPGdisconnect(__LINE__, "CURRENT"); +#line 74 "array.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 74 "array.pgc" + + + return (0); +} diff --git a/src/interfaces/ecpg/test/expected/sql-array.stderr b/src/interfaces/ecpg/test/expected/sql-array.stderr new file mode 100644 index 00000000000..00eda214549 --- /dev/null +++ b/src/interfaces/ecpg/test/expected/sql-array.stderr @@ -0,0 +1,60 @@ +[NO_PID]: ECPGdebug: set to 1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGconnect: opening database regress1 on port +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGsetcommit line 29 action = on connection = regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGtrans line 31 action = begin transaction connection = regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 33: QUERY: create table test ( f float , i int , a int [ 10 ] , text char ( 10 ) ) on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 33 Ok: CREATE TABLE +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 35: QUERY: insert into test ( f , i , a , text ) values ( 404.90 , 3 , '{0,1,2,3,4,5,6,7,8,9}' , 'abcdefghij' ) on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 35 Ok: INSERT 0 1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 37: QUERY: insert into test ( f , i , a , text ) values ( 140787.0 , 2 , array [9,8,7,6,5,4,3,2,1,0] , 'klmnopqrst' ) on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 37 Ok: INSERT 0 1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 39: QUERY: insert into test ( f , i , a , text ) values ( 14.07 , 1 , array [9,8,7,6,5,4,3,2,1,0] , '0123456789' ) on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 39 Ok: INSERT 0 1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGtrans line 41 action = commit connection = regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGtrans line 43 action = begin transaction connection = regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 45: QUERY: select f , text from test where i = 1 on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 45: Correctly got 1 tuples with 2 fields +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGget_data line 45: RESULT: 14.07 offset: -1 array: Yes +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGget_data line 45: RESULT: 0123456789 offset: -1 array: Yes +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 53: QUERY: select a , text from test where f = 140787 on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 53: Correctly got 1 tuples with 2 fields +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGis_type_an_array line 53: TYPE database: 1007 C: 5 array: Yes +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGget_data line 53: RESULT: {9,8,7,6,5,4,3,2,1,0} offset: -1 array: Yes +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGget_data line 53: RESULT: klmnopqrst offset: -1 array: Yes +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 63: QUERY: select a from test where f = 140787 on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 63: Correctly got 1 tuples with 1 fields +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGget_data line 63: RESULT: {9,8,7,6,5,4,3,2,1,0} offset: -1 array: Yes +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 70: QUERY: drop table test on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 70 Ok: DROP TABLE +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGtrans line 72 action = commit connection = regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_finish: Connection regress1 closed. +[NO_PID]: sqlca: code: 0, state: 00000 diff --git a/src/interfaces/ecpg/test/expected/sql-array.stdout b/src/interfaces/ecpg/test/expected/sql-array.stdout new file mode 100644 index 00000000000..88c19f2498a --- /dev/null +++ b/src/interfaces/ecpg/test/expected/sql-array.stdout @@ -0,0 +1,13 @@ +Found f=14.070000 text=0123456789 +Found a[0] = 9 +Found a[1] = 8 +Found a[2] = 7 +Found a[3] = 6 +Found a[4] = 5 +Found a[5] = 4 +Found a[6] = 3 +Found a[7] = 2 +Found a[8] = 1 +Found a[9] = 0 +Found text=klmnopqrst +Found text={9,8,7,6,5,4,3,2,1,0} diff --git a/src/interfaces/ecpg/test/expected/sql-binary.c b/src/interfaces/ecpg/test/expected/sql-binary.c new file mode 100644 index 00000000000..deb0220d44f --- /dev/null +++ b/src/interfaces/ecpg/test/expected/sql-binary.c @@ -0,0 +1,164 @@ +/* Processed by ecpg (4.2.1) */ +/* These include files are added by the preprocessor */ +#include +#include +#include +#include +/* End of automatic include section */ + +#line 1 "binary.pgc" +#include +#include + + +#line 1 "regression.h" + + + + + + +#line 4 "binary.pgc" + + +/* exec sql begin declare section */ + + + + + + + +struct TBempl { +#line 9 "binary.pgc" + long idnum ; + +#line 10 "binary.pgc" + char name [ 21 ] ; + +#line 11 "binary.pgc" + short accs ; + +#line 12 "binary.pgc" + char byte [ 20 ] ; + } ;/* exec sql end declare section */ +#line 14 "binary.pgc" + + +int +main (void) +{ + /* exec sql begin declare section */ + + + +#line 20 "binary.pgc" + struct TBempl empl ; + +#line 21 "binary.pgc" + char * data = "\\001\\155\\000\\212" ; +/* exec sql end declare section */ +#line 22 "binary.pgc" + + int i; + + ECPGdebug (1, stderr); + + empl.idnum = 1; + { ECPGconnect(__LINE__, 0, "regress1" , NULL,NULL , NULL, 0); } +#line 28 "binary.pgc" + + if (sqlca.sqlcode) + { + printf ("connect error = %ld\n", sqlca.sqlcode); + exit (sqlca.sqlcode); + } + + { ECPGdo(__LINE__, 0, 1, NULL, "create table empl ( idnum integer , name char ( 20 ) , accs smallint , byte bytea ) ", ECPGt_EOIT, ECPGt_EORT);} +#line 36 "binary.pgc" + + if (sqlca.sqlcode) + { + printf ("create error = %ld\n", sqlca.sqlcode); + exit (sqlca.sqlcode); + } + + { ECPGdo(__LINE__, 0, 1, NULL, "insert into empl values ( 1 , 'first user' , 320 , ? ) ", + ECPGt_char,&(data),(long)0,(long)1,(1)*sizeof(char), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} +#line 43 "binary.pgc" + + if (sqlca.sqlcode) + { + printf ("insert error = %ld\n", sqlca.sqlcode); + exit (sqlca.sqlcode); + } + + /* declare C cursor for select name , accs , byte from empl where idnum = ? */ +#line 50 "binary.pgc" + + { ECPGdo(__LINE__, 0, 1, NULL, "declare C cursor for select name , accs , byte from empl where idnum = ? ", + ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} +#line 51 "binary.pgc" + + { ECPGdo(__LINE__, 0, 1, NULL, "fetch C", ECPGt_EOIT, + ECPGt_char,(empl.name),(long)21,(long)1,(21)*sizeof(char), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, + ECPGt_short,&(empl.accs),(long)1,(long)1,sizeof(short), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, + ECPGt_char,(empl.byte),(long)20,(long)1,(20)*sizeof(char), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} +#line 52 "binary.pgc" + + if (sqlca.sqlcode) + { + printf ("fetch error = %ld\n", sqlca.sqlcode); + exit (sqlca.sqlcode); + } + + printf ("name=%s, accs=%d byte=%s\n", empl.name, empl.accs, empl.byte); + + memset(empl.name, 0, 21L); + memset(empl.byte, '#', 20L); + /* declare B binary cursor for select name , accs , byte from empl where idnum = ? */ +#line 63 "binary.pgc" + + { ECPGdo(__LINE__, 0, 1, NULL, "declare B binary cursor for select name , accs , byte from empl where idnum = ? ", + ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} +#line 64 "binary.pgc" + + { ECPGdo(__LINE__, 0, 1, NULL, "fetch B", ECPGt_EOIT, + ECPGt_char,(empl.name),(long)21,(long)1,(21)*sizeof(char), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, + ECPGt_short,&(empl.accs),(long)1,(long)1,sizeof(short), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, + ECPGt_char,(empl.byte),(long)20,(long)1,(20)*sizeof(char), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} +#line 65 "binary.pgc" + + if (sqlca.sqlcode) + { + printf ("fetch error = %ld\n", sqlca.sqlcode); + exit (sqlca.sqlcode); + } + + { ECPGdo(__LINE__, 0, 1, NULL, "close B", ECPGt_EOIT, ECPGt_EORT);} +#line 72 "binary.pgc" + + + /* do not print a.accs because big/little endian will have different outputs here */ + printf ("name=%s, byte=", empl.name); + for (i=0; i<20; i++) + { + if (empl.byte[i] == '#') + break; + printf("(%o)", (unsigned char)empl.byte[i]); + } + printf("\n"); + { ECPGdisconnect(__LINE__, "CURRENT");} +#line 83 "binary.pgc" + + exit (0); +} diff --git a/src/interfaces/ecpg/test/expected/sql-binary.stderr b/src/interfaces/ecpg/test/expected/sql-binary.stderr new file mode 100644 index 00000000000..8b589b7c641 --- /dev/null +++ b/src/interfaces/ecpg/test/expected/sql-binary.stderr @@ -0,0 +1,46 @@ +[NO_PID]: ECPGdebug: set to 1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGconnect: opening database regress1 on port +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 35: QUERY: create table empl ( idnum integer , name char ( 20 ) , accs smallint , byte bytea ) on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 35 Ok: CREATE TABLE +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 43: QUERY: insert into empl values ( 1 , 'first user' , 320 , E'\\001\\155\\000\\212' ) on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 43 Ok: INSERT 0 1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 51: QUERY: declare C cursor for select name , accs , byte from empl where idnum = 1 on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 51 Ok: DECLARE CURSOR +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 52: QUERY: fetch C on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 52: Correctly got 1 tuples with 3 fields +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGget_data line 52: RESULT: first user offset: -1 array: Yes +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGget_data line 52: RESULT: 320 offset: -1 array: Yes +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGget_data line 52: RESULT: \001m\000\212 offset: -1 array: Yes +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 64: QUERY: declare B binary cursor for select name , accs , byte from empl where idnum = 1 on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 64 Ok: DECLARE CURSOR +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 65: QUERY: fetch B on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 65: Correctly got 1 tuples with 3 fields +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGget_data line 65: RESULT: BINARY offset: -1 array: Yes +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGget_data line 65: RESULT: BINARY offset: -1 array: Yes +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGget_data line 65: RESULT: BINARY offset: -1 array: Yes +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 72: QUERY: close B on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ECPGexecute line 72 Ok: CLOSE CURSOR +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_finish: Connection regress1 closed. +[NO_PID]: sqlca: code: 0, state: 00000 diff --git a/src/interfaces/ecpg/test/expected/sql-binary.stdout b/src/interfaces/ecpg/test/expected/sql-binary.stdout new file mode 100644 index 00000000000..e8b92563190 --- /dev/null +++ b/src/interfaces/ecpg/test/expected/sql-binary.stdout @@ -0,0 +1,2 @@ +name=first user , accs=320 byte=\001m\000\212 +name=first user , byte=(1)(155)(0)(212) diff --git a/src/interfaces/ecpg/test/pgtypeslib/dt_test2.pgc b/src/interfaces/ecpg/test/pgtypeslib/dt_test2.pgc index 179f97f56db..1591dde51db 100644 --- a/src/interfaces/ecpg/test/pgtypeslib/dt_test2.pgc +++ b/src/interfaces/ecpg/test/pgtypeslib/dt_test2.pgc @@ -1,20 +1,62 @@ #include #include #include +#include #include #include exec sql include ../regression; +char *dates[] = { "19990108foobar", + "19990108 foobar", + "1999-01-08 foobar", + "January 8, 1999", + "1999-01-08", + "1/8/1999", + "1/18/1999", + "01/02/03", + "1999-Jan-08", + "Jan-08-1999", + "08-Jan-1999", + "99-Jan-08", + "08-Jan-99", + "08-Jan-06", + "Jan-08-99", + "19990108", + "990108", + "1999.008", + "J2451187", + "January 8, 99 BC", + NULL }; + +char *times[] = { "0:04", + "1:59 PDT", + "13:24:40 -8:00", + "13:24:40.495+3", + NULL }; + +char *intervals[] = { "1 minute", + "1 12:59:10", + "2 day 12 hour 59 minute 10 second", + "1 days 12 hrs 59 mins 10 secs", + "1 days 1 hours 1 minutes 1 seconds", + "1 year 59 mins", + "1 year 59 mins foobar", + NULL }; + int main(void) { exec sql begin declare section; date date1; - timestamp ts1; - char* text; + timestamp ts1, ts2; + char *text; + interval *i1; exec sql end declare section; + int i, j; + char *endptr; + ECPGdebug(1, stderr); ts1 = PGTYPEStimestamp_from_asc("2003-12-04 17:34:29", NULL); @@ -28,6 +70,58 @@ main(void) printf("Date of timestamp: %s\n", text); free(text); + for (i = 0; dates[i]; i++) + { + bool err = false; + date1 = PGTYPESdate_from_asc(dates[i], &endptr); + if (date1 == INT_MIN) { + err = true; + } + text = PGTYPESdate_to_asc(date1); + printf("Date[%d]: %s (%c - %c)\n", + i, err ? "-" : text, + endptr ? 'N' : 'Y', + err ? 'T' : 'F'); + free(text); + if (!err) + { + for (j = 0; times[j]; j++) + { + int length = strlen(dates[i]) + + 1 + + strlen(times[j]) + + 1; + char* t = malloc(length); + sprintf(t, "%s %s", dates[i], times[j]); + ts1 = PGTYPEStimestamp_from_asc(t, NULL); + text = PGTYPEStimestamp_to_asc(ts1); + printf("TS[%d,%d]: %s\n", + i, j, errno ? "-" : text); + free(text); + } + } + } + + ts1 = PGTYPEStimestamp_from_asc("2004-04-04 23:23:23", NULL); + + for (i = 0; intervals[i]; i++) + { + i1 = PGTYPESinterval_from_asc(intervals[i], &endptr); + if (*endptr) + printf("endptr set to %s\n", endptr); + if (!i1) + { + printf("Error parsing interval %d\n", i); + continue; + } + j = PGTYPEStimestamp_add_interval(&ts1, i1, &ts2); + if (j < 0) + continue; + text = PGTYPESinterval_to_asc(i1); + printf("interval[%d]: %s\n", i, text ? text : "-"); + free(text); + } + return (0); } diff --git a/src/interfaces/ecpg/test/preproc/Makefile b/src/interfaces/ecpg/test/preproc/Makefile new file mode 100644 index 00000000000..2184beb187f --- /dev/null +++ b/src/interfaces/ecpg/test/preproc/Makefile @@ -0,0 +1,11 @@ +subdir = src/interfaces/ecpg/test/preproc +top_builddir = ../../../../.. +include $(top_builddir)/src/Makefile.global +include $(top_srcdir)/$(subdir)/../Makefile.regress + + +TESTS = define define.c \ + init init.c + +all: $(TESTS) + diff --git a/src/interfaces/ecpg/test/preproc/define.pgc b/src/interfaces/ecpg/test/preproc/define.pgc new file mode 100644 index 00000000000..1a4ac7444b8 --- /dev/null +++ b/src/interfaces/ecpg/test/preproc/define.pgc @@ -0,0 +1,64 @@ +#include +#include + +EXEC SQL include ../regression; + +EXEC SQL typedef long mmInteger; +EXEC SQL typedef char mmChar; +EXEC SQL typedef short mmSmallInt; + +EXEC SQL BEGIN DECLARE SECTION; +struct TBempl +{ + mmInteger idnum; + mmChar name[21]; + mmSmallInt accs; +}; +EXEC SQL END DECLARE SECTION; + +int +main (void) +{ + EXEC SQL BEGIN DECLARE SECTION; + struct TBempl empl; + EXEC SQL END DECLARE SECTION; + + ECPGdebug (1, stderr); + + empl.idnum = 1; + EXEC SQL connect to REGRESSDB1; + if (sqlca.sqlcode) + { + printf ("connect error = %ld\n", sqlca.sqlcode); + exit (sqlca.sqlcode); + } + + EXEC SQL create table empl + (idnum integer, name char (20), accs smallint); + if (sqlca.sqlcode) + { + printf ("create error = %ld\n", sqlca.sqlcode); + exit (sqlca.sqlcode); + } + + EXEC SQL insert into empl values (1, 'first user', 320); + if (sqlca.sqlcode) + { + printf ("insert error = %ld\n", sqlca.sqlcode); + exit (sqlca.sqlcode); + } + + EXEC SQL select idnum, name, accs + into :empl + from empl + where idnum =:empl.idnum; + if (sqlca.sqlcode) + { + printf ("select error = %ld\n", sqlca.sqlcode); + exit (sqlca.sqlcode); + } + printf ("id=%ld name=%s, accs=%d\n", empl.idnum, empl.name, empl.accs); + + EXEC SQL disconnect; + exit (0); +} diff --git a/src/interfaces/ecpg/test/preproc/init.pgc b/src/interfaces/ecpg/test/preproc/init.pgc new file mode 100644 index 00000000000..8521e44ee10 --- /dev/null +++ b/src/interfaces/ecpg/test/preproc/init.pgc @@ -0,0 +1,100 @@ +exec sql include sqlca; + +enum e { ENUM0, ENUM1 }; +struct sa { int member; }; + +static int fa(void) +{ + printf("in fa\n"); + return 2; +} + +static int +fb(int x) +{ + printf("in fb (%d)\n", x); + return x; +} + +static int +fc(const char *x) +{ + printf("in fc (%s)\n", x); + return *x; +} + +static int fd(const char *x,int i) +{ + printf("in fd (%s, %d)\n", x, i); + return (*x)*i; +} + +static int fe(enum e x) +{ + printf("in fe (%d)\n", (int) x); + return (int)x; +} + +static void sqlnotice(char *notice, short trans) +{ + if (!notice) + notice = "-empty-"; + printf("in sqlnotice (%s, %d)\n", notice, trans); +} + +exec sql define NONO 0; + +#define YES 1 + +#ifdef _cplusplus +namespace N +{ + static const int i=2; +}; +#endif + +int main(void) +{ + struct sa x = { 14 },*y = &x; + exec sql begin declare section; + int a=(int)2; + int b=2+2; + int b2=(14*7); + int d=x.member; + int g=fb(2); + int i=3^1; + int j=1?1:2; + + int e=y->member; + int c=10>>2; + bool h=2||1; + long iay /* = 1L */ ; + exec sql end declare section; + + int f=fa(); + +#ifdef _cplusplus + exec sql begin declare section; + int k=N::i; /* compile error */ + exec sql end declare section; +#endif + + ECPGdebug(1, stderr); + + printf("%d %d %d %d %d %d %d %d %d %d %d\n", a, b, b2, c, d, e, f, g, h, i, j); + iay = 0; + printf("%ld\n", iay); + exec sql whenever sqlerror do fa(); + exec sql select now(); + exec sql whenever sqlerror do fb(20); + exec sql select now(); + exec sql whenever sqlerror do fc("50"); + exec sql select now(); + exec sql whenever sqlerror do fd("50",1); + exec sql select now(); + exec sql whenever sqlerror do fe(ENUM0); + exec sql select now(); + exec sql whenever sqlerror do sqlnotice(NULL, NONO); + exec sql select now(); + return 0; +} diff --git a/src/interfaces/ecpg/test/sql/Makefile b/src/interfaces/ecpg/test/sql/Makefile index 381ff6bc6c6..f44ec6a297c 100644 --- a/src/interfaces/ecpg/test/sql/Makefile +++ b/src/interfaces/ecpg/test/sql/Makefile @@ -3,18 +3,24 @@ top_builddir = ../../../../.. include $(top_builddir)/src/Makefile.global include $(top_srcdir)/$(subdir)/../Makefile.regress -TESTS = define define.c \ - dyntest dyntest.c \ - code100 code100.c \ +TESTS = array array.c \ + binary binary.c \ + code100 code100.c \ + copystdout copystdout.c \ + define define.c \ desc desc.c \ + dyntest dyntest.c \ dynalloc dynalloc.c \ dynalloc2 dynalloc2.c \ func func.c \ indicators indicators.c \ quote quote.c \ show show.c \ - update update.c \ - copystdout copystdout.c + update update.c all: $(TESTS) +# bits needs the -c option for the "EXEC SQL TYPE" construct +bits.c: bits.pgc ../regression.h + $(ECPG) -c -o $@ -I$(srcdir) $< + diff --git a/src/interfaces/ecpg/test/sql/array.pgc b/src/interfaces/ecpg/test/sql/array.pgc new file mode 100644 index 00000000000..2444e0158be --- /dev/null +++ b/src/interfaces/ecpg/test/sql/array.pgc @@ -0,0 +1,77 @@ +#include +#include +#include + +exec sql whenever sqlerror sqlprint; + +exec sql include sqlca; +exec sql include ../regression; + +int +main (void) +{ +EXEC SQL BEGIN DECLARE SECTION; + int i = 1; + int *did = &i; + int a[10] = {9,8,7,6,5,4,3,2,1,0}; + char text[25] = "klmnopqrst"; + char *t = (char *)malloc(11); + double f; +EXEC SQL END DECLARE SECTION; + + strcpy(t, "0123456789"); + setlocale(LC_ALL, "C"); + + ECPGdebug(1, stderr); + + EXEC SQL CONNECT TO REGRESSDB1; + + EXEC SQL SET AUTOCOMMIT = ON; + + EXEC SQL BEGIN WORK; + + EXEC SQL CREATE TABLE test (f float, i int, a int[10], text char(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) VALUES(140787.0,2,:a,:text); + + EXEC SQL INSERT INTO test(f,i,a,text) VALUES(14.07,:did,:a,:t); + + EXEC SQL COMMIT; + + EXEC SQL BEGIN WORK; + + EXEC SQL SELECT f,text + INTO :f,:text + FROM test + WHERE i = 1; + + printf("Found f=%f text=%10.10s\n", f, text); + + f=140787; + EXEC SQL SELECT a,text + INTO :a,:t + FROM test + WHERE f = :f; + + for (i = 0; i < 10; i++) + printf("Found a[%d] = %d\n", i, a[i]); + + printf("Found text=%10.10s\n", t); + + EXEC SQL SELECT a + INTO :text + FROM test + WHERE f = :f; + + printf("Found text=%s\n", text); + + EXEC SQL DROP TABLE test; + + EXEC SQL COMMIT; + + EXEC SQL DISCONNECT; + + return (0); +} diff --git a/src/interfaces/ecpg/test/sql/binary.pgc b/src/interfaces/ecpg/test/sql/binary.pgc new file mode 100644 index 00000000000..9be73409135 --- /dev/null +++ b/src/interfaces/ecpg/test/sql/binary.pgc @@ -0,0 +1,85 @@ +#include +#include + +EXEC SQL include ../regression; + +EXEC SQL BEGIN DECLARE SECTION; +struct TBempl +{ + long idnum; + char name[21]; + short accs; + char byte[20]; +}; +EXEC SQL END DECLARE SECTION; + +int +main (void) +{ + EXEC SQL BEGIN DECLARE SECTION; + struct TBempl empl; + char *data = "\\001\\155\\000\\212"; + EXEC SQL END DECLARE SECTION; + int i; + + ECPGdebug (1, stderr); + + empl.idnum = 1; + EXEC SQL connect to REGRESSDB1; + if (sqlca.sqlcode) + { + printf ("connect error = %ld\n", sqlca.sqlcode); + exit (sqlca.sqlcode); + } + + EXEC SQL create table empl + (idnum integer, name char (20), accs smallint, byte bytea); + if (sqlca.sqlcode) + { + printf ("create error = %ld\n", sqlca.sqlcode); + exit (sqlca.sqlcode); + } + + EXEC SQL insert into empl values (1, 'first user', 320, :data); + if (sqlca.sqlcode) + { + printf ("insert error = %ld\n", sqlca.sqlcode); + exit (sqlca.sqlcode); + } + + EXEC SQL DECLARE C CURSOR FOR select name, accs, byte from empl where idnum =:empl.idnum; + EXEC SQL OPEN C; + EXEC SQL FETCH C INTO:empl.name,:empl.accs,:empl.byte; + if (sqlca.sqlcode) + { + printf ("fetch error = %ld\n", sqlca.sqlcode); + exit (sqlca.sqlcode); + } + + printf ("name=%s, accs=%d byte=%s\n", empl.name, empl.accs, empl.byte); + + memset(empl.name, 0, 21L); + memset(empl.byte, '#', 20L); + EXEC SQL DECLARE B BINARY CURSOR FOR select name, accs, byte from empl where idnum =:empl.idnum; + EXEC SQL OPEN B; + EXEC SQL FETCH B INTO :empl.name,:empl.accs,:empl.byte; + if (sqlca.sqlcode) + { + printf ("fetch error = %ld\n", sqlca.sqlcode); + exit (sqlca.sqlcode); + } + + EXEC SQL CLOSE B; + + /* do not print a.accs because big/little endian will have different outputs here */ + printf ("name=%s, byte=", empl.name); + for (i=0; i<20; i++) + { + if (empl.byte[i] == '#') + break; + printf("(%o)", (unsigned char)empl.byte[i]); + } + printf("\n"); + EXEC SQL disconnect; + exit (0); +} -- cgit v1.2.3