diff options
author | Michael Meskes <meskes@postgresql.org> | 2009-02-02 16:14:06 +0000 |
---|---|---|
committer | Michael Meskes <meskes@postgresql.org> | 2009-02-02 16:14:06 +0000 |
commit | 2d3c6911465a2214c0f82fb604c6098d9975c5a5 (patch) | |
tree | acce4aac600cfaf2c9b6b255ff0166a58ba8c657 /src/interfaces/ecpg/test | |
parent | 77ca0453847fe98d109d9874d84dc91ec56d1209 (diff) | |
download | postgresql-2d3c6911465a2214c0f82fb604c6098d9975c5a5.tar.gz postgresql-2d3c6911465a2214c0f82fb604c6098d9975c5a5.zip |
Fixed auto allocation for binary data types.
Diffstat (limited to 'src/interfaces/ecpg/test')
-rw-r--r-- | src/interfaces/ecpg/test/expected/sql-binary.c | 66 | ||||
-rw-r--r-- | src/interfaces/ecpg/test/expected/sql-binary.stderr | 84 | ||||
-rw-r--r-- | src/interfaces/ecpg/test/expected/sql-binary.stdout | 1 | ||||
-rw-r--r-- | src/interfaces/ecpg/test/sql/binary.pgc | 27 |
4 files changed, 122 insertions, 56 deletions
diff --git a/src/interfaces/ecpg/test/expected/sql-binary.c b/src/interfaces/ecpg/test/expected/sql-binary.c index fb2606d4e97..95f8056917d 100644 --- a/src/interfaces/ecpg/test/expected/sql-binary.c +++ b/src/interfaces/ecpg/test/expected/sql-binary.c @@ -51,14 +51,18 @@ main (void) /* exec sql begin declare section */ + #line 20 "binary.pgc" struct TBempl empl ; #line 21 "binary.pgc" + char * pointer = NULL ; + +#line 22 "binary.pgc" char * data = "\\001\\155\\000\\212" ; /* exec sql end declare section */ -#line 22 "binary.pgc" +#line 23 "binary.pgc" int i; @@ -66,7 +70,7 @@ main (void) empl.idnum = 1; { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); } -#line 28 "binary.pgc" +#line 29 "binary.pgc" if (sqlca.sqlcode) { @@ -75,7 +79,7 @@ main (void) } { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table empl ( idnum integer , name char ( 20 ) , accs smallint , byte bytea )", ECPGt_EOIT, ECPGt_EORT);} -#line 36 "binary.pgc" +#line 37 "binary.pgc" if (sqlca.sqlcode) { @@ -86,7 +90,7 @@ main (void) { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into empl values ( 1 , 'first user' , 320 , $1 )", 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" +#line 44 "binary.pgc" if (sqlca.sqlcode) { @@ -95,12 +99,12 @@ main (void) } /* declare C cursor for select name , accs , byte from empl where idnum = $1 */ -#line 50 "binary.pgc" +#line 51 "binary.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare C cursor for select name , accs , byte from empl where idnum = $1 ", 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" +#line 52 "binary.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch C", ECPGt_EOIT, ECPGt_char,(empl.name),(long)21,(long)1,(21)*sizeof(char), @@ -109,7 +113,7 @@ main (void) 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" +#line 53 "binary.pgc" if (sqlca.sqlcode) { @@ -119,15 +123,13 @@ main (void) 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 = $1 */ -#line 63 "binary.pgc" +#line 62 "binary.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare B binary cursor for select name , accs , byte from empl where idnum = $1 ", 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" +#line 63 "binary.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch B", ECPGt_EOIT, ECPGt_char,(empl.name),(long)21,(long)1,(21)*sizeof(char), @@ -136,7 +138,7 @@ main (void) 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" +#line 64 "binary.pgc" if (sqlca.sqlcode) { @@ -145,20 +147,46 @@ main (void) } { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close B", ECPGt_EOIT, ECPGt_EORT);} -#line 72 "binary.pgc" +#line 71 "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; + for (i=0; i<4; i++) printf("(%o)", (unsigned char)empl.byte[i]); - } printf("\n"); + + /* declare A binary cursor for select byte from empl where idnum = $1 */ +#line 79 "binary.pgc" + + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare A binary cursor for select byte from empl where idnum = $1 ", + ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} +#line 80 "binary.pgc" + + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch A", ECPGt_EOIT, + ECPGt_char,&(pointer),(long)0,(long)1,(1)*sizeof(char), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} +#line 81 "binary.pgc" + + if (sqlca.sqlcode) + { + printf ("fetch error = %ld\n", sqlca.sqlcode); + exit (sqlca.sqlcode); + } + + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close A", ECPGt_EOIT, ECPGt_EORT);} +#line 88 "binary.pgc" + + + printf ("pointer="); + for (i=0; i<4; i++) + printf("(%o)", (unsigned char)pointer[i]); + printf("\n"); + free(pointer); + { ECPGdisconnect(__LINE__, "CURRENT");} -#line 83 "binary.pgc" +#line 96 "binary.pgc" exit (0); } diff --git a/src/interfaces/ecpg/test/expected/sql-binary.stderr b/src/interfaces/ecpg/test/expected/sql-binary.stderr index 8f4434fbe5d..f0530f24c11 100644 --- a/src/interfaces/ecpg/test/expected/sql-binary.stderr +++ b/src/interfaces/ecpg/test/expected/sql-binary.stderr @@ -2,65 +2,89 @@ [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 35: query: create table empl ( idnum integer , name char ( 20 ) , accs smallint , byte bytea ); with 0 parameter(s) on connection regress1 +[NO_PID]: ecpg_execute on line 36: query: create table empl ( idnum integer , name char ( 20 ) , accs smallint , byte bytea ); with 0 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 35: using PQexec +[NO_PID]: ecpg_execute on line 36: using PQexec [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 35: OK: CREATE TABLE +[NO_PID]: ecpg_execute on line 36: OK: CREATE TABLE [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 43: query: insert into empl values ( 1 , 'first user' , 320 , $1 ); with 1 parameter(s) on connection regress1 +[NO_PID]: ecpg_execute on line 44: query: insert into empl values ( 1 , 'first user' , 320 , $1 ); with 1 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 43: using PQexecParams +[NO_PID]: ecpg_execute on line 44: using PQexecParams [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: free_params on line 43: parameter 1 = \001\155\000\212 +[NO_PID]: free_params on line 44: parameter 1 = \001\155\000\212 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 43: OK: INSERT 0 1 +[NO_PID]: ecpg_execute on line 44: OK: INSERT 0 1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 51: query: declare C cursor for select name , accs , byte from empl where idnum = $1 ; with 1 parameter(s) on connection regress1 +[NO_PID]: ecpg_execute on line 52: query: declare C cursor for select name , accs , byte from empl where idnum = $1 ; with 1 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 51: using PQexecParams +[NO_PID]: ecpg_execute on line 52: using PQexecParams [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: free_params on line 51: parameter 1 = 1 +[NO_PID]: free_params on line 52: parameter 1 = 1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 51: OK: DECLARE CURSOR +[NO_PID]: ecpg_execute on line 52: OK: DECLARE CURSOR [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 52: query: fetch C; with 0 parameter(s) on connection regress1 +[NO_PID]: ecpg_execute on line 53: query: fetch C; with 0 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 52: using PQexec +[NO_PID]: ecpg_execute on line 53: using PQexec [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 52: correctly got 1 tuples with 3 fields +[NO_PID]: ecpg_execute on line 53: correctly got 1 tuples with 3 fields [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_get_data on line 52: RESULT: first user offset: -1; array: yes +[NO_PID]: ecpg_get_data on line 53: RESULT: first user offset: -1; array: yes [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_get_data on line 52: RESULT: 320 offset: -1; array: yes +[NO_PID]: ecpg_get_data on line 53: RESULT: 320 offset: -1; array: yes [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_get_data on line 52: RESULT: \001m\000\212 offset: -1; array: yes +[NO_PID]: ecpg_get_data on line 53: RESULT: \001m\000\212 offset: -1; array: yes [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 64: query: declare B binary cursor for select name , accs , byte from empl where idnum = $1 ; with 1 parameter(s) on connection regress1 +[NO_PID]: ecpg_execute on line 63: query: declare B binary cursor for select name , accs , byte from empl where idnum = $1 ; with 1 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 64: using PQexecParams +[NO_PID]: ecpg_execute on line 63: using PQexecParams [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: free_params on line 64: parameter 1 = 1 +[NO_PID]: free_params on line 63: parameter 1 = 1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 64: OK: DECLARE CURSOR +[NO_PID]: ecpg_execute on line 63: OK: DECLARE CURSOR [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 65: query: fetch B; with 0 parameter(s) on connection regress1 +[NO_PID]: ecpg_execute on line 64: query: fetch B; with 0 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 65: using PQexec +[NO_PID]: ecpg_execute on line 64: using PQexec [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 65: correctly got 1 tuples with 3 fields +[NO_PID]: ecpg_execute on line 64: correctly got 1 tuples with 3 fields [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_get_data on line 65: RESULT: BINARY offset: -1; array: yes +[NO_PID]: ecpg_get_data on line 64: RESULT: BINARY offset: -1; array: yes [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_get_data on line 65: RESULT: BINARY offset: -1; array: yes +[NO_PID]: ecpg_get_data on line 64: RESULT: BINARY offset: -1; array: yes [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_get_data on line 65: RESULT: BINARY offset: -1; array: yes +[NO_PID]: ecpg_get_data on line 64: RESULT: BINARY offset: -1; array: yes [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 72: query: close B; with 0 parameter(s) on connection regress1 +[NO_PID]: ecpg_execute on line 71: query: close B; with 0 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 72: using PQexec +[NO_PID]: ecpg_execute on line 71: using PQexec [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 72: OK: CLOSE CURSOR +[NO_PID]: ecpg_execute on line 71: OK: CLOSE CURSOR +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_execute on line 80: query: declare A binary cursor for select byte from empl where idnum = $1 ; with 1 parameter(s) on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_execute on line 80: using PQexecParams +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: free_params on line 80: parameter 1 = 1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_execute on line 80: OK: DECLARE CURSOR +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_execute on line 81: query: fetch A; with 0 parameter(s) on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_execute on line 81: using PQexec +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_execute on line 81: correctly got 1 tuples with 1 fields +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_store_result on line 81: allocating memory for 1 tuples +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_get_data on line 81: RESULT: BINARY offset: -1; array: yes +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_execute on line 88: query: close A; with 0 parameter(s) on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_execute on line 88: using PQexec +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_execute on line 88: 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 index e8b92563190..b2a94db6d1d 100644 --- a/src/interfaces/ecpg/test/expected/sql-binary.stdout +++ b/src/interfaces/ecpg/test/expected/sql-binary.stdout @@ -1,2 +1,3 @@ name=first user , accs=320 byte=\001m\000\212 name=first user , byte=(1)(155)(0)(212) +pointer=(1)(155)(0)(212) diff --git a/src/interfaces/ecpg/test/sql/binary.pgc b/src/interfaces/ecpg/test/sql/binary.pgc index 9be73409135..a86aa283b6b 100644 --- a/src/interfaces/ecpg/test/sql/binary.pgc +++ b/src/interfaces/ecpg/test/sql/binary.pgc @@ -18,6 +18,7 @@ main (void) { EXEC SQL BEGIN DECLARE SECTION; struct TBempl empl; + char *pointer = NULL; char *data = "\\001\\155\\000\\212"; EXEC SQL END DECLARE SECTION; int i; @@ -58,8 +59,6 @@ main (void) 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; @@ -73,13 +72,27 @@ main (void) /* 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; + for (i=0; i<4; i++) printf("(%o)", (unsigned char)empl.byte[i]); - } printf("\n"); + + EXEC SQL DECLARE A BINARY CURSOR FOR select byte from empl where idnum =:empl.idnum; + EXEC SQL OPEN A; + EXEC SQL FETCH A INTO :pointer; + if (sqlca.sqlcode) + { + printf ("fetch error = %ld\n", sqlca.sqlcode); + exit (sqlca.sqlcode); + } + + EXEC SQL CLOSE A; + + printf ("pointer="); + for (i=0; i<4; i++) + printf("(%o)", (unsigned char)pointer[i]); + printf("\n"); + free(pointer); + EXEC SQL disconnect; exit (0); } |