非常教程

Sqlite参考手册

C界面 | C Interface

Create Or Redefine SQL Functions

int sqlite3_create_function(
  sqlite3 *db,
  const char *zFunctionName,
  int nArg,
  int eTextRep,
  void *pApp,
  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  void (*xFinal)(sqlite3_context*)
);
int sqlite3_create_function16(
  sqlite3 *db,
  const void *zFunctionName,
  int nArg,
  int eTextRep,
  void *pApp,
  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  void (*xFinal)(sqlite3_context*)
);
int sqlite3_create_function_v2(
  sqlite3 *db,
  const char *zFunctionName,
  int nArg,
  int eTextRep,
  void *pApp,
  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  void (*xFinal)(sqlite3_context*),
  void(*xDestroy)(void*)
);

这些函数(统称为“函数创建例程”)用于添加 SQL 函数或聚合或重新定义现有 SQL 函数或聚合的行为。这些例程之间的唯一区别是第二个参数(要创建的函数的名称)的文本编码以及应用程序数据指针的析构函数回调的存在或不存在。

第一个参数是要添加 SQL 函数的数据库连接。如果应用程序使用多个数据库连接,则必须将应用程序定义的 SQL 函数分别添加到每个数据库连接。

第二个参数是要创建或重新定义的 SQL 函数的名称。在 UTF-8 表示中,名称的长度限制为255个字节,不包括零终结符。请注意,名称长度限制为 UTF-8 字节,而不是字符或 UTF-16 字节。任何尝试创建名称较长的函数都会导致返回 SQLITE_MISUSE 。

第三个参数(nArg)是 SQL 函数或聚合参数的个数。如果此参数为-1,那么 SQL 函数或聚合可以采用介于0和由 sqlite3_limit( SQLITE_LIMIT_FUNCTION_ARG )设置的限制之间的任意数量的参数。如果第三个参数小于-1或大于127,则行为是未定义的。

第四个参数,eTextRep 指定了此 SQL 函数对其参数所喜欢的文本进行编码。如果函数实现在输入上调用 sqlite3_value_text16le() ,或者 SQLITE_UTF16BE(如果实现在输入上调用 sqlite3_value_text16be() ,或者 SQLITE_UTF16(如果使用 sqlite3_value_text16() ),则该应用程序应该将此参数设置为 SQLITE_UTF16LE ;否则为 SQLITE_UTF8 。同一个 SQL 函数可以使用不同的首选文本编码进行多次注册,每种编码都有不同的实现。当同一个函数的多个实现可用时,SQLite 将选择一个涉及最少数据转换的实现。

第四个参数可以选择性地与 SQLITE_DETERMINISTIC 进行或运算,以表示在单个 SQL 语句中给定相同输入的情况下,函数将始终返回相同的结果。大多数 SQL 函数都是确定性的。内置的 random() SQL 函数是一个非确定性函数的例子。SQLite 查询规划器能够对确定性函数执行额外的优化,因此建议尽可能使用 SQLITE_DETERMINISTIC 标志。

第五个参数是一个任意指针。该函数的实现可以使用 sqlite3_user_data() 访问此指针。

第六,第七和第八个参数, xFunc ,xStep 和 xFinal 是指向实现 SQL 函数或聚合的 C 语言函数的指针。标量 SQL 函数仅需要实现 xFunc 回调; NULL 指针必须作为 xStep 和 xFinal 参数传递。集合 SQL 函数需要 xStep 的实现,并且必须为 xFunc 传递 xFinal 和 NULL 指针。要删除现有的 SQL 函数或聚合,请为所有三个函数回调传递 NULL 指针。

如果 sqlite3_create_function_v2() 的第九个参数不是 NULL ,那么它是应用程序数据指针的析构函数。当函数被删除时,通过重载或数据库连接关闭时,调用析构函数。如果调用 sqlite3_create_function_v2() 失败,也会调用析构函数。调用第十个参数的析构函数回调时,会传递一个参数,该参数是应用程序数据指针的副本,它是 sqlite3_create_function_v2() 的第五个参数。

允许注册具有相同名称的相同函数的多个实现,但具有不同数量的参数或不同的优选文本编码。SQLite 将使用与 SQL 函数使用方式最为匹配的实现。具有非负 nArg 参数的函数实现比具有负 nArg 的函数实现更好匹配。首选文本编码与数据库编码相匹配的功能比编码不同的功能更好。编码差异在 UTF16le 和 UTF16be 之间的函数比编码差异在 UTF8 和 UTF16 之间的函数更接近匹配。

内置函数可能会被新的应用程序定义的函数重载。

允许应用程序定义的函数调用其他 SQLite 接口。但是,这些调用不能关闭数据库连接,也不能最终确定或重置运行该函数的预准备语句。

另请参见对象,常量和函数的列表。

 SQLite is in the Public Domain.

C界面 | C Interface相关

1.64-Bit Integer Types
2.A Handle To An Open BLOB
3.An Introduction To The SQLite C/C++ Interface
4.Application Defined Page Cache
5.Attempt To Free Heap Memory
6.Authorizer Action Codes
7.Authorizer Return Codes
8.Automatically Load Statically Linked Extensions
9.Binding Values To Prepared Statements
10.C/C++ Interface For SQLite Version 3
11.C/C++ Interface For SQLite Version 3 (old)
12.Cancel Automatic Extension Loading
13.Checkpoint a database
14.Checkpoint Mode Values
15.Close A BLOB Handle
16.Closing A Database Connection
17.Collation Needed Callbacks
18.Column Names In A Result Set
19.Commit And Rollback Notification Callbacks
20.Compare the ages of two snapshot handles
21.Compile-Time Authorization Callbacks
22.Compile-Time Library Version Numbers
23.Compiling An SQL Statement
24.Configuration Options
25.Configure an auto-checkpoint
26.Configure database connections
27.Configuring The SQLite Library
28.Conflict resolution modes
29.Constants Defining Special Destructor Behavior
30.Convenience Routines For Running Queries
31.Copy And Free SQL Values
32.Count The Number Of Rows Modified
33.Custom Page Cache Object
34.Data Change Notification Callbacks
35.Database Connection Configuration Options
36.Database Connection For Functions
37.Database Connection Handle
38.Database Connection Status
39.Database Snapshot
40.Declare The Schema Of A Virtual Table
41.Declared Datatype Of A Query Result
42.Define New Collating Sequences
43.Deprecated Functions
44.Deprecated Soft Heap Limit Interface
45.Destroy A Prepared Statement Object
46.Destroy a snapshot
47.Determine if a database is read-only
48.Determine If A Prepared Statement Has Been Reset
49.Determine If An SQL Statement Is Complete
50.Determine If An SQL Statement Writes The Database
51.Determine The Virtual Table Conflict Policy
52.Device Characteristics
53.Dynamically Typed Value Object
54.Enable Or Disable Extended Result Codes
55.Enable Or Disable Extension Loading
56.Enable Or Disable Shared Pager Cache
57.Error Codes And Messages
58.Error Logging Interface
59.Evaluate An SQL Statement
60.Experimental Interfaces
61.Extended Result Codes
62.Extract Metadata About A Column Of A Table
63.File Locking Levels
64.Find The Database Handle Of A Prepared Statement
65.Find the next prepared statement
66.Finding The Subtype Of SQL Values
67.Flags For File Open Operations
68.Flags for the xAccess VFS method
69.Flags for the xShmLock VFS method
70.Flush caches to disk mid-transaction
71.Formatted String Printing Functions
72.Free Memory Used By A Database Connection
73.Function Auxiliary Data
74.Function Flags
75.Fundamental Datatypes
76.Impose A Limit On Heap Size
77.Index Of A Parameter With A Given Name
78.Initialize The SQLite Library
79.Interrupt A Long-Running Query
80.Introduction
81.Last Insert Rowid
82.List Of SQLite Constants
83.List Of SQLite Functions
84.List Of SQLite Objects
85.Load An Extension
86.Loadable Extension Thunk
87.Low-Level Control Of Database Files
88.Low-level system error code
89.Maximum xShmLock index
90.Memory Allocation Routines
91.Memory Allocation Subsystem
92.Memory Allocator Statistics
93.Move a BLOB Handle to a New Row
94.Mutex Handle
95.Mutex Methods Object
96.Mutex Types
97.Mutex Verification Routines
98.Mutexes
99.Name Of A Host Parameter
100.Name Of The Folder Holding Database Files
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