前端之家收集整理的这篇文章主要介绍了
sqlite3 callback,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
/*
* test.c
*
* Created on: 2012-6-28
* Author: xy
*/
#include <sqlite3.h>
#include <stdio.h>
static int callback(void *NotUsed,int argc,char **argv,char **azColName){
int i;
for(i=0; i<argc; i++)
printf("%s = %s\n",azColName[i],argv[i] ? argv[i] : "NULL");
printf("\n");
return 0;
}
int main(int argc,char *argv[]){
sqlite3 *db;
char *zErrMsg = 0;
int rc = sqlite3_open("test.db",&db);
if( rc ){
fprintf(stderr,"Can't open database: %s/n",sqlite3_errmsg(db));
sqlite3_close(db);
return -1;
}
rc = sqlite3_exec(db,"\
PRAGMA foreign_keys = ON;\
",&zErrMsg);
if( rc!=sqlITE_OK ){
fprintf(stderr,"1sql error: %s\n",zErrMsg);
sqlite3_free(zErrMsg);
}
/* rc = sqlite3_exec(db,"\
INSERT INTO Students(TeacherId) VALUES(5);\
","2sql error: %s\n",zErrMsg);
sqlite3_free(zErrMsg);
}*/
rc = sqlite3_exec(db,"\
select * from TEACHERs;\
",callback,zErrMsg);
sqlite3_free(zErrMsg);
}
sqlite3_close(db);
}
原文链接:https://www.f2er.com/sqlite/201952.html