diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:15:05 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:15:05 +0000 |
commit | 46651ce6fe013220ed397add242004d764fc0153 (patch) | |
tree | 6e5299f990f88e60174a1d3ae6e48eedd2688b2b /src/interfaces/ecpg/test/preproc/autoprep.pgc | |
parent | Initial commit. (diff) | |
download | postgresql-14-upstream.tar.xz postgresql-14-upstream.zip |
Adding upstream version 14.5.upstream/14.5upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/interfaces/ecpg/test/preproc/autoprep.pgc')
-rw-r--r-- | src/interfaces/ecpg/test/preproc/autoprep.pgc | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/interfaces/ecpg/test/preproc/autoprep.pgc b/src/interfaces/ecpg/test/preproc/autoprep.pgc new file mode 100644 index 0000000..d3d9305 --- /dev/null +++ b/src/interfaces/ecpg/test/preproc/autoprep.pgc @@ -0,0 +1,72 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +/* test automatic prepare for all statements */ +EXEC SQL INCLUDE ../regression; + +static void test(void) { + EXEC SQL BEGIN DECLARE SECTION; + int item[4], ind[4], i = 1; + int item1, ind1; + char sqlstr[64] = "SELECT item2 FROM T ORDER BY item2 NULLS LAST"; + EXEC SQL END DECLARE SECTION; + + ECPGdebug(1, stderr); + EXEC SQL CONNECT TO REGRESSDB1; + + EXEC SQL WHENEVER SQLWARNING SQLPRINT; + EXEC SQL WHENEVER SQLERROR SQLPRINT; + + EXEC SQL CREATE TABLE T ( Item1 int, Item2 int ); + + EXEC SQL INSERT INTO T VALUES ( 1, null ); + EXEC SQL INSERT INTO T VALUES ( 1, :i ); + i++; + EXEC SQL INSERT INTO T VALUES ( 1, :i ); + EXEC SQL PREPARE I AS INSERT INTO T VALUES ( 1, 2 ); + EXEC SQL EXECUTE I; + + EXEC SQL SELECT Item2 INTO :item:ind FROM T ORDER BY Item2 NULLS LAST; + + for (i=0; i<4; i++) + printf("item[%d] = %d\n", i, ind[i] ? -1 : item[i]); + + EXEC SQL DECLARE C CURSOR FOR SELECT Item1 FROM T; + + EXEC SQL OPEN C; + + EXEC SQL FETCH 1 IN C INTO :i; + printf("i = %d\n", i); + + EXEC SQL CLOSE C; + + EXEC SQL PREPARE stmt1 FROM :sqlstr; + + EXEC SQL DECLARE cur1 CURSOR FOR stmt1; + + EXEC SQL OPEN cur1; + + EXEC SQL WHENEVER NOT FOUND DO BREAK; + + i = 0; + while (i < 100) + { + EXEC SQL FETCH cur1 INTO :item1:ind1; + printf("item[%d] = %d\n", i, ind1 ? -1 : item1); + i++; + } + + EXEC SQL CLOSE cur1; + + EXEC SQL DROP TABLE T; + + EXEC SQL DISCONNECT ALL; +} + +int main() { + test(); + test(); /* retry */ + + return 0; +} |