blob: cd5cfda1a4736f98f570942123b6f3eefd853e9d [file] [log] [blame]
drh75897232000-05-29 14:26:00 +00001/*
drhb19a2bc2001-09-16 00:13:26 +00002** 2001 September 15
drh75897232000-05-29 14:26:00 +00003**
drhb19a2bc2001-09-16 00:13:26 +00004** The author disclaims copyright to this source code. In place of
5** a legal notice, here is a blessing:
drh75897232000-05-29 14:26:00 +00006**
drhb19a2bc2001-09-16 00:13:26 +00007** May you do good and not evil.
8** May you find forgiveness for yourself and forgive others.
9** May you share freely, never taking more than you give.
drh75897232000-05-29 14:26:00 +000010**
11*************************************************************************
drhb19a2bc2001-09-16 00:13:26 +000012** This header file defines the interface that the SQLite library
drh6ed48bf2007-06-14 20:57:18 +000013** presents to client programs. If a C-function, structure, datatype,
14** or constant definition does not appear in this file, then it is
15** not a published API of SQLite, is subject to change without
16** notice, and should not be referenced by programs that use SQLite.
drh75897232000-05-29 14:26:00 +000017**
drh6ed48bf2007-06-14 20:57:18 +000018** Some of the definitions that are in this file are marked as
19** "experimental". Experimental interfaces are normally new
20** features recently added to SQLite. We do not anticipate changes
21** to experimental interfaces but reserve to make minor changes if
22** experience from use "in the wild" suggest such changes are prudent.
23**
24** The official C-language API documentation for SQLite is derived
25** from comments in this file. This file is the authoritative source
26** on how SQLite interfaces are suppose to operate.
27**
28** The name of this file under configuration management is "sqlite.h.in".
29** The makefile makes some minor changes to this file (such as inserting
30** the version number) and changes its name to "sqlite3.h" as
31** part of the build process.
32**
drh73be5012007-08-08 12:11:21 +000033** @(#) $Id: sqlite.h.in,v 1.219 2007/08/08 12:11:21 drh Exp $
drh75897232000-05-29 14:26:00 +000034*/
drh12057d52004-09-06 17:34:12 +000035#ifndef _SQLITE3_H_
36#define _SQLITE3_H_
drha18c5682000-10-08 22:20:57 +000037#include <stdarg.h> /* Needed for the definition of va_list */
drh75897232000-05-29 14:26:00 +000038
39/*
drh382c0242001-10-06 16:33:02 +000040** Make sure we can call this stuff from C++.
41*/
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46/*
drh73be5012007-08-08 12:11:21 +000047** Add the ability to override 'extern'
48*/
49#ifndef SQLITE_EXTERN
50# define SQLITE_EXTERN extern
51#endif
52
53/*
drh6ed48bf2007-06-14 20:57:18 +000054** Make sure these symbols where not defined by some previous header
55** file.
drhb86ccfb2003-01-28 23:13:10 +000056*/
drh1e284f42004-10-06 15:52:01 +000057#ifdef SQLITE_VERSION
58# undef SQLITE_VERSION
drh1e284f42004-10-06 15:52:01 +000059#endif
drh6ed48bf2007-06-14 20:57:18 +000060#ifdef SQLITE_VERSION_NUMBER
61# undef SQLITE_VERSION_NUMBER
62#endif
danielk197799ba19e2005-02-05 07:33:34 +000063
64/*
drh6ed48bf2007-06-14 20:57:18 +000065** CAPI3REF: Compile-Time Library Version Numbers
66**
67** The version of the SQLite library is contained in the sqlite3.h
68** header file in a #define named SQLITE_VERSION. The SQLITE_VERSION
69** macro resolves to a string constant.
70**
71** The format of the version string is "X.Y.Z", where
danielk197799ba19e2005-02-05 07:33:34 +000072** X is the major version number, Y is the minor version number and Z
drh6ed48bf2007-06-14 20:57:18 +000073** is the release number. The X.Y.Z might be followed by "alpha" or "beta".
danielk197799ba19e2005-02-05 07:33:34 +000074** For example "3.1.1beta".
75**
drh6ed48bf2007-06-14 20:57:18 +000076** The X value is always 3 in SQLite. The X value only changes when
77** backwards compatibility is broken and we intend to never break
78** backwards compatibility. The Y value only changes when
79** there are major feature enhancements that are forwards compatible
80** but not backwards compatible. The Z value is incremented with
81** each release but resets back to 0 when Y is incremented.
82**
danielk197799ba19e2005-02-05 07:33:34 +000083** The SQLITE_VERSION_NUMBER is an integer with the value
danielk1977e48b1f12007-05-24 09:44:10 +000084** (X*1000000 + Y*1000 + Z). For example, for version "3.1.1beta",
danielk197799ba19e2005-02-05 07:33:34 +000085** SQLITE_VERSION_NUMBER is set to 3001001. To detect if they are using
86** version 3.1.1 or greater at compile time, programs may use the test
87** (SQLITE_VERSION_NUMBER>=3001001).
drh6ed48bf2007-06-14 20:57:18 +000088**
89** See also: [sqlite3_libversion()] and [sqlite3_libversion_number()].
danielk197799ba19e2005-02-05 07:33:34 +000090*/
drh6ed48bf2007-06-14 20:57:18 +000091#define SQLITE_VERSION "--VERS--"
danielk197799ba19e2005-02-05 07:33:34 +000092#define SQLITE_VERSION_NUMBER --VERSION-NUMBER--
drhb86ccfb2003-01-28 23:13:10 +000093
94/*
drh6ed48bf2007-06-14 20:57:18 +000095** CAPI3REF: Run-Time Library Version Numbers
96**
97** These routines return values equivalent to the header constants
98** [SQLITE_VERSION] and [SQLITE_VERSION_NUMBER]. The values returned
99** by this routines should only be different from the header values
100** if you compile your program using an sqlite3.h header from a
101** different version of SQLite that the version of the library you
102** link against.
103**
104** The sqlite3_version[] string constant contains the text of the
105** [SQLITE_VERSION] string. The sqlite3_libversion() function returns
106** a poiner to the sqlite3_version[] string constant. The function
107** is provided for DLL users who can only access functions and not
108** constants within the DLL.
drhb217a572000-08-22 13:40:18 +0000109*/
drh73be5012007-08-08 12:11:21 +0000110SQLITE_EXTERN const char sqlite3_version[];
drha3f70cb2004-09-30 14:24:50 +0000111const char *sqlite3_libversion(void);
danielk197799ba19e2005-02-05 07:33:34 +0000112int sqlite3_libversion_number(void);
113
114/*
drh6ed48bf2007-06-14 20:57:18 +0000115** CAPI3REF: Database Connection Handle
116**
117** Each open SQLite database is represented by pointer to an instance of the
118** opaque structure named "sqlite3". It is useful to think of an sqlite3
119** pointer as an object. The [sqlite3_open] interface is its constructor
120** and [sqlite3_close] is its destructor. There are many other interfaces
121** (such as [sqlite3_prepare_v2], [sqlite3_create_function], and
122** [sqlite3_busy_timeout] to name but three) that are methods on this
123** object.
drh75897232000-05-29 14:26:00 +0000124*/
drh9bb575f2004-09-06 17:24:11 +0000125typedef struct sqlite3 sqlite3;
danielk197765904932004-05-26 06:18:37 +0000126
drh75897232000-05-29 14:26:00 +0000127
128/*
drh6ed48bf2007-06-14 20:57:18 +0000129** CAPI3REF: 64-Bit Integer Types
130**
drhefad9992004-06-22 12:13:55 +0000131** Some compilers do not support the "long long" datatype. So we have
drh6ed48bf2007-06-14 20:57:18 +0000132** to do compiler-specific typedefs for 64-bit signed and unsigned integers.
133**
134** Many SQLite interface functions require a 64-bit integer arguments.
135** Those interfaces are declared using this typedef.
drhefad9992004-06-22 12:13:55 +0000136*/
drh27436af2006-03-28 23:57:17 +0000137#ifdef SQLITE_INT64_TYPE
drh9b8f4472006-04-04 01:54:55 +0000138 typedef SQLITE_INT64_TYPE sqlite_int64;
drh27436af2006-03-28 23:57:17 +0000139 typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
140#elif defined(_MSC_VER) || defined(__BORLANDC__)
drhefad9992004-06-22 12:13:55 +0000141 typedef __int64 sqlite_int64;
drh1211de32004-07-26 12:24:22 +0000142 typedef unsigned __int64 sqlite_uint64;
drhefad9992004-06-22 12:13:55 +0000143#else
144 typedef long long int sqlite_int64;
drh1211de32004-07-26 12:24:22 +0000145 typedef unsigned long long int sqlite_uint64;
drhefad9992004-06-22 12:13:55 +0000146#endif
147
drhb37df7b2005-10-13 02:09:49 +0000148/*
149** If compiling for a processor that lacks floating point support,
150** substitute integer for floating-point
151*/
152#ifdef SQLITE_OMIT_FLOATING_POINT
153# define double sqlite_int64
154#endif
drhefad9992004-06-22 12:13:55 +0000155
156/*
drh6ed48bf2007-06-14 20:57:18 +0000157** CAPI3REF: Closing A Database Connection
drh75897232000-05-29 14:26:00 +0000158**
159** Call this function with a pointer to a structure that was previously
drh6ed48bf2007-06-14 20:57:18 +0000160** returned from [sqlite3_open()] and the corresponding database will by
161** closed.
danielk197796d81f92004-06-19 03:33:57 +0000162**
drh6ed48bf2007-06-14 20:57:18 +0000163** All SQL statements prepared using [sqlite3_prepare_v2()] or
164** [sqlite3_prepare16_v2()] must be destroyed using [sqlite3_finalize()]
165** before this routine is called. Otherwise, SQLITE_BUSY is returned and the
danielk197796d81f92004-06-19 03:33:57 +0000166** database connection remains open.
drh75897232000-05-29 14:26:00 +0000167*/
danielk1977f9d64d22004-06-19 08:18:07 +0000168int sqlite3_close(sqlite3 *);
drh75897232000-05-29 14:26:00 +0000169
170/*
171** The type for a callback function.
drh6ed48bf2007-06-14 20:57:18 +0000172** This is legacy and deprecated. It is included for historical
173** compatibility and is not documented.
drh75897232000-05-29 14:26:00 +0000174*/
drh12057d52004-09-06 17:34:12 +0000175typedef int (*sqlite3_callback)(void*,int,char**, char**);
drh75897232000-05-29 14:26:00 +0000176
177/*
drh6ed48bf2007-06-14 20:57:18 +0000178** CAPI3REF: One-Step Query Execution Interface
179**
180** This interface is used to do a one-time evaluatation of zero
181** or more SQL statements. UTF-8 text of the SQL statements to
182** be evaluted is passed in as the second parameter. The statements
183** are prepared one by one using [sqlite3_prepare()], evaluated
184** using [sqlite3_step()], then destroyed using [sqlite3_finalize()].
drh75897232000-05-29 14:26:00 +0000185**
186** If one or more of the SQL statements are queries, then
187** the callback function specified by the 3rd parameter is
188** invoked once for each row of the query result. This callback
189** should normally return 0. If the callback returns a non-zero
190** value then the query is aborted, all subsequent SQL statements
danielk19776f8a5032004-05-10 10:34:51 +0000191** are skipped and the sqlite3_exec() function returns the SQLITE_ABORT.
drh75897232000-05-29 14:26:00 +0000192**
drh6ed48bf2007-06-14 20:57:18 +0000193** The 4th parameter to this interface is an arbitrary pointer that is
194** passed through to the callback function as its first parameter.
drh75897232000-05-29 14:26:00 +0000195**
196** The 2nd parameter to the callback function is the number of
drhb19a2bc2001-09-16 00:13:26 +0000197** columns in the query result. The 3rd parameter to the callback
drh6ed48bf2007-06-14 20:57:18 +0000198** is an array of strings holding the values for each column
199** as extracted using [sqlite3_column_text()].
200** The 4th parameter to the callback is an array of strings
201** obtained using [sqlite3_column_name()] and holding
drhb19a2bc2001-09-16 00:13:26 +0000202** the names of each column.
drh75897232000-05-29 14:26:00 +0000203**
204** The callback function may be NULL, even for queries. A NULL
205** callback is not an error. It just means that no callback
206** will be invoked.
207**
208** If an error occurs while parsing or evaluating the SQL (but
209** not while executing the callback) then an appropriate error
drh6ed48bf2007-06-14 20:57:18 +0000210** message is written into memory obtained from [sqlite3_malloc()] and
drhb19a2bc2001-09-16 00:13:26 +0000211** *errmsg is made to point to that message. The calling function
212** is responsible for freeing the memory that holds the error
drh6ed48bf2007-06-14 20:57:18 +0000213** message. Use [sqlite3_free()] for this. If errmsg==NULL,
drhb86ccfb2003-01-28 23:13:10 +0000214** then no error message is ever written.
drhb19a2bc2001-09-16 00:13:26 +0000215**
216** The return value is is SQLITE_OK if there are no errors and
drh6ed48bf2007-06-14 20:57:18 +0000217** some other [SQLITE_OK | return code] if there is an error.
218** The particular return value depends on the type of error.
drh58b95762000-06-02 01:17:37 +0000219**
drh75897232000-05-29 14:26:00 +0000220*/
danielk19776f8a5032004-05-10 10:34:51 +0000221int sqlite3_exec(
drh6ed48bf2007-06-14 20:57:18 +0000222 sqlite3*, /* An open database */
223 const char *sql, /* SQL to be evaluted */
224 int (*callback)(void*,int,char**,char**), /* Callback function */
225 void *, /* 1st argument to callback */
226 char **errmsg /* Error msg written here */
drh75897232000-05-29 14:26:00 +0000227);
228
drh58b95762000-06-02 01:17:37 +0000229/*
drh6ed48bf2007-06-14 20:57:18 +0000230** CAPI3REF: Result Codes
231** KEYWORDS: SQLITE_OK
232**
233** Many SQLite functions return an integer result code from the set shown
234** above in order to indicates success or failure.
235**
236** The result codes above are the only ones returned by SQLite in its
237** default configuration. However, the [sqlite3_extended_result_codes()]
238** API can be used to set a database connectoin to return more detailed
239** result codes.
240**
241** See also: [SQLITE_IOERR_READ | extended result codes]
242**
drh58b95762000-06-02 01:17:37 +0000243*/
drh717e6402001-09-27 03:22:32 +0000244#define SQLITE_OK 0 /* Successful result */
drh15b9a152006-01-31 20:49:13 +0000245/* beginning-of-error-codes */
drh717e6402001-09-27 03:22:32 +0000246#define SQLITE_ERROR 1 /* SQL error or missing database */
drh2db0bbc2005-08-11 02:10:18 +0000247#define SQLITE_INTERNAL 2 /* NOT USED. Internal logic error in SQLite */
drh717e6402001-09-27 03:22:32 +0000248#define SQLITE_PERM 3 /* Access permission denied */
249#define SQLITE_ABORT 4 /* Callback routine requested an abort */
250#define SQLITE_BUSY 5 /* The database file is locked */
251#define SQLITE_LOCKED 6 /* A table in the database is locked */
252#define SQLITE_NOMEM 7 /* A malloc() failed */
253#define SQLITE_READONLY 8 /* Attempt to write a readonly database */
drh24cd67e2004-05-10 16:18:47 +0000254#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
drh717e6402001-09-27 03:22:32 +0000255#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
256#define SQLITE_CORRUPT 11 /* The database disk image is malformed */
drh2db0bbc2005-08-11 02:10:18 +0000257#define SQLITE_NOTFOUND 12 /* NOT USED. Table or record not found */
drh717e6402001-09-27 03:22:32 +0000258#define SQLITE_FULL 13 /* Insertion failed because database is full */
259#define SQLITE_CANTOPEN 14 /* Unable to open the database file */
drh4f0ee682007-03-30 20:43:40 +0000260#define SQLITE_PROTOCOL 15 /* NOT USED. Database lock protocol error */
drh24cd67e2004-05-10 16:18:47 +0000261#define SQLITE_EMPTY 16 /* Database is empty */
drh717e6402001-09-27 03:22:32 +0000262#define SQLITE_SCHEMA 17 /* The database schema changed */
drhc797d4d2007-05-08 01:08:49 +0000263#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
drh717e6402001-09-27 03:22:32 +0000264#define SQLITE_CONSTRAINT 19 /* Abort due to contraint violation */
drh8aff1012001-12-22 14:49:24 +0000265#define SQLITE_MISMATCH 20 /* Data type mismatch */
drh247be432002-05-10 05:44:55 +0000266#define SQLITE_MISUSE 21 /* Library used incorrectly */
drh8766c342002-11-09 00:33:15 +0000267#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
drhed6c8672003-01-12 18:02:16 +0000268#define SQLITE_AUTH 23 /* Authorization denied */
drh1c2d8412003-03-31 00:30:47 +0000269#define SQLITE_FORMAT 24 /* Auxiliary database format error */
danielk19776f8a5032004-05-10 10:34:51 +0000270#define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
drhc602f9a2004-02-12 19:01:04 +0000271#define SQLITE_NOTADB 26 /* File opened that is not a database file */
danielk19776f8a5032004-05-10 10:34:51 +0000272#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
273#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
drh15b9a152006-01-31 20:49:13 +0000274/* end-of-error-codes */
drh717e6402001-09-27 03:22:32 +0000275
drhaf9ff332002-01-16 21:00:27 +0000276/*
drh6ed48bf2007-06-14 20:57:18 +0000277** CAPI3REF: Extended Result Codes
drh4ac285a2006-09-15 07:28:50 +0000278**
drh6ed48bf2007-06-14 20:57:18 +0000279** In its default configuration, SQLite API routines return one of 26 integer
280** result codes described at result-codes. However, experience has shown that
281** many of these result codes are too course-grained. They do not provide as
282** much information about problems as users might like. In an effort to
283** address this, newer versions of SQLite (version 3.3.8 and later) include
284** support for additional result codes that provide more detailed information
285** about errors. The extended result codes are enabled (or disabled) for
286** each database
287** connection using the [sqlite3_extended_result_codes()] API.
288**
289** Some of the available extended result codes are listed above.
290** We expect the number of extended result codes will be expand
291** over time. Software that uses extended result codes should expect
292** to see new result codes in future releases of SQLite.
293**
294** The symbolic name for an extended result code always contains a related
295** primary result code as a prefix. Primary result codes contain a single
296** "_" character. Extended result codes contain two or more "_" characters.
297** The numeric value of an extended result code can be converted to its
298** corresponding primary result code by masking off the lower 8 bytes.
drh4ac285a2006-09-15 07:28:50 +0000299**
300** The SQLITE_OK result code will never be extended. It will always
301** be exactly zero.
drh4ac285a2006-09-15 07:28:50 +0000302*/
303#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))
304#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))
305#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8))
306#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8))
307#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8))
308#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8))
309#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8))
310#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8))
311#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8))
danielk1977979f38e2007-03-27 16:19:51 +0000312#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8))
danielk1977e965ac72007-06-13 15:22:28 +0000313#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8))
drh4ac285a2006-09-15 07:28:50 +0000314
315/*
drh6ed48bf2007-06-14 20:57:18 +0000316** CAPI3REF: Enable Or Disable Extended Result Codes
317**
318** This routine enables or disables the
319** [SQLITE_IOERR_READ | extended result codes] feature.
320** By default, SQLite API routines return one of only 26 integer
321** [SQLITE_OK | result codes]. When extended result codes
322** are enabled by this routine, the repetoire of result codes can be
323** much larger and can (hopefully) provide more detailed information
324** about the cause of an error.
325**
326** The second argument is a boolean value that turns extended result
327** codes on and off. Extended result codes are off by default for
328** backwards compatibility with older versions of SQLite.
drh4ac285a2006-09-15 07:28:50 +0000329*/
330int sqlite3_extended_result_codes(sqlite3*, int onoff);
331
332/*
drh6ed48bf2007-06-14 20:57:18 +0000333** CAPI3REF: Last Insert Rowid
334**
335** Each entry in an SQLite table has a unique 64-bit signed integer key
336** called the "rowid". The rowid is always available as an undeclared
337** column named ROWID, OID, or _ROWID_. If the table has a column of
338** type INTEGER PRIMARY KEY then that column is another an alias for the
339** rowid.
340**
341** This routine returns the rowid of the most recent INSERT into
342** the database from the database connection given in the first
343** argument. If no inserts have ever occurred on this database
344** connection, zero is returned.
345**
346** If an INSERT occurs within a trigger, then the rowid of the
347** inserted row is returned by this routine as long as the trigger
348** is running. But once the trigger terminates, the value returned
349** by this routine reverts to the last value inserted before the
350** trigger fired.
drhaf9ff332002-01-16 21:00:27 +0000351*/
drhefad9992004-06-22 12:13:55 +0000352sqlite_int64 sqlite3_last_insert_rowid(sqlite3*);
drhaf9ff332002-01-16 21:00:27 +0000353
drhc8d30ac2002-04-12 10:08:59 +0000354/*
drh6ed48bf2007-06-14 20:57:18 +0000355** CAPI3REF: Count The Number Of Rows Modified
356**
drhc8d30ac2002-04-12 10:08:59 +0000357** This function returns the number of database rows that were changed
drh930cc582007-03-28 13:07:40 +0000358** (or inserted or deleted) by the most recent SQL statement. Only
359** changes that are directly specified by the INSERT, UPDATE, or
360** DELETE statement are counted. Auxiliary changes caused by
drh6ed48bf2007-06-14 20:57:18 +0000361** triggers are not counted. Use the [sqlite3_total_changes()] function
362** to find the total number of changes including changes caused by triggers.
363**
364** Within the body of a trigger, the sqlite3_changes() interface can be
365** called to find the number of
drh930cc582007-03-28 13:07:40 +0000366** changes in the most recently completed INSERT, UPDATE, or DELETE
367** statement within the body of the trigger.
drhc8d30ac2002-04-12 10:08:59 +0000368**
369** All changes are counted, even if they were later undone by a
370** ROLLBACK or ABORT. Except, changes associated with creating and
371** dropping tables are not counted.
372**
drh6ed48bf2007-06-14 20:57:18 +0000373** If a callback invokes [sqlite3_exec()] or [sqlite3_step()] recursively,
drh930cc582007-03-28 13:07:40 +0000374** then the changes in the inner, recursive call are counted together
375** with the changes in the outer call.
drhc8d30ac2002-04-12 10:08:59 +0000376**
377** SQLite implements the command "DELETE FROM table" without a WHERE clause
378** by dropping and recreating the table. (This is much faster than going
drha6b81ba2007-06-27 10:21:38 +0000379** through and deleting individual elements from the table.) Because of
drhc8d30ac2002-04-12 10:08:59 +0000380** this optimization, the change count for "DELETE FROM table" will be
381** zero regardless of the number of elements that were originally in the
382** table. To get an accurate count of the number of rows deleted, use
383** "DELETE FROM table WHERE 1" instead.
384*/
danielk1977f9d64d22004-06-19 08:18:07 +0000385int sqlite3_changes(sqlite3*);
drhc8d30ac2002-04-12 10:08:59 +0000386
rdcf146a772004-02-25 22:51:06 +0000387/*
drh6ed48bf2007-06-14 20:57:18 +0000388** CAPI3REF: Total Number Of Rows Modified
389***
danielk1977b28af712004-06-21 06:50:26 +0000390** This function returns the number of database rows that have been
391** modified by INSERT, UPDATE or DELETE statements since the database handle
392** was opened. This includes UPDATE, INSERT and DELETE statements executed
393** as part of trigger programs. All changes are counted as soon as the
394** statement that makes them is completed (when the statement handle is
drh6ed48bf2007-06-14 20:57:18 +0000395** passed to [sqlite3_reset()] or [sqlite_finalise()]).
396**
397** See also the [sqlite3_change()] interface.
rdcf146a772004-02-25 22:51:06 +0000398**
399** SQLite implements the command "DELETE FROM table" without a WHERE clause
400** by dropping and recreating the table. (This is much faster than going
401** through and deleting individual elements form the table.) Because of
402** this optimization, the change count for "DELETE FROM table" will be
403** zero regardless of the number of elements that were originally in the
404** table. To get an accurate count of the number of rows deleted, use
405** "DELETE FROM table WHERE 1" instead.
rdcf146a772004-02-25 22:51:06 +0000406*/
danielk1977b28af712004-06-21 06:50:26 +0000407int sqlite3_total_changes(sqlite3*);
408
drh6ed48bf2007-06-14 20:57:18 +0000409/*
410** CAPI3REF: Interrupt A Long-Running Query
411**
412** This function causes any pending database operation to abort and
drh4c504392000-10-16 22:06:40 +0000413** return at its earliest opportunity. This routine is typically
drh66b89c82000-11-28 20:47:17 +0000414** called in response to a user action such as pressing "Cancel"
drh4c504392000-10-16 22:06:40 +0000415** or Ctrl-C where the user wants a long query operation to halt
416** immediately.
drh930cc582007-03-28 13:07:40 +0000417**
drh6ed48bf2007-06-14 20:57:18 +0000418** It is safe to call this routine from a thread different from the
419** thread that is currently running the database operation.
420**
421** The SQL operation that is interrupted will return [SQLITE_INTERRUPT].
422** If an interrupted operation was an update that is inside an
423** explicit transaction, then the entire transaction will be rolled
424** back automatically.
drh4c504392000-10-16 22:06:40 +0000425*/
danielk1977f9d64d22004-06-19 08:18:07 +0000426void sqlite3_interrupt(sqlite3*);
drh4c504392000-10-16 22:06:40 +0000427
drh6ed48bf2007-06-14 20:57:18 +0000428/*
429** CAPI3REF: Determine If An SQL Statement Is Complete
430**
431** These functions return true if the given input string comprises
danielk197761de0d12004-05-27 23:56:16 +0000432** one or more complete SQL statements. For the sqlite3_complete() call,
433** the parameter must be a nul-terminated UTF-8 string. For
434** sqlite3_complete16(), a nul-terminated machine byte order UTF-16 string
435** is required.
drh75897232000-05-29 14:26:00 +0000436**
drh6ed48bf2007-06-14 20:57:18 +0000437** These routines are useful for command-line input to determine if the
438** currently entered text forms one or more complete SQL statements or
439** if additional input is needed before sending the statements into
440** SQLite for parsing. The algorithm is simple. If the
drh930cc582007-03-28 13:07:40 +0000441** last token other than spaces and comments is a semicolon, then return
442** true. Actually, the algorithm is a little more complicated than that
443** in order to deal with triggers, but the basic idea is the same: the
444** statement is not complete unless it ends in a semicolon.
drh75897232000-05-29 14:26:00 +0000445*/
danielk19776f8a5032004-05-10 10:34:51 +0000446int sqlite3_complete(const char *sql);
danielk197761de0d12004-05-27 23:56:16 +0000447int sqlite3_complete16(const void *sql);
drh75897232000-05-29 14:26:00 +0000448
drh2dfbbca2000-07-28 14:32:48 +0000449/*
drh6ed48bf2007-06-14 20:57:18 +0000450** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
451**
452** This routine identifies a callback function that might be invoked
453** whenever an attempt is made to open a database table
454** that another thread or process has locked.
455** If the busy callback is NULL, then [SQLITE_BUSY]
456** (or sometimes [SQLITE_IOERR_BLOCKED])
457** is returned immediately upon encountering the lock.
458** If the busy callback is not NULL, then the
459** callback will be invoked with two arguments. The
drh86939b52007-01-10 12:54:51 +0000460** first argument to the handler is a copy of the void* pointer which
461** is the third argument to this routine. The second argument to
462** the handler is the number of times that the busy handler has
drh6ed48bf2007-06-14 20:57:18 +0000463** been invoked for this locking event. If the
464** busy callback returns 0, then no additional attempts are made to
465** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned.
466** If the callback returns non-zero, then another attempt is made to open the
467** database for reading and the cycle repeats.
drh2dfbbca2000-07-28 14:32:48 +0000468**
drh86939b52007-01-10 12:54:51 +0000469** The presence of a busy handler does not guarantee that
470** it will be invoked when there is lock contention.
471** If SQLite determines that invoking the busy handler could result in
drh6ed48bf2007-06-14 20:57:18 +0000472** a deadlock, it will return [SQLITE_BUSY] instead.
drh86939b52007-01-10 12:54:51 +0000473** Consider a scenario where one process is holding a read lock that
474** it is trying to promote to a reserved lock and
475** a second process is holding a reserved lock that it is trying
476** to promote to an exclusive lock. The first process cannot proceed
477** because it is blocked by the second and the second process cannot
478** proceed because it is blocked by the first. If both processes
479** invoke the busy handlers, neither will make any progress. Therefore,
drh6ed48bf2007-06-14 20:57:18 +0000480** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
drh86939b52007-01-10 12:54:51 +0000481** will induce the first process to release its read lock and allow
482** the second process to proceed.
483**
drh2dfbbca2000-07-28 14:32:48 +0000484** The default busy callback is NULL.
485**
drh6ed48bf2007-06-14 20:57:18 +0000486** The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED] when
487** SQLite is in the middle of a large transaction where all the
488** changes will not fit into the in-memory cache. SQLite will
489** already hold a RESERVED lock on the database file, but it needs
490** to promote this lock to EXCLUSIVE so that it can spill cache
491** pages into the database file without harm to concurrent
492** readers. If it is unable to promote the lock, then the in-memory
493** cache will be left in an inconsistent state and so the error
494** code is promoted from the relatively benign [SQLITE_BUSY] to
495** the more severe [SQLITE_IOERR_BLOCKED]. This error code promotion
496** forces an automatic rollback of the changes. See the
497** <a href="http://www.sqlite.org/cvstrac/wiki?p=CorruptionFollowingBusyError">
498** CorruptionFollowingBusyError</a> wiki page for a discussion of why
499** this is important.
500**
drh2dfbbca2000-07-28 14:32:48 +0000501** Sqlite is re-entrant, so the busy handler may start a new query.
drh6ed48bf2007-06-14 20:57:18 +0000502** (It is not clear why anyone would every want to do this, but it
drh2dfbbca2000-07-28 14:32:48 +0000503** is allowed, in theory.) But the busy handler may not close the
504** database. Closing the database from a busy handler will delete
505** data structures out from under the executing query and will
drh6ed48bf2007-06-14 20:57:18 +0000506** probably result in a segmentation fault or other runtime error.
507**
508** There can only be a single busy handler defined for each database
509** connection. Setting a new busy handler clears any previous one.
510** Note that calling [sqlite3_busy_timeout()] will also set or clear
511** the busy handler.
drh2dfbbca2000-07-28 14:32:48 +0000512*/
danielk1977f9d64d22004-06-19 08:18:07 +0000513int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
drh2dfbbca2000-07-28 14:32:48 +0000514
515/*
drh6ed48bf2007-06-14 20:57:18 +0000516** CAPI3REF: Set A Busy Timeout
517**
drh2dfbbca2000-07-28 14:32:48 +0000518** This routine sets a busy handler that sleeps for a while when a
519** table is locked. The handler will sleep multiple times until
drh6ed48bf2007-06-14 20:57:18 +0000520** at least "ms" milliseconds of sleeping have been done. After
521** "ms" milliseconds of sleeping, the handler returns 0 which
522** causes [sqlite3_step()] to return [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED].
drh2dfbbca2000-07-28 14:32:48 +0000523**
524** Calling this routine with an argument less than or equal to zero
525** turns off all busy handlers.
drh6ed48bf2007-06-14 20:57:18 +0000526**
527** There can only be a single busy handler for a particular database
528** connection. If another busy handler was defined
529** (using [sqlite3_busy_handler()]) prior to calling
530** this routine, that other busy handler is cleared.
drh2dfbbca2000-07-28 14:32:48 +0000531*/
danielk1977f9d64d22004-06-19 08:18:07 +0000532int sqlite3_busy_timeout(sqlite3*, int ms);
drh2dfbbca2000-07-28 14:32:48 +0000533
drhe3710332000-09-29 13:30:53 +0000534/*
drh6ed48bf2007-06-14 20:57:18 +0000535** CAPI3REF: Convenience Routines For Running Queries
536**
537** This next routine is a convenience wrapper around [sqlite3_exec()].
drhe3710332000-09-29 13:30:53 +0000538** Instead of invoking a user-supplied callback for each row of the
539** result, this routine remembers each row of the result in memory
drh6ed48bf2007-06-14 20:57:18 +0000540** obtained from [sqlite3_malloc()], then returns all of the result after the
drha18c5682000-10-08 22:20:57 +0000541** query has finished.
542**
543** As an example, suppose the query result where this table:
544**
drh6ed48bf2007-06-14 20:57:18 +0000545** <pre>
drha18c5682000-10-08 22:20:57 +0000546** Name | Age
547** -----------------------
548** Alice | 43
549** Bob | 28
550** Cindy | 21
drh6ed48bf2007-06-14 20:57:18 +0000551** </pre>
drha18c5682000-10-08 22:20:57 +0000552**
553** If the 3rd argument were &azResult then after the function returns
drh98699b52000-10-09 12:57:00 +0000554** azResult will contain the following data:
drha18c5682000-10-08 22:20:57 +0000555**
drh6ed48bf2007-06-14 20:57:18 +0000556** <pre>
drha18c5682000-10-08 22:20:57 +0000557** azResult[0] = "Name";
558** azResult[1] = "Age";
559** azResult[2] = "Alice";
560** azResult[3] = "43";
561** azResult[4] = "Bob";
562** azResult[5] = "28";
563** azResult[6] = "Cindy";
564** azResult[7] = "21";
drh6ed48bf2007-06-14 20:57:18 +0000565** </pre>
drha18c5682000-10-08 22:20:57 +0000566**
567** Notice that there is an extra row of data containing the column
568** headers. But the *nrow return value is still 3. *ncolumn is
569** set to 2. In general, the number of values inserted into azResult
570** will be ((*nrow) + 1)*(*ncolumn).
571**
572** After the calling function has finished using the result, it should
danielk19776f8a5032004-05-10 10:34:51 +0000573** pass the result data pointer to sqlite3_free_table() in order to
drha18c5682000-10-08 22:20:57 +0000574** release the memory that was malloc-ed. Because of the way the
drh6ed48bf2007-06-14 20:57:18 +0000575** [sqlite3_malloc()] happens, the calling function must not try to call
576** [sqlite3_free()] directly. Only [sqlite3_free_table()] is able to release
drha18c5682000-10-08 22:20:57 +0000577** the memory properly and safely.
drhe3710332000-09-29 13:30:53 +0000578**
drh6ed48bf2007-06-14 20:57:18 +0000579** The return value of this routine is the same as from [sqlite3_exec()].
drhe3710332000-09-29 13:30:53 +0000580*/
danielk19776f8a5032004-05-10 10:34:51 +0000581int sqlite3_get_table(
drh6ed48bf2007-06-14 20:57:18 +0000582 sqlite3*, /* An open database */
drh9f71c2e2001-11-03 23:57:09 +0000583 const char *sql, /* SQL to be executed */
drhe3710332000-09-29 13:30:53 +0000584 char ***resultp, /* Result written to a char *[] that this points to */
585 int *nrow, /* Number of result rows written here */
586 int *ncolumn, /* Number of result columns written here */
587 char **errmsg /* Error msg written here */
588);
danielk19776f8a5032004-05-10 10:34:51 +0000589void sqlite3_free_table(char **result);
drhe3710332000-09-29 13:30:53 +0000590
drha18c5682000-10-08 22:20:57 +0000591/*
drh6ed48bf2007-06-14 20:57:18 +0000592** CAPI3REF: Formatted String Printing Functions
593**
594** These routines are workalikes of the "printf()" family of functions
595** from the standard C library.
596**
597** The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
598** results into memory obtained from [sqlite_malloc()].
599** The strings returned by these two routines should be
600** released by [sqlite3_free()]. Both routines return a
601** NULL pointer if [sqlite3_malloc()] is unable to allocate enough
602** memory to hold the resulting string.
603**
604** In sqlite3_snprintf() routine is similar to "snprintf()" from
605** the standard C library. The result is written into the
606** buffer supplied as the second parameter whose size is given by
607** the first parameter. Note that the order of the
608** first two parameters is reversed from snprintf(). This is an
609** historical accident that cannot be fixed without breaking
610** backwards compatibility. Note also that sqlite3_snprintf()
611** returns a pointer to its buffer instead of the number of
612** characters actually written into the buffer. We admit that
613** the number of characters written would be a more useful return
614** value but we cannot change the implementation of sqlite3_snprintf()
615** now without breaking compatibility.
616**
617** As long as the buffer size is greater than zero, sqlite3_snprintf()
618** guarantees that the buffer is always zero-terminated. The first
619** parameter "n" is the total size of the buffer, including space for
620** the zero terminator. So the longest string that can be completely
621** written will be n-1 characters.
622**
623** These routines all implement some additional formatting
drh4f26d6c2004-05-26 23:25:30 +0000624** options that are useful for constructing SQL statements.
drha18c5682000-10-08 22:20:57 +0000625** All of the usual printf formatting options apply. In addition, there
drh6ed48bf2007-06-14 20:57:18 +0000626** is are "%q" and "%Q" options.
627**
628** The %q option works like %s in that it substitutes a null-terminated
drh66b89c82000-11-28 20:47:17 +0000629** string from the argument list. But %q also doubles every '\'' character.
drha18c5682000-10-08 22:20:57 +0000630** %q is designed for use inside a string literal. By doubling each '\''
drh66b89c82000-11-28 20:47:17 +0000631** character it escapes that character and allows it to be inserted into
drha18c5682000-10-08 22:20:57 +0000632** the string.
633**
634** For example, so some string variable contains text as follows:
635**
drh6ed48bf2007-06-14 20:57:18 +0000636** <blockquote><pre>
637** char *zText = "It's a happy day!";
638** </pre></blockquote>
drha18c5682000-10-08 22:20:57 +0000639**
drh6ed48bf2007-06-14 20:57:18 +0000640** One can use this text in an SQL statement as follows:
drha18c5682000-10-08 22:20:57 +0000641**
drh6ed48bf2007-06-14 20:57:18 +0000642** <blockquote><pre>
643** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);
644** sqlite3_exec(db, zSQL, 0, 0, 0);
645** sqlite3_free(zSQL);
646** </pre></blockquote>
drha18c5682000-10-08 22:20:57 +0000647**
648** Because the %q format string is used, the '\'' character in zText
649** is escaped and the SQL generated is as follows:
650**
drh6ed48bf2007-06-14 20:57:18 +0000651** <blockquote><pre>
652** INSERT INTO table1 VALUES('It''s a happy day!')
653** </pre></blockquote>
drha18c5682000-10-08 22:20:57 +0000654**
655** This is correct. Had we used %s instead of %q, the generated SQL
656** would have looked like this:
657**
drh6ed48bf2007-06-14 20:57:18 +0000658** <blockquote><pre>
659** INSERT INTO table1 VALUES('It's a happy day!');
660** </pre></blockquote>
drha18c5682000-10-08 22:20:57 +0000661**
662** This second example is an SQL syntax error. As a general rule you
663** should always use %q instead of %s when inserting text into a string
664** literal.
drh6ed48bf2007-06-14 20:57:18 +0000665**
666** The %Q option works like %q except it also adds single quotes around
667** the outside of the total string. Or if the parameter in the argument
668** list is a NULL pointer, %Q substitutes the text "NULL" (without single
669** quotes) in place of the %Q option. So, for example, one could say:
670**
671** <blockquote><pre>
672** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
673** sqlite3_exec(db, zSQL, 0, 0, 0);
674** sqlite3_free(zSQL);
675** </pre></blockquote>
676**
677** The code above will render a correct SQL statement in the zSQL
678** variable even if the zText variable is a NULL pointer.
drha18c5682000-10-08 22:20:57 +0000679*/
danielk19776f8a5032004-05-10 10:34:51 +0000680char *sqlite3_mprintf(const char*,...);
681char *sqlite3_vmprintf(const char*, va_list);
drhfeac5f82004-08-01 00:10:45 +0000682char *sqlite3_snprintf(int,char*,const char*, ...);
drh5191b7e2002-03-08 02:12:00 +0000683
drh28dd4792006-06-26 21:35:44 +0000684/*
drh6ed48bf2007-06-14 20:57:18 +0000685** CAPI3REF: Memory Allocation Functions
686**
687** SQLite uses its own memory allocator. On some installations, this
drh28dd4792006-06-26 21:35:44 +0000688** memory allocator is identical to the standard malloc()/realloc()/free()
689** and can be used interchangable. On others, the implementations are
690** different. For maximum portability, it is best not to mix calls
691** to the standard malloc/realloc/free with the sqlite versions.
692*/
693void *sqlite3_malloc(int);
694void *sqlite3_realloc(void*, int);
695void sqlite3_free(void*);
696
drh5191b7e2002-03-08 02:12:00 +0000697/*
drh6ed48bf2007-06-14 20:57:18 +0000698** CAPI3REF: Compile-Time Authorization Callbacks
699***
700** This routine registers a authorizer callback with the SQLite library.
701** The authorizer callback is invoked as SQL statements are being compiled
702** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
703** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()]. At various
704** points during the compilation process, as logic is being created
705** to perform various actions, the authorizer callback is invoked to
706** see if those actions are allowed. The authorizer callback should
707** return SQLITE_OK to allow the action, [SQLITE_IGNORE] to disallow the
708** specific action but allow the SQL statement to continue to be
709** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
710** rejected with an error.
711**
712** Depending on the action, the [SQLITE_IGNORE] and [SQLITE_DENY] return
713** codes might mean something different or they might mean the same
714** thing. If the action is, for example, to perform a delete opertion,
715** then [SQLITE_IGNORE] and [SQLITE_DENY] both cause the statement compilation
716** to fail with an error. But if the action is to read a specific column
717** from a specific table, then [SQLITE_DENY] will cause the entire
718** statement to fail but [SQLITE_IGNORE] will cause a NULL value to be
719** read instead of the actual column value.
720**
721** The first parameter to the authorizer callback is a copy of
722** the third parameter to the sqlite3_set_authorizer() interface.
723** The second parameter to the callback is an integer
724** [SQLITE_COPY | action code] that specifies the particular action
725** to be authorized. The available action codes are
726** [SQLITE_COPY | documented separately]. The third through sixth
727** parameters to the callback are strings that contain additional
728** details about the action to be authorized.
729**
730** An authorizer is used when preparing SQL statements from an untrusted
731** source, to ensure that the SQL statements do not try to access data
732** that they are not allowed to see, or that they do not try to
733** execute malicious statements that damage the database. For
734** example, an application may allow a user to enter arbitrary
735** SQL queries for evaluation by a database. But the application does
736** not want the user to be able to make arbitrary changes to the
737** database. An authorizer could then be put in place while the
738** user-entered SQL is being prepared that disallows everything
739** except SELECT statements.
740**
741** Only a single authorizer can be in place on a database connection
742** at a time. Each call to sqlite3_set_authorizer overrides the
743** previous call. A NULL authorizer means that no authorization
744** callback is invoked. The default authorizer is NULL.
745**
746** Note that the authorizer callback is invoked only during
747** [sqlite3_prepare()] or its variants. Authorization is not
748** performed during statement evaluation in [sqlite3_step()].
drhed6c8672003-01-12 18:02:16 +0000749*/
danielk19776f8a5032004-05-10 10:34:51 +0000750int sqlite3_set_authorizer(
danielk1977f9d64d22004-06-19 08:18:07 +0000751 sqlite3*,
drhe22a3342003-04-22 20:30:37 +0000752 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
drhe5f9c642003-01-13 23:27:31 +0000753 void *pUserData
drhed6c8672003-01-12 18:02:16 +0000754);
755
756/*
drh6ed48bf2007-06-14 20:57:18 +0000757** CAPI3REF: Authorizer Return Codes
758**
759** The [sqlite3_set_authorizer | authorizer callback function] must
760** return either [SQLITE_OK] or one of these two constants in order
761** to signal SQLite whether or not the action is permitted. See the
762** [sqlite3_set_authorizer | authorizer documentation] for additional
763** information.
764*/
765#define SQLITE_DENY 1 /* Abort the SQL statement with an error */
766#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
767
768/*
769** CAPI3REF: Authorizer Action Codes
770**
771** The [sqlite3_set_authorizer()] interface registers a callback function
772** that is invoked to authorizer certain SQL statement actions. The
773** second parameter to the callback is an integer code that specifies
774** what action is being authorized. These are the integer action codes that
775** the authorizer callback may be passed.
776**
777** These action code values signify what kind of operation is to be
778** authorized. The 3rd and 4th parameters to the authorization callback
779** function will be parameters or NULL depending on which of these
780** codes is used as the second parameter. The 5th parameter to the
781** authorizer callback is the name of the database ("main", "temp",
782** etc.) if applicable. The 6th parameter to the authorizer callback
drh5cf590c2003-04-24 01:45:04 +0000783** is the name of the inner-most trigger or view that is responsible for
784** the access attempt or NULL if this access attempt is directly from
drh6ed48bf2007-06-14 20:57:18 +0000785** top-level SQL code.
drhed6c8672003-01-12 18:02:16 +0000786*/
drh6ed48bf2007-06-14 20:57:18 +0000787/******************************************* 3rd ************ 4th ***********/
drhe5f9c642003-01-13 23:27:31 +0000788#define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
789#define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
790#define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
791#define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */
drh77ad4e42003-01-14 02:49:27 +0000792#define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */
drhe5f9c642003-01-13 23:27:31 +0000793#define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */
drh77ad4e42003-01-14 02:49:27 +0000794#define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */
drhe5f9c642003-01-13 23:27:31 +0000795#define SQLITE_CREATE_VIEW 8 /* View Name NULL */
796#define SQLITE_DELETE 9 /* Table Name NULL */
drh77ad4e42003-01-14 02:49:27 +0000797#define SQLITE_DROP_INDEX 10 /* Index Name Table Name */
drhe5f9c642003-01-13 23:27:31 +0000798#define SQLITE_DROP_TABLE 11 /* Table Name NULL */
drh77ad4e42003-01-14 02:49:27 +0000799#define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */
drhe5f9c642003-01-13 23:27:31 +0000800#define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */
drh77ad4e42003-01-14 02:49:27 +0000801#define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */
drhe5f9c642003-01-13 23:27:31 +0000802#define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */
drh77ad4e42003-01-14 02:49:27 +0000803#define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */
drhe5f9c642003-01-13 23:27:31 +0000804#define SQLITE_DROP_VIEW 17 /* View Name NULL */
805#define SQLITE_INSERT 18 /* Table Name NULL */
806#define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */
807#define SQLITE_READ 20 /* Table Name Column Name */
808#define SQLITE_SELECT 21 /* NULL NULL */
809#define SQLITE_TRANSACTION 22 /* NULL NULL */
810#define SQLITE_UPDATE 23 /* Table Name Column Name */
drh81e293b2003-06-06 19:00:42 +0000811#define SQLITE_ATTACH 24 /* Filename NULL */
812#define SQLITE_DETACH 25 /* Database Name NULL */
danielk19771c8c23c2004-11-12 15:53:37 +0000813#define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
danielk19771d54df82004-11-23 15:41:16 +0000814#define SQLITE_REINDEX 27 /* Index Name NULL */
drhe6e04962005-07-23 02:17:03 +0000815#define SQLITE_ANALYZE 28 /* Table Name NULL */
danielk1977f1a381e2006-06-16 08:01:02 +0000816#define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
817#define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
drh5169bbc2006-08-24 14:59:45 +0000818#define SQLITE_FUNCTION 31 /* Function Name NULL */
drh6ed48bf2007-06-14 20:57:18 +0000819#define SQLITE_COPY 0 /* No longer used */
drhed6c8672003-01-12 18:02:16 +0000820
821/*
drh6ed48bf2007-06-14 20:57:18 +0000822** CAPI3REF: Tracing And Profiling Functions
823**
824** These routines register callback functions that can be used for
825** tracing and profiling the execution of SQL statements.
826** The callback function registered by sqlite3_trace() is invoked
827** at the first [sqlite3_step()] for the evaluation of an SQL statement.
828** The callback function registered by sqlite3_profile() is invoked
829** as each SQL statement finishes and includes
drh19e2d372005-08-29 23:00:03 +0000830** information on how long that statement ran.
831**
832** The sqlite3_profile() API is currently considered experimental and
833** is subject to change.
drh18de4822003-01-16 16:28:53 +0000834*/
danielk1977f9d64d22004-06-19 08:18:07 +0000835void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
drh19e2d372005-08-29 23:00:03 +0000836void *sqlite3_profile(sqlite3*,
837 void(*xProfile)(void*,const char*,sqlite_uint64), void*);
drh18de4822003-01-16 16:28:53 +0000838
danielk1977348bb5d2003-10-18 09:37:26 +0000839/*
drh6ed48bf2007-06-14 20:57:18 +0000840** CAPI3REF: Query Progress Callbacks
841**
danielk1977348bb5d2003-10-18 09:37:26 +0000842** This routine configures a callback function - the progress callback - that
drh6ed48bf2007-06-14 20:57:18 +0000843** is invoked periodically during long running calls to [sqlite3_exec()],
844** [sqlite3_step()] and [sqlite3_get_table()]. An example use for this
845** interface is to keep a GUI updated during a large query.
danielk1977348bb5d2003-10-18 09:37:26 +0000846**
847** The progress callback is invoked once for every N virtual machine opcodes,
848** where N is the second argument to this function. The progress callback
849** itself is identified by the third argument to this function. The fourth
850** argument to this function is a void pointer passed to the progress callback
851** function each time it is invoked.
852**
drh6ed48bf2007-06-14 20:57:18 +0000853** If a call to [sqlite3_exec()], [sqlite3_step()], or [sqlite3_get_table()]
854** results in fewer than N opcodes being executed, then the progress
855** callback is never invoked.
danielk1977348bb5d2003-10-18 09:37:26 +0000856**
drh6ed48bf2007-06-14 20:57:18 +0000857** Only a single progress callback function may be registered for each
858** open database connection. Every call to sqlite3_progress_handler()
859** overwrites the results of the previous call.
danielk1977348bb5d2003-10-18 09:37:26 +0000860** To remove the progress callback altogether, pass NULL as the third
861** argument to this function.
862**
863** If the progress callback returns a result other than 0, then the current
drh6ed48bf2007-06-14 20:57:18 +0000864** query is immediately terminated and any database changes rolled back.
865** The containing [sqlite3_exec()], [sqlite3_step()], or
866** [sqlite3_get_table()] call returns SQLITE_INTERRUPT. This feature
867** can be used, for example, to implement the "Cancel" button on a
868** progress dialog box in a GUI.
danielk1977348bb5d2003-10-18 09:37:26 +0000869*/
danielk1977f9d64d22004-06-19 08:18:07 +0000870void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
danielk1977348bb5d2003-10-18 09:37:26 +0000871
drhaa940ea2004-01-15 02:44:03 +0000872/*
drh6ed48bf2007-06-14 20:57:18 +0000873** CAPI3REF: Opening A New Database Connection
drhaa940ea2004-01-15 02:44:03 +0000874**
drh4f26d6c2004-05-26 23:25:30 +0000875** Open the sqlite database file "filename". The "filename" is UTF-8
876** encoded for sqlite3_open() and UTF-16 encoded in the native byte order
drh6ed48bf2007-06-14 20:57:18 +0000877** for sqlite3_open16(). An [sqlite3*] handle is returned in *ppDb, even
drh4f26d6c2004-05-26 23:25:30 +0000878** if an error occurs. If the database is opened (or created) successfully,
879** then SQLITE_OK is returned. Otherwise an error code is returned. The
880** sqlite3_errmsg() or sqlite3_errmsg16() routines can be used to obtain
881** an English language description of the error.
drh22fbcb82004-02-01 01:22:50 +0000882**
drh6ed48bf2007-06-14 20:57:18 +0000883** If the database file does not exist, then a new database will be created
884** as needed. The default encoding for the database will be UTF-8 if
885** sqlite3_open() is called and UTF-16 if sqlite3_open16 is used.
danielk197765904932004-05-26 06:18:37 +0000886**
887** Whether or not an error occurs when it is opened, resources associated
drh6ed48bf2007-06-14 20:57:18 +0000888** with the [sqlite3*] handle should be released by passing it to
danielk197765904932004-05-26 06:18:37 +0000889** sqlite3_close() when it is no longer required.
drh6ed48bf2007-06-14 20:57:18 +0000890**
891** Note to windows users: The encoding used for the filename argument
892** of sqlite3_open() must be UTF-8, not whatever codepage is currently
893** defined. Filenames containing international characters must be converted
894** to UTF-8 prior to passing them into sqlite3_open().
danielk197765904932004-05-26 06:18:37 +0000895*/
896int sqlite3_open(
897 const char *filename, /* Database filename (UTF-8) */
danielk19774f057f92004-06-08 00:02:33 +0000898 sqlite3 **ppDb /* OUT: SQLite db handle */
danielk197765904932004-05-26 06:18:37 +0000899);
danielk197765904932004-05-26 06:18:37 +0000900int sqlite3_open16(
901 const void *filename, /* Database filename (UTF-16) */
danielk19774f057f92004-06-08 00:02:33 +0000902 sqlite3 **ppDb /* OUT: SQLite db handle */
danielk197765904932004-05-26 06:18:37 +0000903);
danielk1977295ba552004-05-19 10:34:51 +0000904
danielk197765904932004-05-26 06:18:37 +0000905/*
drh6ed48bf2007-06-14 20:57:18 +0000906** CAPI3REF: Error Codes And Messages
907**
908** The sqlite3_errcode() interface returns the numeric
909** [SQLITE_OK | result code] or [SQLITE_IOERR_READ | extended result code]
910** for the most recent failed sqlite3_* API call associated
911** with [sqlite3] handle 'db'. If a prior API call failed but the
912** most recent API call succeeded, the return value from sqlite3_errcode()
913** is undefined.
914**
915** The sqlite3_errmsg() and sqlite3_errmsg16() return English-langauge
916** text that describes the error, as either UTF8 or UTF16 respectively.
917** Memory to hold the error message string is managed internally. The
918** string may be overwritten or deallocated by subsequent calls to SQLite
919** interface functions.
danielk197765904932004-05-26 06:18:37 +0000920**
921** Calls to many sqlite3_* functions set the error code and string returned
drh6ed48bf2007-06-14 20:57:18 +0000922** by [sqlite3_errcode()], [sqlite3_errmsg()], and [sqlite3_errmsg16()]
923** (overwriting the previous values). Note that calls to [sqlite3_errcode()],
924** [sqlite3_errmsg()], and [sqlite3_errmsg16()] themselves do not affect the
925** results of future invocations. Calls to API routines that do not return
926** an error code (examples: [sqlite3_data_count()] or [sqlite3_mprintf()]) do
927** not change the error code returned by this routine.
danielk197765904932004-05-26 06:18:37 +0000928**
929** Assuming no other intervening sqlite3_* API calls are made, the error
930** code returned by this function is associated with the same error as
drh6ed48bf2007-06-14 20:57:18 +0000931** the strings returned by [sqlite3_errmsg()] and [sqlite3_errmsg16()].
danielk197765904932004-05-26 06:18:37 +0000932*/
933int sqlite3_errcode(sqlite3 *db);
danielk197765904932004-05-26 06:18:37 +0000934const char *sqlite3_errmsg(sqlite3*);
danielk197765904932004-05-26 06:18:37 +0000935const void *sqlite3_errmsg16(sqlite3*);
936
937/*
drh6ed48bf2007-06-14 20:57:18 +0000938** CAPI3REF: SQL Statement Object
939**
940** Instance of this object represent single SQL statements. This
941** is variously known as a "prepared statement" or a
942** "compiled SQL statement" or simply as a "statement".
943**
944** The life of a statement object goes something like this:
945**
946** <ol>
947** <li> Create the object using [sqlite3_prepare_v2()] or a related
948** function.
949** <li> Bind values to host parameters using
950** [sqlite3_bind_blob | sqlite3_bind_* interfaces].
951** <li> Run the SQL by calling [sqlite3_step()] one or more times.
952** <li> Reset the statement using [sqlite3_reset()] then go back
953** to step 2. Do this zero or more times.
954** <li> Destroy the object using [sqlite3_finalize()].
955** </ol>
956**
957** Refer to documentation on individual methods above for additional
958** information.
danielk197765904932004-05-26 06:18:37 +0000959*/
danielk1977fc57d7b2004-05-26 02:04:57 +0000960typedef struct sqlite3_stmt sqlite3_stmt;
961
danielk1977e3209e42004-05-20 01:40:18 +0000962/*
drh6ed48bf2007-06-14 20:57:18 +0000963** CAPI3REF: Compiling An SQL Statement
danielk197765904932004-05-26 06:18:37 +0000964**
drh6ed48bf2007-06-14 20:57:18 +0000965** To execute an SQL query, it must first be compiled into a byte-code
966** program using one of these routines.
967**
968** The first argument "db" is an [sqlite3 | SQLite database handle]
969** obtained from a prior call to [sqlite3_open()] or [sqlite3_open16()].
970** The second argument "zSql" is the statement to be compiled, encoded
971** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2()
972** interfaces uses UTF-8 and sqlite3_prepare16() and sqlite3_prepare16_v2()
drh21f06722007-07-19 12:41:39 +0000973** use UTF-16.
974**
975** If the nByte argument is less
drh6ed48bf2007-06-14 20:57:18 +0000976** than zero, then zSql is read up to the first zero terminator. If
drh21f06722007-07-19 12:41:39 +0000977** nByte is non-negative, then it is the maximum number of
978** bytes read from zSql. When nByte is non-negative, the
979** zSql string ends at either the first '\000' character or
980** until the nByte-th byte, whichever comes first.
danielk197765904932004-05-26 06:18:37 +0000981**
982** *pzTail is made to point to the first byte past the end of the first
983** SQL statement in zSql. This routine only compiles the first statement
984** in zSql, so *pzTail is left pointing to what remains uncompiled.
985**
drh6ed48bf2007-06-14 20:57:18 +0000986** *ppStmt is left pointing to a compiled
987** [sqlite3_stmt | SQL statement structure] that can be
988** executed using [sqlite3_step()]. Or if there is an error, *ppStmt may be
danielk197765904932004-05-26 06:18:37 +0000989** set to NULL. If the input text contained no SQL (if the input is and
drh6ed48bf2007-06-14 20:57:18 +0000990** empty string or a comment) then *ppStmt is set to NULL. The calling
991** procedure is responsible for deleting the compiled SQL statement
992** using [sqlite3_finalize()] after it has finished with it.
danielk197765904932004-05-26 06:18:37 +0000993**
drh6ed48bf2007-06-14 20:57:18 +0000994** On success, [SQLITE_OK] is returned. Otherwise an
995** [SQLITE_ERROR | error code] is returned.
996**
997** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are
998** recommended for all new programs. The two older interfaces are retained
999** for backwards compatibility, but their use is discouraged.
1000** In the "v2" interfaces, the prepared statement
1001** that is returned (the [sqlite3_stmt] object) contains a copy of the
1002** original SQL text. This causes the [sqlite3_step()] interface to
1003** behave a differently in two ways:
1004**
1005** <ol>
1006** <li>
1007** If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
1008** always used to do, [sqlite3_step()] will automatically recompile the SQL
1009** statement and try to run it again. If the schema has changed in a way
1010** that makes the statement no longer valid, [sqlite3_step()] will still
1011** return [SQLITE_SCHEMA]. But unlike the legacy behavior, [SQLITE_SCHEMA] is
1012** now a fatal error. Calling [sqlite3_prepare_v2()] again will not make the
1013** error go away. Note: use [sqlite3_errmsg()] to find the text of the parsing
1014** error that results in an [SQLITE_SCHEMA] return.
1015** </li>
1016**
1017** <li>
1018** When an error occurs,
1019** [sqlite3_step()] will return one of the detailed
1020** [SQLITE_ERROR | result codes] or
1021** [SQLITE_IOERR_READ | extended result codes] such as directly.
1022** The legacy behavior was that [sqlite3_step()] would only return a generic
1023** [SQLITE_ERROR] result code and you would have to make a second call to
1024** [sqlite3_reset()] in order to find the underlying cause of the problem.
1025** With the "v2" prepare interfaces, the underlying reason for the error is
1026** returned immediately.
1027** </li>
1028** </ol>
danielk197765904932004-05-26 06:18:37 +00001029*/
1030int sqlite3_prepare(
1031 sqlite3 *db, /* Database handle */
1032 const char *zSql, /* SQL statement, UTF-8 encoded */
drh21f06722007-07-19 12:41:39 +00001033 int nByte, /* Maximum length of zSql in bytes. */
danielk197765904932004-05-26 06:18:37 +00001034 sqlite3_stmt **ppStmt, /* OUT: Statement handle */
1035 const char **pzTail /* OUT: Pointer to unused portion of zSql */
1036);
drh6ed48bf2007-06-14 20:57:18 +00001037int sqlite3_prepare_v2(
1038 sqlite3 *db, /* Database handle */
1039 const char *zSql, /* SQL statement, UTF-8 encoded */
drh21f06722007-07-19 12:41:39 +00001040 int nByte, /* Maximum length of zSql in bytes. */
drh6ed48bf2007-06-14 20:57:18 +00001041 sqlite3_stmt **ppStmt, /* OUT: Statement handle */
1042 const char **pzTail /* OUT: Pointer to unused portion of zSql */
1043);
danielk197765904932004-05-26 06:18:37 +00001044int sqlite3_prepare16(
1045 sqlite3 *db, /* Database handle */
1046 const void *zSql, /* SQL statement, UTF-16 encoded */
drh21f06722007-07-19 12:41:39 +00001047 int nByte, /* Maximum length of zSql in bytes. */
danielk197765904932004-05-26 06:18:37 +00001048 sqlite3_stmt **ppStmt, /* OUT: Statement handle */
1049 const void **pzTail /* OUT: Pointer to unused portion of zSql */
1050);
drhb900aaf2006-11-09 00:24:53 +00001051int sqlite3_prepare16_v2(
1052 sqlite3 *db, /* Database handle */
1053 const void *zSql, /* SQL statement, UTF-16 encoded */
drh21f06722007-07-19 12:41:39 +00001054 int nByte, /* Maximum length of zSql in bytes. */
drhb900aaf2006-11-09 00:24:53 +00001055 sqlite3_stmt **ppStmt, /* OUT: Statement handle */
1056 const void **pzTail /* OUT: Pointer to unused portion of zSql */
1057);
1058
1059/*
drh6ed48bf2007-06-14 20:57:18 +00001060** CAPI3REF: Dynamically Typed Value Object
1061**
1062** SQLite uses dynamic typing for the values it stores. Values can
1063** be integers, floating point values, strings, BLOBs, or NULL. When
1064** passing around values internally, each value is represented as
1065** an instance of the sqlite3_value object.
drhf4479502004-05-27 03:12:53 +00001066*/
drhf4479502004-05-27 03:12:53 +00001067typedef struct Mem sqlite3_value;
1068
1069/*
drh6ed48bf2007-06-14 20:57:18 +00001070** CAPI3REF: SQL Function Context Object
drh4f26d6c2004-05-26 23:25:30 +00001071**
drh6ed48bf2007-06-14 20:57:18 +00001072** The context in which an SQL function executes is stored in an
1073** sqlite3_context object. A pointer to such an object is the
1074** first parameter to user-defined SQL functions.
1075*/
1076typedef struct sqlite3_context sqlite3_context;
1077
1078/*
1079** CAPI3REF: Binding Values To Prepared Statements
1080**
1081** In the SQL strings input to [sqlite3_prepare_v2()] and its variants,
1082** one or more literals can be replace by a parameter in one of these
1083** forms:
1084**
1085** <ul>
1086** <li> ?
1087** <li> ?NNN
1088** <li> :AAA
1089** <li> @AAA
1090** <li> $VVV
1091** </ul>
1092**
1093** In the parameter forms shown above NNN is an integer literal,
1094** AAA is an alphanumeric identifier and VVV is a variable name according
1095** to the syntax rules of the TCL programming language.
1096** The values of these parameters (also called "host parameter names")
1097** can be set using the sqlite3_bind_*() routines defined here.
1098**
1099** The first argument to the sqlite3_bind_*() routines always is a pointer
1100** to the [sqlite3_stmt] object returned from [sqlite3_prepare_v2()] or
1101** its variants. The second
1102** argument is the index of the parameter to be set. The first parameter has
1103** an index of 1. When the same named parameter is used more than once, second
1104** and subsequent
1105** occurrences have the same index as the first occurrence. The index for
1106** named parameters can be looked up using the
1107** [sqlite3_bind_parameter_name()] API if desired. The index for "?NNN"
1108** parametes is the value of NNN.
1109** The NNN value must be between 1 and the compile-time
1110** parameter SQLITE_MAX_VARIABLE_NUMBER (default value: 999).
1111** See <a href="limits.html">limits.html</a> for additional information.
1112**
1113** The third argument is the value to bind to the parameter.
1114**
1115** In those
1116** routines that have a fourth argument, its value is the number of bytes
1117** in the parameter. To be clear: the value is the number of bytes in the
1118** string, not the number of characters. The number
1119** of bytes does not include the zero-terminator at the end of strings.
1120** If the fourth parameter is negative, the length of the string is
1121** number of bytes up to the first zero terminator.
drh4f26d6c2004-05-26 23:25:30 +00001122**
drh930cc582007-03-28 13:07:40 +00001123** The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
drh900dfba2004-07-21 15:21:36 +00001124** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
1125** text after SQLite has finished with it. If the fifth argument is the
drh6ed48bf2007-06-14 20:57:18 +00001126** special value [SQLITE_STATIC], then the library assumes that the information
drh900dfba2004-07-21 15:21:36 +00001127** is in static, unmanaged space and does not need to be freed. If the
drh6ed48bf2007-06-14 20:57:18 +00001128** fifth argument has the value [SQLITE_TRANSIENT], then SQLite makes its
1129** own private copy of the data immediately, before the sqlite3_bind_*()
1130** routine returns.
drh4f26d6c2004-05-26 23:25:30 +00001131**
drh6ed48bf2007-06-14 20:57:18 +00001132** The sqlite3_bind_zeroblob() routine binds a BLOB of length n that
1133** is filled with zeros. A zeroblob uses a fixed amount of memory
1134** (just an integer to hold it size) while it is being processed.
1135** Zeroblobs are intended to serve as place-holders for BLOBs whose
1136** content is later written using
1137** [sqlite3_blob_open | increment BLOB I/O] routines.
1138**
1139** The sqlite3_bind_*() routines must be called after
1140** [sqlite3_prepare_v2()] (and its variants) or [sqlite3_reset()] and
1141** before [sqlite3_step()].
1142** Bindings are not cleared by the [sqlite3_reset()] routine.
1143** Unbound parameters are interpreted as NULL.
1144**
1145** These routines return [SQLITE_OK] on success or an error code if
1146** anything goes wrong. [SQLITE_RANGE] is returned if the parameter
1147** index is out of range. [SQLITE_NOMEM] is returned if malloc fails.
1148** [SQLITE_MISUSE] is returned if these routines are called on a virtual
1149** machine that is the wrong state or which has already been finalized.
drh4f26d6c2004-05-26 23:25:30 +00001150*/
danielk1977d8123362004-06-12 09:25:12 +00001151int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
drhf4479502004-05-27 03:12:53 +00001152int sqlite3_bind_double(sqlite3_stmt*, int, double);
1153int sqlite3_bind_int(sqlite3_stmt*, int, int);
drhefad9992004-06-22 12:13:55 +00001154int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite_int64);
drhf4479502004-05-27 03:12:53 +00001155int sqlite3_bind_null(sqlite3_stmt*, int);
danielk1977d8123362004-06-12 09:25:12 +00001156int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));
1157int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
drhf4479502004-05-27 03:12:53 +00001158int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
drhb026e052007-05-02 01:34:31 +00001159int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
drh4f26d6c2004-05-26 23:25:30 +00001160
1161/*
drh6ed48bf2007-06-14 20:57:18 +00001162** CAPI3REF: Number Of Host Parameters
1163**
1164** Return the largest host parameter index in the precompiled statement given
1165** as the argument. When the host parameters are of the forms like ":AAA"
1166** or "?", then they are assigned sequential increasing numbers beginning
1167** with one, so the value returned is the number of parameters. However
1168** if the same host parameter name is used multiple times, each occurrance
1169** is given the same number, so the value returned in that case is the number
1170** of unique host parameter names. If host parameters of the form "?NNN"
1171** are used (where NNN is an integer) then there might be gaps in the
1172** numbering and the value returned by this interface is the index of the
1173** host parameter with the largest index value.
drh75f6a032004-07-15 14:15:00 +00001174*/
1175int sqlite3_bind_parameter_count(sqlite3_stmt*);
1176
1177/*
drh6ed48bf2007-06-14 20:57:18 +00001178** CAPI3REF: Name Of A Host Parameter
1179**
1180** This routine returns a pointer to the name of the n-th parameter in a
1181** [sqlite3_stmt | prepared statement].
1182** Host parameters of the form ":AAA" or "@AAA" or "$VVV" have a name
1183** which is the string ":AAA" or "@AAA" or "$VVV".
1184** In other words, the initial ":" or "$" or "@"
1185** is included as part of the name.
1186** Parameters of the form "?" or "?NNN" have no name.
1187**
1188** The first bound parameter has an index of 1, not 0.
1189**
1190** If the value n is out of range or if the n-th parameter is nameless,
1191** then NULL is returned. The returned string is always in the
1192** UTF-8 encoding even if the named parameter was originally specified
1193** as UTF-16 in [sqlite3_prepare16()] or [sqlite3_prepare16_v2()].
drh895d7472004-08-20 16:02:39 +00001194*/
1195const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
1196
1197/*
drh6ed48bf2007-06-14 20:57:18 +00001198** CAPI3REF: Index Of A Parameter With A Given Name
1199**
1200** This routine returns the index of a host parameter with the given name.
1201** The name must match exactly. If no parameter with the given name is
1202** found, return 0. Parameter names must be UTF8.
drhfa6bc002004-09-07 16:19:52 +00001203*/
1204int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
1205
1206/*
drh6ed48bf2007-06-14 20:57:18 +00001207** CAPI3REF: Reset All Bindings On A Prepared Statement
1208**
1209** Contrary to the intuition of many, [sqlite3_reset()] does not
1210** reset the [sqlite3_bind_blob | bindings] on a
1211** [sqlite3_stmt | prepared statement]. Use this routine to
1212** reset all host parameters to NULL.
danielk1977600dd0b2005-01-20 01:14:23 +00001213*/
1214int sqlite3_clear_bindings(sqlite3_stmt*);
1215
1216/*
drh6ed48bf2007-06-14 20:57:18 +00001217** CAPI3REF: Number Of Columns In A Result Set
1218**
1219** Return the number of columns in the result set returned by the
1220** [sqlite3_stmt | compiled SQL statement]. This routine returns 0
1221** if pStmt is an SQL statement that does not return data (for
1222** example an UPDATE).
danielk197765904932004-05-26 06:18:37 +00001223*/
1224int sqlite3_column_count(sqlite3_stmt *pStmt);
1225
1226/*
drh6ed48bf2007-06-14 20:57:18 +00001227** CAPI3REF: Column Names In A Result Set
1228**
1229** These routines return the name assigned to a particular column
1230** in the result set of a SELECT statement. The sqlite3_column_name()
1231** interface returns a pointer to a UTF8 string and sqlite3_column_name16()
1232** returns a pointer to a UTF16 string. The first parameter is the
1233** [sqlite_stmt | prepared statement] that implements the SELECT statement.
1234** The second parameter is the column number. The left-most column is
1235** number 0.
1236**
1237** The returned string pointer is valid until either the
1238** [sqlite_stmt | prepared statement] is destroyed by [sqlite3_finalize()]
1239** or until the next call sqlite3_column_name() or sqlite3_column_name16()
1240** on the same column.
danielk197765904932004-05-26 06:18:37 +00001241*/
drh6ed48bf2007-06-14 20:57:18 +00001242const char *sqlite3_column_name(sqlite3_stmt*, int N);
1243const void *sqlite3_column_name16(sqlite3_stmt*, int N);
danielk197765904932004-05-26 06:18:37 +00001244
1245/*
drh6ed48bf2007-06-14 20:57:18 +00001246** CAPI3REF: Source Of Data In A Query Result
1247**
1248** These routines provide a means to determine what column of what
1249** table in which database a result of a SELECT statement comes from.
1250** The name of the database or table or column can be returned as
drhbf2564f2007-06-21 15:25:05 +00001251** either a UTF8 or UTF16 string. The _database_ routines return
1252** the database name, the _table_ routines return the table name, and
1253** the origin_ routines return the column name.
1254** The returned string is valid until
drh6ed48bf2007-06-14 20:57:18 +00001255** the [sqlite3_stmt | prepared statement] is destroyed using
1256** [sqlite3_finalize()] or until the same information is requested
drhbf2564f2007-06-21 15:25:05 +00001257** again in a different encoding.
1258**
1259** The names returned are the original un-aliased names of the
1260** database, table, and column.
drh6ed48bf2007-06-14 20:57:18 +00001261**
1262** The first argument to the following calls is a
1263** [sqlite3_stmt | compiled SQL statement].
danielk1977955de522006-02-10 02:27:42 +00001264** These functions return information about the Nth column returned by
1265** the statement, where N is the second function argument.
1266**
drh6ed48bf2007-06-14 20:57:18 +00001267** If the Nth column returned by the statement is an expression
1268** or subquery and is not a column value, then all of these functions
1269** return NULL. Otherwise, they return the
1270** name of the attached database, table and column that query result
1271** column was extracted from.
danielk1977955de522006-02-10 02:27:42 +00001272**
1273** As with all other SQLite APIs, those postfixed with "16" return UTF-16
drh6ed48bf2007-06-14 20:57:18 +00001274** encoded strings, the other functions return UTF-8.
danielk19774b1ae992006-02-10 03:06:10 +00001275**
1276** These APIs are only available if the library was compiled with the
1277** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined.
danielk1977955de522006-02-10 02:27:42 +00001278*/
1279const char *sqlite3_column_database_name(sqlite3_stmt*,int);
1280const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
1281const char *sqlite3_column_table_name(sqlite3_stmt*,int);
1282const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
1283const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
1284const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
1285
1286/*
drh6ed48bf2007-06-14 20:57:18 +00001287** CAPI3REF: Declared Datatype Of A Query Result
1288**
1289** The first parameter is a [sqlite3_stmt | compiled SQL statement].
1290** If this statement is a SELECT statement and the Nth column of the
1291** returned result set of that SELECT is a table column (not an
1292** expression or subquery) then the declared type of the table
1293** column is returned. If the Nth column of the result set is an
1294** expression or subquery, then a NULL pointer is returned.
1295** The returned string is always UTF-8 encoded. For example, in
1296** the database schema:
danielk197765904932004-05-26 06:18:37 +00001297**
1298** CREATE TABLE t1(c1 VARIANT);
1299**
1300** And the following statement compiled:
1301**
danielk1977955de522006-02-10 02:27:42 +00001302** SELECT c1 + 1, c1 FROM t1;
danielk197765904932004-05-26 06:18:37 +00001303**
1304** Then this routine would return the string "VARIANT" for the second
1305** result column (i==1), and a NULL pointer for the first result column
1306** (i==0).
drh6ed48bf2007-06-14 20:57:18 +00001307**
1308** SQLite uses dynamic run-time typing. So just because a column
1309** is declared to contain a particular type does not mean that the
1310** data stored in that column is of the declared type. SQLite is
1311** strongly typed, but the typing is dynamic not static. Type
1312** is associated with individual values, not with the containers
1313** used to hold those values.
danielk197765904932004-05-26 06:18:37 +00001314*/
1315const char *sqlite3_column_decltype(sqlite3_stmt *, int i);
danielk197765904932004-05-26 06:18:37 +00001316const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
1317
danielk1977106bb232004-05-21 10:08:53 +00001318/*
drh6ed48bf2007-06-14 20:57:18 +00001319** CAPI3REF: Evaluate An SQL Statement
danielk1977106bb232004-05-21 10:08:53 +00001320**
drh6ed48bf2007-06-14 20:57:18 +00001321** After an [sqlite3_stmt | SQL statement] has been prepared with a call
1322** to either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or to one of
1323** the legacy interfaces [sqlite3_prepare()] or [sqlite3_prepare16()],
1324** then this function must be called one or more times to evaluate the
1325** statement.
danielk1977106bb232004-05-21 10:08:53 +00001326**
drh6ed48bf2007-06-14 20:57:18 +00001327** The details of the behavior of this sqlite3_step() interface depend
1328** on whether the statement was prepared using the newer "v2" interface
1329** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy
1330** interface [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the
1331** new "v2" interface is recommended for new applications but the legacy
1332** interface will continue to be supported.
danielk1977106bb232004-05-21 10:08:53 +00001333**
drh6ed48bf2007-06-14 20:57:18 +00001334** In the lagacy interface, the return value will be either [SQLITE_BUSY],
1335** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
1336** With the "v2" interface, any of the other [SQLITE_OK | result code]
1337** or [SQLITE_IOERR_READ | extended result code] might be returned as
1338** well.
1339**
1340** [SQLITE_BUSY] means that the database engine was unable to acquire the
1341** database locks it needs to do its job. If the statement is a COMMIT
1342** or occurs outside of an explicit transaction, then you can retry the
1343** statement. If the statement is not a COMMIT and occurs within a
1344** explicit transaction then you should rollback the transaction before
1345** continuing.
1346**
1347** [SQLITE_DONE] means that the statement has finished executing
danielk1977106bb232004-05-21 10:08:53 +00001348** successfully. sqlite3_step() should not be called again on this virtual
drh6ed48bf2007-06-14 20:57:18 +00001349** machine without first calling [sqlite3_reset()] to reset the virtual
1350** machine back to its initial state.
danielk1977106bb232004-05-21 10:08:53 +00001351**
1352** If the SQL statement being executed returns any data, then
drh6ed48bf2007-06-14 20:57:18 +00001353** [SQLITE_ROW] is returned each time a new row of data is ready
danielk1977106bb232004-05-21 10:08:53 +00001354** for processing by the caller. The values may be accessed using
drh6ed48bf2007-06-14 20:57:18 +00001355** the [sqlite3_column_int | column access functions].
1356** sqlite3_step() is called again to retrieve the next row of data.
danielk1977106bb232004-05-21 10:08:53 +00001357**
drh6ed48bf2007-06-14 20:57:18 +00001358** [SQLITE_ERROR] means that a run-time error (such as a constraint
danielk1977106bb232004-05-21 10:08:53 +00001359** violation) has occurred. sqlite3_step() should not be called again on
drh6ed48bf2007-06-14 20:57:18 +00001360** the VM. More information may be found by calling [sqlite3_errmsg()].
1361** With the legacy interface, a more specific error code (example:
1362** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
1363** can be obtained by calling [sqlite3_reset()] on the
1364** [sqlite_stmt | prepared statement]. In the "v2" interface,
1365** the more specific error code is returned directly by sqlite3_step().
danielk1977106bb232004-05-21 10:08:53 +00001366**
drh6ed48bf2007-06-14 20:57:18 +00001367** [SQLITE_MISUSE] means that the this routine was called inappropriately.
1368** Perhaps it was called on a [sqlite_stmt | prepared statement] that has
1369** already been [sqlite3_finalize | finalized] or on one that had
1370** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could
1371** be the case that the same database connection is being used by two or
1372** more threads at the same moment in time.
1373**
1374** <b>Goofy Interface Alert:</b>
1375** In the legacy interface,
1376** the sqlite3_step() API always returns a generic error code,
1377** [SQLITE_ERROR], following any error other than [SQLITE_BUSY]
1378** and [SQLITE_MISUSE]. You must call [sqlite3_reset()] or
1379** [sqlite3_finalize()] in order to find one of the specific
1380** [SQLITE_ERROR | result codes] that better describes the error.
1381** We admit that this is a goofy design. The problem has been fixed
1382** with the "v2" interface. If you prepare all of your SQL statements
1383** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead
1384** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()], then the
1385** more specific [SQLITE_ERROR | result codes] are returned directly
1386** by sqlite3_step(). The use of the "v2" interface is recommended.
danielk1977106bb232004-05-21 10:08:53 +00001387*/
danielk197717240fd2004-05-26 00:07:25 +00001388int sqlite3_step(sqlite3_stmt*);
danielk1977106bb232004-05-21 10:08:53 +00001389
danielk1977106bb232004-05-21 10:08:53 +00001390/*
drh6ed48bf2007-06-14 20:57:18 +00001391** CAPI3REF:
1392**
danielk1977106bb232004-05-21 10:08:53 +00001393** Return the number of values in the current row of the result set.
1394**
drh6ed48bf2007-06-14 20:57:18 +00001395** After a call to [sqlite3_step()] that returns [SQLITE_ROW], this routine
1396** will return the same value as the [sqlite3_column_count()] function.
1397** After [sqlite3_step()] has returned an [SQLITE_DONE], [SQLITE_BUSY], or
1398** a [SQLITE_ERROR | error code], or before [sqlite3_step()] has been
1399** called on the [sqlite_stmt | prepared statement] for the first time,
1400** this routine returns zero.
danielk1977106bb232004-05-21 10:08:53 +00001401*/
danielk197793d46752004-05-23 13:30:58 +00001402int sqlite3_data_count(sqlite3_stmt *pStmt);
danielk19774adee202004-05-08 08:23:19 +00001403
drh4f26d6c2004-05-26 23:25:30 +00001404/*
drh6ed48bf2007-06-14 20:57:18 +00001405** CAPI3REF: Fundamental Datatypes
1406**
1407** Every value in SQLite has one of five fundamental datatypes:
1408**
1409** <ul>
1410** <li> 64-bit signed integer
1411** <li> 64-bit IEEE floating point number
1412** <li> string
1413** <li> BLOB
1414** <li> NULL
1415** </ul>
1416**
1417** These constants are codes for each of those types.
1418**
1419** Note that the SQLITE_TEXT constant was also used in SQLite version 2
1420** for a completely different meaning. Software that links against both
1421** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT not
1422** SQLITE_TEXT.
drh4f26d6c2004-05-26 23:25:30 +00001423*/
drh9c054832004-05-31 18:51:57 +00001424#define SQLITE_INTEGER 1
1425#define SQLITE_FLOAT 2
drh9c054832004-05-31 18:51:57 +00001426#define SQLITE_BLOB 4
1427#define SQLITE_NULL 5
drh1e284f42004-10-06 15:52:01 +00001428#ifdef SQLITE_TEXT
1429# undef SQLITE_TEXT
1430#else
1431# define SQLITE_TEXT 3
1432#endif
1433#define SQLITE3_TEXT 3
1434
1435/*
drh6ed48bf2007-06-14 20:57:18 +00001436** CAPI3REF: Results Values From A Query
1437**
1438** These routines return information about the information
drh4f26d6c2004-05-26 23:25:30 +00001439** in a single column of the current result row of a query. In every
drh6ed48bf2007-06-14 20:57:18 +00001440** case the first argument is a pointer to the
1441** [sqlite3_stmt | SQL statement] that is being
1442** evaluate (the [sqlite_stmt*] that was returned from
1443** [sqlite3_prepare_v2()] or one of its variants) and
drh4f26d6c2004-05-26 23:25:30 +00001444** the second argument is the index of the column for which information
drh6ed48bf2007-06-14 20:57:18 +00001445** should be returned. The left-most column has an index of 0.
danielk1977106bb232004-05-21 10:08:53 +00001446**
drh4f26d6c2004-05-26 23:25:30 +00001447** If the SQL statement is not currently point to a valid row, or if the
drh6ed48bf2007-06-14 20:57:18 +00001448** the column index is out of range, the result is undefined.
1449**
1450** The sqlite3_column_type() routine returns
1451** [SQLITE_INTEGER | datatype code] for the initial data type
1452** of the result column. The returned value is one of [SQLITE_INTEGER],
1453** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. The value
1454** returned by sqlite3_column_type() is only meaningful if no type
1455** conversions have occurred as described below. After a type conversion,
1456** the value returned by sqlite3_column_type() is undefined. Future
1457** versions of SQLite may change the behavior of sqlite3_column_type()
1458** following a type conversion.
1459**
drh6ed48bf2007-06-14 20:57:18 +00001460** If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
1461** routine returns the number of bytes in that BLOB or string.
1462** If the result is a UTF-16 string, then sqlite3_column_bytes() converts
1463** the string to UTF-8 and then returns the number of bytes.
1464** If the result is a numeric value then sqlite3_column_bytes() uses
1465** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
1466** the number of bytes in that string.
1467** The value returned does not include the zero terminator at the end
1468** of the string. For clarity: the value returned is the number of
1469** bytes in the string, not the number of characters.
1470**
1471** The sqlite3_column_bytes16() routine is similar to sqlite3_column_bytes()
1472** but leaves the result in UTF-16 instead of UTF-8.
1473** The zero terminator is not included in this count.
drh4f26d6c2004-05-26 23:25:30 +00001474**
1475** These routines attempt to convert the value where appropriate. For
1476** example, if the internal representation is FLOAT and a text result
drh6ed48bf2007-06-14 20:57:18 +00001477** is requested, [sqlite3_snprintf()] is used internally to do the conversion
drh4f26d6c2004-05-26 23:25:30 +00001478** automatically. The following table details the conversions that
1479** are applied:
1480**
drh6ed48bf2007-06-14 20:57:18 +00001481** <blockquote>
1482** <table border="1">
1483** <tr><th> Internal <th> Requested <th>
1484** <tr><th> Type <th> Type <th> Conversion
drh4f26d6c2004-05-26 23:25:30 +00001485**
drh6ed48bf2007-06-14 20:57:18 +00001486** <tr><td> NULL <td> INTEGER <td> Result is 0
1487** <tr><td> NULL <td> FLOAT <td> Result is 0.0
1488** <tr><td> NULL <td> TEXT <td> Result is NULL pointer
1489** <tr><td> NULL <td> BLOB <td> Result is NULL pointer
1490** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
1491** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
1492** <tr><td> INTEGER <td> BLOB <td> Same as for INTEGER->TEXT
1493** <tr><td> FLOAT <td> INTEGER <td> Convert from float to integer
1494** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
1495** <tr><td> FLOAT <td> BLOB <td> Same as FLOAT->TEXT
1496** <tr><td> TEXT <td> INTEGER <td> Use atoi()
1497** <tr><td> TEXT <td> FLOAT <td> Use atof()
1498** <tr><td> TEXT <td> BLOB <td> No change
1499** <tr><td> BLOB <td> INTEGER <td> Convert to TEXT then use atoi()
1500** <tr><td> BLOB <td> FLOAT <td> Convert to TEXT then use atof()
1501** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed
1502** </table>
1503** </blockquote>
drh4f26d6c2004-05-26 23:25:30 +00001504**
drh6ed48bf2007-06-14 20:57:18 +00001505** The table above makes reference to standard C library functions atoi()
1506** and atof(). SQLite does not really use these functions. It has its
1507** on equavalent internal routines. The atoi() and atof() names are
1508** used in the table for brevity and because they are familiar to most
1509** C programmers.
1510**
1511** Note that when type conversions occur, pointers returned by prior
1512** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
1513** sqlite3_column_text16() may be invalidated.
1514** Type conversions and pointer invalidations might occur
1515** in the following cases:
1516**
1517** <ul>
1518** <li><p> The initial content is a BLOB and sqlite3_column_text()
1519** or sqlite3_column_text16() is called. A zero-terminator might
1520** need to be added to the string.</p></li>
1521**
1522** <li><p> The initial content is UTF-8 text and sqlite3_column_bytes16() or
1523** sqlite3_column_text16() is called. The content must be converted
1524** to UTF-16.</p></li>
1525**
1526** <li><p> The initial content is UTF-16 text and sqlite3_column_bytes() or
1527** sqlite3_column_text() is called. The content must be converted
1528** to UTF-8.</p></li>
1529** </ul>
1530**
1531** Conversions between UTF-16be and UTF-16le are always done in place and do
1532** not invalidate a prior pointer, though of course the content of the buffer
1533** that the prior pointer points to will have been modified. Other kinds
1534** of conversion are done in place when it is possible, but sometime it is
1535** not possible and in those cases prior pointers are invalidated.
1536**
1537** The safest and easiest to remember policy is to invoke these routines
1538** in one of the following ways:
1539**
1540** <ul>
1541** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
1542** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
1543** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
1544** </ul>
1545**
1546** In other words, you should call sqlite3_column_text(), sqlite3_column_blob(),
1547** or sqlite3_column_text16() first to force the result into the desired
1548** format, then invoke sqlite3_column_bytes() or sqlite3_column_bytes16() to
1549** find the size of the result. Do not mix call to sqlite3_column_text() or
1550** sqlite3_column_blob() with calls to sqlite3_column_bytes16(). And do not
1551** mix calls to sqlite3_column_text16() with calls to sqlite3_column_bytes().
danielk1977106bb232004-05-21 10:08:53 +00001552*/
drhf4479502004-05-27 03:12:53 +00001553const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
1554int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
1555int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
1556double sqlite3_column_double(sqlite3_stmt*, int iCol);
1557int sqlite3_column_int(sqlite3_stmt*, int iCol);
drhefad9992004-06-22 12:13:55 +00001558sqlite_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
drhf4479502004-05-27 03:12:53 +00001559const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
1560const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
drh4f26d6c2004-05-26 23:25:30 +00001561int sqlite3_column_type(sqlite3_stmt*, int iCol);
drh4be8b512006-06-13 23:51:34 +00001562sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
danielk19774adee202004-05-08 08:23:19 +00001563
danielk197765904932004-05-26 06:18:37 +00001564/*
drh6ed48bf2007-06-14 20:57:18 +00001565** CAPI3REF: Destroy A Prepared Statement Object
1566**
1567** The sqlite3_finalize() function is called to delete a
1568** [sqlite3_stmt | compiled SQL statement]. If the statement was
1569** executed successfully, or not executed at all, then SQLITE_OK is returned.
1570** If execution of the statement failed then an
1571** [SQLITE_ERROR | error code] or [SQLITE_IOERR_READ | extended error code]
1572** is returned.
danielk197765904932004-05-26 06:18:37 +00001573**
1574** This routine can be called at any point during the execution of the
drh6ed48bf2007-06-14 20:57:18 +00001575** [sqlite3_stmt | virtual machine]. If the virtual machine has not
1576** completed execution when this routine is called, that is like
1577** encountering an error or an interrupt. (See [sqlite3_interrupt()].)
1578** Incomplete updates may be rolled back and transactions cancelled,
1579** depending on the circumstances, and the
1580** [SQLITE_ERROR | result code] returned will be [SQLITE_ABORT].
danielk197765904932004-05-26 06:18:37 +00001581*/
1582int sqlite3_finalize(sqlite3_stmt *pStmt);
1583
1584/*
drh6ed48bf2007-06-14 20:57:18 +00001585** CAPI3REF: Reset A Prepared Statement Object
1586**
1587** The sqlite3_reset() function is called to reset a
1588** [sqlite_stmt | compiled SQL statement] object.
1589** back to it's initial state, ready to be re-executed.
danielk197765904932004-05-26 06:18:37 +00001590** Any SQL statement variables that had values bound to them using
drh6ed48bf2007-06-14 20:57:18 +00001591** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
1592** Use [sqlite3_clear_bindings()] to reset the bindings.
danielk197765904932004-05-26 06:18:37 +00001593*/
1594int sqlite3_reset(sqlite3_stmt *pStmt);
1595
1596/*
drh6ed48bf2007-06-14 20:57:18 +00001597** CAPI3REF: Create Or Redefine SQL Functions
1598**
1599** The following two functions are used to add SQL functions or aggregates
1600** or to redefine the behavior of existing SQL functions or aggregates. The
danielk197765904932004-05-26 06:18:37 +00001601** difference only between the two is that the second parameter, the
1602** name of the (scalar) function or aggregate, is encoded in UTF-8 for
1603** sqlite3_create_function() and UTF-16 for sqlite3_create_function16().
1604**
drh6ed48bf2007-06-14 20:57:18 +00001605** The first argument is the [sqlite3 | database handle] that holds the
1606** SQL function or aggregate is to be added or redefined. If a single
1607** program uses more than one database handle internally, then SQL
1608** functions or aggregates must be added individually to each database
1609** handle with which they will be used.
danielk197765904932004-05-26 06:18:37 +00001610**
drh6ed48bf2007-06-14 20:57:18 +00001611** The second parameter is the name of the SQL function to be created
1612** or redefined.
1613** The length of the name is limited to 255 bytes, exclusive of the
1614** zero-terminator. Note that the name length limit is in bytes, not
1615** characters. Any attempt to create a function with a longer name
1616** will result in an SQLITE_ERROR error.
1617**
1618** The third parameter is the number of arguments that the SQL function or
1619** aggregate takes. If this parameter is negative, then the SQL function or
danielk197765904932004-05-26 06:18:37 +00001620** aggregate may take any number of arguments.
1621**
drh6ed48bf2007-06-14 20:57:18 +00001622** The fourth parameter, eTextRep, specifies what
1623** [SQLITE_UTF8 | text encoding] this SQL function prefers for
1624** its parameters. Any SQL function implementation should be able to work
1625** work with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
1626** more efficient with one encoding than another. It is allowed to
1627** invoke sqlite_create_function() or sqlite3_create_function16() multiple
1628** times with the same function but with different values of eTextRep.
1629** When multiple implementations of the same function are available, SQLite
1630** will pick the one that involves the least amount of data conversion.
1631** If there is only a single implementation which does not care what
1632** text encoding is used, then the fourth argument should be
1633** [SQLITE_ANY].
1634**
1635** The fifth parameter is an arbitrary pointer. The implementation
1636** of the function can gain access to this pointer using
1637** [sqlite_user_data()].
danielk1977d02eb1f2004-06-06 09:44:03 +00001638**
danielk197765904932004-05-26 06:18:37 +00001639** The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
drh6ed48bf2007-06-14 20:57:18 +00001640** pointers to C-language functions that implement the SQL
1641** function or aggregate. A scalar SQL function requires an implementation of
danielk197765904932004-05-26 06:18:37 +00001642** the xFunc callback only, NULL pointers should be passed as the xStep
drh6ed48bf2007-06-14 20:57:18 +00001643** and xFinal parameters. An aggregate SQL function requires an implementation
1644** of xStep and xFinal and NULL should be passed for xFunc. To delete an
1645** existing SQL function or aggregate, pass NULL for all three function
1646** callback.
1647**
1648** It is permitted to register multiple implementations of the same
1649** functions with the same name but with either differing numbers of
1650** arguments or differing perferred text encodings. SQLite will use
1651** the implementation most closely matches the way in which the
1652** SQL function is used.
danielk197765904932004-05-26 06:18:37 +00001653*/
1654int sqlite3_create_function(
1655 sqlite3 *,
1656 const char *zFunctionName,
1657 int nArg,
1658 int eTextRep,
danielk197765904932004-05-26 06:18:37 +00001659 void*,
1660 void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
1661 void (*xStep)(sqlite3_context*,int,sqlite3_value**),
1662 void (*xFinal)(sqlite3_context*)
1663);
1664int sqlite3_create_function16(
1665 sqlite3*,
1666 const void *zFunctionName,
1667 int nArg,
1668 int eTextRep,
danielk197765904932004-05-26 06:18:37 +00001669 void*,
1670 void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
1671 void (*xStep)(sqlite3_context*,int,sqlite3_value**),
1672 void (*xFinal)(sqlite3_context*)
1673);
1674
1675/*
drh6ed48bf2007-06-14 20:57:18 +00001676** CAPI3REF: Text Encodings
1677**
1678** These constant define integer codes that represent the various
1679** text encodings supported by SQLite.
danielk197765904932004-05-26 06:18:37 +00001680*/
drh6ed48bf2007-06-14 20:57:18 +00001681#define SQLITE_UTF8 1
1682#define SQLITE_UTF16LE 2
1683#define SQLITE_UTF16BE 3
1684#define SQLITE_UTF16 4 /* Use native byte order */
1685#define SQLITE_ANY 5 /* sqlite3_create_function only */
1686#define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
danielk197765904932004-05-26 06:18:37 +00001687
danielk19770ffba6b2004-05-24 09:10:10 +00001688/*
drh6ed48bf2007-06-14 20:57:18 +00001689** CAPI3REF: Obsolete Functions
1690**
1691** These functions are all now obsolete. In order to maintain
1692** backwards compatibility with older code, we continue to support
1693** these functions. However, new development projects should avoid
1694** the use of these functions. To help encourage people to avoid
1695** using these functions, we are not going to tell you want they do.
1696*/
1697int sqlite3_aggregate_count(sqlite3_context*);
1698int sqlite3_expired(sqlite3_stmt*);
1699int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
1700int sqlite3_global_recover(void);
1701
1702
1703/*
1704** CAPI3REF: Obtaining SQL Function Parameter Values
1705**
1706** The C-language implementation of SQL functions and aggregates uses
1707** this set of interface routines to access the parameter values on
1708** the function or aggregate.
1709**
1710** The xFunc (for scalar functions) or xStep (for aggregates) parameters
1711** to [sqlite3_create_function()] and [sqlite3_create_function16()]
1712** define callbacks that implement the SQL functions and aggregates.
1713** The 4th parameter to these callbacks is an array of pointers to
1714** [sqlite3_value] objects. There is one [sqlite3_value] object for
1715** each parameter to the SQL function. These routines are used to
1716** extract values from the [sqlite3_value] objects.
1717**
1718** These routines work just like the corresponding
1719** [sqlite3_column_blob | sqlite3_column_* routines] except that
1720** these routines take a single [sqlite3_value*] pointer instead
1721** of an [sqlite3_stmt*] pointer and an integer column number.
1722**
1723** The sqlite3_value_text16() interface extracts a UTF16 string
1724** in the native byte-order of the host machine. The
1725** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
1726** extract UTF16 strings as big-endian and little-endian respectively.
1727**
1728** The sqlite3_value_numeric_type() interface attempts to apply
1729** numeric affinity to the value. This means that an attempt is
1730** made to convert the value to an integer or floating point. If
1731** such a conversion is possible without loss of information (in order
1732** words if the value is original a string that looks like a number)
1733** then it is done. Otherwise no conversion occurs. The
1734** [SQLITE_INTEGER | datatype] after conversion is returned.
1735**
1736** Please pay particular attention to the fact that the pointer that
1737** is returned from [sqlite3_value_blob()], [sqlite3_value_text()], or
1738** [sqlite3_value_text16()] can be invalidated by a subsequent call to
1739** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite_value_text()],
1740** or [sqlite3_value_text16()].
danielk19770ffba6b2004-05-24 09:10:10 +00001741*/
drhf4479502004-05-27 03:12:53 +00001742const void *sqlite3_value_blob(sqlite3_value*);
1743int sqlite3_value_bytes(sqlite3_value*);
1744int sqlite3_value_bytes16(sqlite3_value*);
1745double sqlite3_value_double(sqlite3_value*);
1746int sqlite3_value_int(sqlite3_value*);
drhefad9992004-06-22 12:13:55 +00001747sqlite_int64 sqlite3_value_int64(sqlite3_value*);
drhf4479502004-05-27 03:12:53 +00001748const unsigned char *sqlite3_value_text(sqlite3_value*);
1749const void *sqlite3_value_text16(sqlite3_value*);
danielk1977d8123362004-06-12 09:25:12 +00001750const void *sqlite3_value_text16le(sqlite3_value*);
1751const void *sqlite3_value_text16be(sqlite3_value*);
danielk197793d46752004-05-23 13:30:58 +00001752int sqlite3_value_type(sqlite3_value*);
drh29d72102006-02-09 22:13:41 +00001753int sqlite3_value_numeric_type(sqlite3_value*);
danielk19770ffba6b2004-05-24 09:10:10 +00001754
1755/*
drh6ed48bf2007-06-14 20:57:18 +00001756** CAPI3REF: Obtain Aggregate Function Context
1757**
1758** The implementation of aggregate SQL functions use this routine to allocate
danielk19770ae8b832004-05-25 12:05:56 +00001759** a structure for storing their state. The first time this routine
1760** is called for a particular aggregate, a new structure of size nBytes
1761** is allocated, zeroed, and returned. On subsequent calls (for the
1762** same aggregate instance) the same buffer is returned. The implementation
1763** of the aggregate can use the returned buffer to accumulate data.
1764**
drh6ed48bf2007-06-14 20:57:18 +00001765** The buffer allocated is freed automatically by SQLite whan the aggregate
1766** query concludes.
1767**
1768** The first parameter should be a copy of the
1769** [sqlite3_context | SQL function context] that is the first
1770** parameter to the callback routine that implements the aggregate
1771** function.
danielk19770ae8b832004-05-25 12:05:56 +00001772*/
drh4f26d6c2004-05-26 23:25:30 +00001773void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
danielk19777e18c252004-05-25 11:47:24 +00001774
1775/*
drh6ed48bf2007-06-14 20:57:18 +00001776** CAPI3REF: User Data For Functions
1777**
1778** The pUserData parameter to the [sqlite3_create_function()]
1779** and [sqlite3_create_function16()] routines
1780** used to register user functions is available to
drhc0f2a012005-07-09 02:39:40 +00001781** the implementation of the function using this call.
danielk19777e18c252004-05-25 11:47:24 +00001782*/
1783void *sqlite3_user_data(sqlite3_context*);
1784
1785/*
drh6ed48bf2007-06-14 20:57:18 +00001786** CAPI3REF: Function Auxiliary Data
1787**
1788** The following two functions may be used by scalar SQL functions to
danielk1977682f68b2004-06-05 10:22:17 +00001789** associate meta-data with argument values. If the same value is passed to
drh6ed48bf2007-06-14 20:57:18 +00001790** multiple invocations of the same SQL function during query execution, under
danielk1977682f68b2004-06-05 10:22:17 +00001791** some circumstances the associated meta-data may be preserved. This may
1792** be used, for example, to add a regular-expression matching scalar
1793** function. The compiled version of the regular expression is stored as
1794** meta-data associated with the SQL value passed as the regular expression
drh6ed48bf2007-06-14 20:57:18 +00001795** pattern. The compiled regular expression can be reused on multiple
1796** invocations of the same function so that the original pattern string
1797** does not need to be recompiled on each invocation.
danielk1977682f68b2004-06-05 10:22:17 +00001798**
drh6ed48bf2007-06-14 20:57:18 +00001799** The sqlite3_get_auxdata() interface returns a pointer to the meta-data
1800** associated with the Nth argument value to the current SQL function
danielk1977682f68b2004-06-05 10:22:17 +00001801** call, where N is the second parameter. If no meta-data has been set for
1802** that value, then a NULL pointer is returned.
1803**
drh6ed48bf2007-06-14 20:57:18 +00001804** The sqlite3_set_auxdata() is used to associate meta-data with an SQL
1805** function argument. The third parameter is a pointer to the meta-data
danielk1977682f68b2004-06-05 10:22:17 +00001806** to be associated with the Nth user function argument value. The fourth
drh6ed48bf2007-06-14 20:57:18 +00001807** parameter specifies a destructor that will be called on the meta-
1808** data pointer to release it when it is no longer required. If the
1809** destructor is NULL, it is not invoked.
danielk1977682f68b2004-06-05 10:22:17 +00001810**
1811** In practice, meta-data is preserved between function calls for
1812** expressions that are constant at compile time. This includes literal
1813** values and SQL variables.
1814*/
1815void *sqlite3_get_auxdata(sqlite3_context*, int);
1816void sqlite3_set_auxdata(sqlite3_context*, int, void*, void (*)(void*));
1817
drha2854222004-06-17 19:04:17 +00001818
1819/*
drh6ed48bf2007-06-14 20:57:18 +00001820** CAPI3REF: Constants Defining Special Destructor Behavior
1821**
drha2854222004-06-17 19:04:17 +00001822** These are special value for the destructor that is passed in as the
drh6ed48bf2007-06-14 20:57:18 +00001823** final argument to routines like [sqlite3_result_blob()]. If the destructor
drha2854222004-06-17 19:04:17 +00001824** argument is SQLITE_STATIC, it means that the content pointer is constant
1825** and will never change. It does not need to be destroyed. The
1826** SQLITE_TRANSIENT value means that the content will likely change in
1827** the near future and that SQLite should make its own private copy of
1828** the content before returning.
drh6c9121a2007-01-26 00:51:43 +00001829**
1830** The typedef is necessary to work around problems in certain
1831** C++ compilers. See ticket #2191.
drha2854222004-06-17 19:04:17 +00001832*/
drh6c9121a2007-01-26 00:51:43 +00001833typedef void (*sqlite3_destructor_type)(void*);
1834#define SQLITE_STATIC ((sqlite3_destructor_type)0)
1835#define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
danielk1977d8123362004-06-12 09:25:12 +00001836
danielk1977682f68b2004-06-05 10:22:17 +00001837/*
drh6ed48bf2007-06-14 20:57:18 +00001838** CAPI3REF: Setting The Result Of An SQL Function
1839**
1840** These routines are used by the xFunc or xFinal callbacks that
1841** implement SQL functions and aggregates. See
1842** [sqlite3_create_function()] and [sqlite3_create_function16()]
1843** for additional information.
1844**
1845** These functions work very much like the
1846** [sqlite3_bind_blob | sqlite3_bind_*] family of functions used
1847** to bind values to host parameters in prepared statements.
1848** Refer to the
1849** [sqlite3_bind_blob | sqlite3_bind_* documentation] for
1850** additional information.
1851**
1852** The sqlite3_result_error() and sqlite3_result_error16() functions
1853** cause the implemented SQL function to throw an exception. The
1854** parameter to sqlite3_result_error() or sqlite3_result_error16()
1855** is the text of an error message.
1856**
1857** The sqlite3_result_toobig() cause the function implementation
1858** to throw and error indicating that a string or BLOB is to long
1859** to represent.
danielk19777e18c252004-05-25 11:47:24 +00001860*/
danielk1977d8123362004-06-12 09:25:12 +00001861void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
drh4f26d6c2004-05-26 23:25:30 +00001862void sqlite3_result_double(sqlite3_context*, double);
danielk19777e18c252004-05-25 11:47:24 +00001863void sqlite3_result_error(sqlite3_context*, const char*, int);
1864void sqlite3_result_error16(sqlite3_context*, const void*, int);
drh6ed48bf2007-06-14 20:57:18 +00001865void sqlite3_result_error_toobig(sqlite3_context*);
drh4f26d6c2004-05-26 23:25:30 +00001866void sqlite3_result_int(sqlite3_context*, int);
drhefad9992004-06-22 12:13:55 +00001867void sqlite3_result_int64(sqlite3_context*, sqlite_int64);
drh4f26d6c2004-05-26 23:25:30 +00001868void sqlite3_result_null(sqlite3_context*);
danielk1977d8123362004-06-12 09:25:12 +00001869void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
1870void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
1871void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
1872void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
drh4f26d6c2004-05-26 23:25:30 +00001873void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
drhb026e052007-05-02 01:34:31 +00001874void sqlite3_result_zeroblob(sqlite3_context*, int n);
drhf9b596e2004-05-26 16:54:42 +00001875
drh52619df2004-06-11 17:48:02 +00001876/*
drh6ed48bf2007-06-14 20:57:18 +00001877** CAPI3REF: Define New Collating Sequences
1878**
1879** These functions are used to add new collation sequences to the
1880** [sqlite3*] handle specified as the first argument.
danielk19777cedc8d2004-06-10 10:50:08 +00001881**
1882** The name of the new collation sequence is specified as a UTF-8 string
drh6ed48bf2007-06-14 20:57:18 +00001883** for sqlite3_create_collation() and sqlite3_create_collation_v2()
1884** and a UTF-16 string for sqlite3_create_collation16(). In all cases
1885** the name is passed as the second function argument.
danielk19777cedc8d2004-06-10 10:50:08 +00001886**
drh6ed48bf2007-06-14 20:57:18 +00001887** The third argument must be one of the constants [SQLITE_UTF8],
1888** [SQLITE_UTF16LE] or [SQLITE_UTF16BE], indicating that the user-supplied
danielk19777cedc8d2004-06-10 10:50:08 +00001889** routine expects to be passed pointers to strings encoded using UTF-8,
1890** UTF-16 little-endian or UTF-16 big-endian respectively.
1891**
1892** A pointer to the user supplied routine must be passed as the fifth
1893** argument. If it is NULL, this is the same as deleting the collation
1894** sequence (so that SQLite cannot call it anymore). Each time the user
1895** supplied function is invoked, it is passed a copy of the void* passed as
1896** the fourth argument to sqlite3_create_collation() or
1897** sqlite3_create_collation16() as its first parameter.
1898**
1899** The remaining arguments to the user-supplied routine are two strings,
1900** each represented by a [length, data] pair and encoded in the encoding
1901** that was passed as the third argument when the collation sequence was
1902** registered. The user routine should return negative, zero or positive if
1903** the first string is less than, equal to, or greater than the second
1904** string. i.e. (STRING1 - STRING2).
drh6ed48bf2007-06-14 20:57:18 +00001905**
1906** The sqlite3_create_collation_v2() works like sqlite3_create_collation()
1907** excapt that it takes an extra argument which is a destructor for
1908** the collation. The destructor is called when the collation is
1909** destroyed and is passed a copy of the fourth parameter void* pointer
1910** of the sqlite3_create_collation_v2(). Collations are destroyed when
1911** they are overridden by later calls to the collation creation functions
1912** or when the [sqlite3*] database handle is closed using [sqlite3_close()].
1913**
1914** The sqlite3_create_collation_v2() interface is experimental and
1915** subject to change in future releases. The other collation creation
1916** functions are stable.
danielk19777cedc8d2004-06-10 10:50:08 +00001917*/
danielk19770202b292004-06-09 09:55:16 +00001918int sqlite3_create_collation(
1919 sqlite3*,
1920 const char *zName,
danielk19777cedc8d2004-06-10 10:50:08 +00001921 int eTextRep,
danielk19770202b292004-06-09 09:55:16 +00001922 void*,
1923 int(*xCompare)(void*,int,const void*,int,const void*)
1924);
drh6ed48bf2007-06-14 20:57:18 +00001925int sqlite3_create_collation_v2(
1926 sqlite3*,
1927 const char *zName,
1928 int eTextRep,
1929 void*,
1930 int(*xCompare)(void*,int,const void*,int,const void*),
1931 void(*xDestroy)(void*)
1932);
danielk19770202b292004-06-09 09:55:16 +00001933int sqlite3_create_collation16(
1934 sqlite3*,
1935 const char *zName,
danielk19777cedc8d2004-06-10 10:50:08 +00001936 int eTextRep,
danielk19770202b292004-06-09 09:55:16 +00001937 void*,
1938 int(*xCompare)(void*,int,const void*,int,const void*)
1939);
1940
danielk19777cedc8d2004-06-10 10:50:08 +00001941/*
drh6ed48bf2007-06-14 20:57:18 +00001942** CAPI3REF: Collation Needed Callbacks
danielk1977a393c032007-05-07 14:58:53 +00001943**
danielk19777cedc8d2004-06-10 10:50:08 +00001944** To avoid having to register all collation sequences before a database
1945** can be used, a single callback function may be registered with the
1946** database handle to be called whenever an undefined collation sequence is
1947** required.
1948**
1949** If the function is registered using the sqlite3_collation_needed() API,
1950** then it is passed the names of undefined collation sequences as strings
1951** encoded in UTF-8. If sqlite3_collation_needed16() is used, the names
1952** are passed as UTF-16 in machine native byte order. A call to either
1953** function replaces any existing callback.
1954**
drh6ed48bf2007-06-14 20:57:18 +00001955** When the callback is invoked, the first argument passed is a copy
danielk19777cedc8d2004-06-10 10:50:08 +00001956** of the second argument to sqlite3_collation_needed() or
1957** sqlite3_collation_needed16(). The second argument is the database
drh6ed48bf2007-06-14 20:57:18 +00001958** handle. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE], or
1959** [SQLITE_UTF16LE], indicating the most desirable form of the collation
danielk19777cedc8d2004-06-10 10:50:08 +00001960** sequence function required. The fourth parameter is the name of the
1961** required collation sequence.
1962**
drh6ed48bf2007-06-14 20:57:18 +00001963** The callback function should register the desired collation using
1964** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
1965** [sqlite3_create_collation_v2()].
danielk19777cedc8d2004-06-10 10:50:08 +00001966*/
1967int sqlite3_collation_needed(
1968 sqlite3*,
1969 void*,
1970 void(*)(void*,sqlite3*,int eTextRep,const char*)
1971);
1972int sqlite3_collation_needed16(
1973 sqlite3*,
1974 void*,
1975 void(*)(void*,sqlite3*,int eTextRep,const void*)
1976);
1977
drh2011d5f2004-07-22 02:40:37 +00001978/*
1979** Specify the key for an encrypted database. This routine should be
1980** called right after sqlite3_open().
1981**
1982** The code to implement this API is not available in the public release
1983** of SQLite.
1984*/
1985int sqlite3_key(
1986 sqlite3 *db, /* Database to be rekeyed */
1987 const void *pKey, int nKey /* The key */
1988);
1989
1990/*
1991** Change the key on an open database. If the current database is not
1992** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the
1993** database is decrypted.
1994**
1995** The code to implement this API is not available in the public release
1996** of SQLite.
1997*/
1998int sqlite3_rekey(
1999 sqlite3 *db, /* Database to be rekeyed */
2000 const void *pKey, int nKey /* The new key */
2001);
danielk19770202b292004-06-09 09:55:16 +00002002
drhab3f9fe2004-08-14 17:10:10 +00002003/*
drh6ed48bf2007-06-14 20:57:18 +00002004** CAPI3REF: Suspend Execution For A Short Time
2005**
danielk1977d84d4832007-06-20 09:09:47 +00002006** This function causes the current thread to suspend execution
drh6ed48bf2007-06-14 20:57:18 +00002007** a number of milliseconds specified in its parameter.
danielk1977600dd0b2005-01-20 01:14:23 +00002008**
2009** If the operating system does not support sleep requests with
drh6ed48bf2007-06-14 20:57:18 +00002010** millisecond time resolution, then the time will be rounded up to
2011** the nearest second. The number of milliseconds of sleep actually
danielk1977600dd0b2005-01-20 01:14:23 +00002012** requested from the operating system is returned.
danielk1977600dd0b2005-01-20 01:14:23 +00002013*/
2014int sqlite3_sleep(int);
2015
2016/*
drh6ed48bf2007-06-14 20:57:18 +00002017** CAPI3REF: Name Of The Folder Holding Temporary Files
drhd89bd002005-01-22 03:03:54 +00002018**
drh6ed48bf2007-06-14 20:57:18 +00002019** If this global variable is made to point to a string which is
2020** the name of a folder (a.ka. directory), then all temporary files
drhab3f9fe2004-08-14 17:10:10 +00002021** created by SQLite will be placed in that directory. If this variable
2022** is NULL pointer, then SQLite does a search for an appropriate temporary
2023** file directory.
2024**
drh6ed48bf2007-06-14 20:57:18 +00002025** Once [sqlite3_open()] has been called, changing this variable will
2026** invalidate the current temporary database, if any. Generally speaking,
2027** it is not safe to invoke this routine after [sqlite3_open()] has
2028** been called.
drhab3f9fe2004-08-14 17:10:10 +00002029*/
drh73be5012007-08-08 12:11:21 +00002030SQLITE_EXTERN char *sqlite3_temp_directory;
drhab3f9fe2004-08-14 17:10:10 +00002031
danielk19776b456a22005-03-21 04:04:02 +00002032/*
drh6ed48bf2007-06-14 20:57:18 +00002033** CAPI3REF: Test To See If The Databse Is In Auto-Commit Mode
danielk19776b456a22005-03-21 04:04:02 +00002034**
drh3e1d8e62005-05-26 16:23:34 +00002035** Test to see whether or not the database connection is in autocommit
2036** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on
2037** by default. Autocommit is disabled by a BEGIN statement and reenabled
2038** by the next COMMIT or ROLLBACK.
drh3e1d8e62005-05-26 16:23:34 +00002039*/
2040int sqlite3_get_autocommit(sqlite3*);
2041
drh51942bc2005-06-12 22:01:42 +00002042/*
drh6ed48bf2007-06-14 20:57:18 +00002043** CAPI3REF: Find The Database Handle Associated With A Prepared Statement
2044**
2045** Return the [sqlite3*] database handle to which a
2046** [sqlite3_stmt | prepared statement] belongs.
2047** This is the same database handle that was
2048** the first argument to the [sqlite3_prepare_v2()] or its variants
2049** that was used to create the statement in the first place.
drh51942bc2005-06-12 22:01:42 +00002050*/
2051sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
drh3e1d8e62005-05-26 16:23:34 +00002052
drh6ed48bf2007-06-14 20:57:18 +00002053
drhb37df7b2005-10-13 02:09:49 +00002054/*
drh6ed48bf2007-06-14 20:57:18 +00002055** CAPI3REF: Commit And Rollback Notification Callbacks
2056**
2057** These routines
2058** register callback functions to be invoked whenever a transaction
2059** is committed or rolled back. The pArg argument is passed through
2060** to the callback. If the callback on a commit hook function
2061** returns non-zero, then the commit is converted into a rollback.
2062**
2063** If another function was previously registered, its pArg value is returned.
2064** Otherwise NULL is returned.
2065**
2066** Registering a NULL function disables the callback.
2067**
2068** For the purposes of this API, a transaction is said to have been
2069** rolled back if an explicit "ROLLBACK" statement is executed, or
2070** an error or constraint causes an implicit rollback to occur. The
2071** callback is not invoked if a transaction is automatically rolled
2072** back because the database connection is closed.
2073**
2074** These are experimental interfaces and are subject to change.
2075*/
2076void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
2077void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
2078
2079/*
2080** CAPI3REF: Data Change Notification Callbacks
2081**
danielk197794eb6a12005-12-15 15:22:08 +00002082** Register a callback function with the database connection identified by the
2083** first argument to be invoked whenever a row is updated, inserted or deleted.
2084** Any callback set by a previous call to this function for the same
2085** database connection is overridden.
2086**
2087** The second argument is a pointer to the function to invoke when a
2088** row is updated, inserted or deleted. The first argument to the callback is
drh6ed48bf2007-06-14 20:57:18 +00002089** a copy of the third argument to sqlite3_update_hook(). The second callback
danielk197794eb6a12005-12-15 15:22:08 +00002090** argument is one of SQLITE_INSERT, SQLITE_DELETE or SQLITE_UPDATE, depending
2091** on the operation that caused the callback to be invoked. The third and
2092** fourth arguments to the callback contain pointers to the database and
2093** table name containing the affected row. The final callback parameter is
2094** the rowid of the row. In the case of an update, this is the rowid after
2095** the update takes place.
2096**
2097** The update hook is not invoked when internal system tables are
2098** modified (i.e. sqlite_master and sqlite_sequence).
danielk197771fd80b2005-12-16 06:54:01 +00002099**
2100** If another function was previously registered, its pArg value is returned.
2101** Otherwise NULL is returned.
danielk197794eb6a12005-12-15 15:22:08 +00002102*/
danielk197771fd80b2005-12-16 06:54:01 +00002103void *sqlite3_update_hook(
danielk197794eb6a12005-12-15 15:22:08 +00002104 sqlite3*,
2105 void(*)(void *,int ,char const *,char const *,sqlite_int64),
2106 void*
2107);
danielk197713a68c32005-12-15 10:11:30 +00002108
danielk1977f3f06bb2005-12-16 15:24:28 +00002109/*
drh6ed48bf2007-06-14 20:57:18 +00002110** CAPI3REF: Enable Or Disable Shared Pager Cache
danielk1977f3f06bb2005-12-16 15:24:28 +00002111**
drh6ed48bf2007-06-14 20:57:18 +00002112** This routine enables or disables the sharing of the database cache
2113** and schema data structures between connections to the same database.
2114** Sharing is enabled if the argument is true and disabled if the argument
2115** is false.
danielk1977f3f06bb2005-12-16 15:24:28 +00002116**
drh6ed48bf2007-06-14 20:57:18 +00002117** Cache sharing is enabled and disabled on a thread-by-thread basis.
2118** Each call to this routine enables or disables cache sharing only for
2119** connections created in the same thread in which this routine is called.
2120** There is no mechanism for sharing cache between database connections
2121** running in different threads.
2122**
2123** Sharing must be disabled prior to shutting down a thread or else
2124** the thread will leak memory. Call this routine with an argument of
2125** 0 to turn off sharing. Or use the sqlite3_thread_cleanup() API.
2126**
2127** This routine must not be called when any database connections
2128** are active in the current thread. Enabling or disabling shared
2129** cache while there are active database connections will result
2130** in memory corruption.
2131**
2132** When the shared cache is enabled, the
2133** following routines must always be called from the same thread:
2134** [sqlite3_open()], [sqlite3_prepare_v2()], [sqlite3_step()],
2135** [sqlite3_reset()], [sqlite3_finalize()], and [sqlite3_close()].
2136** This is due to the fact that the shared cache makes use of
2137** thread-specific storage so that it will be available for sharing
2138** with other connections.
2139**
2140** Virtual tables cannot be used with a shared cache. When shared
2141** cache is enabled, the sqlite3_create_module() API used to register
2142** virtual tables will always return an error.
2143**
2144** This routine returns [SQLITE_OK] if shared cache was
2145** enabled or disabled successfully. An [SQLITE_ERROR | error code]
2146** is returned otherwise.
2147**
2148** Shared cache is disabled by default for backward compatibility.
danielk1977aef0bf62005-12-30 16:28:01 +00002149*/
2150int sqlite3_enable_shared_cache(int);
2151
2152/*
drh6ed48bf2007-06-14 20:57:18 +00002153** CAPI3REF: Attempt To Free Heap Memory
2154**
danielk197752622822006-01-09 09:59:49 +00002155** Attempt to free N bytes of heap memory by deallocating non-essential
2156** memory allocations held by the database library (example: memory
2157** used to cache database pages to improve performance).
2158**
drh6f7adc82006-01-11 21:41:20 +00002159** This function is not a part of standard builds. It is only created
2160** if SQLite is compiled with the SQLITE_ENABLE_MEMORY_MANAGEMENT macro.
danielk197752622822006-01-09 09:59:49 +00002161*/
2162int sqlite3_release_memory(int);
2163
2164/*
drh6ed48bf2007-06-14 20:57:18 +00002165** CAPI3REF: Impose A Limit On Heap Size
2166**
danielk197752622822006-01-09 09:59:49 +00002167** Place a "soft" limit on the amount of heap memory that may be allocated by
2168** SQLite within the current thread. If an internal allocation is requested
drh6ed48bf2007-06-14 20:57:18 +00002169** that would exceed the specified limit, [sqlite3_release_memory()] is invoked
danielk197752622822006-01-09 09:59:49 +00002170** one or more times to free up some space before the allocation is made.
2171**
drh6ed48bf2007-06-14 20:57:18 +00002172** The limit is called "soft", because if [sqlite3_release_memory()] cannot free
danielk197752622822006-01-09 09:59:49 +00002173** sufficient memory to prevent the limit from being exceeded, the memory is
2174** allocated anyway and the current operation proceeds.
2175**
drh6ed48bf2007-06-14 20:57:18 +00002176** Prior to shutting down a thread sqlite3_soft_heap_limit() must be set to
2177** zero (the default) or else the thread will leak memory. Alternatively, use
2178** the [sqlite3_thread_cleanup()] API.
2179**
2180** A negative or zero value for N means that there is no soft heap limit and
2181** [sqlite3_release_memory()] will only be called when memory is exhaused.
2182** The default value for the soft heap limit is zero.
2183**
2184** SQLite makes a best effort to honor the soft heap limit. But if it
2185** is unable to reduce memory usage below the soft limit, execution will
2186** continue without error or notification. This is why the limit is
2187** called a "soft" limit. It is advisory only.
2188**
drh6f7adc82006-01-11 21:41:20 +00002189** This function is only available if the library was compiled with the
2190** SQLITE_ENABLE_MEMORY_MANAGEMENT option set.
danielk197752622822006-01-09 09:59:49 +00002191** memory-management has been enabled.
2192*/
drhd2d4a6b2006-01-10 15:18:27 +00002193void sqlite3_soft_heap_limit(int);
danielk197752622822006-01-09 09:59:49 +00002194
2195/*
drh6ed48bf2007-06-14 20:57:18 +00002196** CAPI3REF: Clean Up Thread Local Storage
2197**
drh6f7adc82006-01-11 21:41:20 +00002198** This routine makes sure that all thread-local storage has been
2199** deallocated for the current thread.
2200**
2201** This routine is not technically necessary. All thread-local storage
2202** will be automatically deallocated once memory-management and
2203** shared-cache are disabled and the soft heap limit has been set
2204** to zero. This routine is provided as a convenience for users who
2205** want to make absolutely sure they have not forgotten something
2206** prior to killing off a thread.
2207*/
2208void sqlite3_thread_cleanup(void);
2209
2210/*
drh6ed48bf2007-06-14 20:57:18 +00002211** CAPI3REF: Extract Metadata About A Column Of A Table
2212**
2213** This routine
2214** returns meta-data about a specific column of a specific database
danielk1977deb802c2006-02-09 13:43:28 +00002215** table accessible using the connection handle passed as the first function
2216** argument.
2217**
2218** The column is identified by the second, third and fourth parameters to
2219** this function. The second parameter is either the name of the database
2220** (i.e. "main", "temp" or an attached database) containing the specified
2221** table or NULL. If it is NULL, then all attached databases are searched
2222** for the table using the same algorithm as the database engine uses to
2223** resolve unqualified table references.
2224**
2225** The third and fourth parameters to this function are the table and column
2226** name of the desired column, respectively. Neither of these parameters
2227** may be NULL.
2228**
2229** Meta information is returned by writing to the memory locations passed as
2230** the 5th and subsequent parameters to this function. Any of these
2231** arguments may be NULL, in which case the corresponding element of meta
2232** information is ommitted.
2233**
drh6ed48bf2007-06-14 20:57:18 +00002234** <pre>
danielk1977deb802c2006-02-09 13:43:28 +00002235** Parameter Output Type Description
2236** -----------------------------------
2237**
2238** 5th const char* Data type
2239** 6th const char* Name of the default collation sequence
2240** 7th int True if the column has a NOT NULL constraint
2241** 8th int True if the column is part of the PRIMARY KEY
2242** 9th int True if the column is AUTOINCREMENT
drh6ed48bf2007-06-14 20:57:18 +00002243** </pre>
danielk1977deb802c2006-02-09 13:43:28 +00002244**
2245**
2246** The memory pointed to by the character pointers returned for the
2247** declaration type and collation sequence is valid only until the next
2248** call to any sqlite API function.
2249**
2250** If the specified table is actually a view, then an error is returned.
2251**
2252** If the specified column is "rowid", "oid" or "_rowid_" and an
2253** INTEGER PRIMARY KEY column has been explicitly declared, then the output
2254** parameters are set for the explicitly declared column. If there is no
2255** explicitly declared IPK column, then the output parameters are set as
2256** follows:
2257**
drh6ed48bf2007-06-14 20:57:18 +00002258** <pre>
danielk1977deb802c2006-02-09 13:43:28 +00002259** data type: "INTEGER"
2260** collation sequence: "BINARY"
2261** not null: 0
2262** primary key: 1
2263** auto increment: 0
drh6ed48bf2007-06-14 20:57:18 +00002264** </pre>
danielk1977deb802c2006-02-09 13:43:28 +00002265**
2266** This function may load one or more schemas from database files. If an
2267** error occurs during this process, or if the requested table or column
2268** cannot be found, an SQLITE error code is returned and an error message
2269** left in the database handle (to be retrieved using sqlite3_errmsg()).
danielk19774b1ae992006-02-10 03:06:10 +00002270**
2271** This API is only available if the library was compiled with the
2272** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined.
danielk1977deb802c2006-02-09 13:43:28 +00002273*/
2274int sqlite3_table_column_metadata(
2275 sqlite3 *db, /* Connection handle */
2276 const char *zDbName, /* Database name or NULL */
2277 const char *zTableName, /* Table name */
2278 const char *zColumnName, /* Column name */
2279 char const **pzDataType, /* OUTPUT: Declared data type */
2280 char const **pzCollSeq, /* OUTPUT: Collation sequence name */
2281 int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */
2282 int *pPrimaryKey, /* OUTPUT: True if column part of PK */
2283 int *pAutoinc /* OUTPUT: True if colums is auto-increment */
2284);
2285
2286/*
drh6ed48bf2007-06-14 20:57:18 +00002287** CAPI3REF: Load An Extension
drh1e397f82006-06-08 15:28:43 +00002288**
2289** Attempt to load an SQLite extension library contained in the file
2290** zFile. The entry point is zProc. zProc may be 0 in which case the
drhc2e87a32006-06-27 15:16:14 +00002291** name of the entry point defaults to "sqlite3_extension_init".
drh1e397f82006-06-08 15:28:43 +00002292**
drh6ed48bf2007-06-14 20:57:18 +00002293** Return [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
drh1e397f82006-06-08 15:28:43 +00002294**
2295** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with
2296** error message text. The calling function should free this memory
drh6ed48bf2007-06-14 20:57:18 +00002297** by calling [sqlite3_free()].
drh1e397f82006-06-08 15:28:43 +00002298**
drh6ed48bf2007-06-14 20:57:18 +00002299** Extension loading must be enabled using [sqlite3_enable_load_extension()]
drhc2e87a32006-06-27 15:16:14 +00002300** prior to calling this API or an error will be returned.
drh1e397f82006-06-08 15:28:43 +00002301*/
2302int sqlite3_load_extension(
2303 sqlite3 *db, /* Load the extension into this database connection */
2304 const char *zFile, /* Name of the shared library containing extension */
2305 const char *zProc, /* Entry point. Derived from zFile if 0 */
2306 char **pzErrMsg /* Put error message here if not 0 */
2307);
2308
2309/*
drh6ed48bf2007-06-14 20:57:18 +00002310** CAPI3REF: Enable Or Disable Extension Loading
2311**
drhc2e87a32006-06-27 15:16:14 +00002312** So as not to open security holes in older applications that are
drh6ed48bf2007-06-14 20:57:18 +00002313** unprepared to deal with extension loading, and as a means of disabling
2314** extension loading while evaluating user-entered SQL, the following
2315** API is provided to turn the [sqlite3_load_extension()] mechanism on and
drhc2e87a32006-06-27 15:16:14 +00002316** off. It is off by default. See ticket #1863.
2317**
2318** Call this routine with onoff==1 to turn extension loading on
2319** and call it with onoff==0 to turn it back off again.
2320*/
2321int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
2322
2323/*
drh6ed48bf2007-06-14 20:57:18 +00002324** CAPI3REF: Make Arrangements To Automatically Load An Extension
drh9eff6162006-06-12 21:59:13 +00002325**
drh1409be62006-08-23 20:07:20 +00002326** Register an extension entry point that is automatically invoked
drh6ed48bf2007-06-14 20:57:18 +00002327** whenever a new database connection is opened using
2328** [sqlite3_open()] or [sqlite3_open16()].
drh1409be62006-08-23 20:07:20 +00002329**
2330** This API can be invoked at program startup in order to register
2331** one or more statically linked extensions that will be available
2332** to all new database connections.
2333**
2334** Duplicate extensions are detected so calling this routine multiple
2335** times with the same extension is harmless.
2336**
2337** This routine stores a pointer to the extension in an array
2338** that is obtained from malloc(). If you run a memory leak
2339** checker on your program and it reports a leak because of this
drh6ed48bf2007-06-14 20:57:18 +00002340** array, then invoke [sqlite3_automatic_extension_reset()] prior
drh1409be62006-08-23 20:07:20 +00002341** to shutdown to free the memory.
2342**
2343** Automatic extensions apply across all threads.
drh6ed48bf2007-06-14 20:57:18 +00002344**
2345** This interface is experimental and is subject to change or
2346** removal in future releases of SQLite.
drh1409be62006-08-23 20:07:20 +00002347*/
2348int sqlite3_auto_extension(void *xEntryPoint);
2349
2350
2351/*
drh6ed48bf2007-06-14 20:57:18 +00002352** CAPI3REF: Reset Automatic Extension Loading
drh1409be62006-08-23 20:07:20 +00002353**
2354** Disable all previously registered automatic extensions. This
drh6ed48bf2007-06-14 20:57:18 +00002355** routine undoes the effect of all prior [sqlite3_automatic_extension()]
drh1409be62006-08-23 20:07:20 +00002356** calls.
2357**
2358** This call disabled automatic extensions in all threads.
drh6ed48bf2007-06-14 20:57:18 +00002359**
2360** This interface is experimental and is subject to change or
2361** removal in future releases of SQLite.
drh1409be62006-08-23 20:07:20 +00002362*/
2363void sqlite3_reset_auto_extension(void);
2364
2365
2366/*
2367****** EXPERIMENTAL - subject to change without notice **************
2368**
drh9eff6162006-06-12 21:59:13 +00002369** The interface to the virtual-table mechanism is currently considered
2370** to be experimental. The interface might change in incompatible ways.
2371** If this is a problem for you, do not use the interface at this time.
2372**
2373** When the virtual-table mechanism stablizes, we will declare the
2374** interface fixed, support it indefinitely, and remove this comment.
2375*/
2376
2377/*
2378** Structures used by the virtual table interface
drhe09daa92006-06-10 13:29:31 +00002379*/
2380typedef struct sqlite3_vtab sqlite3_vtab;
2381typedef struct sqlite3_index_info sqlite3_index_info;
2382typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;
2383typedef struct sqlite3_module sqlite3_module;
drh9eff6162006-06-12 21:59:13 +00002384
2385/*
2386** A module is a class of virtual tables. Each module is defined
2387** by an instance of the following structure. This structure consists
2388** mostly of methods for the module.
2389*/
drhe09daa92006-06-10 13:29:31 +00002390struct sqlite3_module {
2391 int iVersion;
danielk19779da9d472006-06-14 06:58:15 +00002392 int (*xCreate)(sqlite3*, void *pAux,
drhe4102962006-09-11 00:34:22 +00002393 int argc, const char *const*argv,
drh4ca8aac2006-09-10 17:31:58 +00002394 sqlite3_vtab **ppVTab, char**);
danielk19779da9d472006-06-14 06:58:15 +00002395 int (*xConnect)(sqlite3*, void *pAux,
drhe4102962006-09-11 00:34:22 +00002396 int argc, const char *const*argv,
drh4ca8aac2006-09-10 17:31:58 +00002397 sqlite3_vtab **ppVTab, char**);
drhe09daa92006-06-10 13:29:31 +00002398 int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
2399 int (*xDisconnect)(sqlite3_vtab *pVTab);
2400 int (*xDestroy)(sqlite3_vtab *pVTab);
2401 int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);
2402 int (*xClose)(sqlite3_vtab_cursor*);
drh4be8b512006-06-13 23:51:34 +00002403 int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
drhe09daa92006-06-10 13:29:31 +00002404 int argc, sqlite3_value **argv);
2405 int (*xNext)(sqlite3_vtab_cursor*);
danielk1977a298e902006-06-22 09:53:48 +00002406 int (*xEof)(sqlite3_vtab_cursor*);
drhe09daa92006-06-10 13:29:31 +00002407 int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int);
2408 int (*xRowid)(sqlite3_vtab_cursor*, sqlite_int64 *pRowid);
danielk19771f6eec52006-06-16 06:17:47 +00002409 int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite_int64 *);
drhe09daa92006-06-10 13:29:31 +00002410 int (*xBegin)(sqlite3_vtab *pVTab);
2411 int (*xSync)(sqlite3_vtab *pVTab);
2412 int (*xCommit)(sqlite3_vtab *pVTab);
2413 int (*xRollback)(sqlite3_vtab *pVTab);
drhb7f6f682006-07-08 17:06:43 +00002414 int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
drhe94b0c32006-07-08 18:09:15 +00002415 void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
2416 void **ppArg);
danielk1977182c4ba2007-06-27 15:53:34 +00002417
2418 int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
drhe09daa92006-06-10 13:29:31 +00002419};
drh9eff6162006-06-12 21:59:13 +00002420
2421/*
2422** The sqlite3_index_info structure and its substructures is used to
2423** pass information into and receive the reply from the xBestIndex
2424** method of an sqlite3_module. The fields under **Inputs** are the
2425** inputs to xBestIndex and are read-only. xBestIndex inserts its
2426** results into the **Outputs** fields.
2427**
2428** The aConstraint[] array records WHERE clause constraints of the
2429** form:
2430**
2431** column OP expr
2432**
2433** Where OP is =, <, <=, >, or >=. The particular operator is stored
2434** in aConstraint[].op. The index of the column is stored in
2435** aConstraint[].iColumn. aConstraint[].usable is TRUE if the
2436** expr on the right-hand side can be evaluated (and thus the constraint
2437** is usable) and false if it cannot.
2438**
2439** The optimizer automatically inverts terms of the form "expr OP column"
2440** and makes other simplificatinos to the WHERE clause in an attempt to
2441** get as many WHERE clause terms into the form shown above as possible.
2442** The aConstraint[] array only reports WHERE clause terms in the correct
2443** form that refer to the particular virtual table being queried.
2444**
2445** Information about the ORDER BY clause is stored in aOrderBy[].
2446** Each term of aOrderBy records a column of the ORDER BY clause.
2447**
2448** The xBestIndex method must fill aConstraintUsage[] with information
danielk19775fac9f82006-06-13 14:16:58 +00002449** about what parameters to pass to xFilter. If argvIndex>0 then
drh9eff6162006-06-12 21:59:13 +00002450** the right-hand side of the corresponding aConstraint[] is evaluated
2451** and becomes the argvIndex-th entry in argv. If aConstraintUsage[].omit
2452** is true, then the constraint is assumed to be fully handled by the
2453** virtual table and is not checked again by SQLite.
2454**
drh4be8b512006-06-13 23:51:34 +00002455** The idxNum and idxPtr values are recorded and passed into xFilter.
2456** sqlite3_free() is used to free idxPtr if needToFreeIdxPtr is true.
drh9eff6162006-06-12 21:59:13 +00002457**
2458** The orderByConsumed means that output from xFilter will occur in
2459** the correct order to satisfy the ORDER BY clause so that no separate
2460** sorting step is required.
2461**
2462** The estimatedCost value is an estimate of the cost of doing the
2463** particular lookup. A full scan of a table with N entries should have
2464** a cost of N. A binary search of a table of N entries should have a
2465** cost of approximately log(N).
2466*/
drhe09daa92006-06-10 13:29:31 +00002467struct sqlite3_index_info {
2468 /* Inputs */
drh9eff6162006-06-12 21:59:13 +00002469 const int nConstraint; /* Number of entries in aConstraint */
2470 const struct sqlite3_index_constraint {
2471 int iColumn; /* Column on left-hand side of constraint */
2472 unsigned char op; /* Constraint operator */
2473 unsigned char usable; /* True if this constraint is usable */
2474 int iTermOffset; /* Used internally - xBestIndex should ignore */
2475 } *const aConstraint; /* Table of WHERE clause constraints */
2476 const int nOrderBy; /* Number of terms in the ORDER BY clause */
2477 const struct sqlite3_index_orderby {
2478 int iColumn; /* Column number */
2479 unsigned char desc; /* True for DESC. False for ASC. */
2480 } *const aOrderBy; /* The ORDER BY clause */
drhe09daa92006-06-10 13:29:31 +00002481
2482 /* Outputs */
drh9eff6162006-06-12 21:59:13 +00002483 struct sqlite3_index_constraint_usage {
2484 int argvIndex; /* if >0, constraint is part of argv to xFilter */
2485 unsigned char omit; /* Do not code a test for this constraint */
2486 } *const aConstraintUsage;
drh4be8b512006-06-13 23:51:34 +00002487 int idxNum; /* Number used to identify the index */
2488 char *idxStr; /* String, possibly obtained from sqlite3_malloc */
2489 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
drh9eff6162006-06-12 21:59:13 +00002490 int orderByConsumed; /* True if output is already ordered */
2491 double estimatedCost; /* Estimated cost of using this index */
drhe09daa92006-06-10 13:29:31 +00002492};
drh9eff6162006-06-12 21:59:13 +00002493#define SQLITE_INDEX_CONSTRAINT_EQ 2
2494#define SQLITE_INDEX_CONSTRAINT_GT 4
2495#define SQLITE_INDEX_CONSTRAINT_LE 8
2496#define SQLITE_INDEX_CONSTRAINT_LT 16
2497#define SQLITE_INDEX_CONSTRAINT_GE 32
2498#define SQLITE_INDEX_CONSTRAINT_MATCH 64
2499
2500/*
2501** This routine is used to register a new module name with an SQLite
2502** connection. Module names must be registered before creating new
2503** virtual tables on the module, or before using preexisting virtual
2504** tables of the module.
2505*/
drhb9bb7c12006-06-11 23:41:55 +00002506int sqlite3_create_module(
drh9eff6162006-06-12 21:59:13 +00002507 sqlite3 *db, /* SQLite connection to register module with */
2508 const char *zName, /* Name of the module */
danielk1977d1ab1ba2006-06-15 04:28:13 +00002509 const sqlite3_module *, /* Methods for the module */
2510 void * /* Client data for xCreate/xConnect */
drhb9bb7c12006-06-11 23:41:55 +00002511);
drhe09daa92006-06-10 13:29:31 +00002512
drh9eff6162006-06-12 21:59:13 +00002513/*
danielk1977832a58a2007-06-22 15:21:15 +00002514** This routine is identical to the sqlite3_create_module() method above,
2515** except that it allows a destructor function to be specified. It is
2516** even more experimental than the rest of the virtual tables API.
2517*/
2518int sqlite3_create_module_v2(
2519 sqlite3 *db, /* SQLite connection to register module with */
2520 const char *zName, /* Name of the module */
2521 const sqlite3_module *, /* Methods for the module */
2522 void *, /* Client data for xCreate/xConnect */
2523 void(*xDestroy)(void*) /* Module destructor function */
2524);
2525
2526/*
drh9eff6162006-06-12 21:59:13 +00002527** Every module implementation uses a subclass of the following structure
2528** to describe a particular instance of the module. Each subclass will
2529** be taylored to the specific needs of the module implementation. The
2530** purpose of this superclass is to define certain fields that are common
2531** to all module implementations.
drhfe1368e2006-09-10 17:08:29 +00002532**
2533** Virtual tables methods can set an error message by assigning a
2534** string obtained from sqlite3_mprintf() to zErrMsg. The method should
2535** take care that any prior string is freed by a call to sqlite3_free()
2536** prior to assigning a new string to zErrMsg. After the error message
2537** is delivered up to the client application, the string will be automatically
2538** freed by sqlite3_free() and the zErrMsg field will be zeroed. Note
2539** that sqlite3_mprintf() and sqlite3_free() are used on the zErrMsg field
2540** since virtual tables are commonly implemented in loadable extensions which
2541** do not have access to sqlite3MPrintf() or sqlite3Free().
drh9eff6162006-06-12 21:59:13 +00002542*/
2543struct sqlite3_vtab {
drha967e882006-06-13 01:04:52 +00002544 const sqlite3_module *pModule; /* The module for this virtual table */
danielk1977be718892006-06-23 08:05:19 +00002545 int nRef; /* Used internally */
drh4ca8aac2006-09-10 17:31:58 +00002546 char *zErrMsg; /* Error message from sqlite3_mprintf() */
drh9eff6162006-06-12 21:59:13 +00002547 /* Virtual table implementations will typically add additional fields */
2548};
2549
2550/* Every module implementation uses a subclass of the following structure
2551** to describe cursors that point into the virtual table and are used
2552** to loop through the virtual table. Cursors are created using the
2553** xOpen method of the module. Each module implementation will define
2554** the content of a cursor structure to suit its own needs.
2555**
2556** This superclass exists in order to define fields of the cursor that
2557** are common to all implementations.
2558*/
2559struct sqlite3_vtab_cursor {
2560 sqlite3_vtab *pVtab; /* Virtual table of this cursor */
2561 /* Virtual table implementations will typically add additional fields */
2562};
2563
2564/*
2565** The xCreate and xConnect methods of a module use the following API
2566** to declare the format (the names and datatypes of the columns) of
2567** the virtual tables they implement.
2568*/
danielk19777e6ebfb2006-06-12 11:24:37 +00002569int sqlite3_declare_vtab(sqlite3*, const char *zCreateTable);
drhe09daa92006-06-10 13:29:31 +00002570
2571/*
drhb7481e72006-09-16 21:45:14 +00002572** Virtual tables can provide alternative implementations of functions
2573** using the xFindFunction method. But global versions of those functions
2574** must exist in order to be overloaded.
2575**
2576** This API makes sure a global version of a function with a particular
2577** name and number of parameters exists. If no such function exists
2578** before this API is called, a new function is created. The implementation
2579** of the new function always causes an exception to be thrown. So
2580** the new function is not good for anything by itself. Its only
2581** purpose is to be a place-holder function that can be overloaded
2582** by virtual tables.
2583**
2584** This API should be considered part of the virtual table interface,
2585** which is experimental and subject to change.
2586*/
2587int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
2588
2589/*
drh9eff6162006-06-12 21:59:13 +00002590** The interface to the virtual-table mechanism defined above (back up
2591** to a comment remarkably similar to this one) is currently considered
2592** to be experimental. The interface might change in incompatible ways.
2593** If this is a problem for you, do not use the interface at this time.
2594**
2595** When the virtual-table mechanism stablizes, we will declare the
2596** interface fixed, support it indefinitely, and remove this comment.
2597**
2598****** EXPERIMENTAL - subject to change without notice **************
2599*/
2600
danielk19778cbadb02007-05-03 16:31:26 +00002601/*
drh6ed48bf2007-06-14 20:57:18 +00002602** CAPI3REF: A Handle To An Open BLOB
2603**
danielk19778cbadb02007-05-03 16:31:26 +00002604** An instance of the following opaque structure is used to
drh6ed48bf2007-06-14 20:57:18 +00002605** represent an blob-handle. A blob-handle is created by
2606** [sqlite3_blob_open()] and destroyed by [sqlite3_blob_close()].
2607** The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces
2608** can be used to read or write small subsections of the blob.
2609** The [sqltie3_blob_size()] interface returns the size of the
2610** blob in bytes.
danielk19778cbadb02007-05-03 16:31:26 +00002611*/
danielk1977b4e9af92007-05-01 17:49:49 +00002612typedef struct sqlite3_blob sqlite3_blob;
2613
danielk19778cbadb02007-05-03 16:31:26 +00002614/*
drh6ed48bf2007-06-14 20:57:18 +00002615** CAPI3REF: Open A BLOB For Incremental I/O
2616**
danielk19778cbadb02007-05-03 16:31:26 +00002617** Open a handle to the blob located in row iRow,, column zColumn,
2618** table zTable in database zDb. i.e. the same blob that would
2619** be selected by:
2620**
drh6ed48bf2007-06-14 20:57:18 +00002621** <pre>
2622** SELECT zColumn FROM zDb.zTable WHERE rowid = iRow;
2623** </pre>
danielk19778cbadb02007-05-03 16:31:26 +00002624**
2625** If the flags parameter is non-zero, the blob is opened for
2626** read and write access. If it is zero, the blob is opened for read
2627** access.
2628**
drh6ed48bf2007-06-14 20:57:18 +00002629** On success, [SQLITE_OK] is returned and the new
2630** [sqlite3_blob | blob handle] is written to *ppBlob.
2631** Otherwise an error code is returned and
danielk19778cbadb02007-05-03 16:31:26 +00002632** any value written to *ppBlob should not be used by the caller.
2633** This function sets the database-handle error code and message
drh6ed48bf2007-06-14 20:57:18 +00002634** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()].
danielk19778cbadb02007-05-03 16:31:26 +00002635*/
danielk1977b4e9af92007-05-01 17:49:49 +00002636int sqlite3_blob_open(
2637 sqlite3*,
2638 const char *zDb,
2639 const char *zTable,
2640 const char *zColumn,
2641 sqlite_int64 iRow,
2642 int flags,
2643 sqlite3_blob **ppBlob
2644);
2645
danielk19778cbadb02007-05-03 16:31:26 +00002646/*
drh6ed48bf2007-06-14 20:57:18 +00002647** CAPI3REF: Close A BLOB Handle
2648**
2649** Close an open [sqlite3_blob | blob handle].
danielk19778cbadb02007-05-03 16:31:26 +00002650*/
danielk1977b4e9af92007-05-01 17:49:49 +00002651int sqlite3_blob_close(sqlite3_blob *);
2652
danielk19778cbadb02007-05-03 16:31:26 +00002653/*
drh6ed48bf2007-06-14 20:57:18 +00002654** CAPI3REF: Return The Size Of An Open BLOB
2655**
danielk19778cbadb02007-05-03 16:31:26 +00002656** Return the size in bytes of the blob accessible via the open
drh6ed48bf2007-06-14 20:57:18 +00002657** [sqlite3_blob | blob-handle] passed as an argument.
danielk19778cbadb02007-05-03 16:31:26 +00002658*/
danielk1977b4e9af92007-05-01 17:49:49 +00002659int sqlite3_blob_bytes(sqlite3_blob *);
2660
drh9eff6162006-06-12 21:59:13 +00002661/*
drh6ed48bf2007-06-14 20:57:18 +00002662** CAPI3REF: Read Data From A BLOB Incrementally
2663**
2664** This function is used to read data from an open
2665** [sqlite3_blob | blob-handle] into a caller supplied buffer.
2666** n bytes of data are copied into buffer
danielk19778cbadb02007-05-03 16:31:26 +00002667** z from the open blob, starting at offset iOffset.
2668**
drh6ed48bf2007-06-14 20:57:18 +00002669** On success, SQLITE_OK is returned. Otherwise, an
2670** [SQLITE_ERROR | SQLite error code] or an
2671** [SQLITE_IOERR_READ | extended error code] is returned.
danielk19778cbadb02007-05-03 16:31:26 +00002672*/
2673int sqlite3_blob_read(sqlite3_blob *, void *z, int n, int iOffset);
2674
2675/*
drh6ed48bf2007-06-14 20:57:18 +00002676** CAPI3REF: Write Data Into A BLOB Incrementally
2677**
2678** This function is used to write data into an open
2679** [sqlite3_blob | blob-handle] from a user supplied buffer.
2680** n bytes of data are copied from the buffer
danielk19778cbadb02007-05-03 16:31:26 +00002681** pointed to by z into the open blob, starting at offset iOffset.
2682**
drh6ed48bf2007-06-14 20:57:18 +00002683** If the [sqlite3_blob | blob-handle] passed as the first argument
2684** was not opened for writing (the flags parameter to [sqlite3_blob_open()]
2685*** was zero), this function returns [SQLITE_READONLY].
danielk19778cbadb02007-05-03 16:31:26 +00002686**
2687** This function may only modify the contents of the blob, it is
2688** not possible to increase the size of a blob using this API. If
2689** offset iOffset is less than n bytes from the end of the blob,
drh6ed48bf2007-06-14 20:57:18 +00002690** [SQLITE_ERROR] is returned and no data is written.
danielk19778cbadb02007-05-03 16:31:26 +00002691**
drh6ed48bf2007-06-14 20:57:18 +00002692** On success, SQLITE_OK is returned. Otherwise, an
2693** [SQLITE_ERROR | SQLite error code] or an
2694** [SQLITE_IOERR_READ | extended error code] is returned.
danielk19778cbadb02007-05-03 16:31:26 +00002695*/
2696int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
2697
2698/*
drhb37df7b2005-10-13 02:09:49 +00002699** Undo the hack that converts floating point types to integer for
2700** builds on processors without floating point support.
2701*/
2702#ifdef SQLITE_OMIT_FLOATING_POINT
2703# undef double
2704#endif
2705
drh382c0242001-10-06 16:33:02 +00002706#ifdef __cplusplus
2707} /* End of the 'extern "C"' block */
2708#endif
danielk19774adee202004-05-08 08:23:19 +00002709#endif