一、简介
虚拟表是一个呈现 SQL 表接口但不存储在数据库文件中的对象,至少不直接存储。虚拟表机制是 SQLite 的一个特性,允许 SQLite 使用强大的 SQL 查询语言访问和操作数据库文件中除位之外的资源。
下表列出了一些可用于 SQLite 的虚拟表实现。开发者可以在自己的应用中部署这些虚拟表,或者使用下面展示的实现作为模板编写自己的虚拟表。
下面的列表并不详尽。其他虚拟表实现存在于 SQLite 源代码树和其他地方。下面的列表试图捕捉更有趣的虚拟表实现。
2.虚拟表
Name | Description |
---|---|
approximate_match | A demonstration of how to use a virtual table to implement approximate string matching. |
bytecode | A table-valued function that shows the bytecodes of a prepared statement. |
carray | A table-valued function that allows a C-language array of integers, doubles, or strings to be used as table in a query. |
closure | Compute the transitive closure of a set. |
completion | Suggests completions for partially-entered words during interactive SQL input. Used by the CLI to help implement tab-completion. |
csv | A virtual table that represents a comma-separated-value or CSV file (RFC 4180) as a read-only table so that it can be used as part of a larger query. |
dbstat | Provides information about the purpose and use of each page in a database file. Used in the implementation of the sqlite3_analyzer utility program. |
files_of_checkin | Provides information about all files in a single check-in in the Fossil version control system. This virtual table is not part of the SQLite project but is included because it provides an example of how to use virtual tables and because it is used to help version control the SQLite sources. |
fsdir | A table-valued function returning one row for each file in a selected file hierarchy of the host computer. Used by the CLI to help implement the .archive command. |
FTS3 | A high-performance full-text search index. |
FTS5 | A higher-performance full-text search index |
generate_series | A table-valued function returning a sequence of increasing integers, modeled after the table-valued function by the same name in PostgreSQL. |
json_each | A table-valued function for decomposing a JSON string. |
json_tree | A table-valued function for decomposing a JSON string. |
OsQuery | Hundreds of virtual tables that publish various aspects of the host computer, such as the process table, user lists, active network connections, and so forth. OsQuery is a separate project, started by Facebook, hosted on GitHub, and intended for security analysis and intrusion detection OsQuery is not a part of the SQLite project, but is included in this list because it demonstrates how the SQL language and the SQLite virtual table mechanism can be leveraged to provide elegant solutions to important real-world problems. |
pragma | Built-in table-valued functions that return the results of PRAGMA statements for use within ordinary SQL queries. |
RTree | An implementation of the Guttmann R*Tree spatial index idea. |
spellfix1 | A virtual table that implements a spelling correction engine. |
sqlite_btreeinfo | This experimental table-valued function provides information about a single B-tree in a database file, such as the depth, and estimated number of pages and number of entries, and so forth. |
sqlite_dbpage | Key/value store for the raw database file content. The key is the page number and the value is binary page content. |
sqlite_memstat | Provides SQL access to the sqlite3_status64() and sqlite3_db_status() interfaces. |
sqlite_stmt | A table-valued function containing one row for each prepared statement associated with an open database connection. |
swarmvtab | An experimental module providing on-demand read-only access to multiple tables spread across multiple databases, via a single virtual table abstraction. |
tables_used | A table-valued function that shows the tables and indexes that are accessed by a prepared statement. |
tclvar | Represents the global variables of a TCL Interpreter as an SQL table. Used as part of the SQLite test suite. |
templatevtab | A template virtual table implementation useful as a starting point for developers who want to write their own virtual tables |
unionvtab | An experimental module providing on-demand read-only access to multiple tables spread across multiple databases, via a single virtual table abstraction. |
vfsstat | A table-valued function which, in combination with a co-packaged VFS shim provides information on the number of system calls performed by SQLite. |
vtablog | A virtual table that prints diagnostic information on stdout when its key methods are invoked. Intended for interactive analysis and debugging of virtual table interfaces. |
wholenumber | A virtual table returns all integers between 1 and 4294967295. |
zipfile | Represent a ZIP Archive as an SQL table. Works for both reading and writing. Used by the CLI to implement the ability to read and write ZIP Archives. |