sqlite3cc开发接口简介

上传人:xiao****1972 文档编号:84902196 上传时间:2019-03-05 格式:DOC 页数:8 大小:63KB
返回 下载 相关 举报
sqlite3cc开发接口简介_第1页
第1页 / 共8页
sqlite3cc开发接口简介_第2页
第2页 / 共8页
sqlite3cc开发接口简介_第3页
第3页 / 共8页
sqlite3cc开发接口简介_第4页
第4页 / 共8页
sqlite3cc开发接口简介_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《sqlite3cc开发接口简介》由会员分享,可在线阅读,更多相关《sqlite3cc开发接口简介(8页珍藏版)》请在金锄头文库上搜索。

1、1.0 总览SQLite3是SQLite一个全新的版本,它虽然是在SQLite 2.8.13的代码基础之上开发的,但是使用了和之前的版本不兼容的数据库格式和API. SQLite3是为了满足以下的需求而开发的: 支持UTF-16编码. 用户自定义的文本排序方法. 可以对BLOBs字段建立索引.因此为了支持这些特性我改变了数据库的格式,建立了一个与之前版本不兼容的3.0版. 至于其他的兼容性的改变,例如全新的API等等,都将在理论介绍之后向你说明,这样可以使你最快的一次性摆脱兼容性问题. 3.0版的和2.X版的API非常相似,但是有一些重要的改变需要注意. 所有API接口函数和数据结构的前缀都由

2、sqlite_改为了sqlite3_. 这是为了避免同时使用SQLite 2.X和SQLite 3.0这两个版本的时候发生链接冲突. 由于对于C语言应该用什么数据类型来存放UTF-16编码的字符串并没有一致的规范. 因此SQLite使用了普通的void* 类型来指向UTF-16编码的字符串. 客户端使用过程中可以把void*映射成适合他们的系统的任何数据类型. 2.0 C/C+ 接口SQLite 3.0一共有83个API函数,此外还有一些数据结构和预定义(#defines). (完整的API介绍请参看另一份文档.) 不过你们可以放心,这些接口使用起来不会像它的数量所暗示的那么复杂. 最简单的程

3、序仍然使用三个函数就可以完成: sqlite3_open(), sqlite3_exec(), 和 sqlite3_close(). 要是想更好的控制数据库引擎的执行,可以使用提供的sqlite3_prepare()函数把SQL语句编译成字节码,然后在使用sqlite3_step()函数来执行编译后的字节码. 以sqlite3_column_开头的一组API函数用来获取查询结果集中的信息. 许多接口函数都是成对出现的,同时有UTF-8和UTF-16两个版本. 并且提供了一组函数用来执行用户自定义的SQL函数和文本排序函数. 2.1 如何打开关闭数据库 typedef struct sqlite

4、3 sqlite3; int sqlite3_open(const char*, sqlite3*); int sqlite3_open16(const void*, sqlite3*); int sqlite3_close(sqlite3*); const char *sqlite3_errmsg(sqlite3*); const void *sqlite3_errmsg16(sqlite3*); int sqlite3_errcode(sqlite3*);sqlite3_open() 函数返回一个整数错误代码,而不是像第二版中一样返回一个指向sqlite3结构体的指针. sqlite3_o

5、pen() 和 sqlite3_open16() 的不同之处在于sqlite3_open16() 使用UTF-16编码(使用本地主机字节顺序)传递数据库文件名. 如果要创建新数据库, sqlite3_open16() 将内部文本转换为UTF-16编码, 反之sqlite3_open() 将文本转换为UTF-8编码. 打开或者创建数据库的命令会被缓存,直到这个数据库真正被调用的时候才会被执行. 而且允许使用PRAGMA声明来设置如本地文本编码或默认内存页面大小等选项和参数. sqlite3_errcode() 通常用来获取最近调用的API接口返回的错误代码. sqlite3_errmsg() 则

6、用来得到这些错误代码所对应的文字说明. 这些错误信息将以 UTF-8 的编码返回,并且在下一次调用任何SQLite API函数的时候被清除. sqlite3_errmsg16() 和 sqlite3_errmsg() 大体上相同,除了返回的错误信息将以 UTF-16 本机字节顺序编码. 需要注意的是不管sqlite3_open()执行成功与否都要执行sqlite3_close().SQLite3的错误代码相比SQLite2没有任何的改变,它们分别是: #define SQLITE_OK 0 /* Successful result */#define SQLITE_ERROR 1 /* SQL

7、 error or missing database */#define SQLITE_INTERNAL 2 /* An internal logic error in SQLite */#define SQLITE_PERM 3 /* Access permission denied */#define SQLITE_ABORT 4 /* Callback routine requested an abort */#define SQLITE_BUSY 5 /* The database file is locked */#define SQLITE_LOCKED 6 /* A table

8、in the database is locked */#define SQLITE_NOMEM 7 /* A malloc() failed */#define SQLITE_READONLY 8 /* Attempt to write a readonly database */#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite_interrupt() */#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */#define SQLITE_CO

9、RRUPT 11 /* The database disk image is malformed */#define SQLITE_NOTFOUND 12 /* (Internal Only) Table or record not found */#define SQLITE_FULL 13 /* Insertion failed because database is full */#define SQLITE_CANTOPEN 14 /* Unable to open the database file */#define SQLITE_PROTOCOL 15 /* Database l

10、ock protocol error */#define SQLITE_EMPTY 16 /* (Internal Only) Database table is empty */#define SQLITE_SCHEMA 17 /* The database schema changed */#define SQLITE_TOOBIG 18 /* Too much data for one row of a table */#define SQLITE_CONSTRAINT 19 /* Abort due to contraint violation */#define SQLITE_MIS

11、MATCH 20 /* Data type mismatch */#define SQLITE_MISUSE 21 /* Library used incorrectly */#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */#define SQLITE_AUTH 23 /* Authorization denied */#define SQLITE_ROW 100 /* sqlite_step() has another row ready */#define SQLITE_DONE 101 /* sqli

12、te_step() has finished executing */2.2 执行 SQL 语句typedef int (*sqlite_callback)(void*,int,char*, char*); int sqlite3_exec(sqlite3*, const char *sql, sqlite_callback, void*, char*);sqlite3_exec 函数依然像它在SQLite2中一样承担着很多的工作. 该函数的第二个参数中可以编译和执行零个或多个SQL语句. 查询的结果返回给回调函数. 更多地信息可以查看API 参考.使用sqlite3_prepare() sq

13、lite_step()查询的语法为:Create the object using sqlite3_prepare_v2() or a related function. Bind values to host parameters using the sqlite3_bind_*() interfaces. Run the SQL by calling sqlite3_step() one or more times. Reset the statement using sqlite3_reset() then go back to step 2. Do this zero or more

14、times. Destroy the object using sqlite3_finalize(). 在SQLite3里,sqlite3_exec一般是被准备SQL语句接口封装起来使用的. typedef struct sqlite3_stmt sqlite3_stmt; int sqlite3_prepare(sqlite3*, const char*, int, sqlite3_stmt*, const char*); int sqlite3_prepare16(sqlite3*, const void*, int, sqlite3_stmt*, const void*); int sq

15、lite3_finalize(sqlite3_stmt*); int sqlite3_reset(sqlite3_stmt*);sqlite3_prepare 接口把一条SQL语句编译成字节码留给后面的执行函数. 使用该接口访问数据库是当前比较好的的一种方法.int sqlite3_prepare(sqlite3*, const char*, int, sqlite3_stmt*, const char*);sqilte3* 使用sqlite3_open() 打开的类型为sqlite3的指向数据库的指针;const char* is the statement to be compiled, encoded as either UTF-8 or UTF-16.Int If the nByte argument is less than zero, then zS

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号