#include <stdio.h>#include<sqlca.h>#include<sqlda.h>#include<sqltypes.h>#include<sqlstype.h>#defineSUCCESS 0Main () {EXEC SQL INCLUDE SQLCA; EXEC SQL BEGIN DECLARE section; Char*string1; Charstr1[Ten]; Charstr2[Ten]; Charstr3[Ten]; EXEC SQL END DECLARE section; EXEC SQL CREATE DATABASE example3; EXEC SQL DATABASE Example3; if(SQLCODE = =SUCCESS) {EXEC SQL CREATE TABLE Student (AlarmChar(6), snameChar(Ten), SexChar(Ten) ); } EXEC SQL INSERT into Student VALUES ("AAAA","bbbb","1"); EXEC SQL INSERT into Student VALUES ("dddd","dddd","2"); EXEC SQL INSERT into Student VALUES ("CCCC","CCCC","3"); EXEC SQL DECLARE fet_cur CURSOR for SELECT Alarm, sname,sex from Student; EXEC SQL OPEN fet_cur; printf ("sqlcode=%d\n", SQLCODE); for(;;) {memset (str1,0,sizeof(STR1)); memset (STR2,0,sizeof(STR2)); memset (STR3,0,sizeof(STR3)); EXEC SQL FETCH fet_cur into:str1,:str2,:str3; if(SQLCODE! =SUCCESS) {printf ("line=%d, sqlcode=%d", __line__, SQLCODE); Break; } printf ("str1=%s, str2=%s,str2=%s\n", STR1,STR2,STR3); } EXEC SQL CLOSE fet_cur; EXEC SQL CLOSE DATABASE; return(0); }
Informix ESQL/C uses a example of cursors