summaryrefslogtreecommitdiffstats
path: root/src/interfaces/ecpg/test/sql/fetch.pgc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 13:44:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 13:44:03 +0000
commit293913568e6a7a86fd1479e1cff8e2ecb58d6568 (patch)
treefc3b469a3ec5ab71b36ea97cc7aaddb838423a0c /src/interfaces/ecpg/test/sql/fetch.pgc
parentInitial commit. (diff)
downloadpostgresql-16-293913568e6a7a86fd1479e1cff8e2ecb58d6568.tar.xz
postgresql-16-293913568e6a7a86fd1479e1cff8e2ecb58d6568.zip
Adding upstream version 16.2.upstream/16.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/interfaces/ecpg/test/sql/fetch.pgc')
-rw-r--r--src/interfaces/ecpg/test/sql/fetch.pgc58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/interfaces/ecpg/test/sql/fetch.pgc b/src/interfaces/ecpg/test/sql/fetch.pgc
new file mode 100644
index 0000000..31e525e
--- /dev/null
+++ b/src/interfaces/ecpg/test/sql/fetch.pgc
@@ -0,0 +1,58 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+EXEC SQL INCLUDE ../regression;
+
+int main() {
+ EXEC SQL BEGIN DECLARE SECTION;
+ char str[25];
+ int i, count=1, loopcount;
+ EXEC SQL END DECLARE SECTION;
+
+ ECPGdebug(1, stderr);
+ EXEC SQL CONNECT TO REGRESSDB1;
+
+ EXEC SQL WHENEVER SQLWARNING SQLPRINT;
+ EXEC SQL WHENEVER SQLERROR STOP;
+
+ EXEC SQL CREATE TABLE My_Table ( Item1 int, Item2 text );
+
+ EXEC SQL INSERT INTO My_Table VALUES ( 1, 'text1');
+ EXEC SQL INSERT INTO My_Table VALUES ( 2, 'text2');
+ EXEC SQL INSERT INTO My_Table VALUES ( 3, 'text3');
+ EXEC SQL INSERT INTO My_Table VALUES ( 4, 'text4');
+
+ EXEC SQL DECLARE C CURSOR FOR SELECT * FROM My_Table;
+
+ EXEC SQL OPEN C;
+
+ EXEC SQL WHENEVER NOT FOUND DO BREAK;
+ for (loopcount = 0; loopcount < 100; loopcount++) {
+ EXEC SQL FETCH 1 IN C INTO :i, :str;
+ printf("%d: %s\n", i, str);
+ }
+
+ EXEC SQL WHENEVER NOT FOUND CONTINUE;
+ EXEC SQL MOVE BACKWARD 2 IN C;
+
+ EXEC SQL FETCH :count IN C INTO :i, :str;
+ printf("%d: %s\n", i, str);
+
+ EXEC SQL CLOSE C;
+
+ EXEC SQL DECLARE D CURSOR FOR SELECT * FROM My_Table WHERE Item1 = $1;
+
+ EXEC SQL OPEN D using 1;
+
+ EXEC SQL FETCH 1 IN D INTO :i, :str;
+ printf("%d: %s\n", i, str);
+
+ EXEC SQL CLOSE D;
+
+ EXEC SQL DROP TABLE My_Table;
+
+ EXEC SQL DISCONNECT ALL;
+
+ return 0;
+}