www.cnblogs.com/ruiyqinrui

开源、架构、Linux C/C++/python AI BI 运维开发自动化运维。 春风桃李花 秋雨梧桐叶。“力尽不知热 但惜夏日长”。夏不惜,秋不获。@ruiY--秦瑞

python爬虫,C编程,嵌入式开发.hadoop大数据,桉树,onenebula云计算架构.linux运维及驱动开发.

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

1,创建测试数据库,表;

2,数据库连接对象函数

sqlite3是数据库连接对象(database connection object),用来操作数据库(operator DBs);
打开数据库对象函数(open db object function),
int sqlite3_open(
const char *filename, //数据库文件名,指我们在CLI 输入[root@ruiy ~]#sqlite3 /ruiy
sqlite3 **ppDb //创建的数据库连接对象
);

int sqlite3_close(sqlite3) //前面打开的数据库连接对象;


通过interactieve 输入sqlite3 db file fullPath;

完整码子及测试结果

<3,API执行sql>

sqlite3 C API插入数据
执行sql语句函数
int sqlite3_exec(
sqlite3, //打开数据库的连接对象
const char *sql, //执行的sql语句
int (*callback)(void*,int char**,char**), //回调函数
void *, //回调函数的第一个参数
char **errmsg //错误消息
);

哈哈,我这有一张rui的表,

看源码

上面插入birthday 日期时间的地方一定要用单引号哦,亲!

不要gcc编译器就在胡乱报错了;

对比下我们在API语句中执行的sql语句,在数据库CLI下验证插入的数据

 

查询函数,
int sqlite3_get_table(
sqlite3 *db, //数据库连接对象
const char *zSql, //将要执行的sql语句
char ***pazResult, //查询的结果集
int *pnRow, //结果集行数
int *pnColumn, //结果集列数
char **pzErrmsg //查询的错误消息
);
释放结果集
void sqlite3_free_table(char **result);

码子

查询结果

回调函数查询
int (*callback) (
viod*,//从sqlite3_exec传递来的参数
int, //结果集的列数
char**, //列的值
char** //列的名字
);

预处理对象(prepare process object)
int sqlite3_prepare(
sqlite3 *db, //数据库连接对象
const char *zSql, //将要执行的sql语句
int nByte, //sql语句长度 -1
sqlite3_stmt **ppStmt, //sqlite3_stmt对象
const char **pzTail //指向执行的sql语句 0
);

int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int n,void(*)(void*));
int sqlite3_step(sqlite3_stmt*);

预处理对象插入

预处理对象查询

 

预处理对象重复使用
int sqlite3_reset(sqlite3_stmt*);

transaction dispose 事务处理()

 

posted on 2014-08-21 23:09  秦瑞It行程实录  阅读(434)  评论(0编辑  收藏  举报
www.cnblogs.com/ruiyqinrui