Informix ESQL/C使用游标的一个example
时间:2021-07-01 10:21:17
帮助过:4人阅读
<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);
}
Informix ESQL/C使用游标的一个example
标签: