欢迎来到天天文库
浏览记录
ID:37713911
大小:79.00 KB
页数:10页
时间:2019-05-29
《sqlite3数据库c编程》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、linuxc编程操作数据库(sqlite3应用)C/C++语言中调用sqlite的函数接口来实现对数据库的管理(创建数据库、创建表格、插入数据、查询、数据、删除数据等)。首先要编译好sqlite的库文件: libsqlite3.a libsqlite3.la libsqlite3.so libsqlite3.so.0 libsqlite3.so.0.8.6 pkgconfig可执行文件: sqlite3本次测试: sqlite3的库文件目录是:/usr/local/lib 可执行文件sqlite3的目录是:/usr/local/b
2、in 头文件sqlite3.h的目录是:/usr/local/include用ls命令查看如下:[root@localhostconfig]#ls/usr/local/liblibclamav.a libclamunrar_iface.a libclamunrar.so libsqlite3.solibclamav.la libclamunrar_iface.la libclamunrar.so.5 libsqlite3.so.0libclamav.so libclamun
3、rar_iface.so libclamunrar.so.5.0.3 libsqlite3.so.0.8.6libclamav.so.5 libclamunrar_iface.so.5 libmstring.so pkgconfiglibclamav.so.5.0.3 libclamunrar_iface.so.5.0.3 libsqlite3.alibclamunrar.a libclamunrar.la libsqlite3.la此目录下包含库文件: libsqlite3.a
4、libsqlite3.la libsqlite3.so libsqlite3.so.0 libsqlite3.so.0.8.6 pkgconfig开始sqlite编程: 1.下面是一个C程序的例子,显示怎么使用sqlite的C/C++接口.数据库的名字由第一个参数取得且第个参数或更多的参数是SQL执行语句. 这个函数调用sqlite3_open()打开数据库,并且调用sqlite3_close()关闭数据库连接。 程序一:opendbslite.c: viewplain1.#include 2.#include 5、tdlib.h> 3.#include 4.int main( void ) 5.{ 6. sqlite3 *db=NULL; 1. char *zErrMsg = 0; 2. int rc; 3. 4. //打开指定的数据库文件,如果不存在将创建一个同名的数据库文件 5. rc = sqlite3_open("zieckey.db", &db); 6. if( rc ) 7. { 8. fprintf(stderr, "Can't open database: %s/n", sqlite3_errmsg(db)6、); 9. sqlite3_close(db); 10. exit(1); 11. } 12. else printf("You have opened a sqlite3 database named zieckey.db successfully!/nCongratulations! Have fun ! ^-^ /n"); 13. 14. sqlite3_close(db); //关闭数据库 15. return 0; 16.} 编译(问题):[root@localhostliuxltest]#gcc-oopendbsqliteop7、endbsqlite.c /tmp/ccuquUQN.o:Infunction`main':opendbsqlite.c:(.text+0x2e):undefinedreferenceto`sqlite3_open'opendbsqlite.c:(.text+0x42):undefinedreferenceto`sqlite3_errmsg'opendbsqlite.c:(.text+0x67):undefinedreferenceto`sqlite3_close'opendbsqlite.c:(.text+0x8a):undefinedreferenceto`s8、qlite
5、tdlib.h> 3.#include 4.int main( void ) 5.{ 6. sqlite3 *db=NULL; 1. char *zErrMsg = 0; 2. int rc; 3. 4. //打开指定的数据库文件,如果不存在将创建一个同名的数据库文件 5. rc = sqlite3_open("zieckey.db", &db); 6. if( rc ) 7. { 8. fprintf(stderr, "Can't open database: %s/n", sqlite3_errmsg(db)
6、); 9. sqlite3_close(db); 10. exit(1); 11. } 12. else printf("You have opened a sqlite3 database named zieckey.db successfully!/nCongratulations! Have fun ! ^-^ /n"); 13. 14. sqlite3_close(db); //关闭数据库 15. return 0; 16.} 编译(问题):[root@localhostliuxltest]#gcc-oopendbsqliteop
7、endbsqlite.c /tmp/ccuquUQN.o:Infunction`main':opendbsqlite.c:(.text+0x2e):undefinedreferenceto`sqlite3_open'opendbsqlite.c:(.text+0x42):undefinedreferenceto`sqlite3_errmsg'opendbsqlite.c:(.text+0x67):undefinedreferenceto`sqlite3_close'opendbsqlite.c:(.text+0x8a):undefinedreferenceto`s
8、qlite
此文档下载收益归作者所有