使用linux下的C操作SQLLITE
来源:互联网 发布:眼镜厂景品手办淘宝店 编辑:程序博客网 时间:2024/05/16 15:34
from: http://baike.so.com/doc/1529694.html
由于linux下侧重使用命令,没有win的操作容易上手,所以在测试C操作SQLITE时会比较容易出现错误,给大家做一个简单的程序进行测试,演示怎么应用。打开vi编辑器,输入如下代码:
/*c代码*/ #include <stdio.h> #include <sqlite3.h> int main( void ) { sqlite3 *db=NULL; char *zErrMsg = 0; int rc; //打开指定的数据库文件,如果不存在将创建一个同名的数据库文件 rc = sqlite3_open("zieckey.db", &db); if( rc ) { fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); exit(1); } else printf("You have opened a sqlite3 database named zieckey.db successfully!\nCongratulations! Have fun ! ^-^ \n"); sqlite3_close(db); //关闭数据库 return 0; }
退出,保存。(代码输入完成后,按下 Esc 键,然后输入: :wq ,回车就好拉)
好拉,现在编译:[root@localhost temp]# gcc opendbsqlite.c -o db.out
或者遇到这样的问题:
[root@localhost temp]# gcc opendbsqlite.c -o db.out
opendbsqlite.c:11:21: sqlite3.h: 没有那个文件或目录
opendbsqlite.c: In function `main':
opendbsqlite.c:19: `sqlite3' undeclared (first use in this function)
opendbsqlite.c:19: (Each undeclared identifier is reported only once
opendbsqlite.c:19: for each function it appears in.)
opendbsqlite.c:19: `db' undeclared (first use in this function)
这是由于没有找到头文件的原因。
也许会碰到类似这样的问题:
[root@localhost temp]# gcc opendbsqlite.c -o db.out
/tmp/ccTkItnN.o(.text+0x2b): In function `main':
: undefined reference to `sqlite3_open'
/tmp/ccTkItnN.o(.text+0x45): In function `main':
: undefined reference to `sqlite3_errmsg'
/tmp/ccTkItnN.o(.text+0x67): In function `main':
: undefined reference to `sqlite3_close'
/tmp/ccTkItnN.o(.text+0x8f): In function `main':
: undefined reference to `sqlite3_close'
collect2: ld returned 1 exit status
这是个没有找到库文件的问题。
[root@localhost temp]# gcc opendbsqlite.c -o db.out -lsqlite3 -L/usr/local/sqlite3/lib -I/usr/local/sqlite3/include
这样编译应该就可以了
如果还是有错误的话请搜索:(一)Sqlite数据库连接。有更详细的说明解释
- 使用linux下的C操作SQLLITE
- 使用.NET(c#)操作SQLLITE
- 使用.NET(c#)操作SQLLITE
- 使用.NET操作SQLLITE
- 使用fmdb进行SQLlite 操作
- Linux C Sqllite DataBase Options
- Android SQLLite 的基础操作
- sqllite (3) - c# .net 使用 dapper 操作 sqllite 数据库
- linux下使用libmysql++库操作mysql的C API
- linux下使用libmysql++库操作mysql的C API
- linux下使用c进行线程操作
- 数据库的简单使用Sqllite
- sqllite数据库中对时间的操作
- sqllite 使用
- SQLLITE 使用
- linux下的C延时操作
- Linux C 下对文件夹的操作
- Linux C 下的大文件操作
- spring scheduled
- 给android 2.3 提供鼠标支持
- mysql_fetch_assoc()和mysql_fetch_array()以及mysql_fetch_row()、mysql_fetch_object()的区别
- LCA/RMQ预处理
- 自旋锁spinlock使用总结
- 使用linux下的C操作SQLLITE
- 转载_barrier 和 preempt_disable() 学习
- php数组操作
- uva 10025The ? 1 ? 2 ? ... ? n = k problem
- 精确获取时间(QueryPerformanceCounter)
- 通知栏的实现
- HDU 3078 Network
- C++vector用法(转)
- Nightmare之BFS解题报告