From 293913568e6a7a86fd1479e1cff8e2ecb58d6568 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 15:44:03 +0200 Subject: Adding upstream version 16.2. Signed-off-by: Daniel Baumann --- src/interfaces/ecpg/test/sql/fetch.pgc | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/interfaces/ecpg/test/sql/fetch.pgc (limited to 'src/interfaces/ecpg/test/sql/fetch.pgc') 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 +#include +#include + +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; +} -- cgit v1.2.3