From 46651ce6fe013220ed397add242004d764fc0153 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 14:15:05 +0200 Subject: Adding upstream version 14.5. Signed-off-by: Daniel Baumann --- src/interfaces/ecpg/test/compat_oracle/.gitignore | 2 + src/interfaces/ecpg/test/compat_oracle/Makefile | 11 ++++ .../ecpg/test/compat_oracle/char_array.pgc | 64 ++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 src/interfaces/ecpg/test/compat_oracle/.gitignore create mode 100644 src/interfaces/ecpg/test/compat_oracle/Makefile create mode 100644 src/interfaces/ecpg/test/compat_oracle/char_array.pgc (limited to 'src/interfaces/ecpg/test/compat_oracle') diff --git a/src/interfaces/ecpg/test/compat_oracle/.gitignore b/src/interfaces/ecpg/test/compat_oracle/.gitignore new file mode 100644 index 0000000..63b3766 --- /dev/null +++ b/src/interfaces/ecpg/test/compat_oracle/.gitignore @@ -0,0 +1,2 @@ +/char_array +/char_array.c diff --git a/src/interfaces/ecpg/test/compat_oracle/Makefile b/src/interfaces/ecpg/test/compat_oracle/Makefile new file mode 100644 index 0000000..cd4e7e8 --- /dev/null +++ b/src/interfaces/ecpg/test/compat_oracle/Makefile @@ -0,0 +1,11 @@ +subdir = src/interfaces/ecpg/test/compat_oracle +top_builddir = ../../../../.. +include $(top_builddir)/src/Makefile.global +include $(top_srcdir)/$(subdir)/../Makefile.regress + +# Use special oracle compatibility switch for all tests in this directory +ECPG += -C ORACLE + +TESTS = char_array char_array.c + +all: $(TESTS) diff --git a/src/interfaces/ecpg/test/compat_oracle/char_array.pgc b/src/interfaces/ecpg/test/compat_oracle/char_array.pgc new file mode 100644 index 0000000..6a5d383 --- /dev/null +++ b/src/interfaces/ecpg/test/compat_oracle/char_array.pgc @@ -0,0 +1,64 @@ +#include +#include +#include + +EXEC SQL INCLUDE ../regression; + +static void warn(void) +{ + fprintf(stderr, "Warning: At least one column was truncated\n"); +} + +/* Compatible handling of char array to retrieve varchar field to char array + should be fixed-length, blank-padded, then null-terminated. + Conforms to the ANSI Fixed Character type. */ + +int main() { + + EXEC SQL WHENEVER SQLWARNING do warn(); + EXEC SQL WHENEVER SQLERROR STOP; + + const char *ppppp = "XXXXX"; + int loopcount; + EXEC SQL BEGIN DECLARE SECTION; + char shortstr[5]; + char bigstr[11]; + short shstr_ind = 0; + short bigstr_ind = 0; + EXEC SQL END DECLARE SECTION; + + ECPGdebug(1, stderr); + EXEC SQL CONNECT TO REGRESSDB1; + + EXEC SQL CREATE TABLE strdbase (strval varchar(10)); + EXEC SQL INSERT INTO strdbase values (''); + EXEC SQL INSERT INTO strdbase values ('AB'); + EXEC SQL INSERT INTO strdbase values ('ABCD'); + EXEC SQL INSERT INTO strdbase values ('ABCDE'); + EXEC SQL INSERT INTO strdbase values ('ABCDEF'); + EXEC SQL INSERT INTO strdbase values ('ABCDEFGHIJ'); + + EXEC SQL declare C cursor for select strval, strval from strdbase; + EXEC SQL OPEN C; + + EXEC SQL WHENEVER NOT FOUND DO BREAK; + + printf("Full Str. : Short Ind.\n"); + for (loopcount = 0; loopcount < 100; loopcount++) { + strncpy(shortstr, ppppp, sizeof shortstr); + memset(bigstr, 0, sizeof bigstr); + EXEC SQL FETCH C into :bigstr :bigstr_ind, :shortstr :shstr_ind; + printf("\"%s\": \"%s\" %d\n", bigstr, shortstr, shstr_ind); + } + + EXEC SQL CLOSE C; + EXEC SQL DROP TABLE strdbase; + + printf("\nGOOD-BYE!!\n\n"); + + EXEC SQL COMMIT WORK; + + EXEC SQL DISCONNECT ALL; + + return 0; +} -- cgit v1.2.3