Chinaunix首页 | 论坛 | 博客
  • 博客访问: 12399375
  • 博文数量: 1293
  • 博客积分: 13501
  • 博客等级: 上将
  • 技术积分: 17974
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-08 18:11
文章分类

全部博文(1293)

文章存档

2019年(1)

2018年(1)

2016年(118)

2015年(257)

2014年(128)

2013年(222)

2012年(229)

2011年(337)

分类:

2012-10-24 20:15:51


数据表设计


  1. create table tbl_emp(

  2. id integer primary key ,

  3. name varchar(40),

  4. age smallint,

  5. birthday datetime);


sqlite3是数据库连接对象,用来操作数据库

打开数据库对象函数


  1. int sqlite3_open(

  2. const char *filename, /*数据库文件名 */

  3. sqlite3 **ppDb /* 创建的数据库连接对象*/

  4. );


关闭数据库对象函数


  1. int sqlite3_close(sqlite3 */*打开的数据库连接对象*/);


返回数据库错误消息


  1. const char *sqlite3_errmsg(sqlite3*);


编译过程


  1. gcc v1.c

  2. -o v1

  3. -I/usr/local/sqlite3/include

  4. -L/usr/local/sqlite3/lib

  5. -lsqlite3

  6. gcc v1.c -o v1 -I/usr/local/sqlite/include -L/usr/local/sqlite/lib -lsqlite3

  7. export LD_LIBRARY_PATH=/usr/local/sqlite/lib:$LD_LIBRARY_PATH

  8. ./v1


执行sql语句函数


  1. int sqlite3_exec(

  2. sqlite3*, /* 打开的数据库连接对象*/

  3. const char *sql, /* 将要执行的sql语句*/

  4. int (*callback)(void*,int,char**,char**), /* 回调函数*/

  5. void *, /* 回调函数的第一个参数*/

  6. char **errmsg /* 错误的消息*/

  7. );



查询函数


  1. int sqlite3_get_table(

  2. sqlite3 *db, /*数据库连接对象*/

  3. const char *zSql, /*将要执行的sql语句*/

  4. char ***pazResult, /* 查询的结果集 */

  5. int *pnRow, /* 结果集的行数*/

  6. int *pnColumn, /*结果集的列数*/

  7. char **pzErrmsg /* 查询的错误消息*/ );

释放结果集函数


  1. void sqlite3_free_table(char **result);


使用回调函数查询

回调函数


  1. int (*callback)(

  2. void*,/*从sqlite3_exec传递来的参数*/

  3. int,/*结果集的列数*/

  4. char**, /*列的值*/

  5. char**/*列的名字*/

  6. )


预处理对象


  1. int sqlite3_prepare(

  2. sqlite3 *db, /* 数据库连接对象*/

  3. const char *zSql, /*将要执行的sql语句*/

  4. int nByte, /* sql语句的长度 -1*/

  5. sqlite3_stmt **ppStmt, /* sqlite3_stmt对象 */

  6. const char **pzTail /* 指向执行的sql语句 0*/

  7. );

其它函数


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

  2. int sqlite3_step(sqlite3_stmt*);

  3. const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);

  4. int sqlite3_finalize(sqlite3_stmt *pStmt);


预处理对象重复使用


  1. int sqlite3_reset(sqlite3_stmt*);

阅读(2127) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~