db2 数据转json v0.04

本文介绍如何将DB2数据库中的数据高效地转换成JSON格式,涉及SQL查询技巧及处理NULL和Buffer值的方法。
摘要由CSDN通过智能技术生成
#ifndef DB2_CLI_H_
#define DB2_CLI_H_
#ifdef __cplusplus
extern "C"{
#endif
	struct sql_client_information_tag;
	typedef struct sql_client_information_tag* sql_client_handle;
	/**
	 *  函数:   create_sql_handle
	 *          生成一个sql查询客户端句柄
	 *  参数: 
	 *          const char * const db_name  数据库名称
	 *          const char * const u_name   数据库用户名
	 *          const char * const u_pass   数据库密码	 
	 *  返回值:
	 *          NULL 创建失败
	 *          其他 创建成功
	 *  版本号:1.0
	 */
	sql_client_handle create_sql_handle(const char*const db_name,const char*const u_name,const char*const u_pass);
	/**
	 *  函数:   sql_excute_no_result_p
	            执行一个没有返回值的sql语句,比如表创建,表插入,表删除等动作
	            该函数可以传入一个以json格式表示的参数对象
	 *  参数:
	 *          sql_client_handle h   sql查询客户端句柄
	 *          const char * const sql_statement sql语句,sql语句中的可变参数必须以空格结尾
	 *          const char * const p  sql语句变参数的参数取值列表,用json格式表示
	 *  返回值:
	 *          0   执行成功
	 *			非0 执行失败
	 *  版本号:1.0
	 *  作者:  张飞
	 */
	int sql_excute_no_result_p(sql_client_handle h,const char*const sql_statement,const char*const p);
	/**
	 *  函数:   sql_excute_no_result
	            执行一个没有返回值的sql语句,比如表创建,表插入,表删除等动作
	 *  参数: 
	 *          sql_client_handle h   sql查询客户端句柄
	 *          const char * const sql_statement sql语句 
	 *  返回值:
	 *          0   执行成功
	 *			非0 执行失败
	 *  版本号:1.0
	 */
	int sql_excute_no_result(sql_client_handle h, const char*const sql_statement);
	/**
	 *  函数:   sql_excute_with_result
	 *          执行一个有返回值的sql语句,比如select操作
	 *
	 *  参数:
	 *          sql_client_handle h  sql查询客户端句柄
	 *          const char*const sql_statment  sql查询语句,sql语句中的可变参数必须以空格结尾
	 *          const char * const p sql语句变参数的参数取值列表,用json格式表示
	 *          char * const result  sql查询结果缓存
	 *          int *len			 [in]sql查询结果缓存大小
	 *								 [out]查询结果的json字符流大小
	 *  返回值:
	 *         0  执行成功
	 *		   非0 执行失败
	 *  版本号:1.0
	 *
	 */
	int sql_excute_with_result_p(sql_client_handle h ,const char*const sql_statment,const char*const p,char*const result,int *len);
	/**
	 *  函数:   sql_excute_with_result
	 *          执行一个有返回值的sql语句,比如select操作
	 *          该函数可以传入一个以json格式表示的参数对象
	 *  参数: 
	 *          sql_client_handle h  sql查询客户端句柄
	 *          const char*const sql_statment  sql查询语句
	 *          char * const result  sql查询结果缓存
	 *          int *len			 [in]sql查询结果缓存大小
	 *								 [out]查询结果的json字符流大小
	 *  返回值:
	 *         0  执行成功
	 *		   非0 执行失败
	 *  版本号:1.0
	 *
	 */
	int sql_excute_with_result(sql_client_handle h ,const char*const sql_statment,char*const result,int *len);
	/**
	 *  函数:   destroy_sql_handle
	 *          关闭sql查询句柄
	 *  参数: 
	 *          sql_client_handle h sql查询句柄 
	 *  返回值:
	 *          无
	 *  版本号:1.0
	 *
	 */
	void destroy_sql_handle(sql_client_handle h);
#ifdef __cplusplus
};
#endif
#endif //DB2_CLI_H_
// db2_cli.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <sqlcli1.h>
#include <db2_cli.h>
#ifndef _countof
#define _countof(x) (sizeof(x)/sizeof(x[0]))
#endif
#define hints printf
#define errors printf
#define SQL_STATE_LEN 256
#define SQL_ERROR_MSG 256
#define SQL_DBNAME_LEN 256 
#define SQL_USER_NAME_LEN 64
#define SQL_USER_PASS_LEN 64
#define SQL_STATEMENT_LEN 1024


typedef struct  sql_client_information_tag
{
	SQLHENV env_handle;
	SQLHDBC dbc_handle;
}sql_client_information;

typedef int (*fetch_row)(sql_clie
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值