Informix ESQL/C使用游标的一个example
#include <stdio.h> #include <sqlca.h> #include <sqlda.h> #include <sqltypes.h> #include <sqlstype.h> #define SUCCESS 0 main() { EXEC SQL INCLUDE SQLCA; EXEC SQL BEGIN DECLARE SECTION; char *string1; char str1[10]; char str2[10]; char str3[10]; EXEC SQL END DECLARE SECTION; EXEC SQL CREATE DATABASE example3; EXEC SQL DATABASE example3; if (SQLCODE == SUCCESS) { EXEC SQL CREATE TABLE Student ( alarm char(6) , sname char(10), sex char(10) ); } 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); }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。