summaryrefslogtreecommitdiffstats
path: root/src/interfaces/ecpg/test/compat_oracle
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:17:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:17:33 +0000
commit5e45211a64149b3c659b90ff2de6fa982a5a93ed (patch)
tree739caf8c461053357daa9f162bef34516c7bf452 /src/interfaces/ecpg/test/compat_oracle
parentInitial commit. (diff)
downloadpostgresql-15-5e45211a64149b3c659b90ff2de6fa982a5a93ed.tar.xz
postgresql-15-5e45211a64149b3c659b90ff2de6fa982a5a93ed.zip
Adding upstream version 15.5.upstream/15.5
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/interfaces/ecpg/test/compat_oracle')
-rw-r--r--src/interfaces/ecpg/test/compat_oracle/.gitignore2
-rw-r--r--src/interfaces/ecpg/test/compat_oracle/Makefile11
-rw-r--r--src/interfaces/ecpg/test/compat_oracle/char_array.pgc93
3 files changed, 106 insertions, 0 deletions
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..de18cbb
--- /dev/null
+++ b/src/interfaces/ecpg/test/compat_oracle/char_array.pgc
@@ -0,0 +1,93 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <pgtypes_numeric.h>
+
+EXEC SQL INCLUDE sqlda.h;
+
+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;
+ sqlda_t *sqlda = NULL;
+
+ 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;
+ EXEC SQL COMMIT WORK;
+
+ /* SQLDA handling */
+ EXEC SQL WHENEVER SQLWARNING SQLPRINT;
+ EXEC SQL WHENEVER NOT FOUND STOP;
+ EXEC SQL PREPARE stmt1 FROM "SELECT 123::numeric(3,0), 't'::varchar(2)";
+ EXEC SQL DECLARE cur1 CURSOR FOR stmt1;
+ EXEC SQL OPEN cur1;
+ EXEC SQL FETCH NEXT FROM cur1 INTO DESCRIPTOR sqlda;
+
+ printf("\n-----------------\ntype : data\n");
+ for (int i = 0 ; i < sqlda->sqld ; i++)
+ {
+ sqlvar_t v = sqlda->sqlvar[i];
+ char *sqldata = v.sqldata;
+
+ if (v.sqltype == ECPGt_numeric)
+ sqldata =
+ PGTYPESnumeric_to_asc((numeric*) sqlda->sqlvar[i].sqldata, -1);
+
+ printf("%-8s: \"%s\"\n", v.sqlname.data, sqldata);
+ }
+
+ EXEC SQL CLOSE cur1;
+ EXEC SQL COMMIT WORK;
+
+ printf("\nGOOD-BYE!!\n\n");
+
+ EXEC SQL DISCONNECT ALL;
+
+ return 0;
+}