summaryrefslogtreecommitdiffstats
path: root/src/interfaces/ecpg/test/sql/fetch.pgc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:15:05 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:15:05 +0000
commit46651ce6fe013220ed397add242004d764fc0153 (patch)
tree6e5299f990f88e60174a1d3ae6e48eedd2688b2b /src/interfaces/ecpg/test/sql/fetch.pgc
parentInitial commit. (diff)
downloadpostgresql-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/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;
+}