1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
5EXEC SQL INCLUDE ../regression;
6
7int main() {
8  EXEC SQL BEGIN DECLARE SECTION;
9    char str[25];
10    int i, count=1, loopcount;
11  EXEC SQL END DECLARE SECTION;
12
13  ECPGdebug(1, stderr);
14  EXEC SQL CONNECT TO REGRESSDB1;
15
16  EXEC SQL WHENEVER SQLWARNING SQLPRINT;
17  EXEC SQL WHENEVER SQLERROR STOP;
18
19  EXEC SQL CREATE TABLE My_Table ( Item1 int, Item2 text );
20
21  EXEC SQL INSERT INTO My_Table VALUES ( 1, 'text1');
22  EXEC SQL INSERT INTO My_Table VALUES ( 2, 'text2');
23  EXEC SQL INSERT INTO My_Table VALUES ( 3, 'text3');
24  EXEC SQL INSERT INTO My_Table VALUES ( 4, 'text4');
25
26  EXEC SQL DECLARE C CURSOR FOR SELECT * FROM My_Table;
27
28  EXEC SQL OPEN C;
29
30  EXEC SQL WHENEVER NOT FOUND DO BREAK;
31  for (loopcount = 0; loopcount < 100; loopcount++) {
32	EXEC SQL FETCH 1 IN C INTO :i, :str;
33	printf("%d: %s\n", i, str);
34  }
35
36  EXEC SQL WHENEVER NOT FOUND CONTINUE;
37  EXEC SQL MOVE BACKWARD 2 IN C;
38
39  EXEC SQL FETCH :count IN C INTO :i, :str;
40  printf("%d: %s\n", i, str);
41
42  EXEC SQL CLOSE C;
43
44  EXEC SQL DECLARE D CURSOR FOR SELECT * FROM My_Table WHERE Item1 = $1;
45
46  EXEC SQL OPEN D using 1;
47
48  EXEC SQL FETCH 1 IN D INTO :i, :str;
49  printf("%d: %s\n", i, str);
50
51  EXEC SQL CLOSE D;
52
53  EXEC SQL DROP TABLE My_Table;
54
55  EXEC SQL DISCONNECT ALL;
56
57  return 0;
58}
59