sqlite回传函数相关
说了3种基本方法:callback,gettable和预处理stmt方法
下面给出测试代码和测试用数据库,代码如下
#include
#include
#include
#include "sqlite3.h"
//
//typedef int (*sqlite3_callback)(
// void* data, /* Data provided in the 4th argument of sqlite3_exec() */
// int ncols, /* The number of columns in row */
// char** values, /* An array of strings representing fields in the row */
// char** headers /* An array of strings representing column names */
//);
int callback(void* data, int ncols, char** values, char** headers)
{
int i;
int len =0;
int ll=0;
for(i=0; i < ncols; i++)
{
if(strlen(headers[i])>len)
len = strlen(headers[i]);
}
for(i=0; i < ncols; i++)
{
ll = len-strlen(headers[i]);
while(ll)
{
fprintf(stdout," ");
--ll;
}
fprintf(stdout, "%s: %sn", headers[i], values[i]);
}
fprintf(stdout, "n");
return 0;
}
int search_by_callback(const char* db_name, const char* sql_cmd)
{
int i = 0 ;
int j = 0 ;
int nrow = 0, ncolumn = 0;
char **azResult; //二维数组存放结果
sqlite3 *db=NULL;
char *zErrMsg = 0;
int rc;
int len=0;
if(access(db_name, 0) &#