#include <stdio.h>
#include <sqlite3.h> // 头文件 记得链接 动态库 sqlite3
#define DATABASE_PATH "/home/ubuntu/NFS/Formal/T1-NEW/3521d_config.db"
int main(int argc, char *argv[])
{
sqlite3 *db=NULL;
char *zErrMsg = NULL;
int rc;
int rate;
//打开指定的数据库文件,如果不存在将创建一个同名的数据库文件
rc = sqlite3_open(DATABASE_PATH, &db);
if(rc)
{
printf("Can't open database: %s/n", sqlite3_errmsg(db));
sqlite3_close(db);
return 0;
}
int nRow = 0, nColumn = 0;
char **ppResult;
char sql[300];
sprintf(sql,"SELECT nSaveFile FROM SaveSD ");
sqlite3_get_table(db,sql,&ppResult,&nRow,&nColumn,&zErrMsg );
if(nRow > 0)
{
sscanf(ppResult[1],"%d",&rate);
}
sprintf(sql,"SELECT nSDPrecent FROM SaveSD ");
sqlite3_get_table(db,sql,&ppResult,&nRow,&nColumn,&zErrMsg );
if(nRow > 0)
{
sscanf(ppResult[1],"%d",&rate);
}
sprintf(sql,"SELECT nSDI1 nSDI2 nIPC1 nIPC2 nIPC3 nIPC4 FROM SaveSD ");
sqlite3_get_table(db,sql,&ppResult,&nRow,&nColumn,&zErrMsg );
if(nRow > 0)
{
sscanf(ppResult[1],"%d",&rate);
sscanf(ppResult[2],"%d",&rate);
sscanf(ppResult[3],"%d",&rate);
sscanf(ppResult[4],"%d",&rate);
sscanf(ppResult[5],"%d",&rate);
sscanf(ppResult[6],"%d",&rate);
sscanf(ppResult[7],"%d",&rate);
}
//释放掉 azResult 的内存空间
sqlite3_free_table(ppResult);
sqlite3_close(db);
printf("Hello World!\n");
return 0;
}
sqlite3使用
最新推荐文章于 2024-08-06 09:47:19 发布