zoukankan      html  css  js  c++  java
  • 人大金仓KCI

    #include "bin/libkci.h"
    
    static void exit_nicely(KCIConnection *conn)
    {
       KCIConnectionDestory(conn);
       exit(1);
    }
    
    int main()
    {
       KCIConnection *conn;
       KCIResult *res;
       int nFields;
       int i, j;
    
       conninfo = "host = localhost port = 54321 dbname = TEST user = SYSTEM password = SYSTEM";
       conn = KCIConnectionCreate(conninfo);
    //   conn = KCIConnectionCreateDeprecated("localhost", "54321", NULL, NULL , "TEST", "SYSTEM", "SYSTEM", "0");
    
       /* Check to see that the backend connection was successfully made */
       if(KCIConnectionGetStatus(conn) != CONNECTION_OK)
       {
          fprintf(stderr, "Connection to database failed: %s",
                  KCIConnectionGetLastError(conn));
          exit_nicely(conn);
       }
    
       /*
        * Our test case here involves using a cursor, for which we must be inside
        * a transaction block.  We could do the whole thing with a single
        * KCIStatementExecute() of "select * from sys_database", but that's too trivial to make
        * a good example.
        */
       /* Start a transaction block */
       res = KCIStatementExecute(conn, "BEGIN");
    
       if(KCIResultGetStatusCode(res) != EXECUTE_COMMAND_OK)
       {
          fprintf(stderr, "BEGIN command failed: %s", KCIConnectionGetLastError(conn));
          KCIResultDealloc(res);
          exit_nicely(conn);
       }
    
       /*
        * Should clear KCIResult whenever it is no longer needed to avoid memory
        * leaks
        */
       KCIResultDealloc(res);
       /*
        * Fetch rows from sys_database, the system catalog of databases
        */
       res = KCIStatementExecute(conn, "DECLARE myportal CURSOR FOR select * from sys_database");
    
       if(KCIResultGetStatusCode(res) != EXECUTE_COMMAND_OK)
       {
          fprintf(stderr, "DECLARE CURSOR failed: %s", KCIConnectionGetLastError(conn));
          KCIResultDealloc(res);
          exit_nicely(conn);
       }
    
       KCIResultDealloc(res);
       res = KCIStatementExecute(conn, "FETCH ALL in myportal");
    
       if(KCIResultGetStatusCode(res) != EXECUTE_TUPLES_OK)
       {
          fprintf(stderr, "FETCH ALL failed: %s", KCIConnectionGetLastError(conn));
          KCIResultDealloc(res);
          exit_nicely(conn);
       }
    
       /* first, print out the attribute names */
       nFields = KCIResultGetColumnCount(res);
    
       for(i = 0; i < nFields; i++)
       {
          printf("%-15s", KCIResultGetColumnName(res, i));
       }
    
       printf("
    
    ");
    
       /* next, print out the rows */
       for(i = 0; i < KCIResultGetRowCount(res); i++)
       {
          for(j = 0; j < nFields; j++)
          {
             printf("%-15s", KCIResultGetColumnValue(res, i, j));
          }
    
          printf("
    ");
       }
    
       KCIResultDealloc(res);
       /* close the portal ... we don't bother to check for errors ... */
       res = KCIStatementExecute(conn, "CLOSE myportal");
       KCIResultDealloc(res);
       /* end the transaction */
       res = KCIStatementExecute(conn, "END");
       KCIResultDealloc(res);
       /* close the connection to the database and cleanup */
       KCIConnectionDestory(conn);
       return 0;
    }

    编译需要链接库libkci.so

  • 相关阅读:
    Javaweb中的监听器
    Maven
    Ajax
    jQuery
    Spring入门
    spring boot实战——微信点餐系统02:接口信息,分页工具,gson, 注解信息,表单验证,字段返回(时间处理,null处理)
    Nginx
    Spring Data JPA
    spring boot实战——微信点餐系统01:开始代码
    spring boot实战——微信点餐系统00:项目设计,环境搭建
  • 原文地址:https://www.cnblogs.com/zhangxuechao/p/11709896.html
Copyright © 2011-2022 走看看