#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

最新文章

  1. Centos6.5下编译安装mysql 5.6
  2. HDMI学习
  3. hadoop的概念
  4. 我的常用mixin 之 px
  5. 从零开始Grunt
  6. js实现svg图形转存为图片下载
  7. js setTimeout 与 setInterval 以及 for 循环 刷新UI
  8. 基于PCA的人脸识别步骤
  9. 一步一步重写 CodeIgniter 框架 (12) —— 代码再重构,回归 CI
  10. SSH2三大框架整合出错(四)
  11. POJ 3292 Semi-prime H-numbers (素数筛法变形)
  12. Web前端浏览器兼容问题
  13. 模拟jquery底层链式编程
  14. TitleLayout——一个Android轻松实现标题栏的库
  15. react-native从开始趟的坑
  16. linux下各种解压方法
  17. 码农代理免费代理ip端口字段js加密破解
  18. vscode打开django项目pylint提示has not &quot;object&quot; member
  19. 机器学习基础一(TP,TN,FP,FN等)
  20. Select查询命令

热门文章

  1. git fatal: remote origin already exists错误解决方案
  2. pagehelper超过页数仍然可以查出数据
  3. 公共组件及脚手架webpack模板
  4. [LeetCode] 23. Merge k Sorted Lists 合并k个有序链表
  5. makfile通用版本
  6. 阅读java编程思想的总结(一)
  7. Beta冲刺(7/7)——2019.5.29
  8. ES6高级技巧(五)
  9. idea类存在找不到解决办法
  10. 安装Office 2016 出现 Office 16 Click-to-Run Extensibility Component