人大金仓KCI
2015-09-25 10:48
435 查看
#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("\n\n"); /* 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("\n"); } 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
相关文章推荐
- APP发布到应用市场(苹果APP STORE+安卓各大应用市场)
- Css的学习之旅-css的选择器(2)
- 基于h5 ajax实现手机定位(demo)
- 黑马程序员学习(十三) 正则表达式语法大全
- Eclipse常用快捷键
- linux中nginx下禁止某目录执行php程序
- 技术开发人员为什么会无奈苦逼?
- junit常用注解详细说明
- Access denied for user 'root'@'localhost' (using password:YES) 解决方案
- Eclipse中10个最有用的快捷键组合
- eclipse properties editor 安装
- uthash
- C++编译器对字面量的处理方式
- Vivado+FPGA学习之第一次上电
- PN学习理论
- 使用javatar解压tar包等
- EXT读取的数据超长处理
- StringBuffer与String的不同
- MD5加密
- 黑马程序员学习(十二) 正则表达式基本知识