sqlite数据库操作例程:
#include<stdio.h>
#include<sqlite3.h>
#include<string.h>
int main()
{
sqlite3 *db;
char *zErrMsg = 0;
char sql[128]; //存放sqlite执行命令
char buff[1024]; //存放读取到的数据结果
int rc;
int len = 0;
memset(buff,0,sizeof(buff));
rc = sqlite3_open("test.db",&db); //打开数据库
if(rc != SQLITE_OK)
{
printf("zErrMsg = %s\n",zErrMsg);
return -1;
}
memset(sql,'\0',128);
strcpy(sql,"create table student(id integer,name varchar(10),f float);");//创建表
sqlite3_exec(db,sql,0,0,&zErrMsg); //执行sqlite命令语句
memset(sql,'\0',128);
strcpy(sql,"insert into student values(1,'xiaoming',1.1);"); //插入数据
rc = sqlite3_exec(db,sql,0,0,&zErrMsg);
if(rc != SQLITE_OK)
{
printf("zErrMsg = %s\n",zErrMsg);
return -1;
}
memset(sql,'\0',128);
strcpy(sql,"insert into student values(2,'xiaohong'