a
#include<st@R_403_410@.h> #include<sqlite3.h> staticintcallback(void*NotUsed,intargc,char**argv,char**azColName){ inti; for(i=0;i<argc;i++){ printf("%s=%s\n",azColName[i],argv[i]?argv[i]:"NULL"); } printf("\n"); return0; } intmain(intargc,char**argv){ sqlite3*db; char*message=0; intrc; if(argc!=3){ fprintf(stderr,"Usage:%sDATABASEsql-STATEMENT\n",argv[0]); return1; } rc=sqlite3_open(argv[1],&db); if(rc){ fprintf(stderr,"Can'topendatabase:%s\n",sqlite3_errmsg(db)); sqlite3_close(db); return1; } rc=sqlite3_exec(db,argv[2],callback,&message); if(rc!=sqlITE_OK){ fprintf(stderr,"sqlerror:%s\n",message); sqlite3_free(message); } sqlite3_close(db); return0; }
运行命令:
./exampletest_db"createtabletest_table(intval);"
在目录下出现一个test_db文件 就是test_db这个数据库了 :)
参考文献:
[0] An Introduction To The sqlite C/C++ Interfacehttp://www.sqlite.org/cintro.html
[1]sqlite3 C语言API入门http://www.blogjava.net/xylz/archive/2012/09/25/388519.html
原文链接:https://www.f2er.com/sqlite/199749.html