aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/test/compat_oracle/char_array.pgc
diff options
context:
space:
mode:
authorMichael Meskes <meskes@postgresql.org>2018-03-14 00:54:13 +0100
committerMichael Meskes <meskes@postgresql.org>2018-03-14 00:54:13 +0100
commit3b7ab4380440d7b14ee390fabf39f6d87d7491e2 (patch)
tree624029b996d00a119d97bc5f03d1b9ef21a16a5d /src/interfaces/ecpg/test/compat_oracle/char_array.pgc
parentdb2fc801f66a70969cbdd5673ed9d02025c70695 (diff)
downloadpostgresql-3b7ab4380440d7b14ee390fabf39f6d87d7491e2.tar.gz
postgresql-3b7ab4380440d7b14ee390fabf39f6d87d7491e2.zip
Add Oracle like handling of char arrays.
In some cases Oracle Pro*C handles char array differently than ECPG. This patch adds a Oracle compatibility mode to make ECPG behave like Pro*C. Patch by David Rader <davidr@openscg.com>
Diffstat (limited to 'src/interfaces/ecpg/test/compat_oracle/char_array.pgc')
-rw-r--r--src/interfaces/ecpg/test/compat_oracle/char_array.pgc66
1 files changed, 66 insertions, 0 deletions
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 00000000000..8e163398b3a
--- /dev/null
+++ b/src/interfaces/ecpg/test/compat_oracle/char_array.pgc
@@ -0,0 +1,66 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+EXEC SQL INCLUDE ../regression;
+
+static void warn();
+
+/* 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() {
+
+ ECPGdebug(1, stderr);
+ EXEC SQL CONNECT TO REGRESSDB1;
+
+ EXEC SQL WHENEVER SQLWARNING do warn();
+ EXEC SQL WHENEVER SQLERROR SQLPRINT;
+
+ const char *ppppp = "XXXXX";
+
+ EXEC SQL BEGIN DECLARE SECTION;
+ char shortstr[5];
+ char bigstr[11];
+ short shstr_ind = 0;
+ short bigstr_ind = 0;
+ EXEC SQL END DECLARE SECTION;
+
+ 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");
+ while(1) {
+ 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 cstr;
+ EXEC SQL DROP TABLE strdbase;
+
+ printf("\nGOOD-BYE!!\n\n");
+
+ EXEC SQL COMMIT WORK;
+
+ EXEC SQL DISCONNECT ALL;
+
+ return 0;
+}
+
+static void warn(void)
+{
+ fprintf(stderr, "Warning: At least one column was truncated\n");
+}