file: demo1.pgc demo2.pgc
编译:ecpg -c demo1.pgc
cc -o demo1 demo1.c -lecpg
EXEC SQL INCLUDE sqlca;
int main()
{
EXEC SQL CONNECT TO mydb AS connect1 USER project06;
if(sqlca.sqlcode!=0)
{
fprintf(stderr, "error %ld", sqlca.sqlcode);
return(1);
}
EXEC SQL BEGIN DECLARE SECTION;
struct str_r{
int id;
char name[31];
}var1;
EXEC SQL END DECLARE SECTION;
EXEC SQL DECLARE foo CURSOR FOR SELECT ID, NAME FROM Account;
if(sqlca.sqlcode!=0 && sqlca.sqlcode !=100)
{
fprintf(stderr, "select error %ld", sqlca.sqlcode);
EXEC SQL DISCONNECT connect1;
return(1);
}
EXEC SQL OPEN foo;
while(sqlca.sqlcode!=100)
{
EXEC SQL FETCH NEXT FROM foo INTO :var1;
if(sqlca.sqlcode!=0 && sqlca.sqlcode !=100)
{
fprintf(stderr, "fetch error %ld", sqlca.sqlcode);
EXEC SQL DISCONNECT connect1;
return(1);
}
fprintf(stdout, "\nID: %d name;%s", var1.id, var1.name);
}
EXEC SQL CLOSE foo;
EXEC SQL DISCONNECT connect1;
}
|
EXEC SQL INCLUDE sqlca;
int main()
{
EXEC SQL CONNECT TO mydb AS connect1 USER project06;
if(sqlca.sqlcode!=0)
{
fprintf(stderr, "error %ld", sqlca.sqlcode);
return(1);
}
EXEC SQL BEGIN DECLARE SECTION;
int id;
char name[31];
EXEC SQL END DECLARE SECTION;
EXEC SQL DECLARE foo CURSOR FOR SELECT ID, NAME FROM Account;
if(sqlca.sqlcode!=0 && sqlca.sqlcode !=100)
{
fprintf(stderr, "select error %ld", sqlca.sqlcode);
EXEC SQL DISCONNECT connect1;
return(1);
}
EXEC SQL OPEN foo;
while(sqlca.sqlcode!=100)
{
EXEC SQL FETCH NEXT FROM foo INTO :id, :name;
if(sqlca.sqlcode!=0 && sqlca.sqlcode !=100)
{
fprintf(stderr, "fetch error %ld", sqlca.sqlcode);
EXEC SQL DISCONNECT connect1;
return(1);
}
fprintf(stdout, "\nID: %d name;%s", id, name);
}
EXEC SQL CLOSE foo;
EXEC SQL DISCONNECT connect1;
}
|
阅读(1415) | 评论(0) | 转发(0) |