非常教程

Sqlite参考手册

其他 | Miscellaneous

SQLite Changes From Version 3.5.9 To 3.6.0

SQLite版本3.6.0(2008-07-16)包含许多更改。正如SQLite项目的习惯一样,大部分更改都完全向后兼容。但是,版本3.6.0中的一些更改不兼容,可能需要修改应用程序代码和/或makefile。本文档简要介绍SQLite 3.6.0中的变化,特别注意不兼容的变化。

Key Points:

  • 数据库文件格式不变。
  • 所有不兼容性都在模糊的界面上,因此应该对大多数应用程序没有影响。

1.0 Incompatible Changes

不兼容的更改首先被覆盖,因为它们对维护人员和程序员来说是最重要的。

1.1 Overview Of Incompatible Changes

  1. 对sqlite3_vfs对象的更改
1. The signature of the xAccess method has been modified to return an [error code](rescode) and to store its output into an integer pointed to by a parameter, rather than returning the output directly. This change allows the xAccess() method to report failures. In association with this signature change, a new extended error code [SQLITE\_IOERR\_ACCESS](rescode#ioerr_access) has been added. 
2. The xGetTempname method has been removed from [sqlite3\_vfs](c3ref/vfs). In its place, the xOpen method is enhanced to open a temporary file of its own invention when the filename parameter is NULL.
3. Added the xGetLastError() method to [sqlite3\_vfs](c3ref/vfs) for returning filesystem-specific error messages and error codes back to SQLite.
  1. sqlite3_io_methods上xCheckReservedLock方法的签名已被修改,以便它返回一个错误代码并将其布尔结果存储到一个由参数指向的整数中。与此更改相关联,已添加新的扩展错误代码SQLITE_IOERR_CHECKRESERVEDLOCK。
  2. 当SQLite移植到新的操作系统(Unix,Windows和OS / 2以外的操作系统,其端口与核心一起提供)时,必须提供两个新函数sqlite3_os_init()和sqlite3_os_end(),作为端口。
  3. IN和NOT IN操作符在其右手表达式中处理NULL值的方式已被纳入SQL标准和其他SQL数据库引擎。
  4. 在某些情况下,SELECT语句的结果集的列名已被调整,与其他SQL数据库引擎更相似。
  5. 编译时选项的更改:
1. The SQLITE\_MUTEX\_APPDEF compile-time parameter is no longer recognized. As a replacement, alternative [mutex implementations](c3ref/mutex_alloc) may be created at runtime using [sqlite3\_config()](c3ref/config) with the [SQLITE\_CONFIG\_MUTEX](c3ref/c_config_covering_index_scan#sqliteconfigmutex) operator and the [sqlite3\_mutex\_methods](c3ref/mutex_methods) object.
2. Compile-time options OS\_UNIX, OS\_WIN, OS\_OS2, OS\_OTHER, and TEMP\_STORE have been renamed to include an "SQLITE\_" prefix in order to help avoid namespace collisions with application software. The new names of these options are respectively: SQLITE\_OS\_UNIX, SQLITE\_OS\_WIN, SQLITE\_OS\_OS2, SQLITE\_OS\_OTHER, and [SQLITE\_TEMP\_STORE](compile#temp_store).

1.2 Changes To The VFS Layer

SQLite 3.5.0版引入了一个新的操作系统接口层,提供了底层操作系统的抽象。这是一项重要的创新,已被证明有助于移植和维护SQLite。但是,开发人员在3.5.0版本中引入的原始“虚拟文件系统”设计中发现了一些小缺陷,因此SQLite 3.6.0包含一些小的不兼容更改来解决这些缺陷。

要点: 3.6.0版的SQLite操作系统接口中的不兼容变化仅影响使用虚拟文件系统接口或提供应用程序定义的互斥体实现的罕见应用程序,或者使用其他不明确的编译 -时间选项。SQLite版本3.6.0引入的更改对绝大多数使用Unix,Windows和OS / 2的内置接口并使用标准生成配置的SQLite应用程序没有影响。

1.3 Changes In The Way The IN Operator Handles NULLs

所有版本的SQLite直到并包括版本3.5.9都在IN和NOT IN运算符的右侧处理了NULL值。具体来说,SQLite以前忽略了IN和NOT IN右侧的NULL。

假设我们有一个表X1定义如下:

  CREATE TABLE x1(x INTEGER);
  INSERT INTO x1 VALUES(1);
  INSERT INTO x1 VALUES(2);
  INSERT INTO x1 VALUES(NULL);

鉴于上面X1的定义,以下表达式历史上在SQLite中计算为FALSE,但正确的答案实际上是NULL:

  3 IN (1,2,NULL)
  3 IN (SELECT * FROM x1)

同样,以下表达式在历史上的计算结果为TRUE,实际上NULL也是这里的正确答案:

  3 NOT IN (1,2,NULL)
  3 NOT IN (SELECT * FROM x1)

根据SQL:1999标准,SQLite的历史行为不正确,并且与MySQL和PostgreSQL的行为不一致。版本3.6.0改变了IN和NOT IN运算符的行为以符合标准,并提供与其他SQL数据库引擎相同的结果。

要点:对IN和NOT IN操作符处理NULL值的方式的改变在技术上是一种错误修复,而不是设计更改。但是,维护人员应该检查以确保应用程序在升级到版本3.6.0之前不依赖于旧的错误行为。

1.4 Changes To Column Naming Rules

连接子查询报告的列名已被稍微修改,以便更像其他数据库引擎一样工作。考虑以下查询:

  CREATE TABLE t1(a);
  CREATE TABLE t2(x);
  SELECT * FROM (SELECT t1.a FROM t1 JOIN t2 ORDER BY t2.x LIMIT 1) ORDER BY 1;

在版本3.5.9中,上面的查询将返回一个名为“t1.a”的列。在版本3.6.0中,列名称只是“a”。

除非列中包含AS子句,否则SQLite从未对SELECT语句的结果集中的列的名称做出任何承诺。所以对列名的这种改变在技术上不是不兼容。SQLite只是从一个未定义的行为改变到另一个。尽管如此,许多应用程序依赖于SQLite的未指定列命名行为,因此在不兼容的更改子标题下讨论此更改。

1.5 Changes To Compile-Time Options

SQLite的编译时选项由C预处理器宏控制。SQLite 3.6.0版更改了这些宏中某些宏的名称,以便所有特定于SQLite的C预处理器宏都以“SQLITE_”前缀开头。这样做是为了减少与其他软件模块发生名称冲突的风险。

要点:对编译时选项的更改有可能影响定制生成SQLite的项目中的makefile。这些更改应该对应用程序代码和大多数使用SQLite标准默认构建的项目不产生影响。

2.0 Fully Backwards-Compatible Enhancements

除了上面列出的不兼容更改之外,SQLite版本3.6.0还添加了以下向后兼容的更改和增强功能:

  1. 新的sqlite3_config()接口允许应用程序在运行时自定义SQLite的行为。使用sqlite3_config()可能的定制包括以下内容:
1. Specify an alternative mutex implementation using the [SQLITE\_CONFIG\_MUTEX](c3ref/c_config_covering_index_scan#sqliteconfigmutex) verb with the [sqlite3\_mutex\_methods](c3ref/mutex_methods) object.
2. Specify an alternative malloc implementation using the [SQLITE\_CONFIG\_MALLOC](c3ref/c_config_covering_index_scan#sqliteconfigmalloc) verb with the [sqlite3\_mem\_methods](c3ref/mem_methods) object.
3. Partially or fully disable the use of mutexes using [SQLITE\_CONFIG\_SINGLETHREAD](c3ref/c_config_covering_index_scan#sqliteconfigsinglethread), [SQLITE\_CONFIG\_MULTITHREAD](c3ref/c_config_covering_index_scan#sqliteconfigmultithread) and [SQLITE\_CONFIG\_SERIALIZED](c3ref/c_config_covering_index_scan#sqliteconfigserialized).
  1. 一个新的标志SQLITE_OPEN_NOMUTEX可用于sqlite3_open_v2()接口。
  2. 新的sqlite3_status()接口允许应用程序在运行时查询SQLite的性能状态。
  3. sqlite3_memory_used()和sqlite3_memory_highwater()接口已弃用。现在可通过sqlite3_status()获得等效的功能。
  4. 可以调用sqlite3_initialize()接口来显式初始化SQLite子系统。在调用某些接口时会自动调用sqlite3_initialize()接口,因此不需要使用sqlite3_initialize(),但推荐使用它。
  5. sqlite3_shutdown()接口导致SQLite释放sqlite3_initialize()可能分配的任何系统资源(内存分配,互斥锁,打开文件句柄)。
  6. sqlite3_next_stmt()接口允许应用程序发现与数据库连接关联的所有准备好的语句。
  7. 添加page_count PRAGMA以返回页面中基础数据库文件的大小。
  8. 增加了一个新的R *树索引扩展。
 SQLite is in the Public Domain.

其他 | Miscellaneous相关

1.35% Faster Than The Filesystem
2.8+3 Filenames
3.An Asynchronous I/O Module For SQLite
4.Appropriate Uses For SQLite
5.Architecture of SQLite
6.Atomic Commit In SQLite
7.Automatic Undo/Redo With SQLite
8.Benefits of SQLite As A File Format
9.Change in Default Page Size in SQLite Version 3.12.0
10.Clustered Indexes and the WITHOUT ROWID Optimization
11.Compile-time Options
12.Constraint Conflict Resolution in SQLite
13.Custom Builds Of SQLite
14.Deterministic SQL Functions
15.Distinctive Features Of SQLite
16.EXPLAIN QUERY PLAN
17.Features Of SQLite
18.File Format Changes in SQLite
19.Full-Featured SQL
20.High Reliability
21.Hints for Debugging SQLite
22.How SQLite Is Tested
23.How To Compile SQLite
24.How To Download Canonical SQLite Source Code
25.Imposter Tables
26.In-Memory Databases
27.Indexes On Expressions
28.Internal Versus External BLOBs
29.Isolation In SQLite
30.Long Term Support
31.Maintaining Private Branches Of SQLite
32.Many Small Queries Are Efficient In SQLite
33.Measuring and Reducing CPU Usage in SQLite
34.Memory-Mapped I/O
35.NULL Handling in SQLite
36.Partial Indexes
37.Pointer Passing Interfaces
38.Powersafe Overwrite
39.Release History Of SQLite
40.Result and Error Codes
41.Row Values
42.Rowid Tables
43.Run-Time Loadable Extensions
44.SQL Features That SQLite Does Not Implement
45.sqldiff.exe: Database Difference Utility
46.SQLite As An Application File Format
47.SQLite Autoincrement
48.SQLite Backup API
49.SQLite Changes From Version 3.4.2 To 3.5.0
50.SQLite Database Speed Comparison
51.SQLite File IO Specification
52.SQLite Frequently Asked Questions
53.SQLite In 5 Minutes Or Less
54.SQLite is a Self Contained System
55.SQLite Is Serverless
56.SQLite Is Transactional
57.SQLite Library Footprint
58.SQLite Shared-Cache Mode
59.SQLite Unlock-Notify API
60.SQLite Version 3 Overview
61.SQLite: Single File Database
62.Temporary Files Used By SQLite
63.TH3
64.The COMPLETION() Table-Valued Function
65.The CSV Virtual Table
66.The dbhash.exe Utility Program
67.The DBSTAT Virtual Table
68.The Error And Warning Log
69.The generate_series Table-Valued Function
70.The OS Backend (VFS) To SQLite
71.The Spellfix1 Virtual Table
72.The SQLite Amalgamation
73.The SQLite Bytecode Engine
74.The sqlite3_analyzer.exe Utility Program
75.The SQLITE_STMT Virtual Table
76.The UNION Virtual Table
77.The Virtual Database Engine of SQLite
78.Uniform Resource Identifiers
79.Using SQLite In Multi-Threaded Applications
80.Version Numbers in SQLite
81.What If OpenDocument Used SQLite?
82.Why Is SQLite Coded In C
83.Zero-Configuration
Sqlite

SQLite,是一款轻型的数据库,是遵守ACID的关系型数据库管理系统,它包含在一个相对小的C库中。它是D.RichardHipp建立的公有领域项目。它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它,它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了。它能够支持Windows/Linux/Unix等等主流的操作系统,同时能够跟很多程序语言相结合,比如 Tcl、C#、PHP、Java等,还有ODBC接口,同样比起Mysql、PostgreSQL这两款开源的世界著名数据库管理系统来

主页 https://sqlite.org/
源码 https://www.sqlite.org/src/
发布版本 3.21.0

Sqlite目录

1.C界面 | C Interface
2.C Interface: Session Module
3.CLI
4.数据库文件表 | Database File Format
5.数据类 | Datatypes
6.动态内存分配 | Dynamic Memory Allocation
7.外键约束 | Foreign Key Constraints
8.全文索引 | Full-Text Search
9.损坏方式 | How To Corrupt
10.JSON
11.语言 | Language
12.局限性 | Limits
13.锁定和并发 | Locking and Concurrency
14.其他 | Miscellaneous
15.PRAGMA Statements
16.查询计划程序 | Query Planner
17.R*Tree Module
18.RBU Extension
19.语法图 | Syntax Diagrams
20.Tcl Interface
21.虚拟表机制 | Virtual Table Mechanism
22.预写日志 | Write-Ahead Logging
23.SQL 教程
24.SQL 简介
25.SQL 语法
26.SQL DELETE 语句
27.SQL UPDATE 语句
28.SQL NOT NULL 约束
29.SQL 约束
30.SQL CREATE TABLE 语句
31.SQL CREATE DATABASE 语句
32.SQL INSERT INTO SELECT 语句
33.SQL SELECT INTO 语句
34.SQL CREATE VIEW、REPLACE VIEW、 DROP VIEW 语句
35.SQL AUTO INCREMENT 字段
36.SQL ALTER TABLE 语句
37.SQL 撤销索引、表以及数据库
38.SQL CREATE INDEX 语句
39.SQL DEFAULT 约束
40.SQL CHECK 约束
41.SQL FOREIGN KEY 约束
42.SQL PRIMARY KEY 约束
43.SQL UNIQUE 约束
44.SQL 通用数据类型
45.SQL ISNULL()、NVL()、IFNULL() 和 COALESCE() 函数
46.SQL NULL 值 – IS NULL 和 IS NOT NULL
47.SQL Server 和 MySQL 中的 Date 函数
48.SQL MS Access、MySQL 和 SQL Server 数据类型
49.SQL 函数
50.SQL 总结
51.SQL 主机
52.SQL 快速参考
53.SQL ROUND() 函数
54.SQL Server GETDATE() 函数
55.MySQL DATE_FORMAT() 函数
56.MySQL DATEDIFF() 函数
57.MySQL DATE_SUB() 函数
58.MySQL DATE_ADD() 函数
59.MySQL EXTRACT() 函数
60.MySQL DATE() 函数
61.MySQL CURTIME() 函数
62.MySQL CURDATE() 函数
63.MySQL NOW() 函数
64.SQL Server CONVERT() 函数
65.SQL Server DATEDIFF() 函数
66.SQL Server DATEADD() 函数
67.SQL Server DATEPART() 函数
68.SQLite 命令
69.SQLite 安装
70.SQLite 简介
71.SQLite 运算符
72.SQLite Select 语句
73.SQLite 删除表
74.SQLite 创建表
75.SQLite Insert 语句
76.SQLite 分离数据库
77.SQLite 附加数据库
78.SQLite 创建数据库
79.SQLite 数据类型
80.SQLite 语法
81.SQLite Order By
82.SQLite Limit 子句
83.SQLite Glob 子句
84.SQLite Like 子句
85.SQLite Delete 语句
86.SQLite Update 语句
87.SQLite AND/OR 运算符
88.SQLite Where 子句
89.SQLite 表达式
90.SQLite Distinct 关键字
91.SQLite Having 子句
92.SQLite Group By
93.SQLite Join
94.SQLite 约束
95.SQLite PRAGMA
96.SQLite 事务
97.SQLite 视图
98.SQLite Truncate Table
99.SQLite Alter 命令
100.SQLite Indexed By