如果用sqlite3_get_table()取出一个结果集,那么有时候很想打印出来看一下,随手写了一个,记录起来以备不时之需。
int print_data(char **rs,int *row,int *col) { int i = 0; int irow = *row; int icol = *col; char **irs = rs; int itotal = (irow+1) * icol; YY_LOG(YY_NOTICE,"row[%d],col[%d],total[%d]\n",irow,icol,itotal); for (i = 0; i < itotal; i++) { // printf("[%s]",irs[i]); if(0 == (i+1)%icol) { printf("\n"); } //gives every row of record a ENTER symbol } return 0; } static char *g_sql = NULL; //存储sql语句 static int g_return = 0; //保存sqlite3_xxx的返回值 sqlite3 *db_handle = NULL; //数据库联接 static char *err_msg = NULL; //错误原因 static char **g_rs = NULL; //结果集 static int g_row = 0; //取出行数 static int g_col = 0; //取出列数 int main () { g_sql = sqlite3_mprintf("SELECT * FROM table_1"); g_return = sqlite3_get_table(db_handle,g_sql,&g_rs,&g_row,&g_col,&err_msg); print_data(g_rs,&g_col); //调用实例 sqlite3_free_table(g_rs); sqlite3_free(g_sql); return 0; }