前端之家收集整理的这篇文章主要介绍了
sqlite3查询例子,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#include <stdio.h>
#include <stdlib.h>
#include <sqlite3.h>
#define P3SCAN_DB "/usr/local/conf/as.db"
sqlite3 *p3scan_db = NULL;
int main()
{
int ret,i,n;
char *errmsg = NULL,**result = NULL;
int nrow = 0,ncol = 0;
if(sqlite3_open(P3SCAN_DB,&p3scan_db))
{
sqlite3_free(p3scan_db);
return -1;
}
ret = sqlite3_get_table(p3scan_db,"select blackserverip from blackServer;",&result,&nrow,&ncol,&errmsg);
sqlite3_free(errmsg);
if(ret == sqlITE_OK)
{
printf("nrow: %d,ncol: %d\n",nrow,ncol);
if(nrow && result)
{
for(i=1; i<=nrow; i++)
{
printf("%s\n",result[i*ncol]);
}
}
sqlite3_free_table(result);
}
}
编译:
[root@localhost ~]# gcc -o select_blackserverip select_blackserverip.c -lsqlite3
原文链接:https://www.f2er.com/sqlite/201261.html