int main( void )
{
sqlite3 *db=NULL;
char *zErrMsg = 0;
int rc;
//打开数据库连接
rc = sqlite3_open("zieckey.db", &db);
if( rc )
{
fprintf(stderr, "Can't open sqlite: %s/n", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
else printf("open sqlite success/n");
//查询
char* sql = "SELECT rowid,name FROM test ";
int nrow = 0;
int ncolumn = 0;
char ** azResult; //返回结果集
sqlite3_get_table(db , sql , &azResult , &nrow , &ncolumn , &zErrMsg );
printf("row:%d,column:%d/n",nrow,ncolumn);
int i;
int j;
//读取结果集并释放
for(i=0;i<=nrow;i++)
{
for(j=0;j<column; ++j) {
printf("value:%s ",azResult[i*ncolumn+j]);
}
printf("/n");
}
sqlite3_close(db); //关闭数据库
return 0;
}
参考:
https://www.yuque.com/docs/share/d03c4bbb-5e50-4523-ba18-0b0120de7ba0