#include "sqlite.h"
static sqlite3 *db = NULL;
static char *errmsg = NULL;
static char *name = NULL;
int main(int argc, char *argv[])
{
if (argc != 3 ) { //check argv
printf("filename name dis\n");
exit(1);
} else {
printf("wait...\n");
} //do next
int rc,id;
name = malloc(30);
id = atoi(argv[1]);
strcpy(name,argv[2]);
rc = sqlite3_open(DATAPATH, &db); //open datebase
if (rc) {
printf("cant open datebase\n");
}
else {
printf("open datebase success\n");
}
char query[500];//用作sprintf()函数输出的字符串
sprintf(query,"update book set name='%s' where id='d'",name,id); //在""之间的全输入到value中去了
rc = sqlite3_exec(db,query,0,0,&errmsg);
if (rc) {
printf("exec update faild\n");
} else {
printf("exec update success\n");
}
sqlite3_close(db);//close database
return 0;
}
|