文件名称:全面解析_SQLite.pdf
文件大小:2.3MB
文件格式:PDF
更新时间:2019-07-31 04:54:00
全面解析 SQLite 中文开发手册
目录 使用SQLite编程的快速介绍............................................................. 5 下载代码 .......................................................................... 5 创建一个新数据库 .................................................................. 5 使用 SQLite 编写程序 .............................................................. 5 SQLite适用的范围 ..................................................................... 7 SQLite最佳试用场合................................................................ 7 哪些场合适合使用其他的关系型数据库管理系统(RDBMS) ............................... 9 SQLite 第三版总览(简介).............................................................. 10 命名上的变化 ..................................................................... 10 新的文件格式 ..................................................................... 10 弱类型和BLOB技术支持 ............................................................ 11 支持UTF-8和UTF-16............................................................... 11 用户定义的分类排序 ............................................................... 12 64字节的行编号................................................................... 12 改良的并发性 ..................................................................... 13 致谢 ............................................................................. 13 SQLite 第三版中的数据类型............................................................ 14 1.存储类别 ....................................................................... 14 2.列之间的亲和性 ................................................................. 14 3.比较表达式 ..................................................................... 16 4.运算符 ......................................................................... 17 5.分类,排序混合挑选 ........................................................... 17 6.其它亲和性模式 ................................................................. 17 7.用户定义的校对顺序 ............................................................. 18 SQLite 不支持的 SQL 特性............................................................. 20 SQLite的体系结构简介 ................................................................ 21 简介 ............................................................................. 21 接口程序 ......................................................................... 21 Tokenizer ........................................................................ 21 Parser ........................................................................... 22 代码发生器 ....................................................................... 22 虚拟机器 ......................................................................... 22 B-树 ............................................................................. 23 页面高速缓存 ..................................................................... 23 OS 接口程序 ...................................................................... 23 Utilities ........................................................................ 23 测试代码 ......................................................................... 23 SQLite与其他数据库的速度比较 ........................................................ 24 执行程序总结 ..................................................................... 24 测试环境 ......................................................................... 24 测试1:1000 INSERTs............................................................... 25 测试2:在事务处理程序中的 25000 INSERTs........................................... 25 测试3:在编入索引表格中的25000 INSERTs ........................................... 26 测试4:没有索引的 100 SELECTs..................................................... 26 测试5:在一个字符串比较上的100 SELECTs ........................................... 27 2 / 123 测试6:创建索引................................................................... 27 测试7:没有索引的5000 SELECTs .................................................... 27 测试8:没有索引的1000 UPDATEs .................................................... 28 测试9:有索引的25000 UPDATEs ..................................................... 28 测试10:有索引的25000 text UPDATEs ............................................... 28 测试11:来源于SELECT的INSERTs ................................................... 29 测试12:没有索引的DELETE ......................................................... 29 测试13:有索引的DELETE ........................................................... 29 测试14:一个大 DELETE之后的一个大INSERT.......................................... 30 测试15:一个大的DELETE及许多小INSERTs ........................................... 30 测试16:DROP TABLE................................................................ 30 SQLite中的空处理与其它数据库引擎比较 .............................................. 31 SQLite 数据库的速度比较(wiki)........................................................ 34 Test 1: 1000 INSERTs ............................................................. 36 Test 2: 25000 INSERTs in a transaction ........................................... 36 Test 3: 25000 INSERTs into an indexed table ...................................... 37 Test 4: 100 SELECTs without an index ............................................. 37 Test 5: 100 SELECTs on a string comparison ....................................... 38 Test 6: INNER JOIN without an index .............................................. 38 Test 7: Creating an index ........................................................ 38 Test 8: 5000 SELECTs with an index ............................................... 39 Test 9: 1000 UPDATEs without an index ............................................ 39 Test 10: 25000 UPDATEs with an index ............................................. 39 Test 11: 25000 text UPDATEs with an index ........................................ 40 Test 12: INSERTs from a SELECT ................................................... 40 Test 13: INNER JOIN with index on one side ....................................... 41 Test 14: INNER JOIN on text field with index one side ......................... 41 Test 15: 100 SELECTs with subqueries. Subquery is using an index ................. 41 Test 16: DELETE without an index ................................................. 42 Test 17: DELETE with an index .................................................... 42 Test 18: A big INSERT after a DELETE ......................................... 42 Test 19: A big DELETE followed by many small INSERTs ............................. 42 Test 20: DROP TABLE .............................................................. 43 附加文件...................................................................... 43 SQLite在Windows中的性能调试 ........................................................ 44 直接使用SQLite................................................................... 44 2:Indexes 和数据库结构是非常重要的。 ............................................ 44 3:页面规模也很重要 .............................................................. 45 4:成群的索引 .................................................................... 45 5:作为读这篇文章的收获,这里有个不智能的事情需要提醒你。 ........................ 46 SQLite中如何用触发器执行取消和重做逻辑 .............................................. 47 SQLite3 C/C++ 开发接口简介(API函数) ............................................... 55 1.0 总览 ......................................................................... 55 2.0 C/C++ 接口 ................................................................... 55 如何在VS 2003下编译SQLite .......................................................... 61 下载 ............................................................................. 61 创建一个 DLL 工程 ................................................................ 61 3 / 123 把 SQLite 的源文件添加到工程当中去 ............................................... 61 Make a .DEF file ................................................................. 61 如何编译 SQLITE.EXE 命令行程序 ................................................... 62 SQLite常见问题解答 .................................................................. 64 Frequently Asked Questions ....................................................... 64 (1)如何建立自动增长字段? ......................................................... 64 (2)SQLite支持何种数据类型?...................................................... 65 (3)SQLite允许向一个integer型字段中插入字符串!.................................. 65 (4)为什么SQLite不允许在同一个表不同的两行上使用0和0.0作主键? ................. 65 (5)多个应用程序或一个应用程序的多个实例可以同时访问同一个数据库文件吗? .......... 65 (6)SQLite线程安全吗?............................................................ 66 (7)在SQLite数据库中如何列出所有的表和索引? ..................................... 66 (8)SQLite数据库有已知的大小限制吗?.............................................. 67 (9)在SQLite中,VARCHAR字段最长是多少?.......................................... 67 (10)SQLite支持二进制大对象吗?................................................... 67 (11)在SQLite中,如何在一个表上添加或删除一列? .................................. 68 (12)我在数据库中删除了很多数据,但数据库文件没有变小,是Bug吗? ................. 68 (13)我可以在商业产品中使用SQLite而不需支付许可费用吗? .......................... 68 (14)如何在字符串中使用单引号(')? ................................................ 68 (15)SQLITE_SCHEMA error是什么错误?为什么会出现该错误?.......................... 69 (16)为什么 ROUND(9.95,1) 返回 9.9 而不是 10.0? 9.95不应该圆整 (四舍五入)吗?... 70 SQLite的原子提交原理 ................................................................ 71 1.0 简介 ......................................................................... 71 2.0 硬件设定 ..................................................................... 71 3.0 单个文件提交 ................................................................. 73 3.1 实始状态.................................................................. 73 3.2 申请一个共享锁............................................................ 73 3.3 从数据库里面读取信息...................................................... 74 3.4 申请一个Reserved Lock .................................................... 74 3.5 生成一个回滚日志文件...................................................... 75 3.6 修改用户进程中的数据页.................................................... 76 3.7 刷新回滚日志文件到存储设备中.............................................. 76 3.8 获得一个独享锁............................................................ 77 3.9 将变更写入到数据库文件中.................................................. 78 3.10 刷新变更到存储........................................................... 78 3.11 删除回滚日志文件......................................................... 79 3.12 释放锁................................................................... 80 4.0 回滚 ......................................................................... 81 4.1出事了,!!! ......................................................... 81 4.2 Hot Rollback Journals..................................................... 81 4.3 取得数据库的一个独享锁.................................................... 82 4.4 回滚没有完成的变更........................................................ 83 4.5 删除hot日志文件.......................................................... 83 4.6 如果一切正常,没有什么未完成的写操作...................................... 84 5.0 多文件提交 ................................................................... 84 5.1 每个数据库文件单独拥有日志............................................ 85 5.2 主日志文件................................................................ 85 4 / 123 5.3 更新回滚日志文件头........................................................ 86 5.4 修改数据库文件............................................................ 86 5.5 删除主日志文件............................................................ 87 5.6 清除回滚日志.............................................................. 87 6.0原子操作的一些实现细节........................................................ 88 6.1 总是记录整个扇区.......................................................... 88 6.2 写日志文件时垃圾的处理.................................................... 88 6.3 提交前缓存溢出............................................................ 89 7.0 优化 ......................................................................... 89 7.1 在事务间保存缓.......................................................... 90 7.2 独享访问模式.............................................................. 90 7.3 不必将空闲页写进日志...................................................... 90 7.4 单页更新及扇区原子写...................................................... 91 7.5 Filesystems With Safe Append Semantics.................................... 91 8.0 原子提交行为测试 ............................................................. 91 9.0 会导致完蛋的事情 ............................................................. 92 9.1 缺乏文件锁实现............................................................ 92 9.2 不完整的磁盘刷新.......................................................... 92 9.3 文件部分地删除............................................................ 93 9.4 写入到文件中的垃圾........................................................ 93 9.5 删除掉或更名了“hot”日志文件............................................. 93 10.0 总结及未来的路 .............................................................. 93 SQLite的查询优化 .................................................................... 95 一、影响查询性能的因素: ......................................................... 95 二、几个查询优化的转换 ........................................................... 95 三、 几种查询语句的处理(复合查询) .............................................. 95 四、子查询扁平化 ................................................................. 96 五、连接查询 ..................................................................... 98 六、索引 ......................................................................... 99 SQLITE3 使用总结.................................................................... 102 前序: .......................................................................... 102 一、版本 ........................................................................ 102 二、基本编译 .................................................................... 102 三、SQLITE操作入门.............................................................. 103 (1)基本流程................................................................ 103 (2)SQL语句操作 ............................................................ 104 (2)操作二进制.............................................................. 108 (4)事务处理................................................................ 109 四、给数据库加密 ................................................................ 109 五、后记 ........................................................................ 122