人大金仓KCI
2024-10-20 03:25:41
#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
最新文章
- Centos6.5下编译安装mysql 5.6
- HDMI学习
- hadoop的概念
- 我的常用mixin 之 px
- 从零开始Grunt
- js实现svg图形转存为图片下载
- js setTimeout 与 setInterval 以及 for 循环 刷新UI
- 基于PCA的人脸识别步骤
- 一步一步重写 CodeIgniter 框架 (12) —— 代码再重构,回归 CI
- SSH2三大框架整合出错(四)
- POJ 3292 Semi-prime H-numbers (素数筛法变形)
- Web前端浏览器兼容问题
- 模拟jquery底层链式编程
- TitleLayout——一个Android轻松实现标题栏的库
- react-native从开始趟的坑
- linux下各种解压方法
- 码农代理免费代理ip端口字段js加密破解
- vscode打开django项目pylint提示has not ";object"; member
- 机器学习基础一(TP,TN,FP,FN等)
- Select查询命令
热门文章
- git fatal: remote origin already exists错误解决方案
- pagehelper超过页数仍然可以查出数据
- 公共组件及脚手架webpack模板
- [LeetCode] 23. Merge k Sorted Lists 合并k个有序链表
- makfile通用版本
- 阅读java编程思想的总结(一)
- Beta冲刺(7/7)——2019.5.29
- ES6高级技巧(五)
- idea类存在找不到解决办法
- 安装Office 2016 出现 Office 16 Click-to-Run Extensibility Component