码迷,mamicode.com
首页 > 数据库 > 详细

Informix ESQL/C使用游标的一个example

时间:2015-05-29 13:31:51      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:

#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); 
}

 

Informix ESQL/C使用游标的一个example

标签:

原文地址:http://www.cnblogs.com/theCambrian/p/4537971.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!