blob: 1e5cb6aa9d5540b17460d2cb1bb1b38e5e8af4a1 [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
mihailima3f64902008-06-21 13:35:56 +000020** features recently added to SQLite. We do not anticipate changes
drh6ed48bf2007-06-14 20:57:18 +000021** 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**
drhec0a0c82008-08-11 18:29:38 +000033** @(#) $Id: sqlite.h.in,v 1.390 2008/08/11 18:29:38 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
drh6d2069d2007-08-14 01:58:53 +000046
drh382c0242001-10-06 16:33:02 +000047/*
drh73be5012007-08-08 12:11:21 +000048** Add the ability to override 'extern'
49*/
50#ifndef SQLITE_EXTERN
51# define SQLITE_EXTERN extern
52#endif
53
54/*
shanea79c3cc2008-08-11 17:27:01 +000055** Add the ability to mark interfaces as deprecated.
56*/
57#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
58 /* GCC added the deprecated attribute in version 3.1 */
59 #define SQLITE_DEPRECATED __attribute__ ((deprecated))
60#elif defined(_MSC_VER)
61 #define SQLITE_DEPRECATED __declspec(deprecated)
62#else
63 #define SQLITE_DEPRECATED
64#endif
65
66/*
67** Add the ability to mark interfaces as experimental.
68*/
drhec0a0c82008-08-11 18:29:38 +000069#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
shanea79c3cc2008-08-11 17:27:01 +000070 /* GCC added the warning attribute in version 4.0 (I think) */
drhec0a0c82008-08-11 18:29:38 +000071 /* I can confirm that it does not work on version 4.1.0... */
shanea79c3cc2008-08-11 17:27:01 +000072 #define SQLITE_EXPERIMENTAL __attribute__ ((warning ("is experimental")))
73#elif defined(_MSC_VER)
74 #define SQLITE_EXPERIMENTAL __declspec(deprecated("was declared experimental"))
75#else
76 #define SQLITE_EXPERIMENTAL
77#endif
78
79/*
mihailim362cc832008-06-21 06:16:42 +000080** Ensure these symbols were not defined by some previous header file.
drhb86ccfb2003-01-28 23:13:10 +000081*/
drh1e284f42004-10-06 15:52:01 +000082#ifdef SQLITE_VERSION
83# undef SQLITE_VERSION
drh1e284f42004-10-06 15:52:01 +000084#endif
drh6ed48bf2007-06-14 20:57:18 +000085#ifdef SQLITE_VERSION_NUMBER
86# undef SQLITE_VERSION_NUMBER
87#endif
danielk197799ba19e2005-02-05 07:33:34 +000088
89/*
drhb25f9d82008-07-23 15:40:06 +000090** CAPI3REF: Compile-Time Library Version Numbers {H10010} <S60100>
drh6ed48bf2007-06-14 20:57:18 +000091**
drh33c1be32008-01-30 16:16:14 +000092** The SQLITE_VERSION and SQLITE_VERSION_NUMBER #defines in
93** the sqlite3.h file specify the version of SQLite with which
94** that header file is associated.
danielk197799ba19e2005-02-05 07:33:34 +000095**
drh7663e362008-02-14 23:24:16 +000096** The "version" of SQLite is a string of the form "X.Y.Z".
drh33c1be32008-01-30 16:16:14 +000097** The phrase "alpha" or "beta" might be appended after the Z.
98** The X value is major version number always 3 in SQLite3.
mihailim362cc832008-06-21 06:16:42 +000099** The X value only changes when backwards compatibility is
100** broken and we intend to never break backwards compatibility.
101** The Y value is the minor version number and only changes when
drh6ed48bf2007-06-14 20:57:18 +0000102** there are major feature enhancements that are forwards compatible
mihailim362cc832008-06-21 06:16:42 +0000103** but not backwards compatible.
104** The Z value is the release number and is incremented with
105** each release but resets back to 0 whenever Y is incremented.
drh6ed48bf2007-06-14 20:57:18 +0000106**
drh6ed48bf2007-06-14 20:57:18 +0000107** See also: [sqlite3_libversion()] and [sqlite3_libversion_number()].
drh33c1be32008-01-30 16:16:14 +0000108**
109** INVARIANTS:
110**
drh9a247912008-07-22 18:45:08 +0000111** {H10011} The SQLITE_VERSION #define in the sqlite3.h header file shall
drh4766b292008-06-26 02:53:02 +0000112** evaluate to a string literal that is the SQLite version
drhb25f9d82008-07-23 15:40:06 +0000113** with which the header file is associated.
drh33c1be32008-01-30 16:16:14 +0000114**
drh9a247912008-07-22 18:45:08 +0000115** {H10014} The SQLITE_VERSION_NUMBER #define shall resolve to an integer
mihailim362cc832008-06-21 06:16:42 +0000116** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z
117** are the major version, minor version, and release number.
danielk197799ba19e2005-02-05 07:33:34 +0000118*/
drh6ed48bf2007-06-14 20:57:18 +0000119#define SQLITE_VERSION "--VERS--"
drhb4d58ae2008-02-21 20:17:06 +0000120#define SQLITE_VERSION_NUMBER --VERSION-NUMBER--
drhb86ccfb2003-01-28 23:13:10 +0000121
122/*
drh9a247912008-07-22 18:45:08 +0000123** CAPI3REF: Run-Time Library Version Numbers {H10020} <S60100>
drh33c1be32008-01-30 16:16:14 +0000124** KEYWORDS: sqlite3_version
drh6ed48bf2007-06-14 20:57:18 +0000125**
drh33c1be32008-01-30 16:16:14 +0000126** These features provide the same information as the [SQLITE_VERSION]
127** and [SQLITE_VERSION_NUMBER] #defines in the header, but are associated
128** with the library instead of the header file. Cautious programmers might
mihailim362cc832008-06-21 06:16:42 +0000129** include a check in their application to verify that
130** sqlite3_libversion_number() always returns the value
drhfddfa2d2007-12-05 18:05:16 +0000131** [SQLITE_VERSION_NUMBER].
drh6ed48bf2007-06-14 20:57:18 +0000132**
drh33c1be32008-01-30 16:16:14 +0000133** The sqlite3_libversion() function returns the same information as is
134** in the sqlite3_version[] string constant. The function is provided
135** for use in DLLs since DLL users usually do not have direct access to string
drhfddfa2d2007-12-05 18:05:16 +0000136** constants within the DLL.
drh33c1be32008-01-30 16:16:14 +0000137**
138** INVARIANTS:
139**
drh9a247912008-07-22 18:45:08 +0000140** {H10021} The [sqlite3_libversion_number()] interface shall return
drh9cd29642008-07-23 00:52:55 +0000141** an integer equal to [SQLITE_VERSION_NUMBER].
drh33c1be32008-01-30 16:16:14 +0000142**
drh9a247912008-07-22 18:45:08 +0000143** {H10022} The [sqlite3_version] string constant shall contain
drh9cd29642008-07-23 00:52:55 +0000144** the text of the [SQLITE_VERSION] string.
drh33c1be32008-01-30 16:16:14 +0000145**
drh9a247912008-07-22 18:45:08 +0000146** {H10023} The [sqlite3_libversion()] function shall return
drh9cd29642008-07-23 00:52:55 +0000147** a pointer to the [sqlite3_version] string constant.
drhb217a572000-08-22 13:40:18 +0000148*/
drh73be5012007-08-08 12:11:21 +0000149SQLITE_EXTERN const char sqlite3_version[];
drha3f70cb2004-09-30 14:24:50 +0000150const char *sqlite3_libversion(void);
danielk197799ba19e2005-02-05 07:33:34 +0000151int sqlite3_libversion_number(void);
152
153/*
drh9a247912008-07-22 18:45:08 +0000154** CAPI3REF: Test To See If The Library Is Threadsafe {H10100} <S60100>
drhb67e8bf2007-08-30 20:09:48 +0000155**
drh33c1be32008-01-30 16:16:14 +0000156** SQLite can be compiled with or without mutexes. When
drh4766b292008-06-26 02:53:02 +0000157** the [SQLITE_THREADSAFE] C preprocessor macro is true, mutexes
mlcreechb2799412008-03-07 03:20:31 +0000158** are enabled and SQLite is threadsafe. When that macro is false,
drh33c1be32008-01-30 16:16:14 +0000159** the mutexes are omitted. Without the mutexes, it is not safe
mihailim362cc832008-06-21 06:16:42 +0000160** to use SQLite concurrently from more than one thread.
drhb67e8bf2007-08-30 20:09:48 +0000161**
mihailim362cc832008-06-21 06:16:42 +0000162** Enabling mutexes incurs a measurable performance penalty.
drh33c1be32008-01-30 16:16:14 +0000163** So if speed is of utmost importance, it makes sense to disable
164** the mutexes. But for maximum safety, mutexes should be enabled.
165** The default behavior is for mutexes to be enabled.
166**
167** This interface can be used by a program to make sure that the
168** version of SQLite that it is linking against was compiled with
drh4766b292008-06-26 02:53:02 +0000169** the desired setting of the [SQLITE_THREADSAFE] macro.
170**
171** This interface only reports on the compile-time mutex setting
172** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
173** SQLITE_THREADSAFE=1 then mutexes are enabled by default but
174** can be fully or partially disabled using a call to [sqlite3_config()]
175** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
176** or [SQLITE_CONFIG_MUTEX]. The return value of this function shows
177** only the default compile-time setting, not any run-time changes
178** to that setting.
drh33c1be32008-01-30 16:16:14 +0000179**
180** INVARIANTS:
181**
drh9a247912008-07-22 18:45:08 +0000182** {H10101} The [sqlite3_threadsafe()] function shall return nonzero if
drh4766b292008-06-26 02:53:02 +0000183** SQLite was compiled with the its mutexes enabled by default
184** or zero if SQLite was compiled such that mutexes are
drh9cd29642008-07-23 00:52:55 +0000185** permanently disabled.
drh4766b292008-06-26 02:53:02 +0000186**
drh9a247912008-07-22 18:45:08 +0000187** {H10102} The value returned by the [sqlite3_threadsafe()] function
drh4766b292008-06-26 02:53:02 +0000188** shall not change when mutex setting are modified at
189** runtime using the [sqlite3_config()] interface and
190** especially the [SQLITE_CONFIG_SINGLETHREAD],
191** [SQLITE_CONFIG_MULTITHREAD], [SQLITE_CONFIG_SERIALIZED],
drh9cd29642008-07-23 00:52:55 +0000192** and [SQLITE_CONFIG_MUTEX] verbs.
drhb67e8bf2007-08-30 20:09:48 +0000193*/
194int sqlite3_threadsafe(void);
195
196/*
drh9cd29642008-07-23 00:52:55 +0000197** CAPI3REF: Database Connection Handle {H12000} <S40200>
drha06f17f2008-05-11 11:07:06 +0000198** KEYWORDS: {database connection} {database connections}
drh6ed48bf2007-06-14 20:57:18 +0000199**
mihailim362cc832008-06-21 06:16:42 +0000200** Each open SQLite database is represented by a pointer to an instance of
201** the opaque structure named "sqlite3". It is useful to think of an sqlite3
drh8bacf972007-08-25 16:21:29 +0000202** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and
mihailim362cc832008-06-21 06:16:42 +0000203** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
204** is its destructor. There are many other interfaces (such as
205** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
206** [sqlite3_busy_timeout()] to name but three) that are methods on an
207** sqlite3 object.
drh75897232000-05-29 14:26:00 +0000208*/
drh9bb575f2004-09-06 17:24:11 +0000209typedef struct sqlite3 sqlite3;
danielk197765904932004-05-26 06:18:37 +0000210
drh75897232000-05-29 14:26:00 +0000211/*
drh9cd29642008-07-23 00:52:55 +0000212** CAPI3REF: 64-Bit Integer Types {H10200} <S10110>
drh33c1be32008-01-30 16:16:14 +0000213** KEYWORDS: sqlite_int64 sqlite_uint64
drh6ed48bf2007-06-14 20:57:18 +0000214**
drh33c1be32008-01-30 16:16:14 +0000215** Because there is no cross-platform way to specify 64-bit integer types
drhfddfa2d2007-12-05 18:05:16 +0000216** SQLite includes typedefs for 64-bit signed and unsigned integers.
drh6ed48bf2007-06-14 20:57:18 +0000217**
mihailim362cc832008-06-21 06:16:42 +0000218** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
219** The sqlite_int64 and sqlite_uint64 types are supported for backwards
220** compatibility only.
drh33c1be32008-01-30 16:16:14 +0000221**
222** INVARIANTS:
223**
drh9a247912008-07-22 18:45:08 +0000224** {H10201} The [sqlite_int64] and [sqlite3_int64] type shall specify
mihailim362cc832008-06-21 06:16:42 +0000225** a 64-bit signed integer.
drh33c1be32008-01-30 16:16:14 +0000226**
drh9a247912008-07-22 18:45:08 +0000227** {H10202} The [sqlite_uint64] and [sqlite3_uint64] type shall specify
drh33c1be32008-01-30 16:16:14 +0000228** a 64-bit unsigned integer.
drhefad9992004-06-22 12:13:55 +0000229*/
drh27436af2006-03-28 23:57:17 +0000230#ifdef SQLITE_INT64_TYPE
drh9b8f4472006-04-04 01:54:55 +0000231 typedef SQLITE_INT64_TYPE sqlite_int64;
drh27436af2006-03-28 23:57:17 +0000232 typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
233#elif defined(_MSC_VER) || defined(__BORLANDC__)
drhefad9992004-06-22 12:13:55 +0000234 typedef __int64 sqlite_int64;
drh1211de32004-07-26 12:24:22 +0000235 typedef unsigned __int64 sqlite_uint64;
drhefad9992004-06-22 12:13:55 +0000236#else
237 typedef long long int sqlite_int64;
drh1211de32004-07-26 12:24:22 +0000238 typedef unsigned long long int sqlite_uint64;
drhefad9992004-06-22 12:13:55 +0000239#endif
drh6d2069d2007-08-14 01:58:53 +0000240typedef sqlite_int64 sqlite3_int64;
241typedef sqlite_uint64 sqlite3_uint64;
drhefad9992004-06-22 12:13:55 +0000242
drhb37df7b2005-10-13 02:09:49 +0000243/*
244** If compiling for a processor that lacks floating point support,
mihailim362cc832008-06-21 06:16:42 +0000245** substitute integer for floating-point.
drhb37df7b2005-10-13 02:09:49 +0000246*/
247#ifdef SQLITE_OMIT_FLOATING_POINT
drh6d2069d2007-08-14 01:58:53 +0000248# define double sqlite3_int64
drhb37df7b2005-10-13 02:09:49 +0000249#endif
drhefad9992004-06-22 12:13:55 +0000250
251/*
drh9cd29642008-07-23 00:52:55 +0000252** CAPI3REF: Closing A Database Connection {H12010} <S30100><S40200>
drh75897232000-05-29 14:26:00 +0000253**
mihailim362cc832008-06-21 06:16:42 +0000254** This routine is the destructor for the [sqlite3] object.
drh33c1be32008-01-30 16:16:14 +0000255**
mihailim362cc832008-06-21 06:16:42 +0000256** Applications should [sqlite3_finalize | finalize] all [prepared statements]
mihailim15194222008-06-22 09:55:14 +0000257** and [sqlite3_blob_close | close] all [BLOB handles] associated with
mihailim362cc832008-06-21 06:16:42 +0000258** the [sqlite3] object prior to attempting to close the object.
259** The [sqlite3_next_stmt()] interface can be used to locate all
260** [prepared statements] associated with a [database connection] if desired.
261** Typical code might look like this:
drh33c1be32008-01-30 16:16:14 +0000262**
drh55b0cf02008-06-19 17:54:33 +0000263** <blockquote><pre>
264** sqlite3_stmt *pStmt;
265** while( (pStmt = sqlite3_next_stmt(db, 0))!=0 ){
266** &nbsp; sqlite3_finalize(pStmt);
267** }
268** </pre></blockquote>
269**
mihailim362cc832008-06-21 06:16:42 +0000270** If [sqlite3_close()] is invoked while a transaction is open,
drh55b0cf02008-06-19 17:54:33 +0000271** the transaction is automatically rolled back.
drh33c1be32008-01-30 16:16:14 +0000272**
273** INVARIANTS:
274**
drh9a247912008-07-22 18:45:08 +0000275** {H12011} A successful call to [sqlite3_close(C)] shall destroy the
drh4766b292008-06-26 02:53:02 +0000276** [database connection] object C.
drh33c1be32008-01-30 16:16:14 +0000277**
drh9a247912008-07-22 18:45:08 +0000278** {H12012} A successful call to [sqlite3_close(C)] shall return SQLITE_OK.
danielk197796d81f92004-06-19 03:33:57 +0000279**
drh9a247912008-07-22 18:45:08 +0000280** {H12013} A successful call to [sqlite3_close(C)] shall release all
drh4766b292008-06-26 02:53:02 +0000281** memory and system resources associated with [database connection]
282** C.
drhe30f4422007-08-21 16:15:55 +0000283**
drh9a247912008-07-22 18:45:08 +0000284** {H12014} A call to [sqlite3_close(C)] on a [database connection] C that
drh4766b292008-06-26 02:53:02 +0000285** has one or more open [prepared statements] shall fail with
286** an [SQLITE_BUSY] error code.
drh33c1be32008-01-30 16:16:14 +0000287**
drh9a247912008-07-22 18:45:08 +0000288** {H12015} A call to [sqlite3_close(C)] where C is a NULL pointer shall
drh4766b292008-06-26 02:53:02 +0000289** return SQLITE_OK.
290**
drh9a247912008-07-22 18:45:08 +0000291** {H12019} When [sqlite3_close(C)] is invoked on a [database connection] C
drh55b0cf02008-06-19 17:54:33 +0000292** that has a pending transaction, the transaction shall be
293** rolled back.
294**
drh9a247912008-07-22 18:45:08 +0000295** ASSUMPTIONS:
drh33c1be32008-01-30 16:16:14 +0000296**
drh4766b292008-06-26 02:53:02 +0000297** {A12016} The C parameter to [sqlite3_close(C)] must be either a NULL
drh9cd29642008-07-23 00:52:55 +0000298** pointer or an [sqlite3] object pointer obtained
drh4766b292008-06-26 02:53:02 +0000299** from [sqlite3_open()], [sqlite3_open16()], or
300** [sqlite3_open_v2()], and not previously closed.
drh75897232000-05-29 14:26:00 +0000301*/
danielk1977f9d64d22004-06-19 08:18:07 +0000302int sqlite3_close(sqlite3 *);
drh75897232000-05-29 14:26:00 +0000303
304/*
305** The type for a callback function.
drh6ed48bf2007-06-14 20:57:18 +0000306** This is legacy and deprecated. It is included for historical
307** compatibility and is not documented.
drh75897232000-05-29 14:26:00 +0000308*/
drh12057d52004-09-06 17:34:12 +0000309typedef int (*sqlite3_callback)(void*,int,char**, char**);
drh75897232000-05-29 14:26:00 +0000310
311/*
drh9cd29642008-07-23 00:52:55 +0000312** CAPI3REF: One-Step Query Execution Interface {H12100} <S10000>
drh6ed48bf2007-06-14 20:57:18 +0000313**
mihailim362cc832008-06-21 06:16:42 +0000314** The sqlite3_exec() interface is a convenient way of running one or more
315** SQL statements without having to write a lot of C code. The UTF-8 encoded
316** SQL statements are passed in as the second parameter to sqlite3_exec().
317** The statements are evaluated one by one until either an error or
318** an interrupt is encountered, or until they are all done. The 3rd parameter
319** is an optional callback that is invoked once for each row of any query
320** results produced by the SQL statements. The 5th parameter tells where
drh33c1be32008-01-30 16:16:14 +0000321** to write any error messages.
drh75897232000-05-29 14:26:00 +0000322**
drh35c61902008-05-20 15:44:30 +0000323** The error message passed back through the 5th parameter is held
324** in memory obtained from [sqlite3_malloc()]. To avoid a memory leak,
325** the calling application should call [sqlite3_free()] on any error
326** message returned through the 5th parameter when it has finished using
327** the error message.
328**
329** If the SQL statement in the 2nd parameter is NULL or an empty string
mihailim362cc832008-06-21 06:16:42 +0000330** or a string containing only whitespace and comments, then no SQL
331** statements are evaluated and the database is not changed.
drh35c61902008-05-20 15:44:30 +0000332**
drh33c1be32008-01-30 16:16:14 +0000333** The sqlite3_exec() interface is implemented in terms of
334** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()].
drh35c61902008-05-20 15:44:30 +0000335** The sqlite3_exec() routine does nothing to the database that cannot be done
drh33c1be32008-01-30 16:16:14 +0000336** by [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()].
drh75897232000-05-29 14:26:00 +0000337**
drh33c1be32008-01-30 16:16:14 +0000338** INVARIANTS:
mihailima3f64902008-06-21 13:35:56 +0000339**
drh9a247912008-07-22 18:45:08 +0000340** {H12101} A successful invocation of [sqlite3_exec(D,S,C,A,E)]
drh4766b292008-06-26 02:53:02 +0000341** shall sequentially evaluate all of the UTF-8 encoded,
342** semicolon-separated SQL statements in the zero-terminated
343** string S within the context of the [database connection] D.
drh75897232000-05-29 14:26:00 +0000344**
drh9a247912008-07-22 18:45:08 +0000345** {H12102} If the S parameter to [sqlite3_exec(D,S,C,A,E)] is NULL then
drh35c61902008-05-20 15:44:30 +0000346** the actions of the interface shall be the same as if the
mihailim362cc832008-06-21 06:16:42 +0000347** S parameter were an empty string.
drh75897232000-05-29 14:26:00 +0000348**
drh9a247912008-07-22 18:45:08 +0000349** {H12104} The return value of [sqlite3_exec()] shall be [SQLITE_OK] if all
drhf50bebf2008-05-19 23:51:55 +0000350** SQL statements run successfully and to completion.
351**
drh9a247912008-07-22 18:45:08 +0000352** {H12105} The return value of [sqlite3_exec()] shall be an appropriate
drh35c61902008-05-20 15:44:30 +0000353** non-zero [error code] if any SQL statement fails.
drh4dd022a2007-12-01 19:23:19 +0000354**
drh9a247912008-07-22 18:45:08 +0000355** {H12107} If one or more of the SQL statements handed to [sqlite3_exec()]
drh33c1be32008-01-30 16:16:14 +0000356** return results and the 3rd parameter is not NULL, then
drhf50bebf2008-05-19 23:51:55 +0000357** the callback function specified by the 3rd parameter shall be
drh33c1be32008-01-30 16:16:14 +0000358** invoked once for each row of result.
drhb19a2bc2001-09-16 00:13:26 +0000359**
drh9a247912008-07-22 18:45:08 +0000360** {H12110} If the callback returns a non-zero value then [sqlite3_exec()]
shane0c6844e2008-05-21 15:01:21 +0000361** shall abort the SQL statement it is currently evaluating,
drh33c1be32008-01-30 16:16:14 +0000362** skip all subsequent SQL statements, and return [SQLITE_ABORT].
drhf50bebf2008-05-19 23:51:55 +0000363**
drh9a247912008-07-22 18:45:08 +0000364** {H12113} The [sqlite3_exec()] routine shall pass its 4th parameter through
drh33c1be32008-01-30 16:16:14 +0000365** as the 1st parameter of the callback.
366**
drh9a247912008-07-22 18:45:08 +0000367** {H12116} The [sqlite3_exec()] routine shall set the 2nd parameter of its
drh33c1be32008-01-30 16:16:14 +0000368** callback to be the number of columns in the current row of
369** result.
370**
drh9a247912008-07-22 18:45:08 +0000371** {H12119} The [sqlite3_exec()] routine shall set the 3rd parameter of its
drh33c1be32008-01-30 16:16:14 +0000372** callback to be an array of pointers to strings holding the
373** values for each column in the current result set row as
374** obtained from [sqlite3_column_text()].
375**
drh9a247912008-07-22 18:45:08 +0000376** {H12122} The [sqlite3_exec()] routine shall set the 4th parameter of its
drh33c1be32008-01-30 16:16:14 +0000377** callback to be an array of pointers to strings holding the
378** names of result columns as obtained from [sqlite3_column_name()].
379**
drh9a247912008-07-22 18:45:08 +0000380** {H12125} If the 3rd parameter to [sqlite3_exec()] is NULL then
drh4766b292008-06-26 02:53:02 +0000381** [sqlite3_exec()] shall silently discard query results.
drh33c1be32008-01-30 16:16:14 +0000382**
drh9a247912008-07-22 18:45:08 +0000383** {H12131} If an error occurs while parsing or evaluating any of the SQL
drh4766b292008-06-26 02:53:02 +0000384** statements in the S parameter of [sqlite3_exec(D,S,C,A,E)] and if
drh35c61902008-05-20 15:44:30 +0000385** the E parameter is not NULL, then [sqlite3_exec()] shall store
386** in *E an appropriate error message written into memory obtained
drhf50bebf2008-05-19 23:51:55 +0000387** from [sqlite3_malloc()].
drh33c1be32008-01-30 16:16:14 +0000388**
drh9a247912008-07-22 18:45:08 +0000389** {H12134} The [sqlite3_exec(D,S,C,A,E)] routine shall set the value of
drh35c61902008-05-20 15:44:30 +0000390** *E to NULL if E is not NULL and there are no errors.
drh33c1be32008-01-30 16:16:14 +0000391**
drh9a247912008-07-22 18:45:08 +0000392** {H12137} The [sqlite3_exec(D,S,C,A,E)] function shall set the [error code]
drh35c61902008-05-20 15:44:30 +0000393** and message accessible via [sqlite3_errcode()],
394** [sqlite3_errmsg()], and [sqlite3_errmsg16()].
drh33c1be32008-01-30 16:16:14 +0000395**
drh9a247912008-07-22 18:45:08 +0000396** {H12138} If the S parameter to [sqlite3_exec(D,S,C,A,E)] is NULL or an
mihailim362cc832008-06-21 06:16:42 +0000397** empty string or contains nothing other than whitespace, comments,
398** and/or semicolons, then results of [sqlite3_errcode()],
drhf50bebf2008-05-19 23:51:55 +0000399** [sqlite3_errmsg()], and [sqlite3_errmsg16()]
400** shall reset to indicate no errors.
401**
drh9a247912008-07-22 18:45:08 +0000402** ASSUMPTIONS:
drh33c1be32008-01-30 16:16:14 +0000403**
drh4766b292008-06-26 02:53:02 +0000404** {A12141} The first parameter to [sqlite3_exec()] must be an valid and open
drh33c1be32008-01-30 16:16:14 +0000405** [database connection].
406**
drh4766b292008-06-26 02:53:02 +0000407** {A12142} The database connection must not be closed while
drh33c1be32008-01-30 16:16:14 +0000408** [sqlite3_exec()] is running.
mihailima3f64902008-06-21 13:35:56 +0000409**
drh4766b292008-06-26 02:53:02 +0000410** {A12143} The calling function should use [sqlite3_free()] to free
drh33c1be32008-01-30 16:16:14 +0000411** the memory that *errmsg is left pointing at once the error
412** message is no longer needed.
413**
drh4766b292008-06-26 02:53:02 +0000414** {A12145} The SQL statement text in the 2nd parameter to [sqlite3_exec()]
drh33c1be32008-01-30 16:16:14 +0000415** must remain unchanged while [sqlite3_exec()] is running.
drh75897232000-05-29 14:26:00 +0000416*/
danielk19776f8a5032004-05-10 10:34:51 +0000417int sqlite3_exec(
drh6ed48bf2007-06-14 20:57:18 +0000418 sqlite3*, /* An open database */
shane236ce972008-05-30 15:35:30 +0000419 const char *sql, /* SQL to be evaluated */
drh6ed48bf2007-06-14 20:57:18 +0000420 int (*callback)(void*,int,char**,char**), /* Callback function */
421 void *, /* 1st argument to callback */
422 char **errmsg /* Error msg written here */
drh75897232000-05-29 14:26:00 +0000423);
424
drh58b95762000-06-02 01:17:37 +0000425/*
drhb25f9d82008-07-23 15:40:06 +0000426** CAPI3REF: Result Codes {H10210} <S10700>
drh33c1be32008-01-30 16:16:14 +0000427** KEYWORDS: SQLITE_OK {error code} {error codes}
mihailimefc8e8a2008-06-21 16:47:09 +0000428** KEYWORDS: {result code} {result codes}
drh6ed48bf2007-06-14 20:57:18 +0000429**
430** Many SQLite functions return an integer result code from the set shown
drh33c1be32008-01-30 16:16:14 +0000431** here in order to indicates success or failure.
drh6ed48bf2007-06-14 20:57:18 +0000432**
drh4766b292008-06-26 02:53:02 +0000433** New error codes may be added in future versions of SQLite.
434**
drh6ed48bf2007-06-14 20:57:18 +0000435** See also: [SQLITE_IOERR_READ | extended result codes]
drh58b95762000-06-02 01:17:37 +0000436*/
drh717e6402001-09-27 03:22:32 +0000437#define SQLITE_OK 0 /* Successful result */
drh15b9a152006-01-31 20:49:13 +0000438/* beginning-of-error-codes */
drh717e6402001-09-27 03:22:32 +0000439#define SQLITE_ERROR 1 /* SQL error or missing database */
drh89e0dde2007-12-12 12:25:21 +0000440#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
drh717e6402001-09-27 03:22:32 +0000441#define SQLITE_PERM 3 /* Access permission denied */
442#define SQLITE_ABORT 4 /* Callback routine requested an abort */
443#define SQLITE_BUSY 5 /* The database file is locked */
444#define SQLITE_LOCKED 6 /* A table in the database is locked */
445#define SQLITE_NOMEM 7 /* A malloc() failed */
446#define SQLITE_READONLY 8 /* Attempt to write a readonly database */
drh24cd67e2004-05-10 16:18:47 +0000447#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
drh717e6402001-09-27 03:22:32 +0000448#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
449#define SQLITE_CORRUPT 11 /* The database disk image is malformed */
drh2db0bbc2005-08-11 02:10:18 +0000450#define SQLITE_NOTFOUND 12 /* NOT USED. Table or record not found */
drh717e6402001-09-27 03:22:32 +0000451#define SQLITE_FULL 13 /* Insertion failed because database is full */
452#define SQLITE_CANTOPEN 14 /* Unable to open the database file */
drh4f0ee682007-03-30 20:43:40 +0000453#define SQLITE_PROTOCOL 15 /* NOT USED. Database lock protocol error */
drh24cd67e2004-05-10 16:18:47 +0000454#define SQLITE_EMPTY 16 /* Database is empty */
drh717e6402001-09-27 03:22:32 +0000455#define SQLITE_SCHEMA 17 /* The database schema changed */
drhc797d4d2007-05-08 01:08:49 +0000456#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
danielk19776eb91d22007-09-21 04:27:02 +0000457#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
drh8aff1012001-12-22 14:49:24 +0000458#define SQLITE_MISMATCH 20 /* Data type mismatch */
drh247be432002-05-10 05:44:55 +0000459#define SQLITE_MISUSE 21 /* Library used incorrectly */
drh8766c342002-11-09 00:33:15 +0000460#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
drhed6c8672003-01-12 18:02:16 +0000461#define SQLITE_AUTH 23 /* Authorization denied */
drh1c2d8412003-03-31 00:30:47 +0000462#define SQLITE_FORMAT 24 /* Auxiliary database format error */
danielk19776f8a5032004-05-10 10:34:51 +0000463#define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
drhc602f9a2004-02-12 19:01:04 +0000464#define SQLITE_NOTADB 26 /* File opened that is not a database file */
danielk19776f8a5032004-05-10 10:34:51 +0000465#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
466#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
drh15b9a152006-01-31 20:49:13 +0000467/* end-of-error-codes */
drh717e6402001-09-27 03:22:32 +0000468
drhaf9ff332002-01-16 21:00:27 +0000469/*
drhb25f9d82008-07-23 15:40:06 +0000470** CAPI3REF: Extended Result Codes {H10220} <S10700>
drh33c1be32008-01-30 16:16:14 +0000471** KEYWORDS: {extended error code} {extended error codes}
mihailimefc8e8a2008-06-21 16:47:09 +0000472** KEYWORDS: {extended result code} {extended result codes}
drh4ac285a2006-09-15 07:28:50 +0000473**
drh6ed48bf2007-06-14 20:57:18 +0000474** In its default configuration, SQLite API routines return one of 26 integer
mihailim362cc832008-06-21 06:16:42 +0000475** [SQLITE_OK | result codes]. However, experience has shown that many of
476** these result codes are too coarse-grained. They do not provide as
drhf5befa02007-12-06 02:42:07 +0000477** much information about problems as programmers might like. In an effort to
drh6ed48bf2007-06-14 20:57:18 +0000478** address this, newer versions of SQLite (version 3.3.8 and later) include
479** support for additional result codes that provide more detailed information
drh33c1be32008-01-30 16:16:14 +0000480** about errors. The extended result codes are enabled or disabled
mihailim362cc832008-06-21 06:16:42 +0000481** on a per database connection basis using the
482** [sqlite3_extended_result_codes()] API.
mihailima3f64902008-06-21 13:35:56 +0000483**
drh33c1be32008-01-30 16:16:14 +0000484** Some of the available extended result codes are listed here.
485** One may expect the number of extended result codes will be expand
486** over time. Software that uses extended result codes should expect
487** to see new result codes in future releases of SQLite.
drh4ac285a2006-09-15 07:28:50 +0000488**
489** The SQLITE_OK result code will never be extended. It will always
490** be exactly zero.
mihailima3f64902008-06-21 13:35:56 +0000491**
drh33c1be32008-01-30 16:16:14 +0000492** INVARIANTS:
493**
drh9a247912008-07-22 18:45:08 +0000494** {H10223} The symbolic name for an extended result code shall contains
drh33c1be32008-01-30 16:16:14 +0000495** a related primary result code as a prefix.
496**
drh9a247912008-07-22 18:45:08 +0000497** {H10224} Primary result code names shall contain a single "_" character.
drh33c1be32008-01-30 16:16:14 +0000498**
drh9a247912008-07-22 18:45:08 +0000499** {H10225} Extended result code names shall contain two or more "_" characters.
drh33c1be32008-01-30 16:16:14 +0000500**
drh9a247912008-07-22 18:45:08 +0000501** {H10226} The numeric value of an extended result code shall contain the
mlcreechb2799412008-03-07 03:20:31 +0000502** numeric value of its corresponding primary result code in
drh33c1be32008-01-30 16:16:14 +0000503** its least significant 8 bits.
drh4ac285a2006-09-15 07:28:50 +0000504*/
danielk1977861f7452008-06-05 11:39:11 +0000505#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))
506#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))
507#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8))
508#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8))
509#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8))
510#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8))
511#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8))
512#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8))
513#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8))
514#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8))
515#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8))
516#define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8))
517#define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8))
518#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
drh4ac285a2006-09-15 07:28:50 +0000519
520/*
drh9cd29642008-07-23 00:52:55 +0000521** CAPI3REF: Flags For File Open Operations {H10230} <H11120> <H12700>
drh6d2069d2007-08-14 01:58:53 +0000522**
mlcreechb2799412008-03-07 03:20:31 +0000523** These bit values are intended for use in the
drh33c1be32008-01-30 16:16:14 +0000524** 3rd parameter to the [sqlite3_open_v2()] interface and
525** in the 4th parameter to the xOpen method of the
drhd84f9462007-08-15 11:28:56 +0000526** [sqlite3_vfs] object.
drh6d2069d2007-08-14 01:58:53 +0000527*/
528#define SQLITE_OPEN_READONLY 0x00000001
529#define SQLITE_OPEN_READWRITE 0x00000002
530#define SQLITE_OPEN_CREATE 0x00000004
531#define SQLITE_OPEN_DELETEONCLOSE 0x00000008
532#define SQLITE_OPEN_EXCLUSIVE 0x00000010
533#define SQLITE_OPEN_MAIN_DB 0x00000100
534#define SQLITE_OPEN_TEMP_DB 0x00000200
drh33f4e022007-09-03 15:19:34 +0000535#define SQLITE_OPEN_TRANSIENT_DB 0x00000400
536#define SQLITE_OPEN_MAIN_JOURNAL 0x00000800
537#define SQLITE_OPEN_TEMP_JOURNAL 0x00001000
538#define SQLITE_OPEN_SUBJOURNAL 0x00002000
539#define SQLITE_OPEN_MASTER_JOURNAL 0x00004000
danielk19779a6284c2008-07-10 17:52:49 +0000540#define SQLITE_OPEN_NOMUTEX 0x00008000
drh6d2069d2007-08-14 01:58:53 +0000541
542/*
drh9cd29642008-07-23 00:52:55 +0000543** CAPI3REF: Device Characteristics {H10240} <H11120>
drh6d2069d2007-08-14 01:58:53 +0000544**
drh33c1be32008-01-30 16:16:14 +0000545** The xDeviceCapabilities method of the [sqlite3_io_methods]
drhfddfa2d2007-12-05 18:05:16 +0000546** object returns an integer which is a vector of the these
drh6d2069d2007-08-14 01:58:53 +0000547** bit values expressing I/O characteristics of the mass storage
548** device that holds the file that the [sqlite3_io_methods]
drh33c1be32008-01-30 16:16:14 +0000549** refers to.
drh6d2069d2007-08-14 01:58:53 +0000550**
drh33c1be32008-01-30 16:16:14 +0000551** The SQLITE_IOCAP_ATOMIC property means that all writes of
552** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
drh6d2069d2007-08-14 01:58:53 +0000553** mean that writes of blocks that are nnn bytes in size and
554** are aligned to an address which is an integer multiple of
drh33c1be32008-01-30 16:16:14 +0000555** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
drh6d2069d2007-08-14 01:58:53 +0000556** that when data is appended to a file, the data is appended
557** first then the size of the file is extended, never the other
drh33c1be32008-01-30 16:16:14 +0000558** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
drh6d2069d2007-08-14 01:58:53 +0000559** information is written to disk in the same order as calls
560** to xWrite().
561*/
562#define SQLITE_IOCAP_ATOMIC 0x00000001
563#define SQLITE_IOCAP_ATOMIC512 0x00000002
564#define SQLITE_IOCAP_ATOMIC1K 0x00000004
565#define SQLITE_IOCAP_ATOMIC2K 0x00000008
566#define SQLITE_IOCAP_ATOMIC4K 0x00000010
567#define SQLITE_IOCAP_ATOMIC8K 0x00000020
568#define SQLITE_IOCAP_ATOMIC16K 0x00000040
569#define SQLITE_IOCAP_ATOMIC32K 0x00000080
570#define SQLITE_IOCAP_ATOMIC64K 0x00000100
571#define SQLITE_IOCAP_SAFE_APPEND 0x00000200
572#define SQLITE_IOCAP_SEQUENTIAL 0x00000400
573
574/*
drhb25f9d82008-07-23 15:40:06 +0000575** CAPI3REF: File Locking Levels {H10250} <H11120> <H11310>
drh6d2069d2007-08-14 01:58:53 +0000576**
drh33c1be32008-01-30 16:16:14 +0000577** SQLite uses one of these integer values as the second
drh6d2069d2007-08-14 01:58:53 +0000578** argument to calls it makes to the xLock() and xUnlock() methods
drh33c1be32008-01-30 16:16:14 +0000579** of an [sqlite3_io_methods] object.
drh6d2069d2007-08-14 01:58:53 +0000580*/
581#define SQLITE_LOCK_NONE 0
582#define SQLITE_LOCK_SHARED 1
583#define SQLITE_LOCK_RESERVED 2
584#define SQLITE_LOCK_PENDING 3
585#define SQLITE_LOCK_EXCLUSIVE 4
586
587/*
drh9cd29642008-07-23 00:52:55 +0000588** CAPI3REF: Synchronization Type Flags {H10260} <H11120>
drh6d2069d2007-08-14 01:58:53 +0000589**
drh33c1be32008-01-30 16:16:14 +0000590** When SQLite invokes the xSync() method of an
mlcreechb2799412008-03-07 03:20:31 +0000591** [sqlite3_io_methods] object it uses a combination of
drhfddfa2d2007-12-05 18:05:16 +0000592** these integer values as the second argument.
drh6d2069d2007-08-14 01:58:53 +0000593**
drh33c1be32008-01-30 16:16:14 +0000594** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
drh6d2069d2007-08-14 01:58:53 +0000595** sync operation only needs to flush data to mass storage. Inode
mihailima3f64902008-06-21 13:35:56 +0000596** information need not be flushed. The SQLITE_SYNC_NORMAL flag means
597** to use normal fsync() semantics. The SQLITE_SYNC_FULL flag means
danielk1977c16d4632007-08-30 14:49:58 +0000598** to use Mac OS-X style fullsync instead of fsync().
drh6d2069d2007-08-14 01:58:53 +0000599*/
drh6d2069d2007-08-14 01:58:53 +0000600#define SQLITE_SYNC_NORMAL 0x00002
601#define SQLITE_SYNC_FULL 0x00003
602#define SQLITE_SYNC_DATAONLY 0x00010
603
drh6d2069d2007-08-14 01:58:53 +0000604/*
drh9cd29642008-07-23 00:52:55 +0000605** CAPI3REF: OS Interface Open File Handle {H11110} <S20110>
drh6d2069d2007-08-14 01:58:53 +0000606**
607** An [sqlite3_file] object represents an open file in the OS
608** interface layer. Individual OS interface implementations will
609** want to subclass this object by appending additional fields
drh4ff7fa02007-09-01 18:17:21 +0000610** for their own use. The pMethods entry is a pointer to an
drhd84f9462007-08-15 11:28:56 +0000611** [sqlite3_io_methods] object that defines methods for performing
612** I/O operations on the open file.
drh6d2069d2007-08-14 01:58:53 +0000613*/
614typedef struct sqlite3_file sqlite3_file;
615struct sqlite3_file {
drh153c62c2007-08-24 03:51:33 +0000616 const struct sqlite3_io_methods *pMethods; /* Methods for an open file */
drh6d2069d2007-08-14 01:58:53 +0000617};
618
619/*
drh9cd29642008-07-23 00:52:55 +0000620** CAPI3REF: OS Interface File Virtual Methods Object {H11120} <S20110>
drh6d2069d2007-08-14 01:58:53 +0000621**
drh4766b292008-06-26 02:53:02 +0000622** Every file opened by the [sqlite3_vfs] xOpen method populates an
623** [sqlite3_file] object (or, more commonly, a subclass of the
624** [sqlite3_file] object) with a pointer to an instance of this object.
625** This object defines the methods used to perform various operations
626** against the open file represented by the [sqlite3_file] object.
drhd84f9462007-08-15 11:28:56 +0000627**
drhfddfa2d2007-12-05 18:05:16 +0000628** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
629** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
mihailim362cc832008-06-21 06:16:42 +0000630** The second choice is a Mac OS-X style fullsync. The [SQLITE_SYNC_DATAONLY]
631** flag may be ORed in to indicate that only the data of the file
632** and not its inode needs to be synced.
mihailima3f64902008-06-21 13:35:56 +0000633**
drhd84f9462007-08-15 11:28:56 +0000634** The integer values to xLock() and xUnlock() are one of
drh4ff7fa02007-09-01 18:17:21 +0000635** <ul>
636** <li> [SQLITE_LOCK_NONE],
drh79491ab2007-09-04 12:00:00 +0000637** <li> [SQLITE_LOCK_SHARED],
drh4ff7fa02007-09-01 18:17:21 +0000638** <li> [SQLITE_LOCK_RESERVED],
639** <li> [SQLITE_LOCK_PENDING], or
640** <li> [SQLITE_LOCK_EXCLUSIVE].
641** </ul>
mihailima3f64902008-06-21 13:35:56 +0000642** xLock() increases the lock. xUnlock() decreases the lock.
mihailim362cc832008-06-21 06:16:42 +0000643** The xCheckReservedLock() method checks whether any database connection,
644** either in this process or in some other process, is holding a RESERVED,
drhd84f9462007-08-15 11:28:56 +0000645** PENDING, or EXCLUSIVE lock on the file. It returns true
mihailim362cc832008-06-21 06:16:42 +0000646** if such a lock exists and false otherwise.
mihailima3f64902008-06-21 13:35:56 +0000647**
drhcc6bb3e2007-08-31 16:11:35 +0000648** The xFileControl() method is a generic interface that allows custom
649** VFS implementations to directly control an open file using the
mihailim362cc832008-06-21 06:16:42 +0000650** [sqlite3_file_control()] interface. The second "op" argument is an
mihailima3f64902008-06-21 13:35:56 +0000651** integer opcode. The third argument is a generic pointer intended to
mihailim362cc832008-06-21 06:16:42 +0000652** point to a structure that may contain arguments or space in which to
drhcc6bb3e2007-08-31 16:11:35 +0000653** write return values. Potential uses for xFileControl() might be
654** functions to enable blocking locks with timeouts, to change the
655** locking strategy (for example to use dot-file locks), to inquire
drh9e33c2c2007-08-31 18:34:59 +0000656** about the status of a lock, or to break stale locks. The SQLite
mihailima3f64902008-06-21 13:35:56 +0000657** core reserves all opcodes less than 100 for its own use.
drh4ff7fa02007-09-01 18:17:21 +0000658** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available.
mihailim362cc832008-06-21 06:16:42 +0000659** Applications that define a custom xFileControl method should use opcodes
drh9e33c2c2007-08-31 18:34:59 +0000660** greater than 100 to avoid conflicts.
drhd84f9462007-08-15 11:28:56 +0000661**
662** The xSectorSize() method returns the sector size of the
663** device that underlies the file. The sector size is the
664** minimum write that can be performed without disturbing
665** other bytes in the file. The xDeviceCharacteristics()
666** method returns a bit vector describing behaviors of the
667** underlying device:
668**
669** <ul>
drh4ff7fa02007-09-01 18:17:21 +0000670** <li> [SQLITE_IOCAP_ATOMIC]
671** <li> [SQLITE_IOCAP_ATOMIC512]
672** <li> [SQLITE_IOCAP_ATOMIC1K]
673** <li> [SQLITE_IOCAP_ATOMIC2K]
674** <li> [SQLITE_IOCAP_ATOMIC4K]
675** <li> [SQLITE_IOCAP_ATOMIC8K]
676** <li> [SQLITE_IOCAP_ATOMIC16K]
677** <li> [SQLITE_IOCAP_ATOMIC32K]
678** <li> [SQLITE_IOCAP_ATOMIC64K]
679** <li> [SQLITE_IOCAP_SAFE_APPEND]
680** <li> [SQLITE_IOCAP_SEQUENTIAL]
drhd84f9462007-08-15 11:28:56 +0000681** </ul>
682**
683** The SQLITE_IOCAP_ATOMIC property means that all writes of
684** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
685** mean that writes of blocks that are nnn bytes in size and
686** are aligned to an address which is an integer multiple of
687** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
688** that when data is appended to a file, the data is appended
689** first then the size of the file is extended, never the other
690** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
691** information is written to disk in the same order as calls
692** to xWrite().
drh6d2069d2007-08-14 01:58:53 +0000693*/
694typedef struct sqlite3_io_methods sqlite3_io_methods;
695struct sqlite3_io_methods {
696 int iVersion;
697 int (*xClose)(sqlite3_file*);
drh79491ab2007-09-04 12:00:00 +0000698 int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
699 int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
700 int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
drh6d2069d2007-08-14 01:58:53 +0000701 int (*xSync)(sqlite3_file*, int flags);
drh79491ab2007-09-04 12:00:00 +0000702 int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
drh6d2069d2007-08-14 01:58:53 +0000703 int (*xLock)(sqlite3_file*, int);
704 int (*xUnlock)(sqlite3_file*, int);
danielk1977861f7452008-06-05 11:39:11 +0000705 int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);
drhcc6bb3e2007-08-31 16:11:35 +0000706 int (*xFileControl)(sqlite3_file*, int op, void *pArg);
drh6d2069d2007-08-14 01:58:53 +0000707 int (*xSectorSize)(sqlite3_file*);
708 int (*xDeviceCharacteristics)(sqlite3_file*);
709 /* Additional methods may be added in future releases */
710};
711
712/*
drh9cd29642008-07-23 00:52:55 +0000713** CAPI3REF: Standard File Control Opcodes {H11310} <S30800>
drh9e33c2c2007-08-31 18:34:59 +0000714**
715** These integer constants are opcodes for the xFileControl method
mihailim362cc832008-06-21 06:16:42 +0000716** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
drh9e33c2c2007-08-31 18:34:59 +0000717** interface.
718**
drh33c1be32008-01-30 16:16:14 +0000719** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This
mlcreechb2799412008-03-07 03:20:31 +0000720** opcode causes the xFileControl method to write the current state of
drh9e33c2c2007-08-31 18:34:59 +0000721** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
722** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
drh33c1be32008-01-30 16:16:14 +0000723** into an integer that the pArg argument points to. This capability
drh9e33c2c2007-08-31 18:34:59 +0000724** is used during testing and only needs to be supported when SQLITE_TEST
725** is defined.
726*/
727#define SQLITE_FCNTL_LOCKSTATE 1
728
729/*
drh9cd29642008-07-23 00:52:55 +0000730** CAPI3REF: Mutex Handle {H17110} <S20130>
drh6d2069d2007-08-14 01:58:53 +0000731**
drhd84f9462007-08-15 11:28:56 +0000732** The mutex module within SQLite defines [sqlite3_mutex] to be an
drh33c1be32008-01-30 16:16:14 +0000733** abstract type for a mutex object. The SQLite core never looks
734** at the internal representation of an [sqlite3_mutex]. It only
drhd84f9462007-08-15 11:28:56 +0000735** deals with pointers to the [sqlite3_mutex] object.
drh6bdec4a2007-08-16 19:40:16 +0000736**
737** Mutexes are created using [sqlite3_mutex_alloc()].
drh6d2069d2007-08-14 01:58:53 +0000738*/
739typedef struct sqlite3_mutex sqlite3_mutex;
740
741/*
drh9cd29642008-07-23 00:52:55 +0000742** CAPI3REF: OS Interface Object {H11140} <S20100>
drh6d2069d2007-08-14 01:58:53 +0000743**
mihailim362cc832008-06-21 06:16:42 +0000744** An instance of the sqlite3_vfs object defines the interface between
745** the SQLite core and the underlying operating system. The "vfs"
drhd84f9462007-08-15 11:28:56 +0000746** in the name of the object stands for "virtual file system".
drh6d2069d2007-08-14 01:58:53 +0000747**
mihailim362cc832008-06-21 06:16:42 +0000748** The value of the iVersion field is initially 1 but may be larger in
749** future versions of SQLite. Additional fields may be appended to this
drh4766b292008-06-26 02:53:02 +0000750** object when the iVersion value is increased. Note that the structure
751** of the sqlite3_vfs object changes in the transaction between
752** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not
753** modified.
drh6bdec4a2007-08-16 19:40:16 +0000754**
drh4ff7fa02007-09-01 18:17:21 +0000755** The szOsFile field is the size of the subclassed [sqlite3_file]
drhd84f9462007-08-15 11:28:56 +0000756** structure used by this VFS. mxPathname is the maximum length of
757** a pathname in this VFS.
758**
drhb4d58ae2008-02-21 20:17:06 +0000759** Registered sqlite3_vfs objects are kept on a linked list formed by
drh79491ab2007-09-04 12:00:00 +0000760** the pNext pointer. The [sqlite3_vfs_register()]
761** and [sqlite3_vfs_unregister()] interfaces manage this list
762** in a thread-safe way. The [sqlite3_vfs_find()] interface
drh4766b292008-06-26 02:53:02 +0000763** searches the list. Neither the application code nor the VFS
764** implementation should use the pNext pointer.
drhd84f9462007-08-15 11:28:56 +0000765**
mihailima3f64902008-06-21 13:35:56 +0000766** The pNext field is the only field in the sqlite3_vfs
drh1cc8c442007-08-24 16:08:29 +0000767** structure that SQLite will ever modify. SQLite will only access
768** or modify this field while holding a particular static mutex.
769** The application should never modify anything within the sqlite3_vfs
770** object once the object has been registered.
771**
drhd84f9462007-08-15 11:28:56 +0000772** The zName field holds the name of the VFS module. The name must
773** be unique across all VFS modules.
774**
drh9a247912008-07-22 18:45:08 +0000775** {H11141} SQLite will guarantee that the zFilename parameter to xOpen
drh4766b292008-06-26 02:53:02 +0000776** is either a NULL pointer or string obtained
777** from xFullPathname(). SQLite further guarantees that
778** the string will be valid and unchanged until xClose() is
mihailim2a3d38d2008-07-23 13:42:26 +0000779** called. {END} Because of the previous sentense,
drh4766b292008-06-26 02:53:02 +0000780** the [sqlite3_file] can safely store a pointer to the
drh6d2069d2007-08-14 01:58:53 +0000781** filename if it needs to remember the filename for some reason.
drh4766b292008-06-26 02:53:02 +0000782** If the zFilename parameter is xOpen is a NULL pointer then xOpen
783** must invite its own temporary name for the file. Whenever the
784** xFilename parameter is NULL it will also be the case that the
785** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
drhd84f9462007-08-15 11:28:56 +0000786**
drh9a247912008-07-22 18:45:08 +0000787** {H11142} The flags argument to xOpen() includes all bits set in
drhf5befa02007-12-06 02:42:07 +0000788** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]
789** or [sqlite3_open16()] is used, then flags includes at least
790** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]. {END}
drh6d2069d2007-08-14 01:58:53 +0000791** If xOpen() opens a file read-only then it sets *pOutFlags to
mihailim362cc832008-06-21 06:16:42 +0000792** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.
793**
drh9a247912008-07-22 18:45:08 +0000794** {H11143} SQLite will also add one of the following flags to the xOpen()
drh6d2069d2007-08-14 01:58:53 +0000795** call, depending on the object being opened:
mihailim362cc832008-06-21 06:16:42 +0000796**
drh6d2069d2007-08-14 01:58:53 +0000797** <ul>
798** <li> [SQLITE_OPEN_MAIN_DB]
799** <li> [SQLITE_OPEN_MAIN_JOURNAL]
800** <li> [SQLITE_OPEN_TEMP_DB]
801** <li> [SQLITE_OPEN_TEMP_JOURNAL]
drh33f4e022007-09-03 15:19:34 +0000802** <li> [SQLITE_OPEN_TRANSIENT_DB]
drh6d2069d2007-08-14 01:58:53 +0000803** <li> [SQLITE_OPEN_SUBJOURNAL]
804** <li> [SQLITE_OPEN_MASTER_JOURNAL]
drhf5befa02007-12-06 02:42:07 +0000805** </ul> {END}
drhd84f9462007-08-15 11:28:56 +0000806**
drh6d2069d2007-08-14 01:58:53 +0000807** The file I/O implementation can use the object type flags to
mihailim362cc832008-06-21 06:16:42 +0000808** change the way it deals with files. For example, an application
mlcreechb2799412008-03-07 03:20:31 +0000809** that does not care about crash recovery or rollback might make
810** the open of a journal file a no-op. Writes to this journal would
mihailim362cc832008-06-21 06:16:42 +0000811** also be no-ops, and any attempt to read the journal would return
812** SQLITE_IOERR. Or the implementation might recognize that a database
813** file will be doing page-aligned sector reads and writes in a random
mlcreechb2799412008-03-07 03:20:31 +0000814** order and set up its I/O subsystem accordingly.
mihailim362cc832008-06-21 06:16:42 +0000815**
816** SQLite might also add one of the following flags to the xOpen method:
817**
drh6d2069d2007-08-14 01:58:53 +0000818** <ul>
819** <li> [SQLITE_OPEN_DELETEONCLOSE]
820** <li> [SQLITE_OPEN_EXCLUSIVE]
821** </ul>
mihailim362cc832008-06-21 06:16:42 +0000822**
drh9a247912008-07-22 18:45:08 +0000823** {H11145} The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
824** deleted when it is closed. {H11146} The [SQLITE_OPEN_DELETEONCLOSE]
mihailim362cc832008-06-21 06:16:42 +0000825** will be set for TEMP databases, journals and for subjournals.
mihailim04bcc002008-06-22 10:21:27 +0000826**
drh9a247912008-07-22 18:45:08 +0000827** {H11147} The [SQLITE_OPEN_EXCLUSIVE] flag means the file should be opened
drh6d2069d2007-08-14 01:58:53 +0000828** for exclusive access. This flag is set for all files except
mihailim04bcc002008-06-22 10:21:27 +0000829** for the main database file.
mihailim362cc832008-06-21 06:16:42 +0000830**
drh9a247912008-07-22 18:45:08 +0000831** {H11148} At least szOsFile bytes of memory are allocated by SQLite
mihailim362cc832008-06-21 06:16:42 +0000832** to hold the [sqlite3_file] structure passed as the third
mihailim04bcc002008-06-22 10:21:27 +0000833** argument to xOpen. {END} The xOpen method does not have to
drhf5befa02007-12-06 02:42:07 +0000834** allocate the structure; it should just fill it in.
mihailim362cc832008-06-21 06:16:42 +0000835**
drh9a247912008-07-22 18:45:08 +0000836** {H11149} The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
mihailim362cc832008-06-21 06:16:42 +0000837** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
838** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
mihailim04bcc002008-06-22 10:21:27 +0000839** to test whether a file is at least readable. {END} The file can be a
drh6d2069d2007-08-14 01:58:53 +0000840** directory.
mihailim362cc832008-06-21 06:16:42 +0000841**
drh9a247912008-07-22 18:45:08 +0000842** {H11150} SQLite will always allocate at least mxPathname+1 bytes for the
843** output buffer xFullPathname. {H11151} The exact size of the output buffer
mihailim04bcc002008-06-22 10:21:27 +0000844** is also passed as a parameter to both methods. {END} If the output buffer
mihailim362cc832008-06-21 06:16:42 +0000845** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
846** handled as a fatal error by SQLite, vfs implementations should endeavor
847** to prevent this by setting mxPathname to a sufficiently large value.
848**
drhd84f9462007-08-15 11:28:56 +0000849** The xRandomness(), xSleep(), and xCurrentTime() interfaces
850** are not strictly a part of the filesystem, but they are
851** included in the VFS structure for completeness.
drh6d2069d2007-08-14 01:58:53 +0000852** The xRandomness() function attempts to return nBytes bytes
853** of good-quality randomness into zOut. The return value is
mihailim362cc832008-06-21 06:16:42 +0000854** the actual number of bytes of randomness obtained.
855** The xSleep() method causes the calling thread to sleep for at
drhd84f9462007-08-15 11:28:56 +0000856** least the number of microseconds given. The xCurrentTime()
mihailim362cc832008-06-21 06:16:42 +0000857** method returns a Julian Day Number for the current date and time.
drh6d2069d2007-08-14 01:58:53 +0000858*/
drhd84f9462007-08-15 11:28:56 +0000859typedef struct sqlite3_vfs sqlite3_vfs;
860struct sqlite3_vfs {
drh6d2069d2007-08-14 01:58:53 +0000861 int iVersion; /* Structure version number */
862 int szOsFile; /* Size of subclassed sqlite3_file */
drh6d2069d2007-08-14 01:58:53 +0000863 int mxPathname; /* Maximum file pathname length */
drhd84f9462007-08-15 11:28:56 +0000864 sqlite3_vfs *pNext; /* Next registered VFS */
drhd84f9462007-08-15 11:28:56 +0000865 const char *zName; /* Name of this virtual file system */
drh1cc8c442007-08-24 16:08:29 +0000866 void *pAppData; /* Pointer to application-specific data */
drh153c62c2007-08-24 03:51:33 +0000867 int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*,
drh6d2069d2007-08-14 01:58:53 +0000868 int flags, int *pOutFlags);
drh153c62c2007-08-24 03:51:33 +0000869 int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
danielk1977861f7452008-06-05 11:39:11 +0000870 int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
danielk1977adfb9b02007-09-17 07:02:56 +0000871 int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
drh153c62c2007-08-24 03:51:33 +0000872 void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
873 void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
874 void *(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol);
875 void (*xDlClose)(sqlite3_vfs*, void*);
876 int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
877 int (*xSleep)(sqlite3_vfs*, int microseconds);
878 int (*xCurrentTime)(sqlite3_vfs*, double*);
danielk1977bcb97fe2008-06-06 15:49:29 +0000879 int (*xGetLastError)(sqlite3_vfs*, int, char *);
drhd84f9462007-08-15 11:28:56 +0000880 /* New fields may be appended in figure versions. The iVersion
drh6d2069d2007-08-14 01:58:53 +0000881 ** value will increment whenever this happens. */
882};
883
drh50d3f902007-08-27 21:10:36 +0000884/*
drh9cd29642008-07-23 00:52:55 +0000885** CAPI3REF: Flags for the xAccess VFS method {H11190} <H11140>
drh50d3f902007-08-27 21:10:36 +0000886**
drh9a247912008-07-22 18:45:08 +0000887** {H11191} These integer constants can be used as the third parameter to
drhfddfa2d2007-12-05 18:05:16 +0000888** the xAccess method of an [sqlite3_vfs] object. {END} They determine
mihailim04bcc002008-06-22 10:21:27 +0000889** what kind of permissions the xAccess method is looking for.
drh9a247912008-07-22 18:45:08 +0000890** {H11192} With SQLITE_ACCESS_EXISTS, the xAccess method
mihailim04bcc002008-06-22 10:21:27 +0000891** simply checks whether the file exists.
drh9a247912008-07-22 18:45:08 +0000892** {H11193} With SQLITE_ACCESS_READWRITE, the xAccess method
mihailim04bcc002008-06-22 10:21:27 +0000893** checks whether the file is both readable and writable.
drh9a247912008-07-22 18:45:08 +0000894** {H11194} With SQLITE_ACCESS_READ, the xAccess method
mihailim04bcc002008-06-22 10:21:27 +0000895** checks whether the file is readable.
drh50d3f902007-08-27 21:10:36 +0000896*/
danielk1977b4b47412007-08-17 15:53:36 +0000897#define SQLITE_ACCESS_EXISTS 0
898#define SQLITE_ACCESS_READWRITE 1
drh50d3f902007-08-27 21:10:36 +0000899#define SQLITE_ACCESS_READ 2
danielk1977b4b47412007-08-17 15:53:36 +0000900
drh6d2069d2007-08-14 01:58:53 +0000901/*
drh9cd29642008-07-23 00:52:55 +0000902** CAPI3REF: Initialize The SQLite Library {H10130} <S20000><S30100>
drh673299b2008-06-09 21:57:22 +0000903**
drhcb041342008-06-12 00:07:29 +0000904** The sqlite3_initialize() routine initializes the
drh4766b292008-06-26 02:53:02 +0000905** SQLite library. The sqlite3_shutdown() routine
drhcb041342008-06-12 00:07:29 +0000906** deallocates any resources that were allocated by sqlite3_initialize().
drh673299b2008-06-09 21:57:22 +0000907**
drhcb041342008-06-12 00:07:29 +0000908** A call to sqlite3_initialize() is an "effective" call if it is
909** the first time sqlite3_initialize() is invoked during the lifetime of
910** the process, or if it is the first time sqlite3_initialize() is invoked
911** following a call to sqlite3_shutdown(). Only an effective call
912** of sqlite3_initialize() does any initialization. All other calls
drh4766b292008-06-26 02:53:02 +0000913** are harmless no-ops.
drhcb041342008-06-12 00:07:29 +0000914**
915** Among other things, sqlite3_initialize() shall invoke
drh55b0cf02008-06-19 17:54:33 +0000916** sqlite3_os_init(). Similarly, sqlite3_shutdown()
917** shall invoke sqlite3_os_end().
drh673299b2008-06-09 21:57:22 +0000918**
919** The sqlite3_initialize() routine returns SQLITE_OK on success.
drhce5a5a02008-06-10 17:41:44 +0000920** If for some reason, sqlite3_initialize() is unable to initialize
921** the library (perhaps it is unable to allocate a needed resource such
922** as a mutex) it returns an [error code] other than SQLITE_OK.
drh673299b2008-06-09 21:57:22 +0000923**
drhce5a5a02008-06-10 17:41:44 +0000924** The sqlite3_initialize() routine is called internally by many other
drhcb041342008-06-12 00:07:29 +0000925** SQLite interfaces so that an application usually does not need to
drhce5a5a02008-06-10 17:41:44 +0000926** invoke sqlite3_initialize() directly. For example, [sqlite3_open()]
927** calls sqlite3_initialize() so the SQLite library will be automatically
928** initialized when [sqlite3_open()] is called if it has not be initialized
drhcb041342008-06-12 00:07:29 +0000929** already. However, if SQLite is compiled with the SQLITE_OMIT_AUTOINIT
930** compile-time option, then the automatic calls to sqlite3_initialize()
931** are omitted and the application must call sqlite3_initialize() directly
932** prior to using any other SQLite interface. For maximum portability,
933** it is recommended that applications always invoke sqlite3_initialize()
934** directly prior to using any other SQLite interface. Future releases
935** of SQLite may require this. In other words, the behavior exhibited
936** when SQLite is compiled with SQLITE_OMIT_AUTOINIT might become the
937** default behavior in some future release of SQLite.
drh673299b2008-06-09 21:57:22 +0000938**
drhcb041342008-06-12 00:07:29 +0000939** The sqlite3_os_init() routine does operating-system specific
940** initialization of the SQLite library. The sqlite3_os_end()
941** routine undoes the effect of sqlite3_os_init(). Typical tasks
942** performed by these routines include allocation or deallocation
943** of static resources, initialization of global variables,
944** setting up a default [sqlite3_vfs] module, or setting up
mihailima3f64902008-06-21 13:35:56 +0000945** a default configuration using [sqlite3_config()].
drh673299b2008-06-09 21:57:22 +0000946**
drhcb041342008-06-12 00:07:29 +0000947** The application should never invoke either sqlite3_os_init()
948** or sqlite3_os_end() directly. The application should only invoke
949** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init()
mihailima3f64902008-06-21 13:35:56 +0000950** interface is called automatically by sqlite3_initialize() and
drhcb041342008-06-12 00:07:29 +0000951** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate
952** implementations for sqlite3_os_init() and sqlite3_os_end()
953** are built into SQLite when it is compiled for unix, windows, or os/2.
954** When built for other platforms (using the SQLITE_OS_OTHER=1 compile-time
955** option) the application must supply a suitable implementation for
956** sqlite3_os_init() and sqlite3_os_end(). An application-supplied
957** implementation of sqlite3_os_init() or sqlite3_os_end()
958** must return SQLITE_OK on success and some other [error code] upon
959** failure.
drh673299b2008-06-09 21:57:22 +0000960*/
drhce5a5a02008-06-10 17:41:44 +0000961int sqlite3_initialize(void);
drh673299b2008-06-09 21:57:22 +0000962int sqlite3_shutdown(void);
drhcb041342008-06-12 00:07:29 +0000963int sqlite3_os_init(void);
964int sqlite3_os_end(void);
drh673299b2008-06-09 21:57:22 +0000965
drhce5a5a02008-06-10 17:41:44 +0000966/*
drh9cd29642008-07-23 00:52:55 +0000967** CAPI3REF: Configuring The SQLite Library {H10145} <S20000><S30200>
drhd5a68d32008-08-04 13:44:57 +0000968** EXPERIMENTAL
drhce5a5a02008-06-10 17:41:44 +0000969**
970** The sqlite3_config() interface is used to make global configuration
971** changes to SQLite in order to tune SQLite to the specific needs of
972** the application. The default configuration is recommended for most
973** applications and so this routine is usually not necessary. It is
974** provided to support rare applications with unusual needs.
975**
976** The sqlite3_config() interface is not threadsafe. The application
977** must insure that no other SQLite interfaces are invoked by other
978** threads while sqlite3_config() is running. Furthermore, sqlite3_config()
979** may only be invoked prior to library initialization using
980** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
981** Note, however, that sqlite3_config() can be called as part of the
drh40257ff2008-06-13 18:24:27 +0000982** implementation of an application-defined [sqlite3_os_init()].
drhce5a5a02008-06-10 17:41:44 +0000983**
984** The first argument to sqlite3_config() is an integer
985** [SQLITE_CONFIG_SINGLETHREAD | configuration option] that determines
986** what property of SQLite is to be configured. Subsequent arguments
987** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option]
988** in the first argument.
989**
990** When a configuration option is set, sqlite3_config() returns SQLITE_OK.
mihailima3f64902008-06-21 13:35:56 +0000991** If the option is unknown or SQLite is unable to set the option
drh40257ff2008-06-13 18:24:27 +0000992** then this routine returns a non-zero [error code].
drhce5a5a02008-06-10 17:41:44 +0000993*/
shanea79c3cc2008-08-11 17:27:01 +0000994SQLITE_EXPERIMENTAL int sqlite3_config(int, ...);
drhce5a5a02008-06-10 17:41:44 +0000995
996/*
drh633e6d52008-07-28 19:34:53 +0000997** CAPI3REF: Configure database connections {H10180} <S20000>
drhd5a68d32008-08-04 13:44:57 +0000998** EXPERIMENTAL
drh633e6d52008-07-28 19:34:53 +0000999**
1000** The sqlite3_db_config() interface is used to make configuration
drh2462e322008-07-31 14:47:54 +00001001** changes to a [database connection]. The interface is similar to
1002** [sqlite3_config()] except that the changes apply to a single
1003** [database connection] (specified in the first argument). The
1004** sqlite3_db_config() interface can only be used immediately after
1005** the database connection is created using [sqlite3_open()],
1006** [sqlite3_open16()], or [sqlite3_open_v2()].
1007**
1008** The second argument to sqlite3_db_config(D,V,...) is the
1009** configuration verb - an integer code that indicates what
1010** aspect of the [database connection] is being configured.
drhe9d1c722008-08-04 20:13:26 +00001011** The only choice for this value is [SQLITE_DBCONFIG_LOOKASIDE].
drh2462e322008-07-31 14:47:54 +00001012** New verbs are likely to be added in future releases of SQLite.
drhe9d1c722008-08-04 20:13:26 +00001013** Additional arguments depend on the verb.
drh633e6d52008-07-28 19:34:53 +00001014*/
shanea79c3cc2008-08-11 17:27:01 +00001015SQLITE_EXPERIMENTAL int sqlite3_db_config(sqlite3*, int op, ...);
drh633e6d52008-07-28 19:34:53 +00001016
1017/*
drh9cd29642008-07-23 00:52:55 +00001018** CAPI3REF: Memory Allocation Routines {H10155} <S20120>
drhd5a68d32008-08-04 13:44:57 +00001019** EXPERIMENTAL
drhfec00ea2008-06-14 16:56:21 +00001020**
1021** An instance of this object defines the interface between SQLite
mihailima3f64902008-06-21 13:35:56 +00001022** and low-level memory allocation routines.
drhfec00ea2008-06-14 16:56:21 +00001023**
1024** This object is used in only one place in the SQLite interface.
1025** A pointer to an instance of this object is the argument to
drh4766b292008-06-26 02:53:02 +00001026** [sqlite3_config()] when the configuration option is
drhfec00ea2008-06-14 16:56:21 +00001027** [SQLITE_CONFIG_MALLOC]. By creating an instance of this object
drh4766b292008-06-26 02:53:02 +00001028** and passing it to [sqlite3_config()] during configuration, an
drhfec00ea2008-06-14 16:56:21 +00001029** application can specify an alternative memory allocation subsystem
1030** for SQLite to use for all of its dynamic memory needs.
1031**
1032** Note that SQLite comes with a built-in memory allocator that is
1033** perfectly adequate for the overwhelming majority of applications
1034** and that this object is only useful to a tiny minority of applications
1035** with specialized memory allocation requirements. This object is
1036** also used during testing of SQLite in order to specify an alternative
1037** memory allocator that simulates memory out-of-memory conditions in
1038** order to verify that SQLite recovers gracefully from such
1039** conditions.
1040**
drh4766b292008-06-26 02:53:02 +00001041** The xMalloc, xFree, and xRealloc methods must work like the
drhfec00ea2008-06-14 16:56:21 +00001042** malloc(), free(), and realloc() functions from the standard library.
1043**
1044** xSize should return the allocated size of a memory allocation
1045** previously obtained from xMalloc or xRealloc. The allocated size
1046** is always at least as big as the requested size but may be larger.
1047**
1048** The xRoundup method returns what would be the allocated size of
1049** a memory allocation given a particular requested size. Most memory
1050** allocators round up memory allocations at least to the next multiple
mihailima3f64902008-06-21 13:35:56 +00001051** of 8. Some allocators round up to a larger multiple or to a power of 2.
drhe5ae5732008-06-15 02:51:47 +00001052**
drhfec00ea2008-06-14 16:56:21 +00001053** The xInit method initializes the memory allocator. (For example,
1054** it might allocate any require mutexes or initialize internal data
1055** structures. The xShutdown method is invoked (indirectly) by
1056** [sqlite3_shutdown()] and should deallocate any resources acquired
1057** by xInit. The pAppData pointer is used as the only parameter to
1058** xInit and xShutdown.
1059*/
1060typedef struct sqlite3_mem_methods sqlite3_mem_methods;
1061struct sqlite3_mem_methods {
1062 void *(*xMalloc)(int); /* Memory allocation function */
1063 void (*xFree)(void*); /* Free a prior allocation */
1064 void *(*xRealloc)(void*,int); /* Resize an allocation */
1065 int (*xSize)(void*); /* Return the size of an allocation */
1066 int (*xRoundup)(int); /* Round up request size to allocation size */
1067 int (*xInit)(void*); /* Initialize the memory allocator */
1068 void (*xShutdown)(void*); /* Deinitialize the memory allocator */
1069 void *pAppData; /* Argument to xInit() and xShutdown() */
1070};
1071
1072/*
drh9cd29642008-07-23 00:52:55 +00001073** CAPI3REF: Configuration Options {H10160} <S20000>
drhd5a68d32008-08-04 13:44:57 +00001074** EXPERIMENTAL
drhce5a5a02008-06-10 17:41:44 +00001075**
1076** These constants are the available integer configuration options that
1077** can be passed as the first argument to the [sqlite3_config()] interface.
mihailima3f64902008-06-21 13:35:56 +00001078**
drha911abe2008-07-16 13:29:51 +00001079** New configuration options may be added in future releases of SQLite.
1080** Existing configuration options might be discontinued. Applications
1081** should check the return code from [sqlite3_config()] to make sure that
1082** the call worked. The [sqlite3_config()] interface will return a
1083** non-zero [error code] if a discontinued or unsupported configuration option
1084** is invoked.
1085**
drhce5a5a02008-06-10 17:41:44 +00001086** <dl>
1087** <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
1088** <dd>There are no arguments to this option. This option disables
1089** all mutexing and puts SQLite into a mode where it can only be used
1090** by a single thread.</dd>
1091**
1092** <dt>SQLITE_CONFIG_MULTITHREAD</dt>
1093** <dd>There are no arguments to this option. This option disables
1094** mutexing on [database connection] and [prepared statement] objects.
1095** The application is responsible for serializing access to
1096** [database connections] and [prepared statements]. But other mutexes
1097** are enabled so that SQLite will be safe to use in a multi-threaded
1098** environment.</dd>
1099**
1100** <dt>SQLITE_CONFIG_SERIALIZED</dt>
1101** <dd>There are no arguments to this option. This option enables
1102** all mutexes including the recursive
1103** mutexes on [database connection] and [prepared statement] objects.
1104** In this mode (which is the default when SQLite is compiled with
drh4766b292008-06-26 02:53:02 +00001105** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access
drhce5a5a02008-06-10 17:41:44 +00001106** to [database connections] and [prepared statements] so that the
1107** application is free to use the same [database connection] or the
drh31d38cf2008-07-12 20:35:08 +00001108** same [prepared statement] in different threads at the same time.
1109**
1110** <p>This configuration option merely sets the default mutex
1111** behavior to serialize access to [database connections]. Individual
1112** [database connections] can override this setting
1113** using the [SQLITE_OPEN_NOMUTEX] flag to [sqlite3_open_v2()].</p></dd>
drhce5a5a02008-06-10 17:41:44 +00001114**
1115** <dt>SQLITE_CONFIG_MALLOC</dt>
drhfec00ea2008-06-14 16:56:21 +00001116** <dd>This option takes a single argument which is a pointer to an
mihailimdb4f2ad2008-06-21 11:20:48 +00001117** instance of the [sqlite3_mem_methods] structure. The argument specifies
1118** alternative low-level memory allocation routines to be used in place of
drhfec00ea2008-06-14 16:56:21 +00001119** the memory allocation routines built into SQLite.</dd>
drhce5a5a02008-06-10 17:41:44 +00001120**
drh33589792008-06-18 13:27:46 +00001121** <dt>SQLITE_CONFIG_GETMALLOC</dt>
1122** <dd>This option takes a single argument which is a pointer to an
1123** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods]
1124** structure is filled with the currently defined memory allocation routines.
1125** This option can be used to overload the default memory allocation
1126** routines with a wrapper that simulations memory allocation failure or
1127** tracks memory usage, for example.</dd>
1128**
drhfec00ea2008-06-14 16:56:21 +00001129** <dt>SQLITE_CONFIG_MEMSTATUS</dt>
danielk197795c232d2008-07-28 05:22:35 +00001130** <dd>This option takes single argument of type int, interpreted as a
1131** boolean, which enables or disables the collection of memory allocation
1132** statistics. When disabled, the following SQLite interfaces become
1133** non-operational:
drhce5a5a02008-06-10 17:41:44 +00001134** <ul>
1135** <li> [sqlite3_memory_used()]
1136** <li> [sqlite3_memory_highwater()]
1137** <li> [sqlite3_soft_heap_limit()]
drh0a60a382008-07-31 17:16:05 +00001138** <li> [sqlite3_status()]
drhce5a5a02008-06-10 17:41:44 +00001139** </ul>
1140** </dd>
drh33589792008-06-18 13:27:46 +00001141**
1142** <dt>SQLITE_CONFIG_SCRATCH</dt>
1143** <dd>This option specifies a static memory buffer that SQLite can use for
1144** scratch memory. There are three arguments: A pointer to the memory, the
drh9ac3fe92008-06-18 18:12:04 +00001145** size of each scratch buffer (sz), and the number of buffers (N). The sz
drh0a60a382008-07-31 17:16:05 +00001146** argument must be a multiple of 16. The sz parameter should be a few bytes
1147** larger than the actual scratch space required due internal overhead.
1148** The first
1149** argument should point to an allocation of at least sz*N bytes of memory.
drh33589792008-06-18 13:27:46 +00001150** SQLite will use no more than one scratch buffer at once per thread, so
mihailimdb4f2ad2008-06-21 11:20:48 +00001151** N should be set to the expected maximum number of threads. The sz
drh33589792008-06-18 13:27:46 +00001152** parameter should be 6 times the size of the largest database page size.
1153** Scratch buffers are used as part of the btree balance operation. If
1154** The btree balancer needs additional memory beyond what is provided by
1155** scratch buffers or if no scratch buffer space is specified, then SQLite
mihailimdb4f2ad2008-06-21 11:20:48 +00001156** goes to [sqlite3_malloc()] to obtain the memory it needs.</dd>
drh33589792008-06-18 13:27:46 +00001157**
1158** <dt>SQLITE_CONFIG_PAGECACHE</dt>
1159** <dd>This option specifies a static memory buffer that SQLite can use for
mihailimdb4f2ad2008-06-21 11:20:48 +00001160** the database page cache. There are three arguments: A pointer to the
1161** memory, the size of each page buffer (sz), and the number of pages (N).
1162** The sz argument must be a power of two between 512 and 32768. The first
drh0a60a382008-07-31 17:16:05 +00001163** argument should point to an allocation of at least sz*N bytes of memory.
mihailimdb4f2ad2008-06-21 11:20:48 +00001164** SQLite will use the memory provided by the first argument to satisfy its
1165** memory needs for the first N pages that it adds to cache. If additional
1166** page cache memory is needed beyond what is provided by this option, then
drh0a60a382008-07-31 17:16:05 +00001167** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1168** The implementation might use one or more of the N buffers to hold
1169** memory accounting information. </dd>
drh33589792008-06-18 13:27:46 +00001170**
1171** <dt>SQLITE_CONFIG_HEAP</dt>
1172** <dd>This option specifies a static memory buffer that SQLite will use
1173** for all of its dynamic memory allocation needs beyond those provided
1174** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
1175** There are three arguments: A pointer to the memory, the number of
drh8a42cbd2008-07-10 18:13:42 +00001176** bytes in the memory buffer, and the minimum allocation size. If
1177** the first pointer (the memory pointer) is NULL, then SQLite reverts
1178** to using its default memory allocator (the system malloc() implementation),
1179** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. If the
1180** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
1181** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
1182** allocator is engaged to handle all of SQLites memory allocation needs.</dd>
drh33589792008-06-18 13:27:46 +00001183**
1184** <dt>SQLITE_CONFIG_MUTEX</dt>
1185** <dd>This option takes a single argument which is a pointer to an
mihailimdb4f2ad2008-06-21 11:20:48 +00001186** instance of the [sqlite3_mutex_methods] structure. The argument specifies
drh33589792008-06-18 13:27:46 +00001187** alternative low-level mutex routines to be used in place
1188** the mutex routines built into SQLite.</dd>
1189**
drh584ff182008-07-14 18:38:17 +00001190** <dt>SQLITE_CONFIG_GETMUTEX</dt>
drh33589792008-06-18 13:27:46 +00001191** <dd>This option takes a single argument which is a pointer to an
1192** instance of the [sqlite3_mutex_methods] structure. The
1193** [sqlite3_mutex_methods]
1194** structure is filled with the currently defined mutex routines.
1195** This option can be used to overload the default mutex allocation
1196** routines with a wrapper used to track mutex usage for performance
1197** profiling or testing, for example.</dd>
drh633e6d52008-07-28 19:34:53 +00001198**
1199** <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1200** <dd>This option takes two arguments that determine the default
1201** memory allcation lookaside optimization. The first argument is the
1202** size of each lookaside buffer slot and the second is the number of
1203** slots allocated to each database connection.</dd>
1204**
1205** </dl>
mihailima3f64902008-06-21 13:35:56 +00001206*/
drh40257ff2008-06-13 18:24:27 +00001207#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1208#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1209#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
drhfec00ea2008-06-14 16:56:21 +00001210#define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
drh33589792008-06-18 13:27:46 +00001211#define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */
1212#define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */
1213#define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */
1214#define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */
1215#define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */
1216#define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */
1217#define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */
danielk197731fab4f2008-07-25 08:48:59 +00001218#define SQLITE_CONFIG_CHUNKALLOC 12 /* int threshold */
drh633e6d52008-07-28 19:34:53 +00001219#define SQLITE_CONFIG_LOOKASIDE 13 /* int int */
danielk19772d340812008-07-24 08:20:40 +00001220
drhe9d1c722008-08-04 20:13:26 +00001221/*
1222** CAPI3REF: Configuration Options {H10170} <S20000>
1223** EXPERIMENTAL
1224**
1225** These constants are the available integer configuration options that
1226** can be passed as the second argument to the [sqlite3_db_config()] interface.
1227**
1228** New configuration options may be added in future releases of SQLite.
1229** Existing configuration options might be discontinued. Applications
1230** should check the return code from [sqlite3_db_config()] to make sure that
1231** the call worked. The [sqlite3_db_config()] interface will return a
1232** non-zero [error code] if a discontinued or unsupported configuration option
1233** is invoked.
1234**
1235** <dl>
1236** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
1237** <dd>This option takes three additional arguments that determine the
1238** [lookaside memory allocator] configuration for the [database connection].
1239** The first argument (the third parameter to [sqlite3_db_config()] is a
1240** pointer to a memory buffer to use for lookaside memory. The first
1241** argument may be NULL in which case SQLite will allocate the lookaside
1242** buffer itself using [sqlite3_malloc()]. The second argument is the
1243** size of each lookaside buffer slot and the third argument is the number of
1244** slots. The size of the buffer in the first argument must be greater than
1245** or equal to the product of the second and third arguments.</dd>
1246**
1247** </dl>
1248*/
1249#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
1250
drhce5a5a02008-06-10 17:41:44 +00001251
drh673299b2008-06-09 21:57:22 +00001252/*
drhb25f9d82008-07-23 15:40:06 +00001253** CAPI3REF: Enable Or Disable Extended Result Codes {H12200} <S10700>
drh6ed48bf2007-06-14 20:57:18 +00001254**
drh33c1be32008-01-30 16:16:14 +00001255** The sqlite3_extended_result_codes() routine enables or disables the
mihailimefc8e8a2008-06-21 16:47:09 +00001256** [extended result codes] feature of SQLite. The extended result
1257** codes are disabled by default for historical compatibility considerations.
drh6ed48bf2007-06-14 20:57:18 +00001258**
drh33c1be32008-01-30 16:16:14 +00001259** INVARIANTS:
1260**
drh9a247912008-07-22 18:45:08 +00001261** {H12201} Each new [database connection] shall have the
mihailimdb4f2ad2008-06-21 11:20:48 +00001262** [extended result codes] feature disabled by default.
drh33c1be32008-01-30 16:16:14 +00001263**
drh9a247912008-07-22 18:45:08 +00001264** {H12202} The [sqlite3_extended_result_codes(D,F)] interface shall enable
mihailimdb4f2ad2008-06-21 11:20:48 +00001265** [extended result codes] for the [database connection] D
1266** if the F parameter is true, or disable them if F is false.
drh4ac285a2006-09-15 07:28:50 +00001267*/
1268int sqlite3_extended_result_codes(sqlite3*, int onoff);
1269
1270/*
drh9cd29642008-07-23 00:52:55 +00001271** CAPI3REF: Last Insert Rowid {H12220} <S10700>
drh6ed48bf2007-06-14 20:57:18 +00001272**
drh33c1be32008-01-30 16:16:14 +00001273** Each entry in an SQLite table has a unique 64-bit signed
1274** integer key called the "rowid". The rowid is always available
drhfddfa2d2007-12-05 18:05:16 +00001275** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
drh33c1be32008-01-30 16:16:14 +00001276** names are not also used by explicitly declared columns. If
drhfddfa2d2007-12-05 18:05:16 +00001277** the table has a column of type INTEGER PRIMARY KEY then that column
mlcreechb2799412008-03-07 03:20:31 +00001278** is another alias for the rowid.
drh6ed48bf2007-06-14 20:57:18 +00001279**
drh33c1be32008-01-30 16:16:14 +00001280** This routine returns the rowid of the most recent
mihailimdb4f2ad2008-06-21 11:20:48 +00001281** successful INSERT into the database from the [database connection]
1282** in the first argument. If no successful INSERTs
1283** have ever occurred on that database connection, zero is returned.
drh6ed48bf2007-06-14 20:57:18 +00001284**
mihailimdb4f2ad2008-06-21 11:20:48 +00001285** If an INSERT occurs within a trigger, then the rowid of the inserted
1286** row is returned by this routine as long as the trigger is running.
1287** But once the trigger terminates, the value returned by this routine
1288** reverts to the last value inserted before the trigger fired.
drhe30f4422007-08-21 16:15:55 +00001289**
drh33c1be32008-01-30 16:16:14 +00001290** An INSERT that fails due to a constraint violation is not a
mihailimdb4f2ad2008-06-21 11:20:48 +00001291** successful INSERT and does not change the value returned by this
drh33c1be32008-01-30 16:16:14 +00001292** routine. Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
drhdc1d9f12007-10-27 16:25:16 +00001293** and INSERT OR ABORT make no changes to the return value of this
mihailimdb4f2ad2008-06-21 11:20:48 +00001294** routine when their insertion fails. When INSERT OR REPLACE
drhdc1d9f12007-10-27 16:25:16 +00001295** encounters a constraint violation, it does not fail. The
1296** INSERT continues to completion after deleting rows that caused
1297** the constraint problem so INSERT OR REPLACE will always change
mihailimdb4f2ad2008-06-21 11:20:48 +00001298** the return value of this interface.
drhdc1d9f12007-10-27 16:25:16 +00001299**
mihailimdb4f2ad2008-06-21 11:20:48 +00001300** For the purposes of this routine, an INSERT is considered to
drh33c1be32008-01-30 16:16:14 +00001301** be successful even if it is subsequently rolled back.
1302**
1303** INVARIANTS:
1304**
drh9a247912008-07-22 18:45:08 +00001305** {H12221} The [sqlite3_last_insert_rowid()] function returns the rowid
mihailimdb4f2ad2008-06-21 11:20:48 +00001306** of the most recent successful INSERT performed on the same
1307** [database connection] and within the same or higher level
1308** trigger context, or zero if there have been no qualifying inserts.
drh33c1be32008-01-30 16:16:14 +00001309**
drh9a247912008-07-22 18:45:08 +00001310** {H12223} The [sqlite3_last_insert_rowid()] function returns the
drh33c1be32008-01-30 16:16:14 +00001311** same value when called from the same trigger context
1312** immediately before and after a ROLLBACK.
1313**
drh9a247912008-07-22 18:45:08 +00001314** ASSUMPTIONS:
drh33c1be32008-01-30 16:16:14 +00001315**
drh4766b292008-06-26 02:53:02 +00001316** {A12232} If a separate thread performs a new INSERT on the same
drh33c1be32008-01-30 16:16:14 +00001317** database connection while the [sqlite3_last_insert_rowid()]
1318** function is running and thus changes the last insert rowid,
1319** then the value returned by [sqlite3_last_insert_rowid()] is
1320** unpredictable and might not equal either the old or the new
1321** last insert rowid.
drhaf9ff332002-01-16 21:00:27 +00001322*/
drh6d2069d2007-08-14 01:58:53 +00001323sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
drhaf9ff332002-01-16 21:00:27 +00001324
drhc8d30ac2002-04-12 10:08:59 +00001325/*
drh9cd29642008-07-23 00:52:55 +00001326** CAPI3REF: Count The Number Of Rows Modified {H12240} <S10600>
drh6ed48bf2007-06-14 20:57:18 +00001327**
drh33c1be32008-01-30 16:16:14 +00001328** This function returns the number of database rows that were changed
drhfddfa2d2007-12-05 18:05:16 +00001329** or inserted or deleted by the most recently completed SQL statement
mihailimdb4f2ad2008-06-21 11:20:48 +00001330** on the [database connection] specified by the first parameter.
1331** Only changes that are directly specified by the INSERT, UPDATE,
1332** or DELETE statement are counted. Auxiliary changes caused by
drh33c1be32008-01-30 16:16:14 +00001333** triggers are not counted. Use the [sqlite3_total_changes()] function
drh6ed48bf2007-06-14 20:57:18 +00001334** to find the total number of changes including changes caused by triggers.
1335**
mlcreechb2799412008-03-07 03:20:31 +00001336** A "row change" is a change to a single row of a single table
drh33c1be32008-01-30 16:16:14 +00001337** caused by an INSERT, DELETE, or UPDATE statement. Rows that
1338** are changed as side effects of REPLACE constraint resolution,
1339** rollback, ABORT processing, DROP TABLE, or by any other
1340** mechanisms do not count as direct row changes.
1341**
1342** A "trigger context" is a scope of execution that begins and
1343** ends with the script of a trigger. Most SQL statements are
1344** evaluated outside of any trigger. This is the "top level"
1345** trigger context. If a trigger fires from the top level, a
1346** new trigger context is entered for the duration of that one
1347** trigger. Subtriggers create subcontexts for their duration.
1348**
1349** Calling [sqlite3_exec()] or [sqlite3_step()] recursively does
1350** not create a new trigger context.
1351**
1352** This function returns the number of direct row changes in the
1353** most recent INSERT, UPDATE, or DELETE statement within the same
1354** trigger context.
1355**
mihailimdb4f2ad2008-06-21 11:20:48 +00001356** Thus, when called from the top level, this function returns the
drh33c1be32008-01-30 16:16:14 +00001357** number of changes in the most recent INSERT, UPDATE, or DELETE
mihailimdb4f2ad2008-06-21 11:20:48 +00001358** that also occurred at the top level. Within the body of a trigger,
1359** the sqlite3_changes() interface can be called to find the number of
drh930cc582007-03-28 13:07:40 +00001360** changes in the most recently completed INSERT, UPDATE, or DELETE
drhf5befa02007-12-06 02:42:07 +00001361** statement within the body of the same trigger.
mihailimdb4f2ad2008-06-21 11:20:48 +00001362** However, the number returned does not include changes
1363** caused by subtriggers since those have their own context.
drhc8d30ac2002-04-12 10:08:59 +00001364**
mihailimdb4f2ad2008-06-21 11:20:48 +00001365** SQLite implements the command "DELETE FROM table" without a WHERE clause
1366** by dropping and recreating the table. (This is much faster than going
1367** through and deleting individual elements from the table.) Because of this
1368** optimization, the deletions in "DELETE FROM table" are not row changes and
1369** will not be counted by the sqlite3_changes() or [sqlite3_total_changes()]
1370** functions, regardless of the number of elements that were originally
1371** in the table. To get an accurate count of the number of rows deleted, use
drhc8d30ac2002-04-12 10:08:59 +00001372** "DELETE FROM table WHERE 1" instead.
drhe30f4422007-08-21 16:15:55 +00001373**
drh33c1be32008-01-30 16:16:14 +00001374** INVARIANTS:
1375**
drh9a247912008-07-22 18:45:08 +00001376** {H12241} The [sqlite3_changes()] function shall return the number of
drh33c1be32008-01-30 16:16:14 +00001377** row changes caused by the most recent INSERT, UPDATE,
1378** or DELETE statement on the same database connection and
drhe63b2c22008-05-21 13:44:13 +00001379** within the same or higher trigger context, or zero if there have
drh33c1be32008-01-30 16:16:14 +00001380** not been any qualifying row changes.
1381**
drh9a247912008-07-22 18:45:08 +00001382** {H12243} Statements of the form "DELETE FROM tablename" with no
mihailimdb4f2ad2008-06-21 11:20:48 +00001383** WHERE clause shall cause subsequent calls to
drhe63b2c22008-05-21 13:44:13 +00001384** [sqlite3_changes()] to return zero, regardless of the
1385** number of rows originally in the table.
1386**
drh9a247912008-07-22 18:45:08 +00001387** ASSUMPTIONS:
drh33c1be32008-01-30 16:16:14 +00001388**
drh4766b292008-06-26 02:53:02 +00001389** {A12252} If a separate thread makes changes on the same database connection
drh33c1be32008-01-30 16:16:14 +00001390** while [sqlite3_changes()] is running then the value returned
shane26b34032008-05-23 17:21:09 +00001391** is unpredictable and not meaningful.
drhc8d30ac2002-04-12 10:08:59 +00001392*/
danielk1977f9d64d22004-06-19 08:18:07 +00001393int sqlite3_changes(sqlite3*);
drhc8d30ac2002-04-12 10:08:59 +00001394
rdcf146a772004-02-25 22:51:06 +00001395/*
drh9cd29642008-07-23 00:52:55 +00001396** CAPI3REF: Total Number Of Rows Modified {H12260} <S10600>
mihailimdb4f2ad2008-06-21 11:20:48 +00001397**
1398** This function returns the number of row changes caused by INSERT,
1399** UPDATE or DELETE statements since the [database connection] was opened.
1400** The count includes all changes from all trigger contexts. However,
1401** the count does not include changes used to implement REPLACE constraints,
1402** do rollbacks or ABORT processing, or DROP table processing.
1403** The changes are counted as soon as the statement that makes them is
1404** completed (when the statement handle is passed to [sqlite3_reset()] or
drh33c1be32008-01-30 16:16:14 +00001405** [sqlite3_finalize()]).
drh6ed48bf2007-06-14 20:57:18 +00001406**
mihailimdb4f2ad2008-06-21 11:20:48 +00001407** SQLite implements the command "DELETE FROM table" without a WHERE clause
1408** by dropping and recreating the table. (This is much faster than going
1409** through and deleting individual elements from the table.) Because of this
1410** optimization, the deletions in "DELETE FROM table" are not row changes and
1411** will not be counted by the sqlite3_changes() or [sqlite3_total_changes()]
1412** functions, regardless of the number of elements that were originally
1413** in the table. To get an accurate count of the number of rows deleted, use
rdcf146a772004-02-25 22:51:06 +00001414** "DELETE FROM table WHERE 1" instead.
drhe30f4422007-08-21 16:15:55 +00001415**
drh33c1be32008-01-30 16:16:14 +00001416** See also the [sqlite3_changes()] interface.
1417**
1418** INVARIANTS:
mihailimdb4f2ad2008-06-21 11:20:48 +00001419**
drh9a247912008-07-22 18:45:08 +00001420** {H12261} The [sqlite3_total_changes()] returns the total number
drh33c1be32008-01-30 16:16:14 +00001421** of row changes caused by INSERT, UPDATE, and/or DELETE
1422** statements on the same [database connection], in any
mihailimdb4f2ad2008-06-21 11:20:48 +00001423** trigger context, since the database connection was created.
drh33c1be32008-01-30 16:16:14 +00001424**
drh9a247912008-07-22 18:45:08 +00001425** {H12263} Statements of the form "DELETE FROM tablename" with no
drhe63b2c22008-05-21 13:44:13 +00001426** WHERE clause shall not change the value returned
mihailimdb4f2ad2008-06-21 11:20:48 +00001427** by [sqlite3_total_changes()].
drhe63b2c22008-05-21 13:44:13 +00001428**
drh9a247912008-07-22 18:45:08 +00001429** ASSUMPTIONS:
drh33c1be32008-01-30 16:16:14 +00001430**
drh4766b292008-06-26 02:53:02 +00001431** {A12264} If a separate thread makes changes on the same database connection
mihailima3f64902008-06-21 13:35:56 +00001432** while [sqlite3_total_changes()] is running then the value
shane26b34032008-05-23 17:21:09 +00001433** returned is unpredictable and not meaningful.
rdcf146a772004-02-25 22:51:06 +00001434*/
danielk1977b28af712004-06-21 06:50:26 +00001435int sqlite3_total_changes(sqlite3*);
1436
drh6ed48bf2007-06-14 20:57:18 +00001437/*
drh9cd29642008-07-23 00:52:55 +00001438** CAPI3REF: Interrupt A Long-Running Query {H12270} <S30500>
drh6ed48bf2007-06-14 20:57:18 +00001439**
drh33c1be32008-01-30 16:16:14 +00001440** This function causes any pending database operation to abort and
1441** return at its earliest opportunity. This routine is typically
mihailimebe796c2008-06-21 20:11:17 +00001442** called in response to a user action such as pressing "Cancel"
drh4c504392000-10-16 22:06:40 +00001443** or Ctrl-C where the user wants a long query operation to halt
1444** immediately.
drh930cc582007-03-28 13:07:40 +00001445**
drh33c1be32008-01-30 16:16:14 +00001446** It is safe to call this routine from a thread different from the
1447** thread that is currently running the database operation. But it
mihailimdb4f2ad2008-06-21 11:20:48 +00001448** is not safe to call this routine with a [database connection] that
drh871f6ca2007-08-14 18:03:14 +00001449** is closed or might close before sqlite3_interrupt() returns.
drh6ed48bf2007-06-14 20:57:18 +00001450**
mihailimdb4f2ad2008-06-21 11:20:48 +00001451** If an SQL operation is very nearly finished at the time when
1452** sqlite3_interrupt() is called, then it might not have an opportunity
1453** to be interrupted and might continue to completion.
1454**
1455** An SQL operation that is interrupted will return [SQLITE_INTERRUPT].
1456** If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
1457** that is inside an explicit transaction, then the entire transaction
1458** will be rolled back automatically.
1459**
drh33c1be32008-01-30 16:16:14 +00001460** A call to sqlite3_interrupt() has no effect on SQL statements
drhf5befa02007-12-06 02:42:07 +00001461** that are started after sqlite3_interrupt() returns.
drh33c1be32008-01-30 16:16:14 +00001462**
1463** INVARIANTS:
1464**
drh9a247912008-07-22 18:45:08 +00001465** {H12271} The [sqlite3_interrupt()] interface will force all running
drh33c1be32008-01-30 16:16:14 +00001466** SQL statements associated with the same database connection
mihailimdb4f2ad2008-06-21 11:20:48 +00001467** to halt after processing at most one additional row of data.
drh33c1be32008-01-30 16:16:14 +00001468**
drh9a247912008-07-22 18:45:08 +00001469** {H12272} Any SQL statement that is interrupted by [sqlite3_interrupt()]
drh33c1be32008-01-30 16:16:14 +00001470** will return [SQLITE_INTERRUPT].
1471**
drh9a247912008-07-22 18:45:08 +00001472** ASSUMPTIONS:
drh33c1be32008-01-30 16:16:14 +00001473**
drh4766b292008-06-26 02:53:02 +00001474** {A12279} If the database connection closes while [sqlite3_interrupt()]
drh33c1be32008-01-30 16:16:14 +00001475** is running then bad things will likely happen.
drh4c504392000-10-16 22:06:40 +00001476*/
danielk1977f9d64d22004-06-19 08:18:07 +00001477void sqlite3_interrupt(sqlite3*);
drh4c504392000-10-16 22:06:40 +00001478
drh6ed48bf2007-06-14 20:57:18 +00001479/*
drh9cd29642008-07-23 00:52:55 +00001480** CAPI3REF: Determine If An SQL Statement Is Complete {H10510} <S70200>
drh75897232000-05-29 14:26:00 +00001481**
drh6ed48bf2007-06-14 20:57:18 +00001482** These routines are useful for command-line input to determine if the
drhf5befa02007-12-06 02:42:07 +00001483** currently entered text seems to form complete a SQL statement or
1484** if additional input is needed before sending the text into
drhfddfa2d2007-12-05 18:05:16 +00001485** SQLite for parsing. These routines return true if the input string
1486** appears to be a complete SQL statement. A statement is judged to be
drh33c1be32008-01-30 16:16:14 +00001487** complete if it ends with a semicolon token and is not a fragment of a
1488** CREATE TRIGGER statement. Semicolons that are embedded within
1489** string literals or quoted identifier names or comments are not
1490** independent tokens (they are part of the token in which they are
1491** embedded) and thus do not count as a statement terminator.
1492**
mihailimdb4f2ad2008-06-21 11:20:48 +00001493** These routines do not parse the SQL statements thus
1494** will not detect syntactically incorrect SQL.
drhfddfa2d2007-12-05 18:05:16 +00001495**
drh33c1be32008-01-30 16:16:14 +00001496** INVARIANTS:
1497**
drh9a247912008-07-22 18:45:08 +00001498** {H10511} A successful evaluation of [sqlite3_complete()] or
drhbd0b1b52008-07-07 19:52:09 +00001499** [sqlite3_complete16()] functions shall
1500** return a numeric 1 if and only if the last non-whitespace
mihailimdb4f2ad2008-06-21 11:20:48 +00001501** token in their input is a semicolon that is not in between
1502** the BEGIN and END of a CREATE TRIGGER statement.
drh33c1be32008-01-30 16:16:14 +00001503**
drh9a247912008-07-22 18:45:08 +00001504** {H10512} If a memory allocation error occurs during an invocation
drhbd0b1b52008-07-07 19:52:09 +00001505** of [sqlite3_complete()] or [sqlite3_complete16()] then the
1506** routine shall return [SQLITE_NOMEM].
1507**
drh9a247912008-07-22 18:45:08 +00001508** ASSUMPTIONS:
drh33c1be32008-01-30 16:16:14 +00001509**
drh4ead1482008-06-26 18:16:05 +00001510** {A10512} The input to [sqlite3_complete()] must be a zero-terminated
drh33c1be32008-01-30 16:16:14 +00001511** UTF-8 string.
1512**
drh4ead1482008-06-26 18:16:05 +00001513** {A10513} The input to [sqlite3_complete16()] must be a zero-terminated
drh33c1be32008-01-30 16:16:14 +00001514** UTF-16 string in native byte order.
drh75897232000-05-29 14:26:00 +00001515*/
danielk19776f8a5032004-05-10 10:34:51 +00001516int sqlite3_complete(const char *sql);
danielk197761de0d12004-05-27 23:56:16 +00001517int sqlite3_complete16(const void *sql);
drh75897232000-05-29 14:26:00 +00001518
drh2dfbbca2000-07-28 14:32:48 +00001519/*
drh9cd29642008-07-23 00:52:55 +00001520** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors {H12310} <S40400>
drh6ed48bf2007-06-14 20:57:18 +00001521**
mihailimdb4f2ad2008-06-21 11:20:48 +00001522** This routine sets a callback function that might be invoked whenever
1523** an attempt is made to open a database table that another thread
1524** or process has locked.
1525**
1526** If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]
1527** is returned immediately upon encountering the lock. If the busy callback
1528** is not NULL, then the callback will be invoked with two arguments.
1529**
1530** The first argument to the handler is a copy of the void* pointer which
1531** is the third argument to sqlite3_busy_handler(). The second argument to
1532** the handler callback is the number of times that the busy handler has
1533** been invoked for this locking event. If the
drh6ed48bf2007-06-14 20:57:18 +00001534** busy callback returns 0, then no additional attempts are made to
1535** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned.
drh33c1be32008-01-30 16:16:14 +00001536** If the callback returns non-zero, then another attempt
drhfddfa2d2007-12-05 18:05:16 +00001537** is made to open the database for reading and the cycle repeats.
drh2dfbbca2000-07-28 14:32:48 +00001538**
mihailimdb4f2ad2008-06-21 11:20:48 +00001539** The presence of a busy handler does not guarantee that it will be invoked
1540** when there is lock contention. If SQLite determines that invoking the busy
1541** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
1542** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler.
drh86939b52007-01-10 12:54:51 +00001543** Consider a scenario where one process is holding a read lock that
1544** it is trying to promote to a reserved lock and
1545** a second process is holding a reserved lock that it is trying
1546** to promote to an exclusive lock. The first process cannot proceed
1547** because it is blocked by the second and the second process cannot
1548** proceed because it is blocked by the first. If both processes
drhf5befa02007-12-06 02:42:07 +00001549** invoke the busy handlers, neither will make any progress. Therefore,
drh6ed48bf2007-06-14 20:57:18 +00001550** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
drh86939b52007-01-10 12:54:51 +00001551** will induce the first process to release its read lock and allow
1552** the second process to proceed.
1553**
drh33c1be32008-01-30 16:16:14 +00001554** The default busy callback is NULL.
drh2dfbbca2000-07-28 14:32:48 +00001555**
drh33c1be32008-01-30 16:16:14 +00001556** The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED]
drhfddfa2d2007-12-05 18:05:16 +00001557** when SQLite is in the middle of a large transaction where all the
drh33c1be32008-01-30 16:16:14 +00001558** changes will not fit into the in-memory cache. SQLite will
drh6ed48bf2007-06-14 20:57:18 +00001559** already hold a RESERVED lock on the database file, but it needs
1560** to promote this lock to EXCLUSIVE so that it can spill cache
1561** pages into the database file without harm to concurrent
drh33c1be32008-01-30 16:16:14 +00001562** readers. If it is unable to promote the lock, then the in-memory
drh6ed48bf2007-06-14 20:57:18 +00001563** cache will be left in an inconsistent state and so the error
1564** code is promoted from the relatively benign [SQLITE_BUSY] to
drh33c1be32008-01-30 16:16:14 +00001565** the more severe [SQLITE_IOERR_BLOCKED]. This error code promotion
1566** forces an automatic rollback of the changes. See the
mihailimdb4f2ad2008-06-21 11:20:48 +00001567** <a href="/cvstrac/wiki?p=CorruptionFollowingBusyError">
drh6ed48bf2007-06-14 20:57:18 +00001568** CorruptionFollowingBusyError</a> wiki page for a discussion of why
1569** this is important.
mihailimdb4f2ad2008-06-21 11:20:48 +00001570**
1571** There can only be a single busy handler defined for each
1572** [database connection]. Setting a new busy handler clears any
1573** previously set handler. Note that calling [sqlite3_busy_timeout()]
1574** will also set or clear the busy handler.
drhd677b3d2007-08-20 22:48:41 +00001575**
drh33c1be32008-01-30 16:16:14 +00001576** INVARIANTS:
1577**
drh9a247912008-07-22 18:45:08 +00001578** {H12311} The [sqlite3_busy_handler(D,C,A)] function shall replace
drhcf538f42008-06-27 14:51:52 +00001579** busy callback in the [database connection] D with a new
1580** a new busy handler C and application data pointer A.
drh33c1be32008-01-30 16:16:14 +00001581**
drh9a247912008-07-22 18:45:08 +00001582** {H12312} Newly created [database connections] shall have a busy
drhcf538f42008-06-27 14:51:52 +00001583** handler of NULL.
drh33c1be32008-01-30 16:16:14 +00001584**
drh9a247912008-07-22 18:45:08 +00001585** {H12314} When two or more [database connections] share a
mihailimdb4f2ad2008-06-21 11:20:48 +00001586** [sqlite3_enable_shared_cache | common cache],
drh33c1be32008-01-30 16:16:14 +00001587** the busy handler for the database connection currently using
drhcf538f42008-06-27 14:51:52 +00001588** the cache shall be invoked when the cache encounters a lock.
drh33c1be32008-01-30 16:16:14 +00001589**
drh9a247912008-07-22 18:45:08 +00001590** {H12316} If a busy handler callback returns zero, then the SQLite interface
drhcf538f42008-06-27 14:51:52 +00001591** that provoked the locking event shall return [SQLITE_BUSY].
drh33c1be32008-01-30 16:16:14 +00001592**
drh9a247912008-07-22 18:45:08 +00001593** {H12318} SQLite shall invokes the busy handler with two arguments which
drh33c1be32008-01-30 16:16:14 +00001594** are a copy of the pointer supplied by the 3rd parameter to
1595** [sqlite3_busy_handler()] and a count of the number of prior
1596** invocations of the busy handler for the same locking event.
1597**
drh9a247912008-07-22 18:45:08 +00001598** ASSUMPTIONS:
drh33c1be32008-01-30 16:16:14 +00001599**
drhcf538f42008-06-27 14:51:52 +00001600** {A12319} A busy handler must not close the database connection
mihailimdb4f2ad2008-06-21 11:20:48 +00001601** or [prepared statement] that invoked the busy handler.
drh2dfbbca2000-07-28 14:32:48 +00001602*/
danielk1977f9d64d22004-06-19 08:18:07 +00001603int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
drh2dfbbca2000-07-28 14:32:48 +00001604
1605/*
drhb25f9d82008-07-23 15:40:06 +00001606** CAPI3REF: Set A Busy Timeout {H12340} <S40410>
drh6ed48bf2007-06-14 20:57:18 +00001607**
mihailimdb4f2ad2008-06-21 11:20:48 +00001608** This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
1609** for a specified amount of time when a table is locked. The handler
1610** will sleep multiple times until at least "ms" milliseconds of sleeping
drh9a247912008-07-22 18:45:08 +00001611** have accumulated. {H12343} After "ms" milliseconds of sleeping,
mihailimdb4f2ad2008-06-21 11:20:48 +00001612** the handler returns 0 which causes [sqlite3_step()] to return
1613** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED].
drh2dfbbca2000-07-28 14:32:48 +00001614**
drh33c1be32008-01-30 16:16:14 +00001615** Calling this routine with an argument less than or equal to zero
drh2dfbbca2000-07-28 14:32:48 +00001616** turns off all busy handlers.
drh6ed48bf2007-06-14 20:57:18 +00001617**
mihailimdb4f2ad2008-06-21 11:20:48 +00001618** There can only be a single busy handler for a particular
1619** [database connection] any any given moment. If another busy handler
1620** was defined (using [sqlite3_busy_handler()]) prior to calling
drh6ed48bf2007-06-14 20:57:18 +00001621** this routine, that other busy handler is cleared.
drh33c1be32008-01-30 16:16:14 +00001622**
1623** INVARIANTS:
1624**
drh9a247912008-07-22 18:45:08 +00001625** {H12341} The [sqlite3_busy_timeout()] function shall override any prior
drh33c1be32008-01-30 16:16:14 +00001626** [sqlite3_busy_timeout()] or [sqlite3_busy_handler()] setting
drhcf538f42008-06-27 14:51:52 +00001627** on the same [database connection].
drh33c1be32008-01-30 16:16:14 +00001628**
drh9a247912008-07-22 18:45:08 +00001629** {H12343} If the 2nd parameter to [sqlite3_busy_timeout()] is less than
drhcf538f42008-06-27 14:51:52 +00001630** or equal to zero, then the busy handler shall be cleared so that
drh33c1be32008-01-30 16:16:14 +00001631** all subsequent locking events immediately return [SQLITE_BUSY].
1632**
drh9a247912008-07-22 18:45:08 +00001633** {H12344} If the 2nd parameter to [sqlite3_busy_timeout()] is a positive
drhcf538f42008-06-27 14:51:52 +00001634** number N, then a busy handler shall be set that repeatedly calls
1635** the xSleep() method in the [sqlite3_vfs | VFS interface] until
1636** either the lock clears or until the cumulative sleep time
1637** reported back by xSleep() exceeds N milliseconds.
drh2dfbbca2000-07-28 14:32:48 +00001638*/
danielk1977f9d64d22004-06-19 08:18:07 +00001639int sqlite3_busy_timeout(sqlite3*, int ms);
drh2dfbbca2000-07-28 14:32:48 +00001640
drhe3710332000-09-29 13:30:53 +00001641/*
drh9cd29642008-07-23 00:52:55 +00001642** CAPI3REF: Convenience Routines For Running Queries {H12370} <S10000>
drh6ed48bf2007-06-14 20:57:18 +00001643**
drh33c1be32008-01-30 16:16:14 +00001644** Definition: A <b>result table</b> is memory data structure created by the
1645** [sqlite3_get_table()] interface. A result table records the
1646** complete query results from one or more queries.
drha18c5682000-10-08 22:20:57 +00001647**
drh33c1be32008-01-30 16:16:14 +00001648** The table conceptually has a number of rows and columns. But
1649** these numbers are not part of the result table itself. These
1650** numbers are obtained separately. Let N be the number of rows
1651** and M be the number of columns.
1652**
mihailimdb4f2ad2008-06-21 11:20:48 +00001653** A result table is an array of pointers to zero-terminated UTF-8 strings.
1654** There are (N+1)*M elements in the array. The first M pointers point
1655** to zero-terminated strings that contain the names of the columns.
1656** The remaining entries all point to query results. NULL values result
1657** in NULL pointers. All other values are in their UTF-8 zero-terminated
1658** string representation as returned by [sqlite3_column_text()].
drh33c1be32008-01-30 16:16:14 +00001659**
mihailimdb4f2ad2008-06-21 11:20:48 +00001660** A result table might consist of one or more memory allocations.
drh33c1be32008-01-30 16:16:14 +00001661** It is not safe to pass a result table directly to [sqlite3_free()].
1662** A result table should be deallocated using [sqlite3_free_table()].
1663**
1664** As an example of the result table format, suppose a query result
1665** is as follows:
drha18c5682000-10-08 22:20:57 +00001666**
drh8bacf972007-08-25 16:21:29 +00001667** <blockquote><pre>
drha18c5682000-10-08 22:20:57 +00001668** Name | Age
1669** -----------------------
1670** Alice | 43
1671** Bob | 28
1672** Cindy | 21
drh8bacf972007-08-25 16:21:29 +00001673** </pre></blockquote>
drha18c5682000-10-08 22:20:57 +00001674**
drh33c1be32008-01-30 16:16:14 +00001675** There are two column (M==2) and three rows (N==3). Thus the
1676** result table has 8 entries. Suppose the result table is stored
1677** in an array names azResult. Then azResult holds this content:
drha18c5682000-10-08 22:20:57 +00001678**
drh8bacf972007-08-25 16:21:29 +00001679** <blockquote><pre>
1680** azResult&#91;0] = "Name";
1681** azResult&#91;1] = "Age";
1682** azResult&#91;2] = "Alice";
1683** azResult&#91;3] = "43";
1684** azResult&#91;4] = "Bob";
1685** azResult&#91;5] = "28";
1686** azResult&#91;6] = "Cindy";
1687** azResult&#91;7] = "21";
1688** </pre></blockquote>
drha18c5682000-10-08 22:20:57 +00001689**
drh33c1be32008-01-30 16:16:14 +00001690** The sqlite3_get_table() function evaluates one or more
1691** semicolon-separated SQL statements in the zero-terminated UTF-8
1692** string of its 2nd parameter. It returns a result table to the
1693** pointer given in its 3rd parameter.
drha18c5682000-10-08 22:20:57 +00001694**
mihailimdb4f2ad2008-06-21 11:20:48 +00001695** After the calling function has finished using the result, it should
1696** pass the pointer to the result table to sqlite3_free_table() in order to
1697** release the memory that was malloced. Because of the way the
drh33c1be32008-01-30 16:16:14 +00001698** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
mihailimdb4f2ad2008-06-21 11:20:48 +00001699** function must not try to call [sqlite3_free()] directly. Only
drh33c1be32008-01-30 16:16:14 +00001700** [sqlite3_free_table()] is able to release the memory properly and safely.
drhe3710332000-09-29 13:30:53 +00001701**
drh33c1be32008-01-30 16:16:14 +00001702** The sqlite3_get_table() interface is implemented as a wrapper around
1703** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access
1704** to any internal data structures of SQLite. It uses only the public
1705** interface defined here. As a consequence, errors that occur in the
1706** wrapper layer outside of the internal [sqlite3_exec()] call are not
mihailimdb4f2ad2008-06-21 11:20:48 +00001707** reflected in subsequent calls to [sqlite3_errcode()] or [sqlite3_errmsg()].
drh33c1be32008-01-30 16:16:14 +00001708**
1709** INVARIANTS:
1710**
drh9a247912008-07-22 18:45:08 +00001711** {H12371} If a [sqlite3_get_table()] fails a memory allocation, then
drhcf538f42008-06-27 14:51:52 +00001712** it shall free the result table under construction, abort the
1713** query in process, skip any subsequent queries, set the
1714** *pazResult output pointer to NULL and return [SQLITE_NOMEM].
drh33c1be32008-01-30 16:16:14 +00001715**
drh9a247912008-07-22 18:45:08 +00001716** {H12373} If the pnColumn parameter to [sqlite3_get_table()] is not NULL
drhcf538f42008-06-27 14:51:52 +00001717** then a successful invocation of [sqlite3_get_table()] shall
1718** write the number of columns in the
1719** result set of the query into *pnColumn.
drh33c1be32008-01-30 16:16:14 +00001720**
drh9a247912008-07-22 18:45:08 +00001721** {H12374} If the pnRow parameter to [sqlite3_get_table()] is not NULL
drhcf538f42008-06-27 14:51:52 +00001722** then a successful invocation of [sqlite3_get_table()] shall
1723** writes the number of rows in the
1724** result set of the query into *pnRow.
drh33c1be32008-01-30 16:16:14 +00001725**
drh9a247912008-07-22 18:45:08 +00001726** {H12376} A successful invocation of [sqlite3_get_table()] that computes
drhcf538f42008-06-27 14:51:52 +00001727** N rows of result with C columns per row shall make *pazResult
1728** point to an array of pointers to (N+1)*C strings where the first
1729** C strings are column names as obtained from
1730** [sqlite3_column_name()] and the rest are column result values
1731** obtained from [sqlite3_column_text()].
1732**
drh9a247912008-07-22 18:45:08 +00001733** {H12379} The values in the pazResult array returned by [sqlite3_get_table()]
drhcf538f42008-06-27 14:51:52 +00001734** shall remain valid until cleared by [sqlite3_free_table()].
1735**
drh9a247912008-07-22 18:45:08 +00001736** {H12382} When an error occurs during evaluation of [sqlite3_get_table()]
drhcf538f42008-06-27 14:51:52 +00001737** the function shall set *pazResult to NULL, write an error message
1738** into memory obtained from [sqlite3_malloc()], make
1739** **pzErrmsg point to that error message, and return a
1740** appropriate [error code].
drhe3710332000-09-29 13:30:53 +00001741*/
danielk19776f8a5032004-05-10 10:34:51 +00001742int sqlite3_get_table(
drhcf538f42008-06-27 14:51:52 +00001743 sqlite3 *db, /* An open database */
1744 const char *zSql, /* SQL to be evaluated */
1745 char ***pazResult, /* Results of the query */
1746 int *pnRow, /* Number of result rows written here */
1747 int *pnColumn, /* Number of result columns written here */
1748 char **pzErrmsg /* Error msg written here */
drhe3710332000-09-29 13:30:53 +00001749);
danielk19776f8a5032004-05-10 10:34:51 +00001750void sqlite3_free_table(char **result);
drhe3710332000-09-29 13:30:53 +00001751
drha18c5682000-10-08 22:20:57 +00001752/*
drh9cd29642008-07-23 00:52:55 +00001753** CAPI3REF: Formatted String Printing Functions {H17400} <S70000><S20000>
drh6ed48bf2007-06-14 20:57:18 +00001754**
1755** These routines are workalikes of the "printf()" family of functions
1756** from the standard C library.
1757**
drh33c1be32008-01-30 16:16:14 +00001758** The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
drh6d2069d2007-08-14 01:58:53 +00001759** results into memory obtained from [sqlite3_malloc()].
drh33c1be32008-01-30 16:16:14 +00001760** The strings returned by these two routines should be
mihailim04bcc002008-06-22 10:21:27 +00001761** released by [sqlite3_free()]. Both routines return a
drh6ed48bf2007-06-14 20:57:18 +00001762** NULL pointer if [sqlite3_malloc()] is unable to allocate enough
1763** memory to hold the resulting string.
1764**
drh33c1be32008-01-30 16:16:14 +00001765** In sqlite3_snprintf() routine is similar to "snprintf()" from
drh6ed48bf2007-06-14 20:57:18 +00001766** the standard C library. The result is written into the
1767** buffer supplied as the second parameter whose size is given by
drh33c1be32008-01-30 16:16:14 +00001768** the first parameter. Note that the order of the
drh6ed48bf2007-06-14 20:57:18 +00001769** first two parameters is reversed from snprintf(). This is an
1770** historical accident that cannot be fixed without breaking
drh33c1be32008-01-30 16:16:14 +00001771** backwards compatibility. Note also that sqlite3_snprintf()
drh6ed48bf2007-06-14 20:57:18 +00001772** returns a pointer to its buffer instead of the number of
drh33c1be32008-01-30 16:16:14 +00001773** characters actually written into the buffer. We admit that
drh6ed48bf2007-06-14 20:57:18 +00001774** the number of characters written would be a more useful return
1775** value but we cannot change the implementation of sqlite3_snprintf()
1776** now without breaking compatibility.
1777**
drh33c1be32008-01-30 16:16:14 +00001778** As long as the buffer size is greater than zero, sqlite3_snprintf()
1779** guarantees that the buffer is always zero-terminated. The first
drh6ed48bf2007-06-14 20:57:18 +00001780** parameter "n" is the total size of the buffer, including space for
drh33c1be32008-01-30 16:16:14 +00001781** the zero terminator. So the longest string that can be completely
drh6ed48bf2007-06-14 20:57:18 +00001782** written will be n-1 characters.
1783**
1784** These routines all implement some additional formatting
drh4f26d6c2004-05-26 23:25:30 +00001785** options that are useful for constructing SQL statements.
shane26b34032008-05-23 17:21:09 +00001786** All of the usual printf() formatting options apply. In addition, there
drh153c62c2007-08-24 03:51:33 +00001787** is are "%q", "%Q", and "%z" options.
drh6ed48bf2007-06-14 20:57:18 +00001788**
drh33c1be32008-01-30 16:16:14 +00001789** The %q option works like %s in that it substitutes a null-terminated
drh66b89c82000-11-28 20:47:17 +00001790** string from the argument list. But %q also doubles every '\'' character.
drh33c1be32008-01-30 16:16:14 +00001791** %q is designed for use inside a string literal. By doubling each '\''
drh66b89c82000-11-28 20:47:17 +00001792** character it escapes that character and allows it to be inserted into
drha18c5682000-10-08 22:20:57 +00001793** the string.
1794**
mihailimdb4f2ad2008-06-21 11:20:48 +00001795** For example, assume the string variable zText contains text as follows:
drha18c5682000-10-08 22:20:57 +00001796**
drh6ed48bf2007-06-14 20:57:18 +00001797** <blockquote><pre>
1798** char *zText = "It's a happy day!";
1799** </pre></blockquote>
drha18c5682000-10-08 22:20:57 +00001800**
drh6ed48bf2007-06-14 20:57:18 +00001801** One can use this text in an SQL statement as follows:
drha18c5682000-10-08 22:20:57 +00001802**
drh6ed48bf2007-06-14 20:57:18 +00001803** <blockquote><pre>
1804** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);
1805** sqlite3_exec(db, zSQL, 0, 0, 0);
1806** sqlite3_free(zSQL);
1807** </pre></blockquote>
drha18c5682000-10-08 22:20:57 +00001808**
1809** Because the %q format string is used, the '\'' character in zText
1810** is escaped and the SQL generated is as follows:
1811**
drh6ed48bf2007-06-14 20:57:18 +00001812** <blockquote><pre>
1813** INSERT INTO table1 VALUES('It''s a happy day!')
1814** </pre></blockquote>
drha18c5682000-10-08 22:20:57 +00001815**
1816** This is correct. Had we used %s instead of %q, the generated SQL
1817** would have looked like this:
1818**
drh6ed48bf2007-06-14 20:57:18 +00001819** <blockquote><pre>
1820** INSERT INTO table1 VALUES('It's a happy day!');
1821** </pre></blockquote>
drha18c5682000-10-08 22:20:57 +00001822**
mihailimdb4f2ad2008-06-21 11:20:48 +00001823** This second example is an SQL syntax error. As a general rule you should
1824** always use %q instead of %s when inserting text into a string literal.
drh6ed48bf2007-06-14 20:57:18 +00001825**
drh33c1be32008-01-30 16:16:14 +00001826** The %Q option works like %q except it also adds single quotes around
mihailimdb4f2ad2008-06-21 11:20:48 +00001827** the outside of the total string. Additionally, if the parameter in the
1828** argument list is a NULL pointer, %Q substitutes the text "NULL" (without
mihailim04bcc002008-06-22 10:21:27 +00001829** single quotes) in place of the %Q option. So, for example, one could say:
drh6ed48bf2007-06-14 20:57:18 +00001830**
1831** <blockquote><pre>
1832** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
1833** sqlite3_exec(db, zSQL, 0, 0, 0);
1834** sqlite3_free(zSQL);
1835** </pre></blockquote>
1836**
1837** The code above will render a correct SQL statement in the zSQL
1838** variable even if the zText variable is a NULL pointer.
drh153c62c2007-08-24 03:51:33 +00001839**
drh33c1be32008-01-30 16:16:14 +00001840** The "%z" formatting option works exactly like "%s" with the
drh153c62c2007-08-24 03:51:33 +00001841** addition that after the string has been read and copied into
drhfddfa2d2007-12-05 18:05:16 +00001842** the result, [sqlite3_free()] is called on the input string. {END}
drh33c1be32008-01-30 16:16:14 +00001843**
1844** INVARIANTS:
1845**
drh9a247912008-07-22 18:45:08 +00001846** {H17403} The [sqlite3_mprintf()] and [sqlite3_vmprintf()] interfaces
drh33c1be32008-01-30 16:16:14 +00001847** return either pointers to zero-terminated UTF-8 strings held in
1848** memory obtained from [sqlite3_malloc()] or NULL pointers if
1849** a call to [sqlite3_malloc()] fails.
1850**
drh9a247912008-07-22 18:45:08 +00001851** {H17406} The [sqlite3_snprintf()] interface writes a zero-terminated
drh33c1be32008-01-30 16:16:14 +00001852** UTF-8 string into the buffer pointed to by the second parameter
1853** provided that the first parameter is greater than zero.
1854**
drh9a247912008-07-22 18:45:08 +00001855** {H17407} The [sqlite3_snprintf()] interface does not write slots of
drh33c1be32008-01-30 16:16:14 +00001856** its output buffer (the second parameter) outside the range
1857** of 0 through N-1 (where N is the first parameter)
1858** regardless of the length of the string
1859** requested by the format specification.
drha18c5682000-10-08 22:20:57 +00001860*/
danielk19776f8a5032004-05-10 10:34:51 +00001861char *sqlite3_mprintf(const char*,...);
1862char *sqlite3_vmprintf(const char*, va_list);
drhfeac5f82004-08-01 00:10:45 +00001863char *sqlite3_snprintf(int,char*,const char*, ...);
drh5191b7e2002-03-08 02:12:00 +00001864
drh28dd4792006-06-26 21:35:44 +00001865/*
drh9cd29642008-07-23 00:52:55 +00001866** CAPI3REF: Memory Allocation Subsystem {H17300} <S20000>
drhd84f9462007-08-15 11:28:56 +00001867**
drh33c1be32008-01-30 16:16:14 +00001868** The SQLite core uses these three routines for all of its own
1869** internal memory allocation needs. "Core" in the previous sentence
drhf5befa02007-12-06 02:42:07 +00001870** does not include operating-system specific VFS implementation. The
shane26b34032008-05-23 17:21:09 +00001871** Windows VFS uses native malloc() and free() for some operations.
drhd64621d2007-11-05 17:54:17 +00001872**
drh33c1be32008-01-30 16:16:14 +00001873** The sqlite3_malloc() routine returns a pointer to a block
drhfddfa2d2007-12-05 18:05:16 +00001874** of memory at least N bytes in length, where N is the parameter.
drh33c1be32008-01-30 16:16:14 +00001875** If sqlite3_malloc() is unable to obtain sufficient free
1876** memory, it returns a NULL pointer. If the parameter N to
drhfddfa2d2007-12-05 18:05:16 +00001877** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
1878** a NULL pointer.
1879**
drh33c1be32008-01-30 16:16:14 +00001880** Calling sqlite3_free() with a pointer previously returned
drhfddfa2d2007-12-05 18:05:16 +00001881** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
drh33c1be32008-01-30 16:16:14 +00001882** that it might be reused. The sqlite3_free() routine is
drhfddfa2d2007-12-05 18:05:16 +00001883** a no-op if is called with a NULL pointer. Passing a NULL pointer
drh33c1be32008-01-30 16:16:14 +00001884** to sqlite3_free() is harmless. After being freed, memory
drhfddfa2d2007-12-05 18:05:16 +00001885** should neither be read nor written. Even reading previously freed
1886** memory might result in a segmentation fault or other severe error.
drh33c1be32008-01-30 16:16:14 +00001887** Memory corruption, a segmentation fault, or other severe error
drhfddfa2d2007-12-05 18:05:16 +00001888** might result if sqlite3_free() is called with a non-NULL pointer that
1889** was not obtained from sqlite3_malloc() or sqlite3_free().
1890**
drh33c1be32008-01-30 16:16:14 +00001891** The sqlite3_realloc() interface attempts to resize a
drhfddfa2d2007-12-05 18:05:16 +00001892** prior memory allocation to be at least N bytes, where N is the
1893** second parameter. The memory allocation to be resized is the first
drh33c1be32008-01-30 16:16:14 +00001894** parameter. If the first parameter to sqlite3_realloc()
drhfddfa2d2007-12-05 18:05:16 +00001895** is a NULL pointer then its behavior is identical to calling
1896** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc().
drh33c1be32008-01-30 16:16:14 +00001897** If the second parameter to sqlite3_realloc() is zero or
drhfddfa2d2007-12-05 18:05:16 +00001898** negative then the behavior is exactly the same as calling
1899** sqlite3_free(P) where P is the first parameter to sqlite3_realloc().
mihailimdb4f2ad2008-06-21 11:20:48 +00001900** sqlite3_realloc() returns a pointer to a memory allocation
drhfddfa2d2007-12-05 18:05:16 +00001901** of at least N bytes in size or NULL if sufficient memory is unavailable.
drh33c1be32008-01-30 16:16:14 +00001902** If M is the size of the prior allocation, then min(N,M) bytes
drhfddfa2d2007-12-05 18:05:16 +00001903** of the prior allocation are copied into the beginning of buffer returned
1904** by sqlite3_realloc() and the prior allocation is freed.
drh33c1be32008-01-30 16:16:14 +00001905** If sqlite3_realloc() returns NULL, then the prior allocation
drhfddfa2d2007-12-05 18:05:16 +00001906** is not freed.
1907**
drh33c1be32008-01-30 16:16:14 +00001908** The memory returned by sqlite3_malloc() and sqlite3_realloc()
drhf5befa02007-12-06 02:42:07 +00001909** is always aligned to at least an 8 byte boundary. {END}
1910**
mihailimdb4f2ad2008-06-21 11:20:48 +00001911** The default implementation of the memory allocation subsystem uses
1912** the malloc(), realloc() and free() provided by the standard C library.
drh9a247912008-07-22 18:45:08 +00001913** {H17382} However, if SQLite is compiled with the
mihailimdb4f2ad2008-06-21 11:20:48 +00001914** SQLITE_MEMORY_SIZE=<i>NNN</i> C preprocessor macro (where <i>NNN</i>
1915** is an integer), then SQLite create a static array of at least
1916** <i>NNN</i> bytes in size and uses that array for all of its dynamic
1917** memory allocation needs. {END} Additional memory allocator options
1918** may be added in future releases.
drhd64621d2007-11-05 17:54:17 +00001919**
1920** In SQLite version 3.5.0 and 3.5.1, it was possible to define
1921** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
1922** implementation of these routines to be omitted. That capability
mihailimdb4f2ad2008-06-21 11:20:48 +00001923** is no longer provided. Only built-in memory allocators can be used.
drh8bacf972007-08-25 16:21:29 +00001924**
shane26b34032008-05-23 17:21:09 +00001925** The Windows OS interface layer calls
drh8bacf972007-08-25 16:21:29 +00001926** the system malloc() and free() directly when converting
1927** filenames between the UTF-8 encoding used by SQLite
shane26b34032008-05-23 17:21:09 +00001928** and whatever filename encoding is used by the particular Windows
drh8bacf972007-08-25 16:21:29 +00001929** installation. Memory allocation errors are detected, but
1930** they are reported back as [SQLITE_CANTOPEN] or
1931** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
drh33c1be32008-01-30 16:16:14 +00001932**
1933** INVARIANTS:
1934**
drh9a247912008-07-22 18:45:08 +00001935** {H17303} The [sqlite3_malloc(N)] interface returns either a pointer to
mihailimdb4f2ad2008-06-21 11:20:48 +00001936** a newly checked-out block of at least N bytes of memory
1937** that is 8-byte aligned, or it returns NULL if it is unable
1938** to fulfill the request.
drh33c1be32008-01-30 16:16:14 +00001939**
drh9a247912008-07-22 18:45:08 +00001940** {H17304} The [sqlite3_malloc(N)] interface returns a NULL pointer if
drh33c1be32008-01-30 16:16:14 +00001941** N is less than or equal to zero.
1942**
drh9a247912008-07-22 18:45:08 +00001943** {H17305} The [sqlite3_free(P)] interface releases memory previously
drh33c1be32008-01-30 16:16:14 +00001944** returned from [sqlite3_malloc()] or [sqlite3_realloc()],
1945** making it available for reuse.
1946**
drh9a247912008-07-22 18:45:08 +00001947** {H17306} A call to [sqlite3_free(NULL)] is a harmless no-op.
drh33c1be32008-01-30 16:16:14 +00001948**
drh9a247912008-07-22 18:45:08 +00001949** {H17310} A call to [sqlite3_realloc(0,N)] is equivalent to a call
drh33c1be32008-01-30 16:16:14 +00001950** to [sqlite3_malloc(N)].
1951**
drh9a247912008-07-22 18:45:08 +00001952** {H17312} A call to [sqlite3_realloc(P,0)] is equivalent to a call
drh33c1be32008-01-30 16:16:14 +00001953** to [sqlite3_free(P)].
1954**
drh9a247912008-07-22 18:45:08 +00001955** {H17315} The SQLite core uses [sqlite3_malloc()], [sqlite3_realloc()],
drh33c1be32008-01-30 16:16:14 +00001956** and [sqlite3_free()] for all of its memory allocation and
1957** deallocation needs.
1958**
drh9a247912008-07-22 18:45:08 +00001959** {H17318} The [sqlite3_realloc(P,N)] interface returns either a pointer
drh33c1be32008-01-30 16:16:14 +00001960** to a block of checked-out memory of at least N bytes in size
1961** that is 8-byte aligned, or a NULL pointer.
1962**
drh9a247912008-07-22 18:45:08 +00001963** {H17321} When [sqlite3_realloc(P,N)] returns a non-NULL pointer, it first
mihailimdb4f2ad2008-06-21 11:20:48 +00001964** copies the first K bytes of content from P into the newly
1965** allocated block, where K is the lesser of N and the size of
1966** the buffer P.
drh33c1be32008-01-30 16:16:14 +00001967**
drh9a247912008-07-22 18:45:08 +00001968** {H17322} When [sqlite3_realloc(P,N)] returns a non-NULL pointer, it first
drh33c1be32008-01-30 16:16:14 +00001969** releases the buffer P.
1970**
drh9a247912008-07-22 18:45:08 +00001971** {H17323} When [sqlite3_realloc(P,N)] returns NULL, the buffer P is
drh33c1be32008-01-30 16:16:14 +00001972** not modified or released.
1973**
drh9a247912008-07-22 18:45:08 +00001974** ASSUMPTIONS:
drh33c1be32008-01-30 16:16:14 +00001975**
drh4766b292008-06-26 02:53:02 +00001976** {A17350} The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
mihailimdb4f2ad2008-06-21 11:20:48 +00001977** must be either NULL or else pointers obtained from a prior
1978** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
1979** not yet been released.
drh33c1be32008-01-30 16:16:14 +00001980**
drh4766b292008-06-26 02:53:02 +00001981** {A17351} The application must not read or write any part of
drh33c1be32008-01-30 16:16:14 +00001982** a block of memory after it has been released using
1983** [sqlite3_free()] or [sqlite3_realloc()].
drh28dd4792006-06-26 21:35:44 +00001984*/
drhf3a65f72007-08-22 20:18:21 +00001985void *sqlite3_malloc(int);
1986void *sqlite3_realloc(void*, int);
drh28dd4792006-06-26 21:35:44 +00001987void sqlite3_free(void*);
1988
drh5191b7e2002-03-08 02:12:00 +00001989/*
drh9cd29642008-07-23 00:52:55 +00001990** CAPI3REF: Memory Allocator Statistics {H17370} <S30210>
drhd84f9462007-08-15 11:28:56 +00001991**
drh33c1be32008-01-30 16:16:14 +00001992** SQLite provides these two interfaces for reporting on the status
1993** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
mihailimdb4f2ad2008-06-21 11:20:48 +00001994** routines, which form the built-in memory allocation subsystem.
drhd84f9462007-08-15 11:28:56 +00001995**
drh33c1be32008-01-30 16:16:14 +00001996** INVARIANTS:
1997**
drh9a247912008-07-22 18:45:08 +00001998** {H17371} The [sqlite3_memory_used()] routine returns the number of bytes
mihailima3f64902008-06-21 13:35:56 +00001999** of memory currently outstanding (malloced but not freed).
drh33c1be32008-01-30 16:16:14 +00002000**
drh9a247912008-07-22 18:45:08 +00002001** {H17373} The [sqlite3_memory_highwater()] routine returns the maximum
mihailimdb4f2ad2008-06-21 11:20:48 +00002002** value of [sqlite3_memory_used()] since the high-water mark
2003** was last reset.
drh33c1be32008-01-30 16:16:14 +00002004**
drh9a247912008-07-22 18:45:08 +00002005** {H17374} The values returned by [sqlite3_memory_used()] and
drh33c1be32008-01-30 16:16:14 +00002006** [sqlite3_memory_highwater()] include any overhead
2007** added by SQLite in its implementation of [sqlite3_malloc()],
2008** but not overhead added by the any underlying system library
2009** routines that [sqlite3_malloc()] may call.
mihailima3f64902008-06-21 13:35:56 +00002010**
drh9a247912008-07-22 18:45:08 +00002011** {H17375} The memory high-water mark is reset to the current value of
drh33c1be32008-01-30 16:16:14 +00002012** [sqlite3_memory_used()] if and only if the parameter to
2013** [sqlite3_memory_highwater()] is true. The value returned
shane26b34032008-05-23 17:21:09 +00002014** by [sqlite3_memory_highwater(1)] is the high-water mark
drh33c1be32008-01-30 16:16:14 +00002015** prior to the reset.
drhd84f9462007-08-15 11:28:56 +00002016*/
drh153c62c2007-08-24 03:51:33 +00002017sqlite3_int64 sqlite3_memory_used(void);
2018sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
drhd84f9462007-08-15 11:28:56 +00002019
2020/*
drh9cd29642008-07-23 00:52:55 +00002021** CAPI3REF: Pseudo-Random Number Generator {H17390} <S20000>
drh2fa18682008-03-19 14:15:34 +00002022**
2023** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
2024** select random ROWIDs when inserting new records into a table that
2025** already uses the largest possible ROWID. The PRNG is also used for
2026** the build-in random() and randomblob() SQL functions. This interface allows
shane26b34032008-05-23 17:21:09 +00002027** applications to access the same PRNG for other purposes.
drh2fa18682008-03-19 14:15:34 +00002028**
2029** A call to this routine stores N bytes of randomness into buffer P.
2030**
2031** The first time this routine is invoked (either internally or by
2032** the application) the PRNG is seeded using randomness obtained
2033** from the xRandomness method of the default [sqlite3_vfs] object.
2034** On all subsequent invocations, the pseudo-randomness is generated
2035** internally and without recourse to the [sqlite3_vfs] xRandomness
2036** method.
2037**
2038** INVARIANTS:
2039**
drh9a247912008-07-22 18:45:08 +00002040** {H17392} The [sqlite3_randomness(N,P)] interface writes N bytes of
drh2fa18682008-03-19 14:15:34 +00002041** high-quality pseudo-randomness into buffer P.
2042*/
2043void sqlite3_randomness(int N, void *P);
2044
2045/*
drh9cd29642008-07-23 00:52:55 +00002046** CAPI3REF: Compile-Time Authorization Callbacks {H12500} <S70100>
drhfddfa2d2007-12-05 18:05:16 +00002047**
drh33c1be32008-01-30 16:16:14 +00002048** This routine registers a authorizer callback with a particular
drhf47ce562008-03-20 18:00:49 +00002049** [database connection], supplied in the first argument.
drh6ed48bf2007-06-14 20:57:18 +00002050** The authorizer callback is invoked as SQL statements are being compiled
2051** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
drh33c1be32008-01-30 16:16:14 +00002052** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()]. At various
drh6ed48bf2007-06-14 20:57:18 +00002053** points during the compilation process, as logic is being created
2054** to perform various actions, the authorizer callback is invoked to
drhf5befa02007-12-06 02:42:07 +00002055** see if those actions are allowed. The authorizer callback should
drhf47ce562008-03-20 18:00:49 +00002056** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the
drh6ed48bf2007-06-14 20:57:18 +00002057** specific action but allow the SQL statement to continue to be
2058** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
mihailima3f64902008-06-21 13:35:56 +00002059** rejected with an error. If the authorizer callback returns
drhf5befa02007-12-06 02:42:07 +00002060** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]
mihailima3f64902008-06-21 13:35:56 +00002061** then the [sqlite3_prepare_v2()] or equivalent call that triggered
drh33c1be32008-01-30 16:16:14 +00002062** the authorizer will fail with an error message.
drh6ed48bf2007-06-14 20:57:18 +00002063**
drhf5befa02007-12-06 02:42:07 +00002064** When the callback returns [SQLITE_OK], that means the operation
drh33c1be32008-01-30 16:16:14 +00002065** requested is ok. When the callback returns [SQLITE_DENY], the
drhf5befa02007-12-06 02:42:07 +00002066** [sqlite3_prepare_v2()] or equivalent call that triggered the
drh33c1be32008-01-30 16:16:14 +00002067** authorizer will fail with an error message explaining that
2068** access is denied. If the authorizer code is [SQLITE_READ]
drhf47ce562008-03-20 18:00:49 +00002069** and the callback returns [SQLITE_IGNORE] then the
2070** [prepared statement] statement is constructed to substitute
2071** a NULL value in place of the table column that would have
drh33c1be32008-01-30 16:16:14 +00002072** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE]
2073** return can be used to deny an untrusted user access to individual
2074** columns of a table.
drh6ed48bf2007-06-14 20:57:18 +00002075**
mihailima3f64902008-06-21 13:35:56 +00002076** The first parameter to the authorizer callback is a copy of the third
2077** parameter to the sqlite3_set_authorizer() interface. The second parameter
2078** to the callback is an integer [SQLITE_COPY | action code] that specifies
2079** the particular action to be authorized. The third through sixth parameters
2080** to the callback are zero-terminated strings that contain additional
2081** details about the action to be authorized.
drh6ed48bf2007-06-14 20:57:18 +00002082**
drhf47ce562008-03-20 18:00:49 +00002083** An authorizer is used when [sqlite3_prepare | preparing]
mihailimebe796c2008-06-21 20:11:17 +00002084** SQL statements from an untrusted source, to ensure that the SQL statements
2085** do not try to access data they are not allowed to see, or that they do not
2086** try to execute malicious statements that damage the database. For
drh6ed48bf2007-06-14 20:57:18 +00002087** example, an application may allow a user to enter arbitrary
2088** SQL queries for evaluation by a database. But the application does
2089** not want the user to be able to make arbitrary changes to the
2090** database. An authorizer could then be put in place while the
drhf47ce562008-03-20 18:00:49 +00002091** user-entered SQL is being [sqlite3_prepare | prepared] that
2092** disallows everything except [SELECT] statements.
2093**
2094** Applications that need to process SQL from untrusted sources
2095** might also consider lowering resource limits using [sqlite3_limit()]
2096** and limiting database size using the [max_page_count] [PRAGMA]
2097** in addition to using an authorizer.
drh6ed48bf2007-06-14 20:57:18 +00002098**
drh33c1be32008-01-30 16:16:14 +00002099** Only a single authorizer can be in place on a database connection
drh6ed48bf2007-06-14 20:57:18 +00002100** at a time. Each call to sqlite3_set_authorizer overrides the
drh33c1be32008-01-30 16:16:14 +00002101** previous call. Disable the authorizer by installing a NULL callback.
2102** The authorizer is disabled by default.
drh6ed48bf2007-06-14 20:57:18 +00002103**
mihailima3f64902008-06-21 13:35:56 +00002104** Note that the authorizer callback is invoked only during
drh33c1be32008-01-30 16:16:14 +00002105** [sqlite3_prepare()] or its variants. Authorization is not
2106** performed during statement evaluation in [sqlite3_step()].
2107**
2108** INVARIANTS:
2109**
drh9a247912008-07-22 18:45:08 +00002110** {H12501} The [sqlite3_set_authorizer(D,...)] interface registers a
drh33c1be32008-01-30 16:16:14 +00002111** authorizer callback with database connection D.
2112**
drh9a247912008-07-22 18:45:08 +00002113** {H12502} The authorizer callback is invoked as SQL statements are
mihailima3f64902008-06-21 13:35:56 +00002114** being compiled.
drh33c1be32008-01-30 16:16:14 +00002115**
drh9a247912008-07-22 18:45:08 +00002116** {H12503} If the authorizer callback returns any value other than
mihailima3f64902008-06-21 13:35:56 +00002117** [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY], then
drh33c1be32008-01-30 16:16:14 +00002118** the [sqlite3_prepare_v2()] or equivalent call that caused
2119** the authorizer callback to run shall fail with an
2120** [SQLITE_ERROR] error code and an appropriate error message.
2121**
drh9a247912008-07-22 18:45:08 +00002122** {H12504} When the authorizer callback returns [SQLITE_OK], the operation
mihailima3f64902008-06-21 13:35:56 +00002123** described is processed normally.
drh33c1be32008-01-30 16:16:14 +00002124**
drh9a247912008-07-22 18:45:08 +00002125** {H12505} When the authorizer callback returns [SQLITE_DENY], the
drh33c1be32008-01-30 16:16:14 +00002126** [sqlite3_prepare_v2()] or equivalent call that caused the
2127** authorizer callback to run shall fail
2128** with an [SQLITE_ERROR] error code and an error message
2129** explaining that access is denied.
2130**
drh9a247912008-07-22 18:45:08 +00002131** {H12506} If the authorizer code (the 2nd parameter to the authorizer
drh33c1be32008-01-30 16:16:14 +00002132** callback) is [SQLITE_READ] and the authorizer callback returns
mihailima3f64902008-06-21 13:35:56 +00002133** [SQLITE_IGNORE], then the prepared statement is constructed to
drh33c1be32008-01-30 16:16:14 +00002134** insert a NULL value in place of the table column that would have
2135** been read if [SQLITE_OK] had been returned.
2136**
drh9a247912008-07-22 18:45:08 +00002137** {H12507} If the authorizer code (the 2nd parameter to the authorizer
drh33c1be32008-01-30 16:16:14 +00002138** callback) is anything other than [SQLITE_READ], then
mihailima3f64902008-06-21 13:35:56 +00002139** a return of [SQLITE_IGNORE] has the same effect as [SQLITE_DENY].
drh33c1be32008-01-30 16:16:14 +00002140**
drh9a247912008-07-22 18:45:08 +00002141** {H12510} The first parameter to the authorizer callback is a copy of
drh33c1be32008-01-30 16:16:14 +00002142** the third parameter to the [sqlite3_set_authorizer()] interface.
2143**
drh9a247912008-07-22 18:45:08 +00002144** {H12511} The second parameter to the callback is an integer
drh33c1be32008-01-30 16:16:14 +00002145** [SQLITE_COPY | action code] that specifies the particular action
2146** to be authorized.
2147**
drh9a247912008-07-22 18:45:08 +00002148** {H12512} The third through sixth parameters to the callback are
mihailima3f64902008-06-21 13:35:56 +00002149** zero-terminated strings that contain
drh33c1be32008-01-30 16:16:14 +00002150** additional details about the action to be authorized.
2151**
drh9a247912008-07-22 18:45:08 +00002152** {H12520} Each call to [sqlite3_set_authorizer()] overrides
drh33c1be32008-01-30 16:16:14 +00002153** any previously installed authorizer.
2154**
drh9a247912008-07-22 18:45:08 +00002155** {H12521} A NULL authorizer means that no authorization
drh33c1be32008-01-30 16:16:14 +00002156** callback is invoked.
2157**
drh9a247912008-07-22 18:45:08 +00002158** {H12522} The default authorizer is NULL.
drhed6c8672003-01-12 18:02:16 +00002159*/
danielk19776f8a5032004-05-10 10:34:51 +00002160int sqlite3_set_authorizer(
danielk1977f9d64d22004-06-19 08:18:07 +00002161 sqlite3*,
drhe22a3342003-04-22 20:30:37 +00002162 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
drhe5f9c642003-01-13 23:27:31 +00002163 void *pUserData
drhed6c8672003-01-12 18:02:16 +00002164);
2165
2166/*
drh9cd29642008-07-23 00:52:55 +00002167** CAPI3REF: Authorizer Return Codes {H12590} <H12500>
drh6ed48bf2007-06-14 20:57:18 +00002168**
2169** The [sqlite3_set_authorizer | authorizer callback function] must
2170** return either [SQLITE_OK] or one of these two constants in order
2171** to signal SQLite whether or not the action is permitted. See the
2172** [sqlite3_set_authorizer | authorizer documentation] for additional
2173** information.
2174*/
2175#define SQLITE_DENY 1 /* Abort the SQL statement with an error */
2176#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
2177
2178/*
drh9cd29642008-07-23 00:52:55 +00002179** CAPI3REF: Authorizer Action Codes {H12550} <H12500>
drh6ed48bf2007-06-14 20:57:18 +00002180**
2181** The [sqlite3_set_authorizer()] interface registers a callback function
mihailima3f64902008-06-21 13:35:56 +00002182** that is invoked to authorize certain SQL statement actions. The
drh6ed48bf2007-06-14 20:57:18 +00002183** second parameter to the callback is an integer code that specifies
2184** what action is being authorized. These are the integer action codes that
drh33c1be32008-01-30 16:16:14 +00002185** the authorizer callback may be passed.
drh6ed48bf2007-06-14 20:57:18 +00002186**
mihailima3f64902008-06-21 13:35:56 +00002187** These action code values signify what kind of operation is to be
drh33c1be32008-01-30 16:16:14 +00002188** authorized. The 3rd and 4th parameters to the authorization
drhf5befa02007-12-06 02:42:07 +00002189** callback function will be parameters or NULL depending on which of these
drh33c1be32008-01-30 16:16:14 +00002190** codes is used as the second parameter. The 5th parameter to the
mihailima3f64902008-06-21 13:35:56 +00002191** authorizer callback is the name of the database ("main", "temp",
drh33c1be32008-01-30 16:16:14 +00002192** etc.) if applicable. The 6th parameter to the authorizer callback
drh5cf590c2003-04-24 01:45:04 +00002193** is the name of the inner-most trigger or view that is responsible for
mihailima3f64902008-06-21 13:35:56 +00002194** the access attempt or NULL if this access attempt is directly from
drh6ed48bf2007-06-14 20:57:18 +00002195** top-level SQL code.
drh33c1be32008-01-30 16:16:14 +00002196**
2197** INVARIANTS:
2198**
drh9a247912008-07-22 18:45:08 +00002199** {H12551} The second parameter to an
shane26b34032008-05-23 17:21:09 +00002200** [sqlite3_set_authorizer | authorizer callback] is always an integer
drh33c1be32008-01-30 16:16:14 +00002201** [SQLITE_COPY | authorizer code] that specifies what action
2202** is being authorized.
2203**
drh9a247912008-07-22 18:45:08 +00002204** {H12552} The 3rd and 4th parameters to the
mihailima3f64902008-06-21 13:35:56 +00002205** [sqlite3_set_authorizer | authorization callback]
2206** will be parameters or NULL depending on which
drh33c1be32008-01-30 16:16:14 +00002207** [SQLITE_COPY | authorizer code] is used as the second parameter.
2208**
drh9a247912008-07-22 18:45:08 +00002209** {H12553} The 5th parameter to the
drh33c1be32008-01-30 16:16:14 +00002210** [sqlite3_set_authorizer | authorizer callback] is the name
2211** of the database (example: "main", "temp", etc.) if applicable.
2212**
drh9a247912008-07-22 18:45:08 +00002213** {H12554} The 6th parameter to the
drh33c1be32008-01-30 16:16:14 +00002214** [sqlite3_set_authorizer | authorizer callback] is the name
2215** of the inner-most trigger or view that is responsible for
mihailima3f64902008-06-21 13:35:56 +00002216** the access attempt or NULL if this access attempt is directly from
drh33c1be32008-01-30 16:16:14 +00002217** top-level SQL code.
drhed6c8672003-01-12 18:02:16 +00002218*/
drh6ed48bf2007-06-14 20:57:18 +00002219/******************************************* 3rd ************ 4th ***********/
drhe5f9c642003-01-13 23:27:31 +00002220#define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
2221#define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
2222#define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
2223#define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */
drh77ad4e42003-01-14 02:49:27 +00002224#define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */
drhe5f9c642003-01-13 23:27:31 +00002225#define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */
drh77ad4e42003-01-14 02:49:27 +00002226#define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */
drhe5f9c642003-01-13 23:27:31 +00002227#define SQLITE_CREATE_VIEW 8 /* View Name NULL */
2228#define SQLITE_DELETE 9 /* Table Name NULL */
drh77ad4e42003-01-14 02:49:27 +00002229#define SQLITE_DROP_INDEX 10 /* Index Name Table Name */
drhe5f9c642003-01-13 23:27:31 +00002230#define SQLITE_DROP_TABLE 11 /* Table Name NULL */
drh77ad4e42003-01-14 02:49:27 +00002231#define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */
drhe5f9c642003-01-13 23:27:31 +00002232#define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */
drh77ad4e42003-01-14 02:49:27 +00002233#define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */
drhe5f9c642003-01-13 23:27:31 +00002234#define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */
drh77ad4e42003-01-14 02:49:27 +00002235#define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */
drhe5f9c642003-01-13 23:27:31 +00002236#define SQLITE_DROP_VIEW 17 /* View Name NULL */
2237#define SQLITE_INSERT 18 /* Table Name NULL */
2238#define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */
2239#define SQLITE_READ 20 /* Table Name Column Name */
2240#define SQLITE_SELECT 21 /* NULL NULL */
2241#define SQLITE_TRANSACTION 22 /* NULL NULL */
2242#define SQLITE_UPDATE 23 /* Table Name Column Name */
drh81e293b2003-06-06 19:00:42 +00002243#define SQLITE_ATTACH 24 /* Filename NULL */
2244#define SQLITE_DETACH 25 /* Database Name NULL */
danielk19771c8c23c2004-11-12 15:53:37 +00002245#define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
danielk19771d54df82004-11-23 15:41:16 +00002246#define SQLITE_REINDEX 27 /* Index Name NULL */
drhe6e04962005-07-23 02:17:03 +00002247#define SQLITE_ANALYZE 28 /* Table Name NULL */
danielk1977f1a381e2006-06-16 08:01:02 +00002248#define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
2249#define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
drh5169bbc2006-08-24 14:59:45 +00002250#define SQLITE_FUNCTION 31 /* Function Name NULL */
drh6ed48bf2007-06-14 20:57:18 +00002251#define SQLITE_COPY 0 /* No longer used */
drhed6c8672003-01-12 18:02:16 +00002252
2253/*
drh9cd29642008-07-23 00:52:55 +00002254** CAPI3REF: Tracing And Profiling Functions {H12280} <S60400>
drhd5a68d32008-08-04 13:44:57 +00002255** EXPERIMENTAL
drh6ed48bf2007-06-14 20:57:18 +00002256**
2257** These routines register callback functions that can be used for
2258** tracing and profiling the execution of SQL statements.
drhfddfa2d2007-12-05 18:05:16 +00002259**
drh33c1be32008-01-30 16:16:14 +00002260** The callback function registered by sqlite3_trace() is invoked at
2261** various times when an SQL statement is being run by [sqlite3_step()].
2262** The callback returns a UTF-8 rendering of the SQL statement text
2263** as the statement first begins executing. Additional callbacks occur
shane26b34032008-05-23 17:21:09 +00002264** as each triggered subprogram is entered. The callbacks for triggers
drh33c1be32008-01-30 16:16:14 +00002265** contain a UTF-8 SQL comment that identifies the trigger.
mihailima3f64902008-06-21 13:35:56 +00002266**
drh33c1be32008-01-30 16:16:14 +00002267** The callback function registered by sqlite3_profile() is invoked
2268** as each SQL statement finishes. The profile callback contains
2269** the original statement text and an estimate of wall-clock time
2270** of how long that statement took to run.
drh19e2d372005-08-29 23:00:03 +00002271**
drh33c1be32008-01-30 16:16:14 +00002272** INVARIANTS:
2273**
drh9a247912008-07-22 18:45:08 +00002274** {H12281} The callback function registered by [sqlite3_trace()] is
drh33c1be32008-01-30 16:16:14 +00002275** whenever an SQL statement first begins to execute and
2276** whenever a trigger subprogram first begins to run.
2277**
drh9a247912008-07-22 18:45:08 +00002278** {H12282} Each call to [sqlite3_trace()] overrides the previously
drh33c1be32008-01-30 16:16:14 +00002279** registered trace callback.
2280**
drh9a247912008-07-22 18:45:08 +00002281** {H12283} A NULL trace callback disables tracing.
drh33c1be32008-01-30 16:16:14 +00002282**
drh9a247912008-07-22 18:45:08 +00002283** {H12284} The first argument to the trace callback is a copy of
drh33c1be32008-01-30 16:16:14 +00002284** the pointer which was the 3rd argument to [sqlite3_trace()].
2285**
drh9a247912008-07-22 18:45:08 +00002286** {H12285} The second argument to the trace callback is a
mihailimebe796c2008-06-21 20:11:17 +00002287** zero-terminated UTF-8 string containing the original text
drh33c1be32008-01-30 16:16:14 +00002288** of the SQL statement as it was passed into [sqlite3_prepare_v2()]
2289** or the equivalent, or an SQL comment indicating the beginning
2290** of a trigger subprogram.
2291**
drh9a247912008-07-22 18:45:08 +00002292** {H12287} The callback function registered by [sqlite3_profile()] is invoked
drh33c1be32008-01-30 16:16:14 +00002293** as each SQL statement finishes.
2294**
drh9a247912008-07-22 18:45:08 +00002295** {H12288} The first parameter to the profile callback is a copy of
drh33c1be32008-01-30 16:16:14 +00002296** the 3rd parameter to [sqlite3_profile()].
2297**
drh9a247912008-07-22 18:45:08 +00002298** {H12289} The second parameter to the profile callback is a
drh33c1be32008-01-30 16:16:14 +00002299** zero-terminated UTF-8 string that contains the complete text of
2300** the SQL statement as it was processed by [sqlite3_prepare_v2()]
2301** or the equivalent.
2302**
drh9a247912008-07-22 18:45:08 +00002303** {H12290} The third parameter to the profile callback is an estimate
drh33c1be32008-01-30 16:16:14 +00002304** of the number of nanoseconds of wall-clock time required to
2305** run the SQL statement from start to finish.
drh18de4822003-01-16 16:28:53 +00002306*/
shanea79c3cc2008-08-11 17:27:01 +00002307SQLITE_EXPERIMENTAL void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
2308SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
drh6d2069d2007-08-14 01:58:53 +00002309 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
drh18de4822003-01-16 16:28:53 +00002310
danielk1977348bb5d2003-10-18 09:37:26 +00002311/*
drh9cd29642008-07-23 00:52:55 +00002312** CAPI3REF: Query Progress Callbacks {H12910} <S60400>
drh6ed48bf2007-06-14 20:57:18 +00002313**
drh33c1be32008-01-30 16:16:14 +00002314** This routine configures a callback function - the
drhfddfa2d2007-12-05 18:05:16 +00002315** progress callback - that is invoked periodically during long
2316** running calls to [sqlite3_exec()], [sqlite3_step()] and
mihailima3f64902008-06-21 13:35:56 +00002317** [sqlite3_get_table()]. An example use for this
drh6ed48bf2007-06-14 20:57:18 +00002318** interface is to keep a GUI updated during a large query.
danielk1977348bb5d2003-10-18 09:37:26 +00002319**
shane236ce972008-05-30 15:35:30 +00002320** If the progress callback returns non-zero, the operation is
drh33c1be32008-01-30 16:16:14 +00002321** interrupted. This feature can be used to implement a
2322** "Cancel" button on a GUI dialog box.
danielk1977348bb5d2003-10-18 09:37:26 +00002323**
drh33c1be32008-01-30 16:16:14 +00002324** INVARIANTS:
2325**
drh9a247912008-07-22 18:45:08 +00002326** {H12911} The callback function registered by sqlite3_progress_handler()
drh33c1be32008-01-30 16:16:14 +00002327** is invoked periodically during long running calls to
2328** [sqlite3_step()].
2329**
drh9a247912008-07-22 18:45:08 +00002330** {H12912} The progress callback is invoked once for every N virtual
mihailima3f64902008-06-21 13:35:56 +00002331** machine opcodes, where N is the second argument to
drh33c1be32008-01-30 16:16:14 +00002332** the [sqlite3_progress_handler()] call that registered
mihailima3f64902008-06-21 13:35:56 +00002333** the callback. If N is less than 1, sqlite3_progress_handler()
2334** acts as if a NULL progress handler had been specified.
drh33c1be32008-01-30 16:16:14 +00002335**
drh9a247912008-07-22 18:45:08 +00002336** {H12913} The progress callback itself is identified by the third
mihailima3f64902008-06-21 13:35:56 +00002337** argument to sqlite3_progress_handler().
drh33c1be32008-01-30 16:16:14 +00002338**
drh9a247912008-07-22 18:45:08 +00002339** {H12914} The fourth argument to sqlite3_progress_handler() is a
mihailim04bcc002008-06-22 10:21:27 +00002340** void pointer passed to the progress callback
drh33c1be32008-01-30 16:16:14 +00002341** function each time it is invoked.
2342**
drh9a247912008-07-22 18:45:08 +00002343** {H12915} If a call to [sqlite3_step()] results in fewer than N opcodes
mihailim04bcc002008-06-22 10:21:27 +00002344** being executed, then the progress callback is never invoked.
mihailima3f64902008-06-21 13:35:56 +00002345**
drh9a247912008-07-22 18:45:08 +00002346** {H12916} Every call to [sqlite3_progress_handler()]
shane26b34032008-05-23 17:21:09 +00002347** overwrites any previously registered progress handler.
drh33c1be32008-01-30 16:16:14 +00002348**
drh9a247912008-07-22 18:45:08 +00002349** {H12917} If the progress handler callback is NULL then no progress
drh33c1be32008-01-30 16:16:14 +00002350** handler is invoked.
danielk1977348bb5d2003-10-18 09:37:26 +00002351**
drh9a247912008-07-22 18:45:08 +00002352** {H12918} If the progress callback returns a result other than 0, then
drh33c1be32008-01-30 16:16:14 +00002353** the behavior is a if [sqlite3_interrupt()] had been called.
drh9cd29642008-07-23 00:52:55 +00002354** <S30500>
danielk1977348bb5d2003-10-18 09:37:26 +00002355*/
danielk1977f9d64d22004-06-19 08:18:07 +00002356void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
danielk1977348bb5d2003-10-18 09:37:26 +00002357
drhaa940ea2004-01-15 02:44:03 +00002358/*
drh9cd29642008-07-23 00:52:55 +00002359** CAPI3REF: Opening A New Database Connection {H12700} <S40200>
drhaa940ea2004-01-15 02:44:03 +00002360**
mihailima3f64902008-06-21 13:35:56 +00002361** These routines open an SQLite database file whose name is given by the
2362** filename argument. The filename argument is interpreted as UTF-8 for
2363** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2364** order for sqlite3_open16(). A [database connection] handle is usually
2365** returned in *ppDb, even if an error occurs. The only exception is that
2366** if SQLite is unable to allocate memory to hold the [sqlite3] object,
2367** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]
2368** object. If the database is opened (and/or created) successfully, then
mihailimefc8e8a2008-06-21 16:47:09 +00002369** [SQLITE_OK] is returned. Otherwise an [error code] is returned. The
mihailima3f64902008-06-21 13:35:56 +00002370** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
drh4f26d6c2004-05-26 23:25:30 +00002371** an English language description of the error.
drh22fbcb82004-02-01 01:22:50 +00002372**
drh33c1be32008-01-30 16:16:14 +00002373** The default encoding for the database will be UTF-8 if
mihailima3f64902008-06-21 13:35:56 +00002374** sqlite3_open() or sqlite3_open_v2() is called and
2375** UTF-16 in the native byte order if sqlite3_open16() is used.
danielk197765904932004-05-26 06:18:37 +00002376**
drh33c1be32008-01-30 16:16:14 +00002377** Whether or not an error occurs when it is opened, resources
mihailima3f64902008-06-21 13:35:56 +00002378** associated with the [database connection] handle should be released by
2379** passing it to [sqlite3_close()] when it is no longer required.
drh6d2069d2007-08-14 01:58:53 +00002380**
mihailima3f64902008-06-21 13:35:56 +00002381** The sqlite3_open_v2() interface works like sqlite3_open()
shane26b34032008-05-23 17:21:09 +00002382** except that it accepts two additional parameters for additional control
danielk19779a6284c2008-07-10 17:52:49 +00002383** over the new database connection. The flags parameter can take one of
2384** the following three values, optionally combined with the
drh31d38cf2008-07-12 20:35:08 +00002385** [SQLITE_OPEN_NOMUTEX] flag:
drh6d2069d2007-08-14 01:58:53 +00002386**
mihailima3f64902008-06-21 13:35:56 +00002387** <dl>
2388** <dt>[SQLITE_OPEN_READONLY]</dt>
2389** <dd>The database is opened in read-only mode. If the database does not
2390** already exist, an error is returned.</dd>
drh6d2069d2007-08-14 01:58:53 +00002391**
mihailima3f64902008-06-21 13:35:56 +00002392** <dt>[SQLITE_OPEN_READWRITE]</dt>
2393** <dd>The database is opened for reading and writing if possible, or reading
2394** only if the file is write protected by the operating system. In either
2395** case the database must already exist, otherwise an error is returned.</dd>
drh9da9d962007-08-28 15:47:44 +00002396**
mihailima3f64902008-06-21 13:35:56 +00002397** <dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
2398** <dd>The database is opened for reading and writing, and is creates it if
2399** it does not already exist. This is the behavior that is always used for
2400** sqlite3_open() and sqlite3_open16().</dd>
2401** </dl>
2402**
2403** If the 3rd parameter to sqlite3_open_v2() is not one of the
danielk19779a6284c2008-07-10 17:52:49 +00002404** combinations shown above or one of the combinations shown above combined
drh31d38cf2008-07-12 20:35:08 +00002405** with the [SQLITE_OPEN_NOMUTEX] flag, then the behavior is undefined.
danielk19779a6284c2008-07-10 17:52:49 +00002406**
drh31d38cf2008-07-12 20:35:08 +00002407** If the [SQLITE_OPEN_NOMUTEX] flag is set, then mutexes on the
2408** opened [database connection] are disabled and the appliation must
2409** insure that access to the [database connection] and its associated
2410** [prepared statements] is serialized. The [SQLITE_OPEN_NOMUTEX] flag
2411** is the default behavior is SQLite is configured using the
2412** [SQLITE_CONFIG_MULTITHREAD] or [SQLITE_CONFIG_SINGLETHREAD] options
2413** to [sqlite3_config()]. The [SQLITE_OPEN_NOMUTEX] flag only makes a
2414** difference when SQLite is in its default [SQLITE_CONFIG_SERIALIZED] mode.
drhd9b97cf2008-04-10 13:38:17 +00002415**
mihailima3f64902008-06-21 13:35:56 +00002416** If the filename is ":memory:", then a private, temporary in-memory database
2417** is created for the connection. This in-memory database will vanish when
2418** the database connection is closed. Future versions of SQLite might
2419** make use of additional special filenames that begin with the ":" character.
2420** It is recommended that when a database filename actually does begin with
2421** a ":" character you should prefix the filename with a pathname such as
2422** "./" to avoid ambiguity.
drh6d2069d2007-08-14 01:58:53 +00002423**
mihailima3f64902008-06-21 13:35:56 +00002424** If the filename is an empty string, then a private, temporary
drh33c1be32008-01-30 16:16:14 +00002425** on-disk database will be created. This private database will be
drh3f3b6352007-09-03 20:32:45 +00002426** automatically deleted as soon as the database connection is closed.
2427**
drh33c1be32008-01-30 16:16:14 +00002428** The fourth parameter to sqlite3_open_v2() is the name of the
mihailima3f64902008-06-21 13:35:56 +00002429** [sqlite3_vfs] object that defines the operating system interface that
2430** the new database connection should use. If the fourth parameter is
2431** a NULL pointer then the default [sqlite3_vfs] object is used.
drh6ed48bf2007-06-14 20:57:18 +00002432**
shane26b34032008-05-23 17:21:09 +00002433** <b>Note to Windows users:</b> The encoding used for the filename argument
mihailima3f64902008-06-21 13:35:56 +00002434** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
drh9da9d962007-08-28 15:47:44 +00002435** codepage is currently defined. Filenames containing international
2436** characters must be converted to UTF-8 prior to passing them into
mihailima3f64902008-06-21 13:35:56 +00002437** sqlite3_open() or sqlite3_open_v2().
drh33c1be32008-01-30 16:16:14 +00002438**
2439** INVARIANTS:
2440**
drh9a247912008-07-22 18:45:08 +00002441** {H12701} The [sqlite3_open()], [sqlite3_open16()], and
drh33c1be32008-01-30 16:16:14 +00002442** [sqlite3_open_v2()] interfaces create a new
2443** [database connection] associated with
2444** the database file given in their first parameter.
2445**
drh9a247912008-07-22 18:45:08 +00002446** {H12702} The filename argument is interpreted as UTF-8
drh33c1be32008-01-30 16:16:14 +00002447** for [sqlite3_open()] and [sqlite3_open_v2()] and as UTF-16
2448** in the native byte order for [sqlite3_open16()].
2449**
drh9a247912008-07-22 18:45:08 +00002450** {H12703} A successful invocation of [sqlite3_open()], [sqlite3_open16()],
drh33c1be32008-01-30 16:16:14 +00002451** or [sqlite3_open_v2()] writes a pointer to a new
2452** [database connection] into *ppDb.
2453**
drh9a247912008-07-22 18:45:08 +00002454** {H12704} The [sqlite3_open()], [sqlite3_open16()], and
drh33c1be32008-01-30 16:16:14 +00002455** [sqlite3_open_v2()] interfaces return [SQLITE_OK] upon success,
2456** or an appropriate [error code] on failure.
2457**
drh9a247912008-07-22 18:45:08 +00002458** {H12706} The default text encoding for a new database created using
drh33c1be32008-01-30 16:16:14 +00002459** [sqlite3_open()] or [sqlite3_open_v2()] will be UTF-8.
2460**
drh9a247912008-07-22 18:45:08 +00002461** {H12707} The default text encoding for a new database created using
drh33c1be32008-01-30 16:16:14 +00002462** [sqlite3_open16()] will be UTF-16.
2463**
drh9a247912008-07-22 18:45:08 +00002464** {H12709} The [sqlite3_open(F,D)] interface is equivalent to
drh33c1be32008-01-30 16:16:14 +00002465** [sqlite3_open_v2(F,D,G,0)] where the G parameter is
2466** [SQLITE_OPEN_READWRITE]|[SQLITE_OPEN_CREATE].
2467**
drh9a247912008-07-22 18:45:08 +00002468** {H12711} If the G parameter to [sqlite3_open_v2(F,D,G,V)] contains the
drh33c1be32008-01-30 16:16:14 +00002469** bit value [SQLITE_OPEN_READONLY] then the database is opened
2470** for reading only.
2471**
drh9a247912008-07-22 18:45:08 +00002472** {H12712} If the G parameter to [sqlite3_open_v2(F,D,G,V)] contains the
drh33c1be32008-01-30 16:16:14 +00002473** bit value [SQLITE_OPEN_READWRITE] then the database is opened
2474** reading and writing if possible, or for reading only if the
2475** file is write protected by the operating system.
2476**
danielk1977eaed3562008-08-06 13:40:13 +00002477** {H12713} If the G parameter to [sqlite3_open_v2(F,D,G,V)] omits the
drh33c1be32008-01-30 16:16:14 +00002478** bit value [SQLITE_OPEN_CREATE] and the database does not
2479** previously exist, an error is returned.
2480**
danielk1977eaed3562008-08-06 13:40:13 +00002481** {H12714} If the G parameter to [sqlite3_open_v2(F,D,G,V)] contains the
drh33c1be32008-01-30 16:16:14 +00002482** bit value [SQLITE_OPEN_CREATE] and the database does not
2483** previously exist, then an attempt is made to create and
2484** initialize the database.
2485**
drh9a247912008-07-22 18:45:08 +00002486** {H12717} If the filename argument to [sqlite3_open()], [sqlite3_open16()],
drh33c1be32008-01-30 16:16:14 +00002487** or [sqlite3_open_v2()] is ":memory:", then an private,
2488** ephemeral, in-memory database is created for the connection.
2489** <todo>Is SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE required
2490** in sqlite3_open_v2()?</todo>
2491**
drh9a247912008-07-22 18:45:08 +00002492** {H12719} If the filename is NULL or an empty string, then a private,
shane26b34032008-05-23 17:21:09 +00002493** ephemeral on-disk database will be created.
drh33c1be32008-01-30 16:16:14 +00002494** <todo>Is SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE required
2495** in sqlite3_open_v2()?</todo>
2496**
drh9a247912008-07-22 18:45:08 +00002497** {H12721} The [database connection] created by [sqlite3_open_v2(F,D,G,V)]
mihailima3f64902008-06-21 13:35:56 +00002498** will use the [sqlite3_vfs] object identified by the V parameter,
2499** or the default [sqlite3_vfs] object if V is a NULL pointer.
shane0c6844e2008-05-21 15:01:21 +00002500**
drh9a247912008-07-22 18:45:08 +00002501** {H12723} Two [database connections] will share a common cache if both were
mihailimefc8e8a2008-06-21 16:47:09 +00002502** opened with the same VFS while [shared cache mode] was enabled and
mihailima3f64902008-06-21 13:35:56 +00002503** if both filenames compare equal using memcmp() after having been
2504** processed by the [sqlite3_vfs | xFullPathname] method of the VFS.
danielk197765904932004-05-26 06:18:37 +00002505*/
2506int sqlite3_open(
2507 const char *filename, /* Database filename (UTF-8) */
danielk19774f057f92004-06-08 00:02:33 +00002508 sqlite3 **ppDb /* OUT: SQLite db handle */
danielk197765904932004-05-26 06:18:37 +00002509);
danielk197765904932004-05-26 06:18:37 +00002510int sqlite3_open16(
2511 const void *filename, /* Database filename (UTF-16) */
danielk19774f057f92004-06-08 00:02:33 +00002512 sqlite3 **ppDb /* OUT: SQLite db handle */
danielk197765904932004-05-26 06:18:37 +00002513);
drh6d2069d2007-08-14 01:58:53 +00002514int sqlite3_open_v2(
drh428e2822007-08-30 16:23:19 +00002515 const char *filename, /* Database filename (UTF-8) */
drh6d2069d2007-08-14 01:58:53 +00002516 sqlite3 **ppDb, /* OUT: SQLite db handle */
2517 int flags, /* Flags */
drhd84f9462007-08-15 11:28:56 +00002518 const char *zVfs /* Name of VFS module to use */
drh6d2069d2007-08-14 01:58:53 +00002519);
danielk1977295ba552004-05-19 10:34:51 +00002520
danielk197765904932004-05-26 06:18:37 +00002521/*
drh9cd29642008-07-23 00:52:55 +00002522** CAPI3REF: Error Codes And Messages {H12800} <S60200>
drh6ed48bf2007-06-14 20:57:18 +00002523**
mihailimefc8e8a2008-06-21 16:47:09 +00002524** The sqlite3_errcode() interface returns the numeric [result code] or
2525** [extended result code] for the most recent failed sqlite3_* API call
2526** associated with a [database connection]. If a prior API call failed
2527** but the most recent API call succeeded, the return value from
2528** sqlite3_errcode() is undefined.
drh6ed48bf2007-06-14 20:57:18 +00002529**
drh33c1be32008-01-30 16:16:14 +00002530** The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
mihailimebe796c2008-06-21 20:11:17 +00002531** text that describes the error, as either UTF-8 or UTF-16 respectively.
drh33c1be32008-01-30 16:16:14 +00002532** Memory to hold the error message string is managed internally.
mihailimefc8e8a2008-06-21 16:47:09 +00002533** The application does not need to worry about freeing the result.
mlcreech27358862008-03-01 23:34:46 +00002534** However, the error string might be overwritten or deallocated by
drh33c1be32008-01-30 16:16:14 +00002535** subsequent calls to other SQLite interface functions.
danielk197765904932004-05-26 06:18:37 +00002536**
drhd55d57e2008-07-07 17:53:07 +00002537** If an interface fails with SQLITE_MISUSE, that means the interface
2538** was invoked incorrectly by the application. In that case, the
2539** error code and message may or may not be set.
2540**
drh33c1be32008-01-30 16:16:14 +00002541** INVARIANTS:
danielk197765904932004-05-26 06:18:37 +00002542**
drh9a247912008-07-22 18:45:08 +00002543** {H12801} The [sqlite3_errcode(D)] interface returns the numeric
mihailimefc8e8a2008-06-21 16:47:09 +00002544** [result code] or [extended result code] for the most recently
2545** failed interface call associated with the [database connection] D.
drh33c1be32008-01-30 16:16:14 +00002546**
drh9a247912008-07-22 18:45:08 +00002547** {H12803} The [sqlite3_errmsg(D)] and [sqlite3_errmsg16(D)]
drh33c1be32008-01-30 16:16:14 +00002548** interfaces return English-language text that describes
2549** the error in the mostly recently failed interface call,
mihailimebe796c2008-06-21 20:11:17 +00002550** encoded as either UTF-8 or UTF-16 respectively.
drh33c1be32008-01-30 16:16:14 +00002551**
drh9a247912008-07-22 18:45:08 +00002552** {H12807} The strings returned by [sqlite3_errmsg()] and [sqlite3_errmsg16()]
drhb4d58ae2008-02-21 20:17:06 +00002553** are valid until the next SQLite interface call.
drh33c1be32008-01-30 16:16:14 +00002554**
drh9a247912008-07-22 18:45:08 +00002555** {H12808} Calls to API routines that do not return an error code
drh33c1be32008-01-30 16:16:14 +00002556** (example: [sqlite3_data_count()]) do not
2557** change the error code or message returned by
2558** [sqlite3_errcode()], [sqlite3_errmsg()], or [sqlite3_errmsg16()].
2559**
drh9a247912008-07-22 18:45:08 +00002560** {H12809} Interfaces that are not associated with a specific
drh33c1be32008-01-30 16:16:14 +00002561** [database connection] (examples:
2562** [sqlite3_mprintf()] or [sqlite3_enable_shared_cache()]
2563** do not change the values returned by
2564** [sqlite3_errcode()], [sqlite3_errmsg()], or [sqlite3_errmsg16()].
danielk197765904932004-05-26 06:18:37 +00002565*/
2566int sqlite3_errcode(sqlite3 *db);
danielk197765904932004-05-26 06:18:37 +00002567const char *sqlite3_errmsg(sqlite3*);
danielk197765904932004-05-26 06:18:37 +00002568const void *sqlite3_errmsg16(sqlite3*);
2569
2570/*
drh9cd29642008-07-23 00:52:55 +00002571** CAPI3REF: SQL Statement Object {H13000} <H13010>
drh33c1be32008-01-30 16:16:14 +00002572** KEYWORDS: {prepared statement} {prepared statements}
drh6ed48bf2007-06-14 20:57:18 +00002573**
mihailimefc8e8a2008-06-21 16:47:09 +00002574** An instance of this object represents a single SQL statement.
2575** This object is variously known as a "prepared statement" or a
drh6ed48bf2007-06-14 20:57:18 +00002576** "compiled SQL statement" or simply as a "statement".
mihailimefc8e8a2008-06-21 16:47:09 +00002577**
drh6ed48bf2007-06-14 20:57:18 +00002578** The life of a statement object goes something like this:
2579**
2580** <ol>
2581** <li> Create the object using [sqlite3_prepare_v2()] or a related
2582** function.
mihailimefc8e8a2008-06-21 16:47:09 +00002583** <li> Bind values to [host parameters] using the sqlite3_bind_*()
2584** interfaces.
drh6ed48bf2007-06-14 20:57:18 +00002585** <li> Run the SQL by calling [sqlite3_step()] one or more times.
2586** <li> Reset the statement using [sqlite3_reset()] then go back
2587** to step 2. Do this zero or more times.
2588** <li> Destroy the object using [sqlite3_finalize()].
2589** </ol>
2590**
2591** Refer to documentation on individual methods above for additional
2592** information.
danielk197765904932004-05-26 06:18:37 +00002593*/
danielk1977fc57d7b2004-05-26 02:04:57 +00002594typedef struct sqlite3_stmt sqlite3_stmt;
2595
danielk1977e3209e42004-05-20 01:40:18 +00002596/*
drh9cd29642008-07-23 00:52:55 +00002597** CAPI3REF: Run-time Limits {H12760} <S20600>
drhcaa639f2008-03-20 00:32:20 +00002598**
2599** This interface allows the size of various constructs to be limited
2600** on a connection by connection basis. The first parameter is the
2601** [database connection] whose limit is to be set or queried. The
2602** second parameter is one of the [limit categories] that define a
2603** class of constructs to be size limited. The third parameter is the
2604** new limit for that construct. The function returns the old limit.
2605**
2606** If the new limit is a negative number, the limit is unchanged.
drhf47ce562008-03-20 18:00:49 +00002607** For the limit category of SQLITE_LIMIT_XYZ there is a hard upper
mihailimefc8e8a2008-06-21 16:47:09 +00002608** bound set by a compile-time C preprocessor macro named SQLITE_MAX_XYZ.
drhf47ce562008-03-20 18:00:49 +00002609** (The "_LIMIT_" in the name is changed to "_MAX_".)
2610** Attempts to increase a limit above its hard upper bound are
2611** silently truncated to the hard upper limit.
drhcaa639f2008-03-20 00:32:20 +00002612**
drhbb4957f2008-03-20 14:03:29 +00002613** Run time limits are intended for use in applications that manage
2614** both their own internal database and also databases that are controlled
2615** by untrusted external sources. An example application might be a
2616** webbrowser that has its own databases for storing history and
shane26b34032008-05-23 17:21:09 +00002617** separate databases controlled by JavaScript applications downloaded
shane236ce972008-05-30 15:35:30 +00002618** off the Internet. The internal databases can be given the
drhbb4957f2008-03-20 14:03:29 +00002619** large, default limits. Databases managed by external sources can
2620** be given much smaller limits designed to prevent a denial of service
mihailimefc8e8a2008-06-21 16:47:09 +00002621** attack. Developers might also want to use the [sqlite3_set_authorizer()]
drhf47ce562008-03-20 18:00:49 +00002622** interface to further control untrusted SQL. The size of the database
2623** created by an untrusted script can be contained using the
2624** [max_page_count] [PRAGMA].
drhbb4957f2008-03-20 14:03:29 +00002625**
drha911abe2008-07-16 13:29:51 +00002626** New run-time limit categories may be added in future releases.
drhcaa639f2008-03-20 00:32:20 +00002627**
2628** INVARIANTS:
2629**
drh9a247912008-07-22 18:45:08 +00002630** {H12762} A successful call to [sqlite3_limit(D,C,V)] where V is
mihailimefc8e8a2008-06-21 16:47:09 +00002631** positive changes the limit on the size of construct C in the
2632** [database connection] D to the lesser of V and the hard upper
2633** bound on the size of C that is set at compile-time.
drhcaa639f2008-03-20 00:32:20 +00002634**
drh9a247912008-07-22 18:45:08 +00002635** {H12766} A successful call to [sqlite3_limit(D,C,V)] where V is negative
mihailimefc8e8a2008-06-21 16:47:09 +00002636** leaves the state of the [database connection] D unchanged.
drhcaa639f2008-03-20 00:32:20 +00002637**
drh9a247912008-07-22 18:45:08 +00002638** {H12769} A successful call to [sqlite3_limit(D,C,V)] returns the
mihailimefc8e8a2008-06-21 16:47:09 +00002639** value of the limit on the size of construct C in the
2640** [database connection] D as it was prior to the call.
drhcaa639f2008-03-20 00:32:20 +00002641*/
2642int sqlite3_limit(sqlite3*, int id, int newVal);
2643
2644/*
drh9cd29642008-07-23 00:52:55 +00002645** CAPI3REF: Run-Time Limit Categories {H12790} <H12760>
drhcaa639f2008-03-20 00:32:20 +00002646** KEYWORDS: {limit category} {limit categories}
mihailimefc8e8a2008-06-21 16:47:09 +00002647**
drhcaa639f2008-03-20 00:32:20 +00002648** These constants define various aspects of a [database connection]
2649** that can be limited in size by calls to [sqlite3_limit()].
drhbb4957f2008-03-20 14:03:29 +00002650** The meanings of the various limits are as follows:
2651**
2652** <dl>
2653** <dt>SQLITE_LIMIT_LENGTH</dt>
mihailimefc8e8a2008-06-21 16:47:09 +00002654** <dd>The maximum size of any string or BLOB or table row.<dd>
drhbb4957f2008-03-20 14:03:29 +00002655**
2656** <dt>SQLITE_LIMIT_SQL_LENGTH</dt>
2657** <dd>The maximum length of an SQL statement.</dd>
2658**
2659** <dt>SQLITE_LIMIT_COLUMN</dt>
2660** <dd>The maximum number of columns in a table definition or in the
2661** result set of a SELECT or the maximum number of columns in an index
2662** or in an ORDER BY or GROUP BY clause.</dd>
2663**
2664** <dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
2665** <dd>The maximum depth of the parse tree on any expression.</dd>
2666**
2667** <dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
2668** <dd>The maximum number of terms in a compound SELECT statement.</dd>
2669**
2670** <dt>SQLITE_LIMIT_VDBE_OP</dt>
2671** <dd>The maximum number of instructions in a virtual machine program
2672** used to implement an SQL statement.</dd>
2673**
2674** <dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
2675** <dd>The maximum number of arguments on a function.</dd>
2676**
2677** <dt>SQLITE_LIMIT_ATTACHED</dt>
2678** <dd>The maximum number of attached databases.</dd>
2679**
drhbb4957f2008-03-20 14:03:29 +00002680** <dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
2681** <dd>The maximum length of the pattern argument to the LIKE or
2682** GLOB operators.</dd>
2683**
2684** <dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
2685** <dd>The maximum number of variables in an SQL statement that can
2686** be bound.</dd>
2687** </dl>
drhcaa639f2008-03-20 00:32:20 +00002688*/
2689#define SQLITE_LIMIT_LENGTH 0
2690#define SQLITE_LIMIT_SQL_LENGTH 1
2691#define SQLITE_LIMIT_COLUMN 2
2692#define SQLITE_LIMIT_EXPR_DEPTH 3
2693#define SQLITE_LIMIT_COMPOUND_SELECT 4
2694#define SQLITE_LIMIT_VDBE_OP 5
2695#define SQLITE_LIMIT_FUNCTION_ARG 6
2696#define SQLITE_LIMIT_ATTACHED 7
drhb1a6c3c2008-03-20 16:30:17 +00002697#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
2698#define SQLITE_LIMIT_VARIABLE_NUMBER 9
drhcaa639f2008-03-20 00:32:20 +00002699
2700/*
drh9cd29642008-07-23 00:52:55 +00002701** CAPI3REF: Compiling An SQL Statement {H13010} <S10000>
mihailimefc8e8a2008-06-21 16:47:09 +00002702** KEYWORDS: {SQL statement compiler}
danielk197765904932004-05-26 06:18:37 +00002703**
drh6ed48bf2007-06-14 20:57:18 +00002704** To execute an SQL query, it must first be compiled into a byte-code
mihailimefc8e8a2008-06-21 16:47:09 +00002705** program using one of these routines.
drh6ed48bf2007-06-14 20:57:18 +00002706**
mihailimefc8e8a2008-06-21 16:47:09 +00002707** The first argument, "db", is a [database connection] obtained from a
2708** prior call to [sqlite3_open()], [sqlite3_open_v2()] or [sqlite3_open16()].
2709**
2710** The second argument, "zSql", is the statement to be compiled, encoded
drh6ed48bf2007-06-14 20:57:18 +00002711** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2()
mihailimefc8e8a2008-06-21 16:47:09 +00002712** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2()
mihailim04bcc002008-06-22 10:21:27 +00002713** use UTF-16.
drh21f06722007-07-19 12:41:39 +00002714**
mihailimefc8e8a2008-06-21 16:47:09 +00002715** If the nByte argument is less than zero, then zSql is read up to the
2716** first zero terminator. If nByte is non-negative, then it is the maximum
2717** number of bytes read from zSql. When nByte is non-negative, the
2718** zSql string ends at either the first '\000' or '\u0000' character or
drhb08c2a72008-04-16 00:28:13 +00002719** the nByte-th byte, whichever comes first. If the caller knows
danielk19773a2c8c82008-04-03 14:36:25 +00002720** that the supplied string is nul-terminated, then there is a small
mihailimefc8e8a2008-06-21 16:47:09 +00002721** performance advantage to be gained by passing an nByte parameter that
2722** is equal to the number of bytes in the input string <i>including</i>
mihailim04bcc002008-06-22 10:21:27 +00002723** the nul-terminator bytes.
danielk197765904932004-05-26 06:18:37 +00002724**
drh33c1be32008-01-30 16:16:14 +00002725** *pzTail is made to point to the first byte past the end of the
shane26b34032008-05-23 17:21:09 +00002726** first SQL statement in zSql. These routines only compile the first
drhf5befa02007-12-06 02:42:07 +00002727** statement in zSql, so *pzTail is left pointing to what remains
drh33c1be32008-01-30 16:16:14 +00002728** uncompiled.
danielk197765904932004-05-26 06:18:37 +00002729**
drh33c1be32008-01-30 16:16:14 +00002730** *ppStmt is left pointing to a compiled [prepared statement] that can be
mihailimefc8e8a2008-06-21 16:47:09 +00002731** executed using [sqlite3_step()]. If there is an error, *ppStmt is set
2732** to NULL. If the input text contains no SQL (if the input is an empty
2733** string or a comment) then *ppStmt is set to NULL.
drh4766b292008-06-26 02:53:02 +00002734** {A13018} The calling procedure is responsible for deleting the compiled
mihailimefc8e8a2008-06-21 16:47:09 +00002735** SQL statement using [sqlite3_finalize()] after it has finished with it.
danielk197765904932004-05-26 06:18:37 +00002736**
mihailimefc8e8a2008-06-21 16:47:09 +00002737** On success, [SQLITE_OK] is returned, otherwise an [error code] is returned.
drh6ed48bf2007-06-14 20:57:18 +00002738**
2739** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are
2740** recommended for all new programs. The two older interfaces are retained
2741** for backwards compatibility, but their use is discouraged.
drh33c1be32008-01-30 16:16:14 +00002742** In the "v2" interfaces, the prepared statement
mihailimefc8e8a2008-06-21 16:47:09 +00002743** that is returned (the [sqlite3_stmt] object) contains a copy of the
mihailim04bcc002008-06-22 10:21:27 +00002744** original SQL text. This causes the [sqlite3_step()] interface to
drh6ed48bf2007-06-14 20:57:18 +00002745** behave a differently in two ways:
2746**
2747** <ol>
drh33c1be32008-01-30 16:16:14 +00002748** <li>
drh6ed48bf2007-06-14 20:57:18 +00002749** If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
2750** always used to do, [sqlite3_step()] will automatically recompile the SQL
drh33c1be32008-01-30 16:16:14 +00002751** statement and try to run it again. If the schema has changed in
drhfddfa2d2007-12-05 18:05:16 +00002752** a way that makes the statement no longer valid, [sqlite3_step()] will still
mihailimefc8e8a2008-06-21 16:47:09 +00002753** return [SQLITE_SCHEMA]. But unlike the legacy behavior, [SQLITE_SCHEMA] is
2754** now a fatal error. Calling [sqlite3_prepare_v2()] again will not make the
drh33c1be32008-01-30 16:16:14 +00002755** error go away. Note: use [sqlite3_errmsg()] to find the text
mihailim04bcc002008-06-22 10:21:27 +00002756** of the parsing error that results in an [SQLITE_SCHEMA] return.
drh6ed48bf2007-06-14 20:57:18 +00002757** </li>
2758**
2759** <li>
mihailimefc8e8a2008-06-21 16:47:09 +00002760** When an error occurs, [sqlite3_step()] will return one of the detailed
2761** [error codes] or [extended error codes]. The legacy behavior was that
2762** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code
2763** and you would have to make a second call to [sqlite3_reset()] in order
2764** to find the underlying cause of the problem. With the "v2" prepare
2765** interfaces, the underlying reason for the error is returned immediately.
drh6ed48bf2007-06-14 20:57:18 +00002766** </li>
2767** </ol>
drh33c1be32008-01-30 16:16:14 +00002768**
2769** INVARIANTS:
2770**
drh9a247912008-07-22 18:45:08 +00002771** {H13011} The [sqlite3_prepare(db,zSql,...)] and
drh33c1be32008-01-30 16:16:14 +00002772** [sqlite3_prepare_v2(db,zSql,...)] interfaces interpret the
2773** text in their zSql parameter as UTF-8.
2774**
drh9a247912008-07-22 18:45:08 +00002775** {H13012} The [sqlite3_prepare16(db,zSql,...)] and
drh33c1be32008-01-30 16:16:14 +00002776** [sqlite3_prepare16_v2(db,zSql,...)] interfaces interpret the
2777** text in their zSql parameter as UTF-16 in the native byte order.
2778**
drh9a247912008-07-22 18:45:08 +00002779** {H13013} If the nByte argument to [sqlite3_prepare_v2(db,zSql,nByte,...)]
mihailimefc8e8a2008-06-21 16:47:09 +00002780** and its variants is less than zero, the SQL text is
drh33c1be32008-01-30 16:16:14 +00002781** read from zSql is read up to the first zero terminator.
2782**
drh9a247912008-07-22 18:45:08 +00002783** {H13014} If the nByte argument to [sqlite3_prepare_v2(db,zSql,nByte,...)]
mihailimefc8e8a2008-06-21 16:47:09 +00002784** and its variants is non-negative, then at most nBytes bytes of
drh33c1be32008-01-30 16:16:14 +00002785** SQL text is read from zSql.
2786**
drh9a247912008-07-22 18:45:08 +00002787** {H13015} In [sqlite3_prepare_v2(db,zSql,N,P,pzTail)] and its variants
drh33c1be32008-01-30 16:16:14 +00002788** if the zSql input text contains more than one SQL statement
2789** and pzTail is not NULL, then *pzTail is made to point to the
2790** first byte past the end of the first SQL statement in zSql.
2791** <todo>What does *pzTail point to if there is one statement?</todo>
2792**
drh9a247912008-07-22 18:45:08 +00002793** {H13016} A successful call to [sqlite3_prepare_v2(db,zSql,N,ppStmt,...)]
drh33c1be32008-01-30 16:16:14 +00002794** or one of its variants writes into *ppStmt a pointer to a new
mihailimefc8e8a2008-06-21 16:47:09 +00002795** [prepared statement] or a pointer to NULL if zSql contains
2796** nothing other than whitespace or comments.
drh33c1be32008-01-30 16:16:14 +00002797**
drh9a247912008-07-22 18:45:08 +00002798** {H13019} The [sqlite3_prepare_v2()] interface and its variants return
drh33c1be32008-01-30 16:16:14 +00002799** [SQLITE_OK] or an appropriate [error code] upon failure.
drh17eaae72008-03-03 18:47:28 +00002800**
drh9a247912008-07-22 18:45:08 +00002801** {H13021} Before [sqlite3_prepare(db,zSql,nByte,ppStmt,pzTail)] or its
mihailimefc8e8a2008-06-21 16:47:09 +00002802** variants returns an error (any value other than [SQLITE_OK]),
2803** they first set *ppStmt to NULL.
danielk197765904932004-05-26 06:18:37 +00002804*/
2805int sqlite3_prepare(
2806 sqlite3 *db, /* Database handle */
2807 const char *zSql, /* SQL statement, UTF-8 encoded */
drh21f06722007-07-19 12:41:39 +00002808 int nByte, /* Maximum length of zSql in bytes. */
danielk197765904932004-05-26 06:18:37 +00002809 sqlite3_stmt **ppStmt, /* OUT: Statement handle */
2810 const char **pzTail /* OUT: Pointer to unused portion of zSql */
2811);
drh6ed48bf2007-06-14 20:57:18 +00002812int sqlite3_prepare_v2(
2813 sqlite3 *db, /* Database handle */
2814 const char *zSql, /* SQL statement, UTF-8 encoded */
drh21f06722007-07-19 12:41:39 +00002815 int nByte, /* Maximum length of zSql in bytes. */
drh6ed48bf2007-06-14 20:57:18 +00002816 sqlite3_stmt **ppStmt, /* OUT: Statement handle */
2817 const char **pzTail /* OUT: Pointer to unused portion of zSql */
2818);
danielk197765904932004-05-26 06:18:37 +00002819int sqlite3_prepare16(
2820 sqlite3 *db, /* Database handle */
2821 const void *zSql, /* SQL statement, UTF-16 encoded */
drh21f06722007-07-19 12:41:39 +00002822 int nByte, /* Maximum length of zSql in bytes. */
danielk197765904932004-05-26 06:18:37 +00002823 sqlite3_stmt **ppStmt, /* OUT: Statement handle */
2824 const void **pzTail /* OUT: Pointer to unused portion of zSql */
2825);
drhb900aaf2006-11-09 00:24:53 +00002826int sqlite3_prepare16_v2(
2827 sqlite3 *db, /* Database handle */
2828 const void *zSql, /* SQL statement, UTF-16 encoded */
drh21f06722007-07-19 12:41:39 +00002829 int nByte, /* Maximum length of zSql in bytes. */
drhb900aaf2006-11-09 00:24:53 +00002830 sqlite3_stmt **ppStmt, /* OUT: Statement handle */
2831 const void **pzTail /* OUT: Pointer to unused portion of zSql */
2832);
2833
2834/*
drh9cd29642008-07-23 00:52:55 +00002835** CAPIREF: Retrieving Statement SQL {H13100} <H13000>
danielk1977d0e2a852007-11-14 06:48:48 +00002836**
mihailimefc8e8a2008-06-21 16:47:09 +00002837** This interface can be used to retrieve a saved copy of the original
2838** SQL text used to create a [prepared statement] if that statement was
2839** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
danielk1977d0e2a852007-11-14 06:48:48 +00002840**
drh33c1be32008-01-30 16:16:14 +00002841** INVARIANTS:
2842**
drh9a247912008-07-22 18:45:08 +00002843** {H13101} If the [prepared statement] passed as the argument to
mihailimefc8e8a2008-06-21 16:47:09 +00002844** [sqlite3_sql()] was compiled using either [sqlite3_prepare_v2()] or
2845** [sqlite3_prepare16_v2()], then [sqlite3_sql()] returns
2846** a pointer to a zero-terminated string containing a UTF-8 rendering
drh33c1be32008-01-30 16:16:14 +00002847** of the original SQL statement.
2848**
drh9a247912008-07-22 18:45:08 +00002849** {H13102} If the [prepared statement] passed as the argument to
mihailimefc8e8a2008-06-21 16:47:09 +00002850** [sqlite3_sql()] was compiled using either [sqlite3_prepare()] or
2851** [sqlite3_prepare16()], then [sqlite3_sql()] returns a NULL pointer.
drh33c1be32008-01-30 16:16:14 +00002852**
drh9a247912008-07-22 18:45:08 +00002853** {H13103} The string returned by [sqlite3_sql(S)] is valid until the
drh33c1be32008-01-30 16:16:14 +00002854** [prepared statement] S is deleted using [sqlite3_finalize(S)].
danielk1977d0e2a852007-11-14 06:48:48 +00002855*/
2856const char *sqlite3_sql(sqlite3_stmt *pStmt);
2857
2858/*
drhb25f9d82008-07-23 15:40:06 +00002859** CAPI3REF: Dynamically Typed Value Object {H15000} <S20200>
drhaa28e142008-03-18 13:47:20 +00002860** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
drh6ed48bf2007-06-14 20:57:18 +00002861**
drh33c1be32008-01-30 16:16:14 +00002862** SQLite uses the sqlite3_value object to represent all values
mihailimefc8e8a2008-06-21 16:47:09 +00002863** that can be stored in a database table. SQLite uses dynamic typing
2864** for the values it stores. Values stored in sqlite3_value objects
2865** can be integers, floating point values, strings, BLOBs, or NULL.
drhaa28e142008-03-18 13:47:20 +00002866**
2867** An sqlite3_value object may be either "protected" or "unprotected".
2868** Some interfaces require a protected sqlite3_value. Other interfaces
2869** will accept either a protected or an unprotected sqlite3_value.
mihailimefc8e8a2008-06-21 16:47:09 +00002870** Every interface that accepts sqlite3_value arguments specifies
drhaa28e142008-03-18 13:47:20 +00002871** whether or not it requires a protected sqlite3_value.
2872**
2873** The terms "protected" and "unprotected" refer to whether or not
2874** a mutex is held. A internal mutex is held for a protected
2875** sqlite3_value object but no mutex is held for an unprotected
2876** sqlite3_value object. If SQLite is compiled to be single-threaded
drh4766b292008-06-26 02:53:02 +00002877** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
drh4ead1482008-06-26 18:16:05 +00002878** or if SQLite is run in one of reduced mutex modes
2879** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
mihailimefc8e8a2008-06-21 16:47:09 +00002880** then there is no distinction between protected and unprotected
2881** sqlite3_value objects and they can be used interchangeably. However,
2882** for maximum code portability it is recommended that applications
2883** still make the distinction between between protected and unprotected
drh4ead1482008-06-26 18:16:05 +00002884** sqlite3_value objects even when not strictly required.
drhaa28e142008-03-18 13:47:20 +00002885**
2886** The sqlite3_value objects that are passed as parameters into the
mihailimefc8e8a2008-06-21 16:47:09 +00002887** implementation of [application-defined SQL functions] are protected.
drhaa28e142008-03-18 13:47:20 +00002888** The sqlite3_value object returned by
2889** [sqlite3_column_value()] is unprotected.
2890** Unprotected sqlite3_value objects may only be used with
mihailimefc8e8a2008-06-21 16:47:09 +00002891** [sqlite3_result_value()] and [sqlite3_bind_value()].
drhce5a5a02008-06-10 17:41:44 +00002892** The [sqlite3_value_blob | sqlite3_value_type()] family of
2893** interfaces require protected sqlite3_value objects.
drhf4479502004-05-27 03:12:53 +00002894*/
drhf4479502004-05-27 03:12:53 +00002895typedef struct Mem sqlite3_value;
2896
2897/*
drhb25f9d82008-07-23 15:40:06 +00002898** CAPI3REF: SQL Function Context Object {H16001} <S20200>
drh4f26d6c2004-05-26 23:25:30 +00002899**
drh6ed48bf2007-06-14 20:57:18 +00002900** The context in which an SQL function executes is stored in an
mihailimefc8e8a2008-06-21 16:47:09 +00002901** sqlite3_context object. A pointer to an sqlite3_context object
2902** is always first parameter to [application-defined SQL functions].
2903** The application-defined SQL function implementation will pass this
2904** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
2905** [sqlite3_aggregate_context()], [sqlite3_user_data()],
2906** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
2907** and/or [sqlite3_set_auxdata()].
drh6ed48bf2007-06-14 20:57:18 +00002908*/
2909typedef struct sqlite3_context sqlite3_context;
2910
2911/*
drhb25f9d82008-07-23 15:40:06 +00002912** CAPI3REF: Binding Values To Prepared Statements {H13500} <S70300>
mihailimefc8e8a2008-06-21 16:47:09 +00002913** KEYWORDS: {host parameter} {host parameters} {host parameter name}
mihailimebe796c2008-06-21 20:11:17 +00002914** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
drh6ed48bf2007-06-14 20:57:18 +00002915**
mihailimefc8e8a2008-06-21 16:47:09 +00002916** In the SQL strings input to [sqlite3_prepare_v2()] and its variants,
2917** literals may be replaced by a parameter in one of these forms:
drh6ed48bf2007-06-14 20:57:18 +00002918**
2919** <ul>
2920** <li> ?
2921** <li> ?NNN
drh33c1be32008-01-30 16:16:14 +00002922** <li> :VVV
2923** <li> @VVV
drh6ed48bf2007-06-14 20:57:18 +00002924** <li> $VVV
2925** </ul>
2926**
2927** In the parameter forms shown above NNN is an integer literal,
mihailimefc8e8a2008-06-21 16:47:09 +00002928** and VVV is an alpha-numeric parameter name. The values of these
2929** parameters (also called "host parameter names" or "SQL parameters")
drh6ed48bf2007-06-14 20:57:18 +00002930** can be set using the sqlite3_bind_*() routines defined here.
2931**
mihailimefc8e8a2008-06-21 16:47:09 +00002932** The first argument to the sqlite3_bind_*() routines is always
2933** a pointer to the [sqlite3_stmt] object returned from
2934** [sqlite3_prepare_v2()] or its variants.
2935**
2936** The second argument is the index of the SQL parameter to be set.
2937** The leftmost SQL parameter has an index of 1. When the same named
2938** SQL parameter is used more than once, second and subsequent
2939** occurrences have the same index as the first occurrence.
drh33c1be32008-01-30 16:16:14 +00002940** The index for named parameters can be looked up using the
danielk1977c001fc32008-06-24 09:52:39 +00002941** [sqlite3_bind_parameter_index()] API if desired. The index
drhf5befa02007-12-06 02:42:07 +00002942** for "?NNN" parameters is the value of NNN.
drh4ead1482008-06-26 18:16:05 +00002943** The NNN value must be between 1 and the [sqlite3_limit()]
2944** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
drh6ed48bf2007-06-14 20:57:18 +00002945**
drh33c1be32008-01-30 16:16:14 +00002946** The third argument is the value to bind to the parameter.
drh6ed48bf2007-06-14 20:57:18 +00002947**
mihailimefc8e8a2008-06-21 16:47:09 +00002948** In those routines that have a fourth argument, its value is the
2949** number of bytes in the parameter. To be clear: the value is the
2950** number of <u>bytes</u> in the value, not the number of characters.
drh6ed48bf2007-06-14 20:57:18 +00002951** If the fourth parameter is negative, the length of the string is
shane26b34032008-05-23 17:21:09 +00002952** the number of bytes up to the first zero terminator.
drh4f26d6c2004-05-26 23:25:30 +00002953**
drh930cc582007-03-28 13:07:40 +00002954** The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
drh900dfba2004-07-21 15:21:36 +00002955** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
drh33c1be32008-01-30 16:16:14 +00002956** string after SQLite has finished with it. If the fifth argument is
2957** the special value [SQLITE_STATIC], then SQLite assumes that the
drhfddfa2d2007-12-05 18:05:16 +00002958** information is in static, unmanaged space and does not need to be freed.
drh33c1be32008-01-30 16:16:14 +00002959** If the fifth argument has the value [SQLITE_TRANSIENT], then
drhfddfa2d2007-12-05 18:05:16 +00002960** SQLite makes its own private copy of the data immediately, before
drh33c1be32008-01-30 16:16:14 +00002961** the sqlite3_bind_*() routine returns.
drh4f26d6c2004-05-26 23:25:30 +00002962**
drh33c1be32008-01-30 16:16:14 +00002963** The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
mihailimefc8e8a2008-06-21 16:47:09 +00002964** is filled with zeroes. A zeroblob uses a fixed amount of memory
2965** (just an integer to hold its size) while it is being processed.
shane26b34032008-05-23 17:21:09 +00002966** Zeroblobs are intended to serve as placeholders for BLOBs whose
mihailimefc8e8a2008-06-21 16:47:09 +00002967** content is later written using
2968** [sqlite3_blob_open | incremental BLOB I/O] routines.
2969** A negative value for the zeroblob results in a zero-length BLOB.
drh6ed48bf2007-06-14 20:57:18 +00002970**
drh33c1be32008-01-30 16:16:14 +00002971** The sqlite3_bind_*() routines must be called after
drh6ed48bf2007-06-14 20:57:18 +00002972** [sqlite3_prepare_v2()] (and its variants) or [sqlite3_reset()] and
drh33c1be32008-01-30 16:16:14 +00002973** before [sqlite3_step()].
drh6ed48bf2007-06-14 20:57:18 +00002974** Bindings are not cleared by the [sqlite3_reset()] routine.
drh33c1be32008-01-30 16:16:14 +00002975** Unbound parameters are interpreted as NULL.
drh6ed48bf2007-06-14 20:57:18 +00002976**
drh33c1be32008-01-30 16:16:14 +00002977** These routines return [SQLITE_OK] on success or an error code if
2978** anything goes wrong. [SQLITE_RANGE] is returned if the parameter
shane26b34032008-05-23 17:21:09 +00002979** index is out of range. [SQLITE_NOMEM] is returned if malloc() fails.
drh33c1be32008-01-30 16:16:14 +00002980** [SQLITE_MISUSE] might be returned if these routines are called on a
drhfddfa2d2007-12-05 18:05:16 +00002981** virtual machine that is the wrong state or which has already been finalized.
drh33c1be32008-01-30 16:16:14 +00002982** Detection of misuse is unreliable. Applications should not depend
2983** on SQLITE_MISUSE returns. SQLITE_MISUSE is intended to indicate a
2984** a logic error in the application. Future versions of SQLite might
2985** panic rather than return SQLITE_MISUSE.
2986**
2987** See also: [sqlite3_bind_parameter_count()],
mihailimefc8e8a2008-06-21 16:47:09 +00002988** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
drh33c1be32008-01-30 16:16:14 +00002989**
2990** INVARIANTS:
2991**
drh9a247912008-07-22 18:45:08 +00002992** {H13506} The [SQL statement compiler] recognizes tokens of the forms
mihailimefc8e8a2008-06-21 16:47:09 +00002993** "?", "?NNN", "$VVV", ":VVV", and "@VVV" as SQL parameters,
2994** where NNN is any sequence of one or more digits
2995** and where VVV is any sequence of one or more alphanumeric
2996** characters or "::" optionally followed by a string containing
2997** no spaces and contained within parentheses.
drh33c1be32008-01-30 16:16:14 +00002998**
drh9a247912008-07-22 18:45:08 +00002999** {H13509} The initial value of an SQL parameter is NULL.
drh33c1be32008-01-30 16:16:14 +00003000**
drh9a247912008-07-22 18:45:08 +00003001** {H13512} The index of an "?" SQL parameter is one larger than the
drh33c1be32008-01-30 16:16:14 +00003002** largest index of SQL parameter to the left, or 1 if
3003** the "?" is the leftmost SQL parameter.
3004**
drh9a247912008-07-22 18:45:08 +00003005** {H13515} The index of an "?NNN" SQL parameter is the integer NNN.
drh33c1be32008-01-30 16:16:14 +00003006**
drh9a247912008-07-22 18:45:08 +00003007** {H13518} The index of an ":VVV", "$VVV", or "@VVV" SQL parameter is
shane26b34032008-05-23 17:21:09 +00003008** the same as the index of leftmost occurrences of the same
drh33c1be32008-01-30 16:16:14 +00003009** parameter, or one more than the largest index over all
shane26b34032008-05-23 17:21:09 +00003010** parameters to the left if this is the first occurrence
drh33c1be32008-01-30 16:16:14 +00003011** of this parameter, or 1 if this is the leftmost parameter.
3012**
drh9a247912008-07-22 18:45:08 +00003013** {H13521} The [SQL statement compiler] fails with an [SQLITE_RANGE]
mihailimefc8e8a2008-06-21 16:47:09 +00003014** error if the index of an SQL parameter is less than 1
3015** or greater than the compile-time SQLITE_MAX_VARIABLE_NUMBER
3016** parameter.
drh33c1be32008-01-30 16:16:14 +00003017**
drh9a247912008-07-22 18:45:08 +00003018** {H13524} Calls to [sqlite3_bind_text | sqlite3_bind(S,N,V,...)]
drh33c1be32008-01-30 16:16:14 +00003019** associate the value V with all SQL parameters having an
3020** index of N in the [prepared statement] S.
3021**
drh9a247912008-07-22 18:45:08 +00003022** {H13527} Calls to [sqlite3_bind_text | sqlite3_bind(S,N,...)]
drh33c1be32008-01-30 16:16:14 +00003023** override prior calls with the same values of S and N.
3024**
drh9a247912008-07-22 18:45:08 +00003025** {H13530} Bindings established by [sqlite3_bind_text | sqlite3_bind(S,...)]
drh33c1be32008-01-30 16:16:14 +00003026** persist across calls to [sqlite3_reset(S)].
3027**
drh9a247912008-07-22 18:45:08 +00003028** {H13533} In calls to [sqlite3_bind_blob(S,N,V,L,D)],
drh33c1be32008-01-30 16:16:14 +00003029** [sqlite3_bind_text(S,N,V,L,D)], or
3030** [sqlite3_bind_text16(S,N,V,L,D)] SQLite binds the first L
mihailimefc8e8a2008-06-21 16:47:09 +00003031** bytes of the BLOB or string pointed to by V, when L
drh33c1be32008-01-30 16:16:14 +00003032** is non-negative.
3033**
drh9a247912008-07-22 18:45:08 +00003034** {H13536} In calls to [sqlite3_bind_text(S,N,V,L,D)] or
drh33c1be32008-01-30 16:16:14 +00003035** [sqlite3_bind_text16(S,N,V,L,D)] SQLite binds characters
3036** from V through the first zero character when L is negative.
3037**
drh9a247912008-07-22 18:45:08 +00003038** {H13539} In calls to [sqlite3_bind_blob(S,N,V,L,D)],
drh33c1be32008-01-30 16:16:14 +00003039** [sqlite3_bind_text(S,N,V,L,D)], or
3040** [sqlite3_bind_text16(S,N,V,L,D)] when D is the special
3041** constant [SQLITE_STATIC], SQLite assumes that the value V
3042** is held in static unmanaged space that will not change
3043** during the lifetime of the binding.
3044**
drh9a247912008-07-22 18:45:08 +00003045** {H13542} In calls to [sqlite3_bind_blob(S,N,V,L,D)],
drh33c1be32008-01-30 16:16:14 +00003046** [sqlite3_bind_text(S,N,V,L,D)], or
3047** [sqlite3_bind_text16(S,N,V,L,D)] when D is the special
mihailimefc8e8a2008-06-21 16:47:09 +00003048** constant [SQLITE_TRANSIENT], the routine makes a
3049** private copy of the value V before it returns.
drh33c1be32008-01-30 16:16:14 +00003050**
drh9a247912008-07-22 18:45:08 +00003051** {H13545} In calls to [sqlite3_bind_blob(S,N,V,L,D)],
drh33c1be32008-01-30 16:16:14 +00003052** [sqlite3_bind_text(S,N,V,L,D)], or
3053** [sqlite3_bind_text16(S,N,V,L,D)] when D is a pointer to
3054** a function, SQLite invokes that function to destroy the
mihailimefc8e8a2008-06-21 16:47:09 +00003055** value V after it has finished using the value V.
drh33c1be32008-01-30 16:16:14 +00003056**
drh9a247912008-07-22 18:45:08 +00003057** {H13548} In calls to [sqlite3_bind_zeroblob(S,N,V,L)] the value bound
mihailimefc8e8a2008-06-21 16:47:09 +00003058** is a BLOB of L bytes, or a zero-length BLOB if L is negative.
drhaa28e142008-03-18 13:47:20 +00003059**
drh9a247912008-07-22 18:45:08 +00003060** {H13551} In calls to [sqlite3_bind_value(S,N,V)] the V argument may
drhaa28e142008-03-18 13:47:20 +00003061** be either a [protected sqlite3_value] object or an
3062** [unprotected sqlite3_value] object.
drh4f26d6c2004-05-26 23:25:30 +00003063*/
danielk1977d8123362004-06-12 09:25:12 +00003064int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
drhf4479502004-05-27 03:12:53 +00003065int sqlite3_bind_double(sqlite3_stmt*, int, double);
3066int sqlite3_bind_int(sqlite3_stmt*, int, int);
drh6d2069d2007-08-14 01:58:53 +00003067int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
drhf4479502004-05-27 03:12:53 +00003068int sqlite3_bind_null(sqlite3_stmt*, int);
danielk1977d8123362004-06-12 09:25:12 +00003069int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));
3070int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
drhf4479502004-05-27 03:12:53 +00003071int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
drhb026e052007-05-02 01:34:31 +00003072int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
drh4f26d6c2004-05-26 23:25:30 +00003073
3074/*
drhb25f9d82008-07-23 15:40:06 +00003075** CAPI3REF: Number Of SQL Parameters {H13600} <S70300>
drh6ed48bf2007-06-14 20:57:18 +00003076**
mihailimefc8e8a2008-06-21 16:47:09 +00003077** This routine can be used to find the number of [SQL parameters]
3078** in a [prepared statement]. SQL parameters are tokens of the
drh33c1be32008-01-30 16:16:14 +00003079** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
shane26b34032008-05-23 17:21:09 +00003080** placeholders for values that are [sqlite3_bind_blob | bound]
drh33c1be32008-01-30 16:16:14 +00003081** to the parameters at a later time.
drh605264d2007-08-21 15:13:19 +00003082**
mihailim1c492652008-06-21 18:02:16 +00003083** This routine actually returns the index of the largest (rightmost)
mihailimefc8e8a2008-06-21 16:47:09 +00003084** parameter. For all forms except ?NNN, this will correspond to the
3085** number of unique parameters. If parameters of the ?NNN are used,
3086** there may be gaps in the list.
drh33c1be32008-01-30 16:16:14 +00003087**
3088** See also: [sqlite3_bind_blob|sqlite3_bind()],
3089** [sqlite3_bind_parameter_name()], and
3090** [sqlite3_bind_parameter_index()].
3091**
3092** INVARIANTS:
3093**
drh9a247912008-07-22 18:45:08 +00003094** {H13601} The [sqlite3_bind_parameter_count(S)] interface returns
drh33c1be32008-01-30 16:16:14 +00003095** the largest index of all SQL parameters in the
mihailimefc8e8a2008-06-21 16:47:09 +00003096** [prepared statement] S, or 0 if S contains no SQL parameters.
drh75f6a032004-07-15 14:15:00 +00003097*/
3098int sqlite3_bind_parameter_count(sqlite3_stmt*);
3099
3100/*
drhb25f9d82008-07-23 15:40:06 +00003101** CAPI3REF: Name Of A Host Parameter {H13620} <S70300>
drh6ed48bf2007-06-14 20:57:18 +00003102**
drh33c1be32008-01-30 16:16:14 +00003103** This routine returns a pointer to the name of the n-th
mihailimefc8e8a2008-06-21 16:47:09 +00003104** [SQL parameter] in a [prepared statement].
drhe1b3e802008-04-27 22:29:01 +00003105** SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
3106** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
3107** respectively.
3108** In other words, the initial ":" or "$" or "@" or "?"
drh33c1be32008-01-30 16:16:14 +00003109** is included as part of the name.
mihailimefc8e8a2008-06-21 16:47:09 +00003110** Parameters of the form "?" without a following integer have no name
3111** and are also referred to as "anonymous parameters".
drh6ed48bf2007-06-14 20:57:18 +00003112**
drh33c1be32008-01-30 16:16:14 +00003113** The first host parameter has an index of 1, not 0.
drh6ed48bf2007-06-14 20:57:18 +00003114**
drh33c1be32008-01-30 16:16:14 +00003115** If the value n is out of range or if the n-th parameter is
3116** nameless, then NULL is returned. The returned string is
mihailimefc8e8a2008-06-21 16:47:09 +00003117** always in UTF-8 encoding even if the named parameter was
drhfddfa2d2007-12-05 18:05:16 +00003118** originally specified as UTF-16 in [sqlite3_prepare16()] or
3119** [sqlite3_prepare16_v2()].
drh33c1be32008-01-30 16:16:14 +00003120**
3121** See also: [sqlite3_bind_blob|sqlite3_bind()],
3122** [sqlite3_bind_parameter_count()], and
3123** [sqlite3_bind_parameter_index()].
3124**
3125** INVARIANTS:
3126**
drh9a247912008-07-22 18:45:08 +00003127** {H13621} The [sqlite3_bind_parameter_name(S,N)] interface returns
drh33c1be32008-01-30 16:16:14 +00003128** a UTF-8 rendering of the name of the SQL parameter in
mihailimefc8e8a2008-06-21 16:47:09 +00003129** the [prepared statement] S having index N, or
drh33c1be32008-01-30 16:16:14 +00003130** NULL if there is no SQL parameter with index N or if the
drhe1b3e802008-04-27 22:29:01 +00003131** parameter with index N is an anonymous parameter "?".
drh895d7472004-08-20 16:02:39 +00003132*/
3133const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
3134
3135/*
drhb25f9d82008-07-23 15:40:06 +00003136** CAPI3REF: Index Of A Parameter With A Given Name {H13640} <S70300>
drh6ed48bf2007-06-14 20:57:18 +00003137**
drh33c1be32008-01-30 16:16:14 +00003138** Return the index of an SQL parameter given its name. The
3139** index value returned is suitable for use as the second
3140** parameter to [sqlite3_bind_blob|sqlite3_bind()]. A zero
3141** is returned if no matching parameter is found. The parameter
3142** name must be given in UTF-8 even if the original statement
3143** was prepared from UTF-16 text using [sqlite3_prepare16_v2()].
3144**
3145** See also: [sqlite3_bind_blob|sqlite3_bind()],
3146** [sqlite3_bind_parameter_count()], and
3147** [sqlite3_bind_parameter_index()].
3148**
3149** INVARIANTS:
3150**
drh9a247912008-07-22 18:45:08 +00003151** {H13641} The [sqlite3_bind_parameter_index(S,N)] interface returns
mihailimefc8e8a2008-06-21 16:47:09 +00003152** the index of SQL parameter in the [prepared statement]
drh33c1be32008-01-30 16:16:14 +00003153** S whose name matches the UTF-8 string N, or 0 if there is
3154** no match.
drhfa6bc002004-09-07 16:19:52 +00003155*/
3156int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
3157
3158/*
drhb25f9d82008-07-23 15:40:06 +00003159** CAPI3REF: Reset All Bindings On A Prepared Statement {H13660} <S70300>
drh6ed48bf2007-06-14 20:57:18 +00003160**
mihailimefc8e8a2008-06-21 16:47:09 +00003161** Contrary to the intuition of many, [sqlite3_reset()] does not reset
3162** the [sqlite3_bind_blob | bindings] on a [prepared statement].
3163** Use this routine to reset all host parameters to NULL.
drh33c1be32008-01-30 16:16:14 +00003164**
3165** INVARIANTS:
3166**
drh9a247912008-07-22 18:45:08 +00003167** {H13661} The [sqlite3_clear_bindings(S)] interface resets all SQL
mihailimefc8e8a2008-06-21 16:47:09 +00003168** parameter bindings in the [prepared statement] S back to NULL.
danielk1977600dd0b2005-01-20 01:14:23 +00003169*/
3170int sqlite3_clear_bindings(sqlite3_stmt*);
3171
3172/*
drh9cd29642008-07-23 00:52:55 +00003173** CAPI3REF: Number Of Columns In A Result Set {H13710} <S10700>
drh6ed48bf2007-06-14 20:57:18 +00003174**
mihailimefc8e8a2008-06-21 16:47:09 +00003175** Return the number of columns in the result set returned by the
3176** [prepared statement]. This routine returns 0 if pStmt is an SQL
drh4ead1482008-06-26 18:16:05 +00003177** statement that does not return data (for example an [UPDATE]).
drh33c1be32008-01-30 16:16:14 +00003178**
3179** INVARIANTS:
3180**
drh9a247912008-07-22 18:45:08 +00003181** {H13711} The [sqlite3_column_count(S)] interface returns the number of
mihailimefc8e8a2008-06-21 16:47:09 +00003182** columns in the result set generated by the [prepared statement] S,
3183** or 0 if S does not generate a result set.
danielk197765904932004-05-26 06:18:37 +00003184*/
3185int sqlite3_column_count(sqlite3_stmt *pStmt);
3186
3187/*
drh9cd29642008-07-23 00:52:55 +00003188** CAPI3REF: Column Names In A Result Set {H13720} <S10700>
drh6ed48bf2007-06-14 20:57:18 +00003189**
drh33c1be32008-01-30 16:16:14 +00003190** These routines return the name assigned to a particular column
drh4ead1482008-06-26 18:16:05 +00003191** in the result set of a [SELECT] statement. The sqlite3_column_name()
mihailimefc8e8a2008-06-21 16:47:09 +00003192** interface returns a pointer to a zero-terminated UTF-8 string
drhf5befa02007-12-06 02:42:07 +00003193** and sqlite3_column_name16() returns a pointer to a zero-terminated
mihailimefc8e8a2008-06-21 16:47:09 +00003194** UTF-16 string. The first parameter is the [prepared statement]
drh4ead1482008-06-26 18:16:05 +00003195** that implements the [SELECT] statement. The second parameter is the
mihailimefc8e8a2008-06-21 16:47:09 +00003196** column number. The leftmost column is number 0.
drh6ed48bf2007-06-14 20:57:18 +00003197**
mihailimefc8e8a2008-06-21 16:47:09 +00003198** The returned string pointer is valid until either the [prepared statement]
3199** is destroyed by [sqlite3_finalize()] or until the next call to
3200** sqlite3_column_name() or sqlite3_column_name16() on the same column.
drh4a50aac2007-08-23 02:47:53 +00003201**
drh33c1be32008-01-30 16:16:14 +00003202** If sqlite3_malloc() fails during the processing of either routine
drh4a50aac2007-08-23 02:47:53 +00003203** (for example during a conversion from UTF-8 to UTF-16) then a
3204** NULL pointer is returned.
drh33c1be32008-01-30 16:16:14 +00003205**
3206** The name of a result column is the value of the "AS" clause for
3207** that column, if there is an AS clause. If there is no AS clause
3208** then the name of the column is unspecified and may change from
3209** one release of SQLite to the next.
3210**
3211** INVARIANTS:
3212**
drh9a247912008-07-22 18:45:08 +00003213** {H13721} A successful invocation of the [sqlite3_column_name(S,N)]
mihailimefc8e8a2008-06-21 16:47:09 +00003214** interface returns the name of the Nth column (where 0 is
3215** the leftmost column) for the result set of the
3216** [prepared statement] S as a zero-terminated UTF-8 string.
drh33c1be32008-01-30 16:16:14 +00003217**
drh9a247912008-07-22 18:45:08 +00003218** {H13723} A successful invocation of the [sqlite3_column_name16(S,N)]
mihailimefc8e8a2008-06-21 16:47:09 +00003219** interface returns the name of the Nth column (where 0 is
3220** the leftmost column) for the result set of the
3221** [prepared statement] S as a zero-terminated UTF-16 string
3222** in the native byte order.
drh33c1be32008-01-30 16:16:14 +00003223**
drh9a247912008-07-22 18:45:08 +00003224** {H13724} The [sqlite3_column_name()] and [sqlite3_column_name16()]
drh33c1be32008-01-30 16:16:14 +00003225** interfaces return a NULL pointer if they are unable to
shane26b34032008-05-23 17:21:09 +00003226** allocate memory to hold their normal return strings.
drh33c1be32008-01-30 16:16:14 +00003227**
drh9a247912008-07-22 18:45:08 +00003228** {H13725} If the N parameter to [sqlite3_column_name(S,N)] or
drh33c1be32008-01-30 16:16:14 +00003229** [sqlite3_column_name16(S,N)] is out of range, then the
shane26b34032008-05-23 17:21:09 +00003230** interfaces return a NULL pointer.
mihailimefc8e8a2008-06-21 16:47:09 +00003231**
drh9a247912008-07-22 18:45:08 +00003232** {H13726} The strings returned by [sqlite3_column_name(S,N)] and
drh33c1be32008-01-30 16:16:14 +00003233** [sqlite3_column_name16(S,N)] are valid until the next
3234** call to either routine with the same S and N parameters
3235** or until [sqlite3_finalize(S)] is called.
3236**
drh9a247912008-07-22 18:45:08 +00003237** {H13727} When a result column of a [SELECT] statement contains
shane26b34032008-05-23 17:21:09 +00003238** an AS clause, the name of that column is the identifier
drh33c1be32008-01-30 16:16:14 +00003239** to the right of the AS keyword.
danielk197765904932004-05-26 06:18:37 +00003240*/
drh6ed48bf2007-06-14 20:57:18 +00003241const char *sqlite3_column_name(sqlite3_stmt*, int N);
3242const void *sqlite3_column_name16(sqlite3_stmt*, int N);
danielk197765904932004-05-26 06:18:37 +00003243
3244/*
drh9cd29642008-07-23 00:52:55 +00003245** CAPI3REF: Source Of Data In A Query Result {H13740} <S10700>
drh6ed48bf2007-06-14 20:57:18 +00003246**
drh33c1be32008-01-30 16:16:14 +00003247** These routines provide a means to determine what column of what
drh4ead1482008-06-26 18:16:05 +00003248** table in which database a result of a [SELECT] statement comes from.
drh33c1be32008-01-30 16:16:14 +00003249** The name of the database or table or column can be returned as
mihailimebe796c2008-06-21 20:11:17 +00003250** either a UTF-8 or UTF-16 string. The _database_ routines return
drhbf2564f2007-06-21 15:25:05 +00003251** the database name, the _table_ routines return the table name, and
drh33c1be32008-01-30 16:16:14 +00003252** the origin_ routines return the column name.
mihailim1c492652008-06-21 18:02:16 +00003253** The returned string is valid until the [prepared statement] is destroyed
3254** using [sqlite3_finalize()] or until the same information is requested
drhbf2564f2007-06-21 15:25:05 +00003255** again in a different encoding.
3256**
drh33c1be32008-01-30 16:16:14 +00003257** The names returned are the original un-aliased names of the
drhbf2564f2007-06-21 15:25:05 +00003258** database, table, and column.
drh6ed48bf2007-06-14 20:57:18 +00003259**
drh33c1be32008-01-30 16:16:14 +00003260** The first argument to the following calls is a [prepared statement].
mihailim1c492652008-06-21 18:02:16 +00003261** These functions return information about the Nth column returned by
danielk1977955de522006-02-10 02:27:42 +00003262** the statement, where N is the second function argument.
3263**
mihailim1c492652008-06-21 18:02:16 +00003264** If the Nth column returned by the statement is an expression or
3265** subquery and is not a column value, then all of these functions return
3266** NULL. These routine might also return NULL if a memory allocation error
3267** occurs. Otherwise, they return the name of the attached database, table
3268** and column that query result column was extracted from.
danielk1977955de522006-02-10 02:27:42 +00003269**
drh33c1be32008-01-30 16:16:14 +00003270** As with all other SQLite APIs, those postfixed with "16" return
drhfddfa2d2007-12-05 18:05:16 +00003271** UTF-16 encoded strings, the other functions return UTF-8. {END}
danielk19774b1ae992006-02-10 03:06:10 +00003272**
mihailim1c492652008-06-21 18:02:16 +00003273** These APIs are only available if the library was compiled with the
drh4ead1482008-06-26 18:16:05 +00003274** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
drh32bc3f62007-08-21 20:25:39 +00003275**
drh4766b292008-06-26 02:53:02 +00003276** {A13751}
drh32bc3f62007-08-21 20:25:39 +00003277** If two or more threads call one or more of these routines against the same
3278** prepared statement and column at the same time then the results are
3279** undefined.
drh33c1be32008-01-30 16:16:14 +00003280**
3281** INVARIANTS:
3282**
drh9a247912008-07-22 18:45:08 +00003283** {H13741} The [sqlite3_column_database_name(S,N)] interface returns either
mihailim1c492652008-06-21 18:02:16 +00003284** the UTF-8 zero-terminated name of the database from which the
3285** Nth result column of the [prepared statement] S is extracted,
3286** or NULL if the Nth column of S is a general expression
3287** or if unable to allocate memory to store the name.
3288**
drh9a247912008-07-22 18:45:08 +00003289** {H13742} The [sqlite3_column_database_name16(S,N)] interface returns either
mihailim1c492652008-06-21 18:02:16 +00003290** the UTF-16 native byte order zero-terminated name of the database
3291** from which the Nth result column of the [prepared statement] S is
3292** extracted, or NULL if the Nth column of S is a general expression
3293** or if unable to allocate memory to store the name.
3294**
drh9a247912008-07-22 18:45:08 +00003295** {H13743} The [sqlite3_column_table_name(S,N)] interface returns either
mihailim1c492652008-06-21 18:02:16 +00003296** the UTF-8 zero-terminated name of the table from which the
3297** Nth result column of the [prepared statement] S is extracted,
3298** or NULL if the Nth column of S is a general expression
3299** or if unable to allocate memory to store the name.
3300**
drh9a247912008-07-22 18:45:08 +00003301** {H13744} The [sqlite3_column_table_name16(S,N)] interface returns either
mihailim1c492652008-06-21 18:02:16 +00003302** the UTF-16 native byte order zero-terminated name of the table
3303** from which the Nth result column of the [prepared statement] S is
3304** extracted, or NULL if the Nth column of S is a general expression
3305** or if unable to allocate memory to store the name.
3306**
drh9a247912008-07-22 18:45:08 +00003307** {H13745} The [sqlite3_column_origin_name(S,N)] interface returns either
mihailim1c492652008-06-21 18:02:16 +00003308** the UTF-8 zero-terminated name of the table column from which the
3309** Nth result column of the [prepared statement] S is extracted,
3310** or NULL if the Nth column of S is a general expression
3311** or if unable to allocate memory to store the name.
3312**
drh9a247912008-07-22 18:45:08 +00003313** {H13746} The [sqlite3_column_origin_name16(S,N)] interface returns either
mihailim1c492652008-06-21 18:02:16 +00003314** the UTF-16 native byte order zero-terminated name of the table
3315** column from which the Nth result column of the
3316** [prepared statement] S is extracted, or NULL if the Nth column
3317** of S is a general expression or if unable to allocate memory
drh33c1be32008-01-30 16:16:14 +00003318** to store the name.
mihailim1c492652008-06-21 18:02:16 +00003319**
drh9a247912008-07-22 18:45:08 +00003320** {H13748} The return values from
mihailim1c492652008-06-21 18:02:16 +00003321** [sqlite3_column_database_name | column metadata interfaces]
3322** are valid for the lifetime of the [prepared statement]
drh33c1be32008-01-30 16:16:14 +00003323** or until the encoding is changed by another metadata
3324** interface call for the same prepared statement and column.
3325**
drh9a247912008-07-22 18:45:08 +00003326** ASSUMPTIONS:
drh33c1be32008-01-30 16:16:14 +00003327**
drh4766b292008-06-26 02:53:02 +00003328** {A13751} If two or more threads call one or more
mihailim1c492652008-06-21 18:02:16 +00003329** [sqlite3_column_database_name | column metadata interfaces]
3330** for the same [prepared statement] and result column
drh33c1be32008-01-30 16:16:14 +00003331** at the same time then the results are undefined.
danielk1977955de522006-02-10 02:27:42 +00003332*/
3333const char *sqlite3_column_database_name(sqlite3_stmt*,int);
3334const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
3335const char *sqlite3_column_table_name(sqlite3_stmt*,int);
3336const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
3337const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
3338const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
3339
3340/*
drh9cd29642008-07-23 00:52:55 +00003341** CAPI3REF: Declared Datatype Of A Query Result {H13760} <S10700>
drh6ed48bf2007-06-14 20:57:18 +00003342**
mihailim1c492652008-06-21 18:02:16 +00003343** The first parameter is a [prepared statement].
drh4ead1482008-06-26 18:16:05 +00003344** If this statement is a [SELECT] statement and the Nth column of the
3345** returned result set of that [SELECT] is a table column (not an
drh6ed48bf2007-06-14 20:57:18 +00003346** expression or subquery) then the declared type of the table
drh33c1be32008-01-30 16:16:14 +00003347** column is returned. If the Nth column of the result set is an
drh6ed48bf2007-06-14 20:57:18 +00003348** expression or subquery, then a NULL pointer is returned.
mihailim1c492652008-06-21 18:02:16 +00003349** The returned string is always UTF-8 encoded. {END}
3350**
3351** For example, given the database schema:
danielk197765904932004-05-26 06:18:37 +00003352**
3353** CREATE TABLE t1(c1 VARIANT);
3354**
mihailim1c492652008-06-21 18:02:16 +00003355** and the following statement to be compiled:
danielk197765904932004-05-26 06:18:37 +00003356**
danielk1977955de522006-02-10 02:27:42 +00003357** SELECT c1 + 1, c1 FROM t1;
danielk197765904932004-05-26 06:18:37 +00003358**
mihailim1c492652008-06-21 18:02:16 +00003359** this routine would return the string "VARIANT" for the second result
3360** column (i==1), and a NULL pointer for the first result column (i==0).
drh6ed48bf2007-06-14 20:57:18 +00003361**
3362** SQLite uses dynamic run-time typing. So just because a column
3363** is declared to contain a particular type does not mean that the
3364** data stored in that column is of the declared type. SQLite is
3365** strongly typed, but the typing is dynamic not static. Type
3366** is associated with individual values, not with the containers
3367** used to hold those values.
drh33c1be32008-01-30 16:16:14 +00003368**
3369** INVARIANTS:
3370**
drh9a247912008-07-22 18:45:08 +00003371** {H13761} A successful call to [sqlite3_column_decltype(S,N)] returns a
mihailim1c492652008-06-21 18:02:16 +00003372** zero-terminated UTF-8 string containing the declared datatype
3373** of the table column that appears as the Nth column (numbered
3374** from 0) of the result set to the [prepared statement] S.
drh33c1be32008-01-30 16:16:14 +00003375**
drh9a247912008-07-22 18:45:08 +00003376** {H13762} A successful call to [sqlite3_column_decltype16(S,N)]
drh33c1be32008-01-30 16:16:14 +00003377** returns a zero-terminated UTF-16 native byte order string
3378** containing the declared datatype of the table column that appears
3379** as the Nth column (numbered from 0) of the result set to the
3380** [prepared statement] S.
3381**
drh9a247912008-07-22 18:45:08 +00003382** {H13763} If N is less than 0 or N is greater than or equal to
mihailim1c492652008-06-21 18:02:16 +00003383** the number of columns in the [prepared statement] S,
drh33c1be32008-01-30 16:16:14 +00003384** or if the Nth column of S is an expression or subquery rather
mihailim1c492652008-06-21 18:02:16 +00003385** than a table column, or if a memory allocation failure
drh33c1be32008-01-30 16:16:14 +00003386** occurs during encoding conversions, then
3387** calls to [sqlite3_column_decltype(S,N)] or
3388** [sqlite3_column_decltype16(S,N)] return NULL.
danielk197765904932004-05-26 06:18:37 +00003389*/
drh33c1be32008-01-30 16:16:14 +00003390const char *sqlite3_column_decltype(sqlite3_stmt*,int);
danielk197765904932004-05-26 06:18:37 +00003391const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
3392
mihailimebe796c2008-06-21 20:11:17 +00003393/*
drh9cd29642008-07-23 00:52:55 +00003394** CAPI3REF: Evaluate An SQL Statement {H13200} <S10000>
danielk1977106bb232004-05-21 10:08:53 +00003395**
mihailim1c492652008-06-21 18:02:16 +00003396** After a [prepared statement] has been prepared using either
3397** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
3398** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
3399** must be called one or more times to evaluate the statement.
danielk1977106bb232004-05-21 10:08:53 +00003400**
mihailim1c492652008-06-21 18:02:16 +00003401** The details of the behavior of the sqlite3_step() interface depend
drh6ed48bf2007-06-14 20:57:18 +00003402** on whether the statement was prepared using the newer "v2" interface
3403** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy
3404** interface [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the
3405** new "v2" interface is recommended for new applications but the legacy
3406** interface will continue to be supported.
danielk1977106bb232004-05-21 10:08:53 +00003407**
mihailimebe796c2008-06-21 20:11:17 +00003408** In the legacy interface, the return value will be either [SQLITE_BUSY],
drh6ed48bf2007-06-14 20:57:18 +00003409** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
mihailim1c492652008-06-21 18:02:16 +00003410** With the "v2" interface, any of the other [result codes] or
3411** [extended result codes] might be returned as well.
drh6ed48bf2007-06-14 20:57:18 +00003412**
3413** [SQLITE_BUSY] means that the database engine was unable to acquire the
drh4ead1482008-06-26 18:16:05 +00003414** database locks it needs to do its job. If the statement is a [COMMIT]
drh6ed48bf2007-06-14 20:57:18 +00003415** or occurs outside of an explicit transaction, then you can retry the
drh4ead1482008-06-26 18:16:05 +00003416** statement. If the statement is not a [COMMIT] and occurs within a
drh6ed48bf2007-06-14 20:57:18 +00003417** explicit transaction then you should rollback the transaction before
3418** continuing.
3419**
3420** [SQLITE_DONE] means that the statement has finished executing
danielk1977106bb232004-05-21 10:08:53 +00003421** successfully. sqlite3_step() should not be called again on this virtual
drh6ed48bf2007-06-14 20:57:18 +00003422** machine without first calling [sqlite3_reset()] to reset the virtual
3423** machine back to its initial state.
danielk1977106bb232004-05-21 10:08:53 +00003424**
mihailim1c492652008-06-21 18:02:16 +00003425** If the SQL statement being executed returns any data, then [SQLITE_ROW]
3426** is returned each time a new row of data is ready for processing by the
3427** caller. The values may be accessed using the [column access functions].
drh6ed48bf2007-06-14 20:57:18 +00003428** sqlite3_step() is called again to retrieve the next row of data.
mihailim1c492652008-06-21 18:02:16 +00003429**
drh6ed48bf2007-06-14 20:57:18 +00003430** [SQLITE_ERROR] means that a run-time error (such as a constraint
danielk1977106bb232004-05-21 10:08:53 +00003431** violation) has occurred. sqlite3_step() should not be called again on
drh6ed48bf2007-06-14 20:57:18 +00003432** the VM. More information may be found by calling [sqlite3_errmsg()].
mihailim1c492652008-06-21 18:02:16 +00003433** With the legacy interface, a more specific error code (for example,
drh6ed48bf2007-06-14 20:57:18 +00003434** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
3435** can be obtained by calling [sqlite3_reset()] on the
drh33c1be32008-01-30 16:16:14 +00003436** [prepared statement]. In the "v2" interface,
drh6ed48bf2007-06-14 20:57:18 +00003437** the more specific error code is returned directly by sqlite3_step().
danielk1977106bb232004-05-21 10:08:53 +00003438**
drh6ed48bf2007-06-14 20:57:18 +00003439** [SQLITE_MISUSE] means that the this routine was called inappropriately.
drh33c1be32008-01-30 16:16:14 +00003440** Perhaps it was called on a [prepared statement] that has
mihailim1c492652008-06-21 18:02:16 +00003441** already been [sqlite3_finalize | finalized] or on one that had
drh6ed48bf2007-06-14 20:57:18 +00003442** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could
3443** be the case that the same database connection is being used by two or
3444** more threads at the same moment in time.
3445**
mihailim1c492652008-06-21 18:02:16 +00003446** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
3447** API always returns a generic error code, [SQLITE_ERROR], following any
3448** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call
3449** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the
3450** specific [error codes] that better describes the error.
drh6ed48bf2007-06-14 20:57:18 +00003451** We admit that this is a goofy design. The problem has been fixed
3452** with the "v2" interface. If you prepare all of your SQL statements
3453** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead
mihailim1c492652008-06-21 18:02:16 +00003454** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,
3455** then the more specific [error codes] are returned directly
drh6ed48bf2007-06-14 20:57:18 +00003456** by sqlite3_step(). The use of the "v2" interface is recommended.
drh33c1be32008-01-30 16:16:14 +00003457**
3458** INVARIANTS:
3459**
drh9a247912008-07-22 18:45:08 +00003460** {H13202} If the [prepared statement] S is ready to be run, then
mihailim1c492652008-06-21 18:02:16 +00003461** [sqlite3_step(S)] advances that prepared statement until
3462** completion or until it is ready to return another row of the
3463** result set, or until an [sqlite3_interrupt | interrupt]
3464** or a run-time error occurs.
drh33c1be32008-01-30 16:16:14 +00003465**
drh9a247912008-07-22 18:45:08 +00003466** {H15304} When a call to [sqlite3_step(S)] causes the [prepared statement]
mihailim1c492652008-06-21 18:02:16 +00003467** S to run to completion, the function returns [SQLITE_DONE].
drh33c1be32008-01-30 16:16:14 +00003468**
drh9a247912008-07-22 18:45:08 +00003469** {H15306} When a call to [sqlite3_step(S)] stops because it is ready to
mihailim1c492652008-06-21 18:02:16 +00003470** return another row of the result set, it returns [SQLITE_ROW].
drh33c1be32008-01-30 16:16:14 +00003471**
drh9a247912008-07-22 18:45:08 +00003472** {H15308} If a call to [sqlite3_step(S)] encounters an
mihailim1c492652008-06-21 18:02:16 +00003473** [sqlite3_interrupt | interrupt] or a run-time error,
shane26b34032008-05-23 17:21:09 +00003474** it returns an appropriate error code that is not one of
drh33c1be32008-01-30 16:16:14 +00003475** [SQLITE_OK], [SQLITE_ROW], or [SQLITE_DONE].
3476**
drh9a247912008-07-22 18:45:08 +00003477** {H15310} If an [sqlite3_interrupt | interrupt] or a run-time error
drh33c1be32008-01-30 16:16:14 +00003478** occurs during a call to [sqlite3_step(S)]
3479** for a [prepared statement] S created using
3480** legacy interfaces [sqlite3_prepare()] or
mihailim1c492652008-06-21 18:02:16 +00003481** [sqlite3_prepare16()], then the function returns either
drh33c1be32008-01-30 16:16:14 +00003482** [SQLITE_ERROR], [SQLITE_BUSY], or [SQLITE_MISUSE].
danielk1977106bb232004-05-21 10:08:53 +00003483*/
danielk197717240fd2004-05-26 00:07:25 +00003484int sqlite3_step(sqlite3_stmt*);
danielk1977106bb232004-05-21 10:08:53 +00003485
danielk1977106bb232004-05-21 10:08:53 +00003486/*
drh9cd29642008-07-23 00:52:55 +00003487** CAPI3REF: Number of columns in a result set {H13770} <S10700>
drh6ed48bf2007-06-14 20:57:18 +00003488**
mihailim1c492652008-06-21 18:02:16 +00003489** Returns the number of values in the current row of the result set.
danielk1977106bb232004-05-21 10:08:53 +00003490**
drh33c1be32008-01-30 16:16:14 +00003491** INVARIANTS:
3492**
drh9a247912008-07-22 18:45:08 +00003493** {H13771} After a call to [sqlite3_step(S)] that returns [SQLITE_ROW],
mihailim1c492652008-06-21 18:02:16 +00003494** the [sqlite3_data_count(S)] routine will return the same value
3495** as the [sqlite3_column_count(S)] function.
drh33c1be32008-01-30 16:16:14 +00003496**
drh9a247912008-07-22 18:45:08 +00003497** {H13772} After [sqlite3_step(S)] has returned any value other than
mihailim1c492652008-06-21 18:02:16 +00003498** [SQLITE_ROW] or before [sqlite3_step(S)] has been called on the
3499** [prepared statement] for the first time since it was
3500** [sqlite3_prepare | prepared] or [sqlite3_reset | reset],
3501** the [sqlite3_data_count(S)] routine returns zero.
danielk1977106bb232004-05-21 10:08:53 +00003502*/
danielk197793d46752004-05-23 13:30:58 +00003503int sqlite3_data_count(sqlite3_stmt *pStmt);
danielk19774adee202004-05-08 08:23:19 +00003504
drh4f26d6c2004-05-26 23:25:30 +00003505/*
drhb25f9d82008-07-23 15:40:06 +00003506** CAPI3REF: Fundamental Datatypes {H10265} <S10110><S10120>
drh33c1be32008-01-30 16:16:14 +00003507** KEYWORDS: SQLITE_TEXT
drh6ed48bf2007-06-14 20:57:18 +00003508**
drh9a247912008-07-22 18:45:08 +00003509** {H10266} Every value in SQLite has one of five fundamental datatypes:
drh6ed48bf2007-06-14 20:57:18 +00003510**
3511** <ul>
3512** <li> 64-bit signed integer
3513** <li> 64-bit IEEE floating point number
3514** <li> string
3515** <li> BLOB
3516** <li> NULL
drhfddfa2d2007-12-05 18:05:16 +00003517** </ul> {END}
drh6ed48bf2007-06-14 20:57:18 +00003518**
3519** These constants are codes for each of those types.
3520**
3521** Note that the SQLITE_TEXT constant was also used in SQLite version 2
3522** for a completely different meaning. Software that links against both
mihailim1c492652008-06-21 18:02:16 +00003523** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not
drh6ed48bf2007-06-14 20:57:18 +00003524** SQLITE_TEXT.
drh4f26d6c2004-05-26 23:25:30 +00003525*/
drh9c054832004-05-31 18:51:57 +00003526#define SQLITE_INTEGER 1
3527#define SQLITE_FLOAT 2
drh9c054832004-05-31 18:51:57 +00003528#define SQLITE_BLOB 4
3529#define SQLITE_NULL 5
drh1e284f42004-10-06 15:52:01 +00003530#ifdef SQLITE_TEXT
3531# undef SQLITE_TEXT
3532#else
3533# define SQLITE_TEXT 3
3534#endif
3535#define SQLITE3_TEXT 3
3536
3537/*
drh9cd29642008-07-23 00:52:55 +00003538** CAPI3REF: Result Values From A Query {H13800} <S10700>
mihailim1c492652008-06-21 18:02:16 +00003539** KEYWORDS: {column access functions}
drh6ed48bf2007-06-14 20:57:18 +00003540**
drh33c1be32008-01-30 16:16:14 +00003541** These routines form the "result set query" interface.
3542**
mihailim1c492652008-06-21 18:02:16 +00003543** These routines return information about a single column of the current
3544** result row of a query. In every case the first argument is a pointer
3545** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]
3546** that was returned from [sqlite3_prepare_v2()] or one of its variants)
3547** and the second argument is the index of the column for which information
3548** should be returned. The leftmost column of the result set has the index 0.
danielk1977106bb232004-05-21 10:08:53 +00003549**
mihailim1c492652008-06-21 18:02:16 +00003550** If the SQL statement does not currently point to a valid row, or if the
3551** column index is out of range, the result is undefined.
drh32bc3f62007-08-21 20:25:39 +00003552** These routines may only be called when the most recent call to
3553** [sqlite3_step()] has returned [SQLITE_ROW] and neither
mihailim1c492652008-06-21 18:02:16 +00003554** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently.
drh32bc3f62007-08-21 20:25:39 +00003555** If any of these routines are called after [sqlite3_reset()] or
3556** [sqlite3_finalize()] or after [sqlite3_step()] has returned
3557** something other than [SQLITE_ROW], the results are undefined.
3558** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()]
3559** are called from a different thread while any of these routines
mihailim1c492652008-06-21 18:02:16 +00003560** are pending, then the results are undefined.
drh6ed48bf2007-06-14 20:57:18 +00003561**
mihailim1c492652008-06-21 18:02:16 +00003562** The sqlite3_column_type() routine returns the
drh6ed48bf2007-06-14 20:57:18 +00003563** [SQLITE_INTEGER | datatype code] for the initial data type
3564** of the result column. The returned value is one of [SQLITE_INTEGER],
3565** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. The value
3566** returned by sqlite3_column_type() is only meaningful if no type
3567** conversions have occurred as described below. After a type conversion,
3568** the value returned by sqlite3_column_type() is undefined. Future
3569** versions of SQLite may change the behavior of sqlite3_column_type()
3570** following a type conversion.
3571**
mihailim1c492652008-06-21 18:02:16 +00003572** If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
drh6ed48bf2007-06-14 20:57:18 +00003573** routine returns the number of bytes in that BLOB or string.
mihailimebe796c2008-06-21 20:11:17 +00003574** If the result is a UTF-16 string, then sqlite3_column_bytes() converts
drh6ed48bf2007-06-14 20:57:18 +00003575** the string to UTF-8 and then returns the number of bytes.
3576** If the result is a numeric value then sqlite3_column_bytes() uses
mihailimebe796c2008-06-21 20:11:17 +00003577** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
drh6ed48bf2007-06-14 20:57:18 +00003578** the number of bytes in that string.
3579** The value returned does not include the zero terminator at the end
3580** of the string. For clarity: the value returned is the number of
3581** bytes in the string, not the number of characters.
3582**
drhc0b3abb2007-09-04 12:18:41 +00003583** Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
drh33c1be32008-01-30 16:16:14 +00003584** even empty strings, are always zero terminated. The return
mihailim04bcc002008-06-22 10:21:27 +00003585** value from sqlite3_column_blob() for a zero-length BLOB is an arbitrary
drhc0b3abb2007-09-04 12:18:41 +00003586** pointer, possibly even a NULL pointer.
3587**
drh6ed48bf2007-06-14 20:57:18 +00003588** The sqlite3_column_bytes16() routine is similar to sqlite3_column_bytes()
mihailim1c492652008-06-21 18:02:16 +00003589** but leaves the result in UTF-16 in native byte order instead of UTF-8.
drh6ed48bf2007-06-14 20:57:18 +00003590** The zero terminator is not included in this count.
drh4f26d6c2004-05-26 23:25:30 +00003591**
drhaa28e142008-03-18 13:47:20 +00003592** The object returned by [sqlite3_column_value()] is an
3593** [unprotected sqlite3_value] object. An unprotected sqlite3_value object
3594** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()].
3595** If the [unprotected sqlite3_value] object returned by
3596** [sqlite3_column_value()] is used in any other way, including calls
mihailim1c492652008-06-21 18:02:16 +00003597** to routines like [sqlite3_value_int()], [sqlite3_value_text()],
3598** or [sqlite3_value_bytes()], then the behavior is undefined.
drhaa28e142008-03-18 13:47:20 +00003599**
drh4f26d6c2004-05-26 23:25:30 +00003600** These routines attempt to convert the value where appropriate. For
3601** example, if the internal representation is FLOAT and a text result
mihailim1c492652008-06-21 18:02:16 +00003602** is requested, [sqlite3_snprintf()] is used internally to perform the
3603** conversion automatically. The following table details the conversions
3604** that are applied:
drh4f26d6c2004-05-26 23:25:30 +00003605**
drh6ed48bf2007-06-14 20:57:18 +00003606** <blockquote>
3607** <table border="1">
drh8bacf972007-08-25 16:21:29 +00003608** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion
drh4f26d6c2004-05-26 23:25:30 +00003609**
drh6ed48bf2007-06-14 20:57:18 +00003610** <tr><td> NULL <td> INTEGER <td> Result is 0
3611** <tr><td> NULL <td> FLOAT <td> Result is 0.0
3612** <tr><td> NULL <td> TEXT <td> Result is NULL pointer
3613** <tr><td> NULL <td> BLOB <td> Result is NULL pointer
3614** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
3615** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
mihailim1c492652008-06-21 18:02:16 +00003616** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT
drh6ed48bf2007-06-14 20:57:18 +00003617** <tr><td> FLOAT <td> INTEGER <td> Convert from float to integer
3618** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
3619** <tr><td> FLOAT <td> BLOB <td> Same as FLOAT->TEXT
3620** <tr><td> TEXT <td> INTEGER <td> Use atoi()
3621** <tr><td> TEXT <td> FLOAT <td> Use atof()
3622** <tr><td> TEXT <td> BLOB <td> No change
3623** <tr><td> BLOB <td> INTEGER <td> Convert to TEXT then use atoi()
3624** <tr><td> BLOB <td> FLOAT <td> Convert to TEXT then use atof()
3625** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed
3626** </table>
3627** </blockquote>
drh4f26d6c2004-05-26 23:25:30 +00003628**
drh6ed48bf2007-06-14 20:57:18 +00003629** The table above makes reference to standard C library functions atoi()
3630** and atof(). SQLite does not really use these functions. It has its
shane26b34032008-05-23 17:21:09 +00003631** own equivalent internal routines. The atoi() and atof() names are
drh6ed48bf2007-06-14 20:57:18 +00003632** used in the table for brevity and because they are familiar to most
3633** C programmers.
3634**
3635** Note that when type conversions occur, pointers returned by prior
3636** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
mihailim1c492652008-06-21 18:02:16 +00003637** sqlite3_column_text16() may be invalidated.
drh6ed48bf2007-06-14 20:57:18 +00003638** Type conversions and pointer invalidations might occur
3639** in the following cases:
3640**
3641** <ul>
mihailim1c492652008-06-21 18:02:16 +00003642** <li> The initial content is a BLOB and sqlite3_column_text() or
3643** sqlite3_column_text16() is called. A zero-terminator might
3644** need to be added to the string.</li>
3645** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or
3646** sqlite3_column_text16() is called. The content must be converted
3647** to UTF-16.</li>
3648** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
3649** sqlite3_column_text() is called. The content must be converted
3650** to UTF-8.</li>
drh6ed48bf2007-06-14 20:57:18 +00003651** </ul>
3652**
3653** Conversions between UTF-16be and UTF-16le are always done in place and do
3654** not invalidate a prior pointer, though of course the content of the buffer
3655** that the prior pointer points to will have been modified. Other kinds
mihailim1c492652008-06-21 18:02:16 +00003656** of conversion are done in place when it is possible, but sometimes they
3657** are not possible and in those cases prior pointers are invalidated.
drh6ed48bf2007-06-14 20:57:18 +00003658**
3659** The safest and easiest to remember policy is to invoke these routines
3660** in one of the following ways:
3661**
mihailim1c492652008-06-21 18:02:16 +00003662** <ul>
drh6ed48bf2007-06-14 20:57:18 +00003663** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
3664** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
3665** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
mihailim1c492652008-06-21 18:02:16 +00003666** </ul>
drh6ed48bf2007-06-14 20:57:18 +00003667**
mihailim1c492652008-06-21 18:02:16 +00003668** In other words, you should call sqlite3_column_text(),
3669** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
3670** into the desired format, then invoke sqlite3_column_bytes() or
3671** sqlite3_column_bytes16() to find the size of the result. Do not mix calls
3672** to sqlite3_column_text() or sqlite3_column_blob() with calls to
3673** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()
3674** with calls to sqlite3_column_bytes().
drh32bc3f62007-08-21 20:25:39 +00003675**
3676** The pointers returned are valid until a type conversion occurs as
3677** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
3678** [sqlite3_finalize()] is called. The memory space used to hold strings
mihailim04bcc002008-06-22 10:21:27 +00003679** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned
mihailim1c492652008-06-21 18:02:16 +00003680** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
drh32bc3f62007-08-21 20:25:39 +00003681** [sqlite3_free()].
drh4a50aac2007-08-23 02:47:53 +00003682**
3683** If a memory allocation error occurs during the evaluation of any
3684** of these routines, a default value is returned. The default value
3685** is either the integer 0, the floating point number 0.0, or a NULL
3686** pointer. Subsequent calls to [sqlite3_errcode()] will return
3687** [SQLITE_NOMEM].
drh21ac7f92008-01-31 12:26:49 +00003688**
3689** INVARIANTS:
3690**
drh9a247912008-07-22 18:45:08 +00003691** {H13803} The [sqlite3_column_blob(S,N)] interface converts the
drh21ac7f92008-01-31 12:26:49 +00003692** Nth column in the current row of the result set for
mihailim1c492652008-06-21 18:02:16 +00003693** the [prepared statement] S into a BLOB and then returns a
drh21ac7f92008-01-31 12:26:49 +00003694** pointer to the converted value.
3695**
drh9a247912008-07-22 18:45:08 +00003696** {H13806} The [sqlite3_column_bytes(S,N)] interface returns the
mihailim1c492652008-06-21 18:02:16 +00003697** number of bytes in the BLOB or string (exclusive of the
drh21ac7f92008-01-31 12:26:49 +00003698** zero terminator on the string) that was returned by the
3699** most recent call to [sqlite3_column_blob(S,N)] or
3700** [sqlite3_column_text(S,N)].
3701**
drh9a247912008-07-22 18:45:08 +00003702** {H13809} The [sqlite3_column_bytes16(S,N)] interface returns the
drh21ac7f92008-01-31 12:26:49 +00003703** number of bytes in the string (exclusive of the
3704** zero terminator on the string) that was returned by the
3705** most recent call to [sqlite3_column_text16(S,N)].
3706**
drh9a247912008-07-22 18:45:08 +00003707** {H13812} The [sqlite3_column_double(S,N)] interface converts the
mihailim1c492652008-06-21 18:02:16 +00003708** Nth column in the current row of the result set for the
drh414025d2008-01-31 16:36:40 +00003709** [prepared statement] S into a floating point value and
drh21ac7f92008-01-31 12:26:49 +00003710** returns a copy of that value.
3711**
drh9a247912008-07-22 18:45:08 +00003712** {H13815} The [sqlite3_column_int(S,N)] interface converts the
mihailim1c492652008-06-21 18:02:16 +00003713** Nth column in the current row of the result set for the
drhafc91042008-02-21 02:09:45 +00003714** [prepared statement] S into a 64-bit signed integer and
3715** returns the lower 32 bits of that integer.
drh21ac7f92008-01-31 12:26:49 +00003716**
drh9a247912008-07-22 18:45:08 +00003717** {H13818} The [sqlite3_column_int64(S,N)] interface converts the
mihailim1c492652008-06-21 18:02:16 +00003718** Nth column in the current row of the result set for the
drh414025d2008-01-31 16:36:40 +00003719** [prepared statement] S into a 64-bit signed integer and
drh21ac7f92008-01-31 12:26:49 +00003720** returns a copy of that integer.
3721**
drh9a247912008-07-22 18:45:08 +00003722** {H13821} The [sqlite3_column_text(S,N)] interface converts the
drh21ac7f92008-01-31 12:26:49 +00003723** Nth column in the current row of the result set for
mihailim1c492652008-06-21 18:02:16 +00003724** the [prepared statement] S into a zero-terminated UTF-8
drh21ac7f92008-01-31 12:26:49 +00003725** string and returns a pointer to that string.
3726**
drh9a247912008-07-22 18:45:08 +00003727** {H13824} The [sqlite3_column_text16(S,N)] interface converts the
mihailim1c492652008-06-21 18:02:16 +00003728** Nth column in the current row of the result set for the
drh414025d2008-01-31 16:36:40 +00003729** [prepared statement] S into a zero-terminated 2-byte
mihailim1c492652008-06-21 18:02:16 +00003730** aligned UTF-16 native byte order string and returns
3731** a pointer to that string.
drh21ac7f92008-01-31 12:26:49 +00003732**
drh9a247912008-07-22 18:45:08 +00003733** {H13827} The [sqlite3_column_type(S,N)] interface returns
drh414025d2008-01-31 16:36:40 +00003734** one of [SQLITE_NULL], [SQLITE_INTEGER], [SQLITE_FLOAT],
drh21ac7f92008-01-31 12:26:49 +00003735** [SQLITE_TEXT], or [SQLITE_BLOB] as appropriate for
3736** the Nth column in the current row of the result set for
mihailim1c492652008-06-21 18:02:16 +00003737** the [prepared statement] S.
drh21ac7f92008-01-31 12:26:49 +00003738**
drh9a247912008-07-22 18:45:08 +00003739** {H13830} The [sqlite3_column_value(S,N)] interface returns a
drhaa28e142008-03-18 13:47:20 +00003740** pointer to an [unprotected sqlite3_value] object for the
drh21ac7f92008-01-31 12:26:49 +00003741** Nth column in the current row of the result set for
mihailim1c492652008-06-21 18:02:16 +00003742** the [prepared statement] S.
danielk1977106bb232004-05-21 10:08:53 +00003743*/
drhf4479502004-05-27 03:12:53 +00003744const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
3745int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
3746int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
3747double sqlite3_column_double(sqlite3_stmt*, int iCol);
3748int sqlite3_column_int(sqlite3_stmt*, int iCol);
drh6d2069d2007-08-14 01:58:53 +00003749sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
drhf4479502004-05-27 03:12:53 +00003750const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
3751const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
drh4f26d6c2004-05-26 23:25:30 +00003752int sqlite3_column_type(sqlite3_stmt*, int iCol);
drh4be8b512006-06-13 23:51:34 +00003753sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
danielk19774adee202004-05-08 08:23:19 +00003754
danielk197765904932004-05-26 06:18:37 +00003755/*
drhb25f9d82008-07-23 15:40:06 +00003756** CAPI3REF: Destroy A Prepared Statement Object {H13300} <S70300><S30100>
drh6ed48bf2007-06-14 20:57:18 +00003757**
mihailimebe796c2008-06-21 20:11:17 +00003758** The sqlite3_finalize() function is called to delete a [prepared statement].
3759** If the statement was executed successfully or not executed at all, then
3760** SQLITE_OK is returned. If execution of the statement failed then an
3761** [error code] or [extended error code] is returned.
danielk197765904932004-05-26 06:18:37 +00003762**
3763** This routine can be called at any point during the execution of the
mihailimebe796c2008-06-21 20:11:17 +00003764** [prepared statement]. If the virtual machine has not
drh6ed48bf2007-06-14 20:57:18 +00003765** completed execution when this routine is called, that is like
mihailimebe796c2008-06-21 20:11:17 +00003766** encountering an error or an [sqlite3_interrupt | interrupt].
3767** Incomplete updates may be rolled back and transactions canceled,
3768** depending on the circumstances, and the
drh33c1be32008-01-30 16:16:14 +00003769** [error code] returned will be [SQLITE_ABORT].
3770**
3771** INVARIANTS:
3772**
drh9a247912008-07-22 18:45:08 +00003773** {H11302} The [sqlite3_finalize(S)] interface destroys the
drh33c1be32008-01-30 16:16:14 +00003774** [prepared statement] S and releases all
3775** memory and file resources held by that object.
3776**
drh9a247912008-07-22 18:45:08 +00003777** {H11304} If the most recent call to [sqlite3_step(S)] for the
drh33c1be32008-01-30 16:16:14 +00003778** [prepared statement] S returned an error,
3779** then [sqlite3_finalize(S)] returns that same error.
danielk197765904932004-05-26 06:18:37 +00003780*/
3781int sqlite3_finalize(sqlite3_stmt *pStmt);
3782
3783/*
drh9cd29642008-07-23 00:52:55 +00003784** CAPI3REF: Reset A Prepared Statement Object {H13330} <S70300>
drh6ed48bf2007-06-14 20:57:18 +00003785**
mihailimebe796c2008-06-21 20:11:17 +00003786** The sqlite3_reset() function is called to reset a [prepared statement]
3787** object back to its initial state, ready to be re-executed.
danielk197765904932004-05-26 06:18:37 +00003788** Any SQL statement variables that had values bound to them using
drh6ed48bf2007-06-14 20:57:18 +00003789** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
3790** Use [sqlite3_clear_bindings()] to reset the bindings.
drh33c1be32008-01-30 16:16:14 +00003791**
drh9a247912008-07-22 18:45:08 +00003792** {H11332} The [sqlite3_reset(S)] interface resets the [prepared statement] S
drh33c1be32008-01-30 16:16:14 +00003793** back to the beginning of its program.
3794**
drh9a247912008-07-22 18:45:08 +00003795** {H11334} If the most recent call to [sqlite3_step(S)] for the
drh33c1be32008-01-30 16:16:14 +00003796** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE],
3797** or if [sqlite3_step(S)] has never before been called on S,
3798** then [sqlite3_reset(S)] returns [SQLITE_OK].
3799**
drh9a247912008-07-22 18:45:08 +00003800** {H11336} If the most recent call to [sqlite3_step(S)] for the
drh33c1be32008-01-30 16:16:14 +00003801** [prepared statement] S indicated an error, then
3802** [sqlite3_reset(S)] returns an appropriate [error code].
3803**
drh9a247912008-07-22 18:45:08 +00003804** {H11338} The [sqlite3_reset(S)] interface does not change the values
mihailimebe796c2008-06-21 20:11:17 +00003805** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
danielk197765904932004-05-26 06:18:37 +00003806*/
3807int sqlite3_reset(sqlite3_stmt *pStmt);
3808
3809/*
drh9cd29642008-07-23 00:52:55 +00003810** CAPI3REF: Create Or Redefine SQL Functions {H16100} <S20200>
mihailimefc8e8a2008-06-21 16:47:09 +00003811** KEYWORDS: {function creation routines}
3812** KEYWORDS: {application-defined SQL function}
3813** KEYWORDS: {application-defined SQL functions}
drh6ed48bf2007-06-14 20:57:18 +00003814**
mihailimebe796c2008-06-21 20:11:17 +00003815** These two functions (collectively known as "function creation routines")
3816** are used to add SQL functions or aggregates or to redefine the behavior
3817** of existing SQL functions or aggregates. The only difference between the
3818** two is that the second parameter, the name of the (scalar) function or
3819** aggregate, is encoded in UTF-8 for sqlite3_create_function() and UTF-16
3820** for sqlite3_create_function16().
danielk197765904932004-05-26 06:18:37 +00003821**
drh1c3cfc62008-03-08 12:37:30 +00003822** The first parameter is the [database connection] to which the SQL
mihailimebe796c2008-06-21 20:11:17 +00003823** function is to be added. If a single program uses more than one database
3824** connection internally, then SQL functions must be added individually to
3825** each database connection.
danielk197765904932004-05-26 06:18:37 +00003826**
mihailimebe796c2008-06-21 20:11:17 +00003827** The second parameter is the name of the SQL function to be created or
3828** redefined. The length of the name is limited to 255 bytes, exclusive of
3829** the zero-terminator. Note that the name length limit is in bytes, not
drh6ed48bf2007-06-14 20:57:18 +00003830** characters. Any attempt to create a function with a longer name
mihailimebe796c2008-06-21 20:11:17 +00003831** will result in [SQLITE_ERROR] being returned.
drh6ed48bf2007-06-14 20:57:18 +00003832**
3833** The third parameter is the number of arguments that the SQL function or
3834** aggregate takes. If this parameter is negative, then the SQL function or
danielk197765904932004-05-26 06:18:37 +00003835** aggregate may take any number of arguments.
3836**
mihailimebe796c2008-06-21 20:11:17 +00003837** The fourth parameter, eTextRep, specifies what
drh6ed48bf2007-06-14 20:57:18 +00003838** [SQLITE_UTF8 | text encoding] this SQL function prefers for
3839** its parameters. Any SQL function implementation should be able to work
3840** work with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
3841** more efficient with one encoding than another. It is allowed to
drh6d2069d2007-08-14 01:58:53 +00003842** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
drh6ed48bf2007-06-14 20:57:18 +00003843** times with the same function but with different values of eTextRep.
3844** When multiple implementations of the same function are available, SQLite
3845** will pick the one that involves the least amount of data conversion.
mihailimebe796c2008-06-21 20:11:17 +00003846** If there is only a single implementation which does not care what text
3847** encoding is used, then the fourth argument should be [SQLITE_ANY].
drh6ed48bf2007-06-14 20:57:18 +00003848**
mihailimebe796c2008-06-21 20:11:17 +00003849** The fifth parameter is an arbitrary pointer. The implementation of the
3850** function can gain access to this pointer using [sqlite3_user_data()].
danielk1977d02eb1f2004-06-06 09:44:03 +00003851**
danielk197765904932004-05-26 06:18:37 +00003852** The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
mihailimebe796c2008-06-21 20:11:17 +00003853** pointers to C-language functions that implement the SQL function or
3854** aggregate. A scalar SQL function requires an implementation of the xFunc
3855** callback only, NULL pointers should be passed as the xStep and xFinal
3856** parameters. An aggregate SQL function requires an implementation of xStep
3857** and xFinal and NULL should be passed for xFunc. To delete an existing
3858** SQL function or aggregate, pass NULL for all three function callbacks.
drh6ed48bf2007-06-14 20:57:18 +00003859**
3860** It is permitted to register multiple implementations of the same
3861** functions with the same name but with either differing numbers of
shane26b34032008-05-23 17:21:09 +00003862** arguments or differing preferred text encodings. SQLite will use
drh6ed48bf2007-06-14 20:57:18 +00003863** the implementation most closely matches the way in which the
3864** SQL function is used.
drh21ac7f92008-01-31 12:26:49 +00003865**
3866** INVARIANTS:
3867**
drh9a247912008-07-22 18:45:08 +00003868** {H16103} The [sqlite3_create_function16()] interface behaves exactly
drh21ac7f92008-01-31 12:26:49 +00003869** like [sqlite3_create_function()] in every way except that it
mihailimebe796c2008-06-21 20:11:17 +00003870** interprets the zFunctionName argument as zero-terminated UTF-16
3871** native byte order instead of as zero-terminated UTF-8.
drh21ac7f92008-01-31 12:26:49 +00003872**
drh9a247912008-07-22 18:45:08 +00003873** {H16106} A successful invocation of
drhafc91042008-02-21 02:09:45 +00003874** the [sqlite3_create_function(D,X,N,E,...)] interface registers
mihailimebe796c2008-06-21 20:11:17 +00003875** or replaces callback functions in the [database connection] D
drhafc91042008-02-21 02:09:45 +00003876** used to implement the SQL function named X with N parameters
shane26b34032008-05-23 17:21:09 +00003877** and having a preferred text encoding of E.
drhafc91042008-02-21 02:09:45 +00003878**
drh9a247912008-07-22 18:45:08 +00003879** {H16109} A successful call to [sqlite3_create_function(D,X,N,E,P,F,S,L)]
drhafc91042008-02-21 02:09:45 +00003880** replaces the P, F, S, and L values from any prior calls with
3881** the same D, X, N, and E values.
3882**
drh9a247912008-07-22 18:45:08 +00003883** {H16112} The [sqlite3_create_function(D,X,...)] interface fails with
drhafc91042008-02-21 02:09:45 +00003884** a return code of [SQLITE_ERROR] if the SQL function name X is
3885** longer than 255 bytes exclusive of the zero terminator.
3886**
drh9a247912008-07-22 18:45:08 +00003887** {H16118} Either F must be NULL and S and L are non-NULL or else F
drhafc91042008-02-21 02:09:45 +00003888** is non-NULL and S and L are NULL, otherwise
3889** [sqlite3_create_function(D,X,N,E,P,F,S,L)] returns [SQLITE_ERROR].
3890**
drh9a247912008-07-22 18:45:08 +00003891** {H16121} The [sqlite3_create_function(D,...)] interface fails with an
drhafc91042008-02-21 02:09:45 +00003892** error code of [SQLITE_BUSY] if there exist [prepared statements]
3893** associated with the [database connection] D.
3894**
drh9a247912008-07-22 18:45:08 +00003895** {H16124} The [sqlite3_create_function(D,X,N,...)] interface fails with an
drhafc91042008-02-21 02:09:45 +00003896** error code of [SQLITE_ERROR] if parameter N (specifying the number
3897** of arguments to the SQL function being registered) is less
3898** than -1 or greater than 127.
3899**
drh9a247912008-07-22 18:45:08 +00003900** {H16127} When N is non-negative, the [sqlite3_create_function(D,X,N,...)]
drhafc91042008-02-21 02:09:45 +00003901** interface causes callbacks to be invoked for the SQL function
3902** named X when the number of arguments to the SQL function is
3903** exactly N.
3904**
drh9a247912008-07-22 18:45:08 +00003905** {H16130} When N is -1, the [sqlite3_create_function(D,X,N,...)]
drhafc91042008-02-21 02:09:45 +00003906** interface causes callbacks to be invoked for the SQL function
3907** named X with any number of arguments.
3908**
drh9a247912008-07-22 18:45:08 +00003909** {H16133} When calls to [sqlite3_create_function(D,X,N,...)]
drhafc91042008-02-21 02:09:45 +00003910** specify multiple implementations of the same function X
3911** and when one implementation has N>=0 and the other has N=(-1)
3912** the implementation with a non-zero N is preferred.
3913**
drh9a247912008-07-22 18:45:08 +00003914** {H16136} When calls to [sqlite3_create_function(D,X,N,E,...)]
drhafc91042008-02-21 02:09:45 +00003915** specify multiple implementations of the same function X with
3916** the same number of arguments N but with different
3917** encodings E, then the implementation where E matches the
3918** database encoding is preferred.
3919**
drh9a247912008-07-22 18:45:08 +00003920** {H16139} For an aggregate SQL function created using
mihailimebe796c2008-06-21 20:11:17 +00003921** [sqlite3_create_function(D,X,N,E,P,0,S,L)] the finalizer
drhafc91042008-02-21 02:09:45 +00003922** function L will always be invoked exactly once if the
3923** step function S is called one or more times.
drhaa28e142008-03-18 13:47:20 +00003924**
drh9a247912008-07-22 18:45:08 +00003925** {H16142} When SQLite invokes either the xFunc or xStep function of
drhaa28e142008-03-18 13:47:20 +00003926** an application-defined SQL function or aggregate created
3927** by [sqlite3_create_function()] or [sqlite3_create_function16()],
3928** then the array of [sqlite3_value] objects passed as the
3929** third parameter are always [protected sqlite3_value] objects.
danielk197765904932004-05-26 06:18:37 +00003930*/
3931int sqlite3_create_function(
drh33c1be32008-01-30 16:16:14 +00003932 sqlite3 *db,
danielk197765904932004-05-26 06:18:37 +00003933 const char *zFunctionName,
3934 int nArg,
3935 int eTextRep,
drh33c1be32008-01-30 16:16:14 +00003936 void *pApp,
danielk197765904932004-05-26 06:18:37 +00003937 void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
3938 void (*xStep)(sqlite3_context*,int,sqlite3_value**),
3939 void (*xFinal)(sqlite3_context*)
3940);
3941int sqlite3_create_function16(
drh33c1be32008-01-30 16:16:14 +00003942 sqlite3 *db,
danielk197765904932004-05-26 06:18:37 +00003943 const void *zFunctionName,
3944 int nArg,
3945 int eTextRep,
drh33c1be32008-01-30 16:16:14 +00003946 void *pApp,
danielk197765904932004-05-26 06:18:37 +00003947 void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
3948 void (*xStep)(sqlite3_context*,int,sqlite3_value**),
3949 void (*xFinal)(sqlite3_context*)
3950);
3951
3952/*
drh9cd29642008-07-23 00:52:55 +00003953** CAPI3REF: Text Encodings {H10267} <S50200> <H16100>
drh6ed48bf2007-06-14 20:57:18 +00003954**
3955** These constant define integer codes that represent the various
3956** text encodings supported by SQLite.
danielk197765904932004-05-26 06:18:37 +00003957*/
drh6ed48bf2007-06-14 20:57:18 +00003958#define SQLITE_UTF8 1
3959#define SQLITE_UTF16LE 2
3960#define SQLITE_UTF16BE 3
3961#define SQLITE_UTF16 4 /* Use native byte order */
3962#define SQLITE_ANY 5 /* sqlite3_create_function only */
3963#define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
danielk197765904932004-05-26 06:18:37 +00003964
danielk19770ffba6b2004-05-24 09:10:10 +00003965/*
drhd5a68d32008-08-04 13:44:57 +00003966** CAPI3REF: Deprecated Functions
3967** DEPRECATED
drh6ed48bf2007-06-14 20:57:18 +00003968**
drhd5a68d32008-08-04 13:44:57 +00003969** These functions are [deprecated]. In order to maintain
3970** backwards compatibility with older code, these functions continue
3971** to be supported. However, new applications should avoid
drh6ed48bf2007-06-14 20:57:18 +00003972** the use of these functions. To help encourage people to avoid
3973** using these functions, we are not going to tell you want they do.
3974*/
shanea79c3cc2008-08-11 17:27:01 +00003975SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
3976SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
3977SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
3978SQLITE_DEPRECATED int sqlite3_global_recover(void);
3979SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
3980SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64);
drh6ed48bf2007-06-14 20:57:18 +00003981
3982/*
drh9cd29642008-07-23 00:52:55 +00003983** CAPI3REF: Obtaining SQL Function Parameter Values {H15100} <S20200>
drh6ed48bf2007-06-14 20:57:18 +00003984**
3985** The C-language implementation of SQL functions and aggregates uses
3986** this set of interface routines to access the parameter values on
3987** the function or aggregate.
3988**
3989** The xFunc (for scalar functions) or xStep (for aggregates) parameters
3990** to [sqlite3_create_function()] and [sqlite3_create_function16()]
3991** define callbacks that implement the SQL functions and aggregates.
3992** The 4th parameter to these callbacks is an array of pointers to
drhaa28e142008-03-18 13:47:20 +00003993** [protected sqlite3_value] objects. There is one [sqlite3_value] object for
drh6ed48bf2007-06-14 20:57:18 +00003994** each parameter to the SQL function. These routines are used to
3995** extract values from the [sqlite3_value] objects.
3996**
drhaa28e142008-03-18 13:47:20 +00003997** These routines work only with [protected sqlite3_value] objects.
3998** Any attempt to use these routines on an [unprotected sqlite3_value]
3999** object results in undefined behavior.
4000**
mihailim1c492652008-06-21 18:02:16 +00004001** These routines work just like the corresponding [column access functions]
4002** except that these routines take a single [protected sqlite3_value] object
4003** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
drh6ed48bf2007-06-14 20:57:18 +00004004**
mihailimebe796c2008-06-21 20:11:17 +00004005** The sqlite3_value_text16() interface extracts a UTF-16 string
drh6ed48bf2007-06-14 20:57:18 +00004006** in the native byte-order of the host machine. The
4007** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
mihailimebe796c2008-06-21 20:11:17 +00004008** extract UTF-16 strings as big-endian and little-endian respectively.
drh6ed48bf2007-06-14 20:57:18 +00004009**
4010** The sqlite3_value_numeric_type() interface attempts to apply
4011** numeric affinity to the value. This means that an attempt is
4012** made to convert the value to an integer or floating point. If
drhf5befa02007-12-06 02:42:07 +00004013** such a conversion is possible without loss of information (in other
mihailimebe796c2008-06-21 20:11:17 +00004014** words, if the value is a string that looks like a number)
4015** then the conversion is performed. Otherwise no conversion occurs.
4016** The [SQLITE_INTEGER | datatype] after conversion is returned.
drh6ed48bf2007-06-14 20:57:18 +00004017**
mihailimebe796c2008-06-21 20:11:17 +00004018** Please pay particular attention to the fact that the pointer returned
4019** from [sqlite3_value_blob()], [sqlite3_value_text()], or
drh6ed48bf2007-06-14 20:57:18 +00004020** [sqlite3_value_text16()] can be invalidated by a subsequent call to
drh6d2069d2007-08-14 01:58:53 +00004021** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
mihailimebe796c2008-06-21 20:11:17 +00004022** or [sqlite3_value_text16()].
drhe53831d2007-08-17 01:14:38 +00004023**
4024** These routines must be called from the same thread as
drhaa28e142008-03-18 13:47:20 +00004025** the SQL function that supplied the [sqlite3_value*] parameters.
drhf5befa02007-12-06 02:42:07 +00004026**
drhafc91042008-02-21 02:09:45 +00004027** INVARIANTS:
4028**
drh9a247912008-07-22 18:45:08 +00004029** {H15103} The [sqlite3_value_blob(V)] interface converts the
mihailimebe796c2008-06-21 20:11:17 +00004030** [protected sqlite3_value] object V into a BLOB and then
4031** returns a pointer to the converted value.
drhafc91042008-02-21 02:09:45 +00004032**
drh9a247912008-07-22 18:45:08 +00004033** {H15106} The [sqlite3_value_bytes(V)] interface returns the
mihailimebe796c2008-06-21 20:11:17 +00004034** number of bytes in the BLOB or string (exclusive of the
drhafc91042008-02-21 02:09:45 +00004035** zero terminator on the string) that was returned by the
4036** most recent call to [sqlite3_value_blob(V)] or
4037** [sqlite3_value_text(V)].
4038**
drh9a247912008-07-22 18:45:08 +00004039** {H15109} The [sqlite3_value_bytes16(V)] interface returns the
drhafc91042008-02-21 02:09:45 +00004040** number of bytes in the string (exclusive of the
4041** zero terminator on the string) that was returned by the
4042** most recent call to [sqlite3_value_text16(V)],
4043** [sqlite3_value_text16be(V)], or [sqlite3_value_text16le(V)].
4044**
drh9a247912008-07-22 18:45:08 +00004045** {H15112} The [sqlite3_value_double(V)] interface converts the
drhaa28e142008-03-18 13:47:20 +00004046** [protected sqlite3_value] object V into a floating point value and
drhafc91042008-02-21 02:09:45 +00004047** returns a copy of that value.
4048**
drh9a247912008-07-22 18:45:08 +00004049** {H15115} The [sqlite3_value_int(V)] interface converts the
drhaa28e142008-03-18 13:47:20 +00004050** [protected sqlite3_value] object V into a 64-bit signed integer and
drhafc91042008-02-21 02:09:45 +00004051** returns the lower 32 bits of that integer.
4052**
drh9a247912008-07-22 18:45:08 +00004053** {H15118} The [sqlite3_value_int64(V)] interface converts the
drhaa28e142008-03-18 13:47:20 +00004054** [protected sqlite3_value] object V into a 64-bit signed integer and
drhafc91042008-02-21 02:09:45 +00004055** returns a copy of that integer.
4056**
drh9a247912008-07-22 18:45:08 +00004057** {H15121} The [sqlite3_value_text(V)] interface converts the
mihailimebe796c2008-06-21 20:11:17 +00004058** [protected sqlite3_value] object V into a zero-terminated UTF-8
drhafc91042008-02-21 02:09:45 +00004059** string and returns a pointer to that string.
4060**
drh9a247912008-07-22 18:45:08 +00004061** {H15124} The [sqlite3_value_text16(V)] interface converts the
drhaa28e142008-03-18 13:47:20 +00004062** [protected sqlite3_value] object V into a zero-terminated 2-byte
drhafc91042008-02-21 02:09:45 +00004063** aligned UTF-16 native byte order
4064** string and returns a pointer to that string.
4065**
drh9a247912008-07-22 18:45:08 +00004066** {H15127} The [sqlite3_value_text16be(V)] interface converts the
drhaa28e142008-03-18 13:47:20 +00004067** [protected sqlite3_value] object V into a zero-terminated 2-byte
drhafc91042008-02-21 02:09:45 +00004068** aligned UTF-16 big-endian
4069** string and returns a pointer to that string.
4070**
drh9a247912008-07-22 18:45:08 +00004071** {H15130} The [sqlite3_value_text16le(V)] interface converts the
drhaa28e142008-03-18 13:47:20 +00004072** [protected sqlite3_value] object V into a zero-terminated 2-byte
drhafc91042008-02-21 02:09:45 +00004073** aligned UTF-16 little-endian
4074** string and returns a pointer to that string.
4075**
drh9a247912008-07-22 18:45:08 +00004076** {H15133} The [sqlite3_value_type(V)] interface returns
drhafc91042008-02-21 02:09:45 +00004077** one of [SQLITE_NULL], [SQLITE_INTEGER], [SQLITE_FLOAT],
4078** [SQLITE_TEXT], or [SQLITE_BLOB] as appropriate for
4079** the [sqlite3_value] object V.
4080**
drh9a247912008-07-22 18:45:08 +00004081** {H15136} The [sqlite3_value_numeric_type(V)] interface converts
drhaa28e142008-03-18 13:47:20 +00004082** the [protected sqlite3_value] object V into either an integer or
drhafc91042008-02-21 02:09:45 +00004083** a floating point value if it can do so without loss of
4084** information, and returns one of [SQLITE_NULL],
4085** [SQLITE_INTEGER], [SQLITE_FLOAT], [SQLITE_TEXT], or
mihailimebe796c2008-06-21 20:11:17 +00004086** [SQLITE_BLOB] as appropriate for the
4087** [protected sqlite3_value] object V after the conversion attempt.
danielk19770ffba6b2004-05-24 09:10:10 +00004088*/
drhf4479502004-05-27 03:12:53 +00004089const void *sqlite3_value_blob(sqlite3_value*);
4090int sqlite3_value_bytes(sqlite3_value*);
4091int sqlite3_value_bytes16(sqlite3_value*);
4092double sqlite3_value_double(sqlite3_value*);
4093int sqlite3_value_int(sqlite3_value*);
drh6d2069d2007-08-14 01:58:53 +00004094sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
drhf4479502004-05-27 03:12:53 +00004095const unsigned char *sqlite3_value_text(sqlite3_value*);
4096const void *sqlite3_value_text16(sqlite3_value*);
danielk1977d8123362004-06-12 09:25:12 +00004097const void *sqlite3_value_text16le(sqlite3_value*);
4098const void *sqlite3_value_text16be(sqlite3_value*);
danielk197793d46752004-05-23 13:30:58 +00004099int sqlite3_value_type(sqlite3_value*);
drh29d72102006-02-09 22:13:41 +00004100int sqlite3_value_numeric_type(sqlite3_value*);
danielk19770ffba6b2004-05-24 09:10:10 +00004101
4102/*
drh9cd29642008-07-23 00:52:55 +00004103** CAPI3REF: Obtain Aggregate Function Context {H16210} <S20200>
drh6ed48bf2007-06-14 20:57:18 +00004104**
4105** The implementation of aggregate SQL functions use this routine to allocate
mihailimebe796c2008-06-21 20:11:17 +00004106** a structure for storing their state.
4107**
4108** The first time the sqlite3_aggregate_context() routine is called for a
4109** particular aggregate, SQLite allocates nBytes of memory, zeroes out that
4110** memory, and returns a pointer to it. On second and subsequent calls to
4111** sqlite3_aggregate_context() for the same aggregate function index,
4112** the same buffer is returned. The implementation of the aggregate can use
4113** the returned buffer to accumulate data.
danielk19770ae8b832004-05-25 12:05:56 +00004114**
drhafc91042008-02-21 02:09:45 +00004115** SQLite automatically frees the allocated buffer when the aggregate
4116** query concludes.
drh6ed48bf2007-06-14 20:57:18 +00004117**
mihailimebe796c2008-06-21 20:11:17 +00004118** The first parameter should be a copy of the
4119** [sqlite3_context | SQL function context] that is the first parameter
4120** to the callback routine that implements the aggregate function.
drhe53831d2007-08-17 01:14:38 +00004121**
4122** This routine must be called from the same thread in which
drh605264d2007-08-21 15:13:19 +00004123** the aggregate SQL function is running.
drhafc91042008-02-21 02:09:45 +00004124**
4125** INVARIANTS:
4126**
drh9a247912008-07-22 18:45:08 +00004127** {H16211} The first invocation of [sqlite3_aggregate_context(C,N)] for
drhafc91042008-02-21 02:09:45 +00004128** a particular instance of an aggregate function (for a particular
mihailimebe796c2008-06-21 20:11:17 +00004129** context C) causes SQLite to allocate N bytes of memory,
4130** zero that memory, and return a pointer to the allocated memory.
drhafc91042008-02-21 02:09:45 +00004131**
drh9a247912008-07-22 18:45:08 +00004132** {H16213} If a memory allocation error occurs during
drhafc91042008-02-21 02:09:45 +00004133** [sqlite3_aggregate_context(C,N)] then the function returns 0.
4134**
drh9a247912008-07-22 18:45:08 +00004135** {H16215} Second and subsequent invocations of
drhafc91042008-02-21 02:09:45 +00004136** [sqlite3_aggregate_context(C,N)] for the same context pointer C
4137** ignore the N parameter and return a pointer to the same
4138** block of memory returned by the first invocation.
4139**
drh9a247912008-07-22 18:45:08 +00004140** {H16217} The memory allocated by [sqlite3_aggregate_context(C,N)] is
drhafc91042008-02-21 02:09:45 +00004141** automatically freed on the next call to [sqlite3_reset()]
4142** or [sqlite3_finalize()] for the [prepared statement] containing
4143** the aggregate function associated with context C.
danielk19770ae8b832004-05-25 12:05:56 +00004144*/
drh4f26d6c2004-05-26 23:25:30 +00004145void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
danielk19777e18c252004-05-25 11:47:24 +00004146
4147/*
drh9cd29642008-07-23 00:52:55 +00004148** CAPI3REF: User Data For Functions {H16240} <S20200>
drh6ed48bf2007-06-14 20:57:18 +00004149**
drhafc91042008-02-21 02:09:45 +00004150** The sqlite3_user_data() interface returns a copy of
drhf5befa02007-12-06 02:42:07 +00004151** the pointer that was the pUserData parameter (the 5th parameter)
shane26b34032008-05-23 17:21:09 +00004152** of the [sqlite3_create_function()]
drhf5befa02007-12-06 02:42:07 +00004153** and [sqlite3_create_function16()] routines that originally
4154** registered the application defined function. {END}
drhe53831d2007-08-17 01:14:38 +00004155**
drhafc91042008-02-21 02:09:45 +00004156** This routine must be called from the same thread in which
drhf5befa02007-12-06 02:42:07 +00004157** the application-defined function is running.
drhafc91042008-02-21 02:09:45 +00004158**
4159** INVARIANTS:
4160**
drh9a247912008-07-22 18:45:08 +00004161** {H16243} The [sqlite3_user_data(C)] interface returns a copy of the
drhafc91042008-02-21 02:09:45 +00004162** P pointer from the [sqlite3_create_function(D,X,N,E,P,F,S,L)]
4163** or [sqlite3_create_function16(D,X,N,E,P,F,S,L)] call that
mihailimebe796c2008-06-21 20:11:17 +00004164** registered the SQL function associated with [sqlite3_context] C.
danielk19777e18c252004-05-25 11:47:24 +00004165*/
4166void *sqlite3_user_data(sqlite3_context*);
4167
4168/*
drhb25f9d82008-07-23 15:40:06 +00004169** CAPI3REF: Database Connection For Functions {H16250} <S60600><S20200>
drhfa4a4b92008-03-19 21:45:51 +00004170**
4171** The sqlite3_context_db_handle() interface returns a copy of
4172** the pointer to the [database connection] (the 1st parameter)
shane26b34032008-05-23 17:21:09 +00004173** of the [sqlite3_create_function()]
drhfa4a4b92008-03-19 21:45:51 +00004174** and [sqlite3_create_function16()] routines that originally
4175** registered the application defined function.
4176**
4177** INVARIANTS:
4178**
drh9a247912008-07-22 18:45:08 +00004179** {H16253} The [sqlite3_context_db_handle(C)] interface returns a copy of the
drhfa4a4b92008-03-19 21:45:51 +00004180** D pointer from the [sqlite3_create_function(D,X,N,E,P,F,S,L)]
4181** or [sqlite3_create_function16(D,X,N,E,P,F,S,L)] call that
mihailimebe796c2008-06-21 20:11:17 +00004182** registered the SQL function associated with [sqlite3_context] C.
drhfa4a4b92008-03-19 21:45:51 +00004183*/
4184sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
4185
4186/*
drh9cd29642008-07-23 00:52:55 +00004187** CAPI3REF: Function Auxiliary Data {H16270} <S20200>
drh6ed48bf2007-06-14 20:57:18 +00004188**
4189** The following two functions may be used by scalar SQL functions to
mihailimebe796c2008-06-21 20:11:17 +00004190** associate metadata with argument values. If the same value is passed to
drh6ed48bf2007-06-14 20:57:18 +00004191** multiple invocations of the same SQL function during query execution, under
mihailimebe796c2008-06-21 20:11:17 +00004192** some circumstances the associated metadata may be preserved. This may
danielk1977682f68b2004-06-05 10:22:17 +00004193** be used, for example, to add a regular-expression matching scalar
4194** function. The compiled version of the regular expression is stored as
mihailimebe796c2008-06-21 20:11:17 +00004195** metadata associated with the SQL value passed as the regular expression
drh6ed48bf2007-06-14 20:57:18 +00004196** pattern. The compiled regular expression can be reused on multiple
4197** invocations of the same function so that the original pattern string
4198** does not need to be recompiled on each invocation.
danielk1977682f68b2004-06-05 10:22:17 +00004199**
mihailimebe796c2008-06-21 20:11:17 +00004200** The sqlite3_get_auxdata() interface returns a pointer to the metadata
drhf5befa02007-12-06 02:42:07 +00004201** associated by the sqlite3_set_auxdata() function with the Nth argument
mihailimebe796c2008-06-21 20:11:17 +00004202** value to the application-defined function. If no metadata has been ever
4203** been set for the Nth argument of the function, or if the corresponding
4204** function parameter has changed since the meta-data was set,
4205** then sqlite3_get_auxdata() returns a NULL pointer.
danielk1977682f68b2004-06-05 10:22:17 +00004206**
mihailimebe796c2008-06-21 20:11:17 +00004207** The sqlite3_set_auxdata() interface saves the metadata
4208** pointed to by its 3rd parameter as the metadata for the N-th
drhafc91042008-02-21 02:09:45 +00004209** argument of the application-defined function. Subsequent
drhf5befa02007-12-06 02:42:07 +00004210** calls to sqlite3_get_auxdata() might return this data, if it has
mihailimebe796c2008-06-21 20:11:17 +00004211** not been destroyed.
4212** If it is not NULL, SQLite will invoke the destructor
drhf5befa02007-12-06 02:42:07 +00004213** function given by the 4th parameter to sqlite3_set_auxdata() on
mihailimebe796c2008-06-21 20:11:17 +00004214** the metadata when the corresponding function parameter changes
drhafc91042008-02-21 02:09:45 +00004215** or when the SQL statement completes, whichever comes first.
4216**
mihailimebe796c2008-06-21 20:11:17 +00004217** SQLite is free to call the destructor and drop metadata on any
4218** parameter of any function at any time. The only guarantee is that
4219** the destructor will be called before the metadata is dropped.
danielk1977682f68b2004-06-05 10:22:17 +00004220**
mihailimebe796c2008-06-21 20:11:17 +00004221** In practice, metadata is preserved between function calls for
danielk1977682f68b2004-06-05 10:22:17 +00004222** expressions that are constant at compile time. This includes literal
4223** values and SQL variables.
drhe53831d2007-08-17 01:14:38 +00004224**
drhb21c8cd2007-08-21 19:33:56 +00004225** These routines must be called from the same thread in which
4226** the SQL function is running.
drhafc91042008-02-21 02:09:45 +00004227**
4228** INVARIANTS:
4229**
drh9a247912008-07-22 18:45:08 +00004230** {H16272} The [sqlite3_get_auxdata(C,N)] interface returns a pointer
drhafc91042008-02-21 02:09:45 +00004231** to metadata associated with the Nth parameter of the SQL function
4232** whose context is C, or NULL if there is no metadata associated
4233** with that parameter.
4234**
drh9a247912008-07-22 18:45:08 +00004235** {H16274} The [sqlite3_set_auxdata(C,N,P,D)] interface assigns a metadata
mihailimebe796c2008-06-21 20:11:17 +00004236** pointer P to the Nth parameter of the SQL function with context C.
drhafc91042008-02-21 02:09:45 +00004237**
drh9a247912008-07-22 18:45:08 +00004238** {H16276} SQLite will invoke the destructor D with a single argument
drhafc91042008-02-21 02:09:45 +00004239** which is the metadata pointer P following a call to
4240** [sqlite3_set_auxdata(C,N,P,D)] when SQLite ceases to hold
4241** the metadata.
4242**
drh9a247912008-07-22 18:45:08 +00004243** {H16277} SQLite ceases to hold metadata for an SQL function parameter
drhafc91042008-02-21 02:09:45 +00004244** when the value of that parameter changes.
4245**
drh9a247912008-07-22 18:45:08 +00004246** {H16278} When [sqlite3_set_auxdata(C,N,P,D)] is invoked, the destructor
drhafc91042008-02-21 02:09:45 +00004247** is called for any prior metadata associated with the same function
4248** context C and parameter N.
4249**
drh9a247912008-07-22 18:45:08 +00004250** {H16279} SQLite will call destructors for any metadata it is holding
drhafc91042008-02-21 02:09:45 +00004251** in a particular [prepared statement] S when either
4252** [sqlite3_reset(S)] or [sqlite3_finalize(S)] is called.
danielk1977682f68b2004-06-05 10:22:17 +00004253*/
drhf5befa02007-12-06 02:42:07 +00004254void *sqlite3_get_auxdata(sqlite3_context*, int N);
4255void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
danielk1977682f68b2004-06-05 10:22:17 +00004256
drha2854222004-06-17 19:04:17 +00004257
4258/*
drhb25f9d82008-07-23 15:40:06 +00004259** CAPI3REF: Constants Defining Special Destructor Behavior {H10280} <S30100>
drh6ed48bf2007-06-14 20:57:18 +00004260**
mihailimebe796c2008-06-21 20:11:17 +00004261** These are special values for the destructor that is passed in as the
drh6ed48bf2007-06-14 20:57:18 +00004262** final argument to routines like [sqlite3_result_blob()]. If the destructor
drha2854222004-06-17 19:04:17 +00004263** argument is SQLITE_STATIC, it means that the content pointer is constant
mihailimebe796c2008-06-21 20:11:17 +00004264** and will never change. It does not need to be destroyed. The
drha2854222004-06-17 19:04:17 +00004265** SQLITE_TRANSIENT value means that the content will likely change in
4266** the near future and that SQLite should make its own private copy of
4267** the content before returning.
drh6c9121a2007-01-26 00:51:43 +00004268**
4269** The typedef is necessary to work around problems in certain
4270** C++ compilers. See ticket #2191.
drha2854222004-06-17 19:04:17 +00004271*/
drh6c9121a2007-01-26 00:51:43 +00004272typedef void (*sqlite3_destructor_type)(void*);
4273#define SQLITE_STATIC ((sqlite3_destructor_type)0)
4274#define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
danielk1977d8123362004-06-12 09:25:12 +00004275
danielk1977682f68b2004-06-05 10:22:17 +00004276/*
drh9cd29642008-07-23 00:52:55 +00004277** CAPI3REF: Setting The Result Of An SQL Function {H16400} <S20200>
drh6ed48bf2007-06-14 20:57:18 +00004278**
4279** These routines are used by the xFunc or xFinal callbacks that
4280** implement SQL functions and aggregates. See
4281** [sqlite3_create_function()] and [sqlite3_create_function16()]
4282** for additional information.
4283**
mihailimebe796c2008-06-21 20:11:17 +00004284** These functions work very much like the [parameter binding] family of
4285** functions used to bind values to host parameters in prepared statements.
4286** Refer to the [SQL parameter] documentation for additional information.
drh6ed48bf2007-06-14 20:57:18 +00004287**
drhafc91042008-02-21 02:09:45 +00004288** The sqlite3_result_blob() interface sets the result from
mihailimebe796c2008-06-21 20:11:17 +00004289** an application-defined function to be the BLOB whose content is pointed
drhf5befa02007-12-06 02:42:07 +00004290** to by the second parameter and which is N bytes long where N is the
mihailimebe796c2008-06-21 20:11:17 +00004291** third parameter.
4292**
shane26b34032008-05-23 17:21:09 +00004293** The sqlite3_result_zeroblob() interfaces set the result of
mihailimebe796c2008-06-21 20:11:17 +00004294** the application-defined function to be a BLOB containing all zero
drhf5befa02007-12-06 02:42:07 +00004295** bytes and N bytes in size, where N is the value of the 2nd parameter.
drh6ed48bf2007-06-14 20:57:18 +00004296**
drhafc91042008-02-21 02:09:45 +00004297** The sqlite3_result_double() interface sets the result from
mihailimebe796c2008-06-21 20:11:17 +00004298** an application-defined function to be a floating point value specified
drhf5befa02007-12-06 02:42:07 +00004299** by its 2nd argument.
drhe53831d2007-08-17 01:14:38 +00004300**
drhafc91042008-02-21 02:09:45 +00004301** The sqlite3_result_error() and sqlite3_result_error16() functions
drhf5befa02007-12-06 02:42:07 +00004302** cause the implemented SQL function to throw an exception.
drhafc91042008-02-21 02:09:45 +00004303** SQLite uses the string pointed to by the
drhf5befa02007-12-06 02:42:07 +00004304** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
drhafc91042008-02-21 02:09:45 +00004305** as the text of an error message. SQLite interprets the error
mihailimebe796c2008-06-21 20:11:17 +00004306** message string from sqlite3_result_error() as UTF-8. SQLite
4307** interprets the string from sqlite3_result_error16() as UTF-16 in native
drhafc91042008-02-21 02:09:45 +00004308** byte order. If the third parameter to sqlite3_result_error()
drhf5befa02007-12-06 02:42:07 +00004309** or sqlite3_result_error16() is negative then SQLite takes as the error
4310** message all text up through the first zero character.
drhafc91042008-02-21 02:09:45 +00004311** If the third parameter to sqlite3_result_error() or
drhf5befa02007-12-06 02:42:07 +00004312** sqlite3_result_error16() is non-negative then SQLite takes that many
4313** bytes (not characters) from the 2nd parameter as the error message.
drhafc91042008-02-21 02:09:45 +00004314** The sqlite3_result_error() and sqlite3_result_error16()
mihailimebe796c2008-06-21 20:11:17 +00004315** routines make a private copy of the error message text before
drhafc91042008-02-21 02:09:45 +00004316** they return. Hence, the calling function can deallocate or
drhf5befa02007-12-06 02:42:07 +00004317** modify the text after they return without harm.
drh69544ec2008-02-06 14:11:34 +00004318** The sqlite3_result_error_code() function changes the error code
4319** returned by SQLite as a result of an error in a function. By default,
drh00e087b2008-04-10 17:14:07 +00004320** the error code is SQLITE_ERROR. A subsequent call to sqlite3_result_error()
4321** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
drhf5befa02007-12-06 02:42:07 +00004322**
mihailimebe796c2008-06-21 20:11:17 +00004323** The sqlite3_result_toobig() interface causes SQLite to throw an error
4324** indicating that a string or BLOB is to long to represent.
4325**
4326** The sqlite3_result_nomem() interface causes SQLite to throw an error
4327** indicating that a memory allocation failed.
drhf5befa02007-12-06 02:42:07 +00004328**
drhafc91042008-02-21 02:09:45 +00004329** The sqlite3_result_int() interface sets the return value
drhf5befa02007-12-06 02:42:07 +00004330** of the application-defined function to be the 32-bit signed integer
4331** value given in the 2nd argument.
drhafc91042008-02-21 02:09:45 +00004332** The sqlite3_result_int64() interface sets the return value
drhf5befa02007-12-06 02:42:07 +00004333** of the application-defined function to be the 64-bit signed integer
4334** value given in the 2nd argument.
4335**
drhafc91042008-02-21 02:09:45 +00004336** The sqlite3_result_null() interface sets the return value
drhf5befa02007-12-06 02:42:07 +00004337** of the application-defined function to be NULL.
4338**
mihailimebe796c2008-06-21 20:11:17 +00004339** The sqlite3_result_text(), sqlite3_result_text16(),
drhf5befa02007-12-06 02:42:07 +00004340** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
4341** set the return value of the application-defined function to be
4342** a text string which is represented as UTF-8, UTF-16 native byte order,
4343** UTF-16 little endian, or UTF-16 big endian, respectively.
drhafc91042008-02-21 02:09:45 +00004344** SQLite takes the text result from the application from
drhf5befa02007-12-06 02:42:07 +00004345** the 2nd parameter of the sqlite3_result_text* interfaces.
drhafc91042008-02-21 02:09:45 +00004346** If the 3rd parameter to the sqlite3_result_text* interfaces
mihailimebe796c2008-06-21 20:11:17 +00004347** is negative, then SQLite takes result text from the 2nd parameter
drhf5befa02007-12-06 02:42:07 +00004348** through the first zero character.
drhafc91042008-02-21 02:09:45 +00004349** If the 3rd parameter to the sqlite3_result_text* interfaces
drhf5befa02007-12-06 02:42:07 +00004350** is non-negative, then as many bytes (not characters) of the text
4351** pointed to by the 2nd parameter are taken as the application-defined
4352** function result.
drhafc91042008-02-21 02:09:45 +00004353** If the 4th parameter to the sqlite3_result_text* interfaces
drhf5befa02007-12-06 02:42:07 +00004354** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
mihailimebe796c2008-06-21 20:11:17 +00004355** function as the destructor on the text or BLOB result when it has
drhf5befa02007-12-06 02:42:07 +00004356** finished using that result.
mihailimebe796c2008-06-21 20:11:17 +00004357** If the 4th parameter to the sqlite3_result_text* interfaces or
4358** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite
4359** assumes that the text or BLOB result is in constant space and does not
4360** copy the it or call a destructor when it has finished using that result.
drhafc91042008-02-21 02:09:45 +00004361** If the 4th parameter to the sqlite3_result_text* interfaces
drhf5befa02007-12-06 02:42:07 +00004362** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
4363** then SQLite makes a copy of the result into space obtained from
4364** from [sqlite3_malloc()] before it returns.
4365**
drhafc91042008-02-21 02:09:45 +00004366** The sqlite3_result_value() interface sets the result of
drhaa28e142008-03-18 13:47:20 +00004367** the application-defined function to be a copy the
4368** [unprotected sqlite3_value] object specified by the 2nd parameter. The
drhf5befa02007-12-06 02:42:07 +00004369** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
mihailimebe796c2008-06-21 20:11:17 +00004370** so that the [sqlite3_value] specified in the parameter may change or
drhf5befa02007-12-06 02:42:07 +00004371** be deallocated after sqlite3_result_value() returns without harm.
drhaa28e142008-03-18 13:47:20 +00004372** A [protected sqlite3_value] object may always be used where an
4373** [unprotected sqlite3_value] object is required, so either
4374** kind of [sqlite3_value] object can be used with this interface.
drhf5befa02007-12-06 02:42:07 +00004375**
mihailimebe796c2008-06-21 20:11:17 +00004376** If these routines are called from within the different thread
shane26b34032008-05-23 17:21:09 +00004377** than the one containing the application-defined function that received
drhf5befa02007-12-06 02:42:07 +00004378** the [sqlite3_context] pointer, the results are undefined.
drhafc91042008-02-21 02:09:45 +00004379**
4380** INVARIANTS:
4381**
drh9a247912008-07-22 18:45:08 +00004382** {H16403} The default return value from any SQL function is NULL.
drhafc91042008-02-21 02:09:45 +00004383**
drh9a247912008-07-22 18:45:08 +00004384** {H16406} The [sqlite3_result_blob(C,V,N,D)] interface changes the
mihailimebe796c2008-06-21 20:11:17 +00004385** return value of function C to be a BLOB that is N bytes
drhafc91042008-02-21 02:09:45 +00004386** in length and with content pointed to by V.
4387**
drh9a247912008-07-22 18:45:08 +00004388** {H16409} The [sqlite3_result_double(C,V)] interface changes the
drhafc91042008-02-21 02:09:45 +00004389** return value of function C to be the floating point value V.
4390**
drh9a247912008-07-22 18:45:08 +00004391** {H16412} The [sqlite3_result_error(C,V,N)] interface changes the return
drhafc91042008-02-21 02:09:45 +00004392** value of function C to be an exception with error code
mihailimebe796c2008-06-21 20:11:17 +00004393** [SQLITE_ERROR] and a UTF-8 error message copied from V up to the
drhafc91042008-02-21 02:09:45 +00004394** first zero byte or until N bytes are read if N is positive.
4395**
drh9a247912008-07-22 18:45:08 +00004396** {H16415} The [sqlite3_result_error16(C,V,N)] interface changes the return
drhafc91042008-02-21 02:09:45 +00004397** value of function C to be an exception with error code
mihailimebe796c2008-06-21 20:11:17 +00004398** [SQLITE_ERROR] and a UTF-16 native byte order error message
drhafc91042008-02-21 02:09:45 +00004399** copied from V up to the first zero terminator or until N bytes
4400** are read if N is positive.
4401**
drh9a247912008-07-22 18:45:08 +00004402** {H16418} The [sqlite3_result_error_toobig(C)] interface changes the return
drhafc91042008-02-21 02:09:45 +00004403** value of the function C to be an exception with error code
4404** [SQLITE_TOOBIG] and an appropriate error message.
4405**
drh9a247912008-07-22 18:45:08 +00004406** {H16421} The [sqlite3_result_error_nomem(C)] interface changes the return
drhafc91042008-02-21 02:09:45 +00004407** value of the function C to be an exception with error code
4408** [SQLITE_NOMEM] and an appropriate error message.
4409**
drh9a247912008-07-22 18:45:08 +00004410** {H16424} The [sqlite3_result_error_code(C,E)] interface changes the return
drhafc91042008-02-21 02:09:45 +00004411** value of the function C to be an exception with error code E.
4412** The error message text is unchanged.
4413**
drh9a247912008-07-22 18:45:08 +00004414** {H16427} The [sqlite3_result_int(C,V)] interface changes the
drhafc91042008-02-21 02:09:45 +00004415** return value of function C to be the 32-bit integer value V.
4416**
drh9a247912008-07-22 18:45:08 +00004417** {H16430} The [sqlite3_result_int64(C,V)] interface changes the
drhafc91042008-02-21 02:09:45 +00004418** return value of function C to be the 64-bit integer value V.
4419**
drh9a247912008-07-22 18:45:08 +00004420** {H16433} The [sqlite3_result_null(C)] interface changes the
drhafc91042008-02-21 02:09:45 +00004421** return value of function C to be NULL.
4422**
drh9a247912008-07-22 18:45:08 +00004423** {H16436} The [sqlite3_result_text(C,V,N,D)] interface changes the
mihailimebe796c2008-06-21 20:11:17 +00004424** return value of function C to be the UTF-8 string
drha95174b2008-04-17 17:03:25 +00004425** V up to the first zero if N is negative
drhb08c2a72008-04-16 00:28:13 +00004426** or the first N bytes of V if N is non-negative.
drhafc91042008-02-21 02:09:45 +00004427**
drh9a247912008-07-22 18:45:08 +00004428** {H16439} The [sqlite3_result_text16(C,V,N,D)] interface changes the
mihailimebe796c2008-06-21 20:11:17 +00004429** return value of function C to be the UTF-16 native byte order
4430** string V up to the first zero if N is negative
4431** or the first N bytes of V if N is non-negative.
drhafc91042008-02-21 02:09:45 +00004432**
drh9a247912008-07-22 18:45:08 +00004433** {H16442} The [sqlite3_result_text16be(C,V,N,D)] interface changes the
mihailimebe796c2008-06-21 20:11:17 +00004434** return value of function C to be the UTF-16 big-endian
4435** string V up to the first zero if N is negative
4436** or the first N bytes or V if N is non-negative.
drhafc91042008-02-21 02:09:45 +00004437**
drh9a247912008-07-22 18:45:08 +00004438** {H16445} The [sqlite3_result_text16le(C,V,N,D)] interface changes the
mihailimebe796c2008-06-21 20:11:17 +00004439** return value of function C to be the UTF-16 little-endian
4440** string V up to the first zero if N is negative
4441** or the first N bytes of V if N is non-negative.
drhafc91042008-02-21 02:09:45 +00004442**
drh9a247912008-07-22 18:45:08 +00004443** {H16448} The [sqlite3_result_value(C,V)] interface changes the
mihailimebe796c2008-06-21 20:11:17 +00004444** return value of function C to be the [unprotected sqlite3_value]
drhaa28e142008-03-18 13:47:20 +00004445** object V.
drhafc91042008-02-21 02:09:45 +00004446**
drh9a247912008-07-22 18:45:08 +00004447** {H16451} The [sqlite3_result_zeroblob(C,N)] interface changes the
mihailimebe796c2008-06-21 20:11:17 +00004448** return value of function C to be an N-byte BLOB of all zeros.
drhafc91042008-02-21 02:09:45 +00004449**
drh9a247912008-07-22 18:45:08 +00004450** {H16454} The [sqlite3_result_error()] and [sqlite3_result_error16()]
drhafc91042008-02-21 02:09:45 +00004451** interfaces make a copy of their error message strings before
4452** returning.
4453**
drh9a247912008-07-22 18:45:08 +00004454** {H16457} If the D destructor parameter to [sqlite3_result_blob(C,V,N,D)],
drhafc91042008-02-21 02:09:45 +00004455** [sqlite3_result_text(C,V,N,D)], [sqlite3_result_text16(C,V,N,D)],
4456** [sqlite3_result_text16be(C,V,N,D)], or
4457** [sqlite3_result_text16le(C,V,N,D)] is the constant [SQLITE_STATIC]
4458** then no destructor is ever called on the pointer V and SQLite
4459** assumes that V is immutable.
4460**
drh9a247912008-07-22 18:45:08 +00004461** {H16460} If the D destructor parameter to [sqlite3_result_blob(C,V,N,D)],
drhafc91042008-02-21 02:09:45 +00004462** [sqlite3_result_text(C,V,N,D)], [sqlite3_result_text16(C,V,N,D)],
4463** [sqlite3_result_text16be(C,V,N,D)], or
4464** [sqlite3_result_text16le(C,V,N,D)] is the constant
4465** [SQLITE_TRANSIENT] then the interfaces makes a copy of the
4466** content of V and retains the copy.
4467**
drh9a247912008-07-22 18:45:08 +00004468** {H16463} If the D destructor parameter to [sqlite3_result_blob(C,V,N,D)],
drhafc91042008-02-21 02:09:45 +00004469** [sqlite3_result_text(C,V,N,D)], [sqlite3_result_text16(C,V,N,D)],
4470** [sqlite3_result_text16be(C,V,N,D)], or
4471** [sqlite3_result_text16le(C,V,N,D)] is some value other than
mihailimebe796c2008-06-21 20:11:17 +00004472** the constants [SQLITE_STATIC] and [SQLITE_TRANSIENT] then
drhafc91042008-02-21 02:09:45 +00004473** SQLite will invoke the destructor D with V as its only argument
4474** when it has finished with the V value.
danielk19777e18c252004-05-25 11:47:24 +00004475*/
danielk1977d8123362004-06-12 09:25:12 +00004476void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
drh4f26d6c2004-05-26 23:25:30 +00004477void sqlite3_result_double(sqlite3_context*, double);
danielk19777e18c252004-05-25 11:47:24 +00004478void sqlite3_result_error(sqlite3_context*, const char*, int);
4479void sqlite3_result_error16(sqlite3_context*, const void*, int);
drh6ed48bf2007-06-14 20:57:18 +00004480void sqlite3_result_error_toobig(sqlite3_context*);
danielk1977a1644fd2007-08-29 12:31:25 +00004481void sqlite3_result_error_nomem(sqlite3_context*);
drh69544ec2008-02-06 14:11:34 +00004482void sqlite3_result_error_code(sqlite3_context*, int);
drh4f26d6c2004-05-26 23:25:30 +00004483void sqlite3_result_int(sqlite3_context*, int);
drh6d2069d2007-08-14 01:58:53 +00004484void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
drh4f26d6c2004-05-26 23:25:30 +00004485void sqlite3_result_null(sqlite3_context*);
danielk1977d8123362004-06-12 09:25:12 +00004486void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
4487void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
4488void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
4489void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
drh4f26d6c2004-05-26 23:25:30 +00004490void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
drhb026e052007-05-02 01:34:31 +00004491void sqlite3_result_zeroblob(sqlite3_context*, int n);
drhf9b596e2004-05-26 16:54:42 +00004492
drh52619df2004-06-11 17:48:02 +00004493/*
drh9cd29642008-07-23 00:52:55 +00004494** CAPI3REF: Define New Collating Sequences {H16600} <S20300>
drh6ed48bf2007-06-14 20:57:18 +00004495**
4496** These functions are used to add new collation sequences to the
mihailimebe796c2008-06-21 20:11:17 +00004497** [database connection] specified as the first argument.
danielk19777cedc8d2004-06-10 10:50:08 +00004498**
4499** The name of the new collation sequence is specified as a UTF-8 string
drh6ed48bf2007-06-14 20:57:18 +00004500** for sqlite3_create_collation() and sqlite3_create_collation_v2()
drhafc91042008-02-21 02:09:45 +00004501** and a UTF-16 string for sqlite3_create_collation16(). In all cases
drh6ed48bf2007-06-14 20:57:18 +00004502** the name is passed as the second function argument.
danielk19777cedc8d2004-06-10 10:50:08 +00004503**
drh4145f832007-10-12 18:30:12 +00004504** The third argument may be one of the constants [SQLITE_UTF8],
drh6ed48bf2007-06-14 20:57:18 +00004505** [SQLITE_UTF16LE] or [SQLITE_UTF16BE], indicating that the user-supplied
danielk19777cedc8d2004-06-10 10:50:08 +00004506** routine expects to be passed pointers to strings encoded using UTF-8,
mihailimebe796c2008-06-21 20:11:17 +00004507** UTF-16 little-endian, or UTF-16 big-endian, respectively. The
drh4145f832007-10-12 18:30:12 +00004508** third argument might also be [SQLITE_UTF16_ALIGNED] to indicate that
4509** the routine expects pointers to 16-bit word aligned strings
mihailimebe796c2008-06-21 20:11:17 +00004510** of UTF-16 in the native byte order of the host computer.
danielk19777cedc8d2004-06-10 10:50:08 +00004511**
4512** A pointer to the user supplied routine must be passed as the fifth
drhafc91042008-02-21 02:09:45 +00004513** argument. If it is NULL, this is the same as deleting the collation
drhf5befa02007-12-06 02:42:07 +00004514** sequence (so that SQLite cannot call it anymore).
mihailimebe796c2008-06-21 20:11:17 +00004515** Each time the application supplied function is invoked, it is passed
4516** as its first parameter a copy of the void* passed as the fourth argument
4517** to sqlite3_create_collation() or sqlite3_create_collation16().
danielk19777cedc8d2004-06-10 10:50:08 +00004518**
drhf5befa02007-12-06 02:42:07 +00004519** The remaining arguments to the application-supplied routine are two strings,
drh33c1be32008-01-30 16:16:14 +00004520** each represented by a (length, data) pair and encoded in the encoding
danielk19777cedc8d2004-06-10 10:50:08 +00004521** that was passed as the third argument when the collation sequence was
mihailim04bcc002008-06-22 10:21:27 +00004522** registered. {END} The application defined collation routine should
mihailimebe796c2008-06-21 20:11:17 +00004523** return negative, zero or positive if the first string is less than,
4524** equal to, or greater than the second string. i.e. (STRING1 - STRING2).
drh6ed48bf2007-06-14 20:57:18 +00004525**
4526** The sqlite3_create_collation_v2() works like sqlite3_create_collation()
shane26b34032008-05-23 17:21:09 +00004527** except that it takes an extra argument which is a destructor for
drhafc91042008-02-21 02:09:45 +00004528** the collation. The destructor is called when the collation is
drh6ed48bf2007-06-14 20:57:18 +00004529** destroyed and is passed a copy of the fourth parameter void* pointer
drhf5befa02007-12-06 02:42:07 +00004530** of the sqlite3_create_collation_v2().
mihailimebe796c2008-06-21 20:11:17 +00004531** Collations are destroyed when they are overridden by later calls to the
4532** collation creation functions or when the [database connection] is closed
4533** using [sqlite3_close()].
drhafc91042008-02-21 02:09:45 +00004534**
4535** INVARIANTS:
4536**
drh9a247912008-07-22 18:45:08 +00004537** {H16603} A successful call to the
drhafc91042008-02-21 02:09:45 +00004538** [sqlite3_create_collation_v2(B,X,E,P,F,D)] interface
4539** registers function F as the comparison function used to
mihailimebe796c2008-06-21 20:11:17 +00004540** implement collation X on the [database connection] B for
drhafc91042008-02-21 02:09:45 +00004541** databases having encoding E.
4542**
drh9a247912008-07-22 18:45:08 +00004543** {H16604} SQLite understands the X parameter to
drhafc91042008-02-21 02:09:45 +00004544** [sqlite3_create_collation_v2(B,X,E,P,F,D)] as a zero-terminated
4545** UTF-8 string in which case is ignored for ASCII characters and
4546** is significant for non-ASCII characters.
4547**
drh9a247912008-07-22 18:45:08 +00004548** {H16606} Successive calls to [sqlite3_create_collation_v2(B,X,E,P,F,D)]
drhafc91042008-02-21 02:09:45 +00004549** with the same values for B, X, and E, override prior values
4550** of P, F, and D.
4551**
drh9a247912008-07-22 18:45:08 +00004552** {H16609} If the destructor D in [sqlite3_create_collation_v2(B,X,E,P,F,D)]
drhafc91042008-02-21 02:09:45 +00004553** is not NULL then it is called with argument P when the
4554** collating function is dropped by SQLite.
4555**
drh9a247912008-07-22 18:45:08 +00004556** {H16612} A collating function is dropped when it is overloaded.
drhafc91042008-02-21 02:09:45 +00004557**
drh9a247912008-07-22 18:45:08 +00004558** {H16615} A collating function is dropped when the database connection
drhafc91042008-02-21 02:09:45 +00004559** is closed using [sqlite3_close()].
4560**
drh9a247912008-07-22 18:45:08 +00004561** {H16618} The pointer P in [sqlite3_create_collation_v2(B,X,E,P,F,D)]
drhafc91042008-02-21 02:09:45 +00004562** is passed through as the first parameter to the comparison
4563** function F for all subsequent invocations of F.
4564**
drh9a247912008-07-22 18:45:08 +00004565** {H16621} A call to [sqlite3_create_collation(B,X,E,P,F)] is exactly
drhafc91042008-02-21 02:09:45 +00004566** the same as a call to [sqlite3_create_collation_v2()] with
4567** the same parameters and a NULL destructor.
4568**
drh9a247912008-07-22 18:45:08 +00004569** {H16624} Following a [sqlite3_create_collation_v2(B,X,E,P,F,D)],
drhafc91042008-02-21 02:09:45 +00004570** SQLite uses the comparison function F for all text comparison
mihailimebe796c2008-06-21 20:11:17 +00004571** operations on the [database connection] B on text values that
4572** use the collating sequence named X.
drhafc91042008-02-21 02:09:45 +00004573**
drh9a247912008-07-22 18:45:08 +00004574** {H16627} The [sqlite3_create_collation16(B,X,E,P,F)] works the same
drhafc91042008-02-21 02:09:45 +00004575** as [sqlite3_create_collation(B,X,E,P,F)] except that the
4576** collation name X is understood as UTF-16 in native byte order
4577** instead of UTF-8.
4578**
drh9a247912008-07-22 18:45:08 +00004579** {H16630} When multiple comparison functions are available for the same
drhafc91042008-02-21 02:09:45 +00004580** collating sequence, SQLite chooses the one whose text encoding
4581** requires the least amount of conversion from the default
4582** text encoding of the database.
danielk19777cedc8d2004-06-10 10:50:08 +00004583*/
danielk19770202b292004-06-09 09:55:16 +00004584int sqlite3_create_collation(
4585 sqlite3*,
4586 const char *zName,
danielk19777cedc8d2004-06-10 10:50:08 +00004587 int eTextRep,
danielk19770202b292004-06-09 09:55:16 +00004588 void*,
4589 int(*xCompare)(void*,int,const void*,int,const void*)
4590);
drh6ed48bf2007-06-14 20:57:18 +00004591int sqlite3_create_collation_v2(
4592 sqlite3*,
4593 const char *zName,
4594 int eTextRep,
4595 void*,
4596 int(*xCompare)(void*,int,const void*,int,const void*),
4597 void(*xDestroy)(void*)
4598);
danielk19770202b292004-06-09 09:55:16 +00004599int sqlite3_create_collation16(
4600 sqlite3*,
mihailimbda2e622008-06-23 11:23:14 +00004601 const void *zName,
danielk19777cedc8d2004-06-10 10:50:08 +00004602 int eTextRep,
danielk19770202b292004-06-09 09:55:16 +00004603 void*,
4604 int(*xCompare)(void*,int,const void*,int,const void*)
4605);
4606
danielk19777cedc8d2004-06-10 10:50:08 +00004607/*
drh9cd29642008-07-23 00:52:55 +00004608** CAPI3REF: Collation Needed Callbacks {H16700} <S20300>
danielk1977a393c032007-05-07 14:58:53 +00004609**
danielk19777cedc8d2004-06-10 10:50:08 +00004610** To avoid having to register all collation sequences before a database
4611** can be used, a single callback function may be registered with the
mihailimdc884822008-06-22 08:58:50 +00004612** [database connection] to be called whenever an undefined collation
4613** sequence is required.
danielk19777cedc8d2004-06-10 10:50:08 +00004614**
4615** If the function is registered using the sqlite3_collation_needed() API,
4616** then it is passed the names of undefined collation sequences as strings
drh9a247912008-07-22 18:45:08 +00004617** encoded in UTF-8. {H16703} If sqlite3_collation_needed16() is used,
mihailimdc884822008-06-22 08:58:50 +00004618** the names are passed as UTF-16 in machine native byte order.
4619** A call to either function replaces any existing callback.
danielk19777cedc8d2004-06-10 10:50:08 +00004620**
drhafc91042008-02-21 02:09:45 +00004621** When the callback is invoked, the first argument passed is a copy
danielk19777cedc8d2004-06-10 10:50:08 +00004622** of the second argument to sqlite3_collation_needed() or
drhafc91042008-02-21 02:09:45 +00004623** sqlite3_collation_needed16(). The second argument is the database
mihailimdc884822008-06-22 08:58:50 +00004624** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE],
4625** or [SQLITE_UTF16LE], indicating the most desirable form of the collation
4626** sequence function required. The fourth parameter is the name of the
drhafc91042008-02-21 02:09:45 +00004627** required collation sequence.
danielk19777cedc8d2004-06-10 10:50:08 +00004628**
drh6ed48bf2007-06-14 20:57:18 +00004629** The callback function should register the desired collation using
4630** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
4631** [sqlite3_create_collation_v2()].
drhafc91042008-02-21 02:09:45 +00004632**
4633** INVARIANTS:
4634**
drh9a247912008-07-22 18:45:08 +00004635** {H16702} A successful call to [sqlite3_collation_needed(D,P,F)]
drhafc91042008-02-21 02:09:45 +00004636** or [sqlite3_collation_needed16(D,P,F)] causes
4637** the [database connection] D to invoke callback F with first
4638** parameter P whenever it needs a comparison function for a
4639** collating sequence that it does not know about.
4640**
drh9a247912008-07-22 18:45:08 +00004641** {H16704} Each successful call to [sqlite3_collation_needed()] or
drhafc91042008-02-21 02:09:45 +00004642** [sqlite3_collation_needed16()] overrides the callback registered
4643** on the same [database connection] by prior calls to either
4644** interface.
4645**
drh9a247912008-07-22 18:45:08 +00004646** {H16706} The name of the requested collating function passed in the
drhafc91042008-02-21 02:09:45 +00004647** 4th parameter to the callback is in UTF-8 if the callback
4648** was registered using [sqlite3_collation_needed()] and
4649** is in UTF-16 native byte order if the callback was
4650** registered using [sqlite3_collation_needed16()].
danielk19777cedc8d2004-06-10 10:50:08 +00004651*/
4652int sqlite3_collation_needed(
4653 sqlite3*,
4654 void*,
4655 void(*)(void*,sqlite3*,int eTextRep,const char*)
4656);
4657int sqlite3_collation_needed16(
4658 sqlite3*,
4659 void*,
4660 void(*)(void*,sqlite3*,int eTextRep,const void*)
4661);
4662
drh2011d5f2004-07-22 02:40:37 +00004663/*
4664** Specify the key for an encrypted database. This routine should be
4665** called right after sqlite3_open().
4666**
4667** The code to implement this API is not available in the public release
4668** of SQLite.
4669*/
4670int sqlite3_key(
4671 sqlite3 *db, /* Database to be rekeyed */
4672 const void *pKey, int nKey /* The key */
4673);
4674
4675/*
4676** Change the key on an open database. If the current database is not
4677** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the
4678** database is decrypted.
4679**
4680** The code to implement this API is not available in the public release
4681** of SQLite.
4682*/
4683int sqlite3_rekey(
4684 sqlite3 *db, /* Database to be rekeyed */
4685 const void *pKey, int nKey /* The new key */
4686);
danielk19770202b292004-06-09 09:55:16 +00004687
drhab3f9fe2004-08-14 17:10:10 +00004688/*
drhb25f9d82008-07-23 15:40:06 +00004689** CAPI3REF: Suspend Execution For A Short Time {H10530} <S40410>
drh6ed48bf2007-06-14 20:57:18 +00004690**
mihailimdc884822008-06-22 08:58:50 +00004691** The sqlite3_sleep() function causes the current thread to suspend execution
drhfddfa2d2007-12-05 18:05:16 +00004692** for at least a number of milliseconds specified in its parameter.
danielk1977600dd0b2005-01-20 01:14:23 +00004693**
mihailimdc884822008-06-22 08:58:50 +00004694** If the operating system does not support sleep requests with
4695** millisecond time resolution, then the time will be rounded up to
4696** the nearest second. The number of milliseconds of sleep actually
danielk1977600dd0b2005-01-20 01:14:23 +00004697** requested from the operating system is returned.
drh8bacf972007-08-25 16:21:29 +00004698**
drhafc91042008-02-21 02:09:45 +00004699** SQLite implements this interface by calling the xSleep()
4700** method of the default [sqlite3_vfs] object.
4701**
4702** INVARIANTS:
4703**
drh9a247912008-07-22 18:45:08 +00004704** {H10533} The [sqlite3_sleep(M)] interface invokes the xSleep
drhafc91042008-02-21 02:09:45 +00004705** method of the default [sqlite3_vfs|VFS] in order to
4706** suspend execution of the current thread for at least
4707** M milliseconds.
4708**
drh9a247912008-07-22 18:45:08 +00004709** {H10536} The [sqlite3_sleep(M)] interface returns the number of
drhafc91042008-02-21 02:09:45 +00004710** milliseconds of sleep actually requested of the operating
4711** system, which might be larger than the parameter M.
danielk1977600dd0b2005-01-20 01:14:23 +00004712*/
4713int sqlite3_sleep(int);
4714
4715/*
drhb25f9d82008-07-23 15:40:06 +00004716** CAPI3REF: Name Of The Folder Holding Temporary Files {H10310} <S20000>
drhd89bd002005-01-22 03:03:54 +00004717**
drh6ed48bf2007-06-14 20:57:18 +00004718** If this global variable is made to point to a string which is
shane26b34032008-05-23 17:21:09 +00004719** the name of a folder (a.k.a. directory), then all temporary files
drhab3f9fe2004-08-14 17:10:10 +00004720** created by SQLite will be placed in that directory. If this variable
mihailimdc884822008-06-22 08:58:50 +00004721** is a NULL pointer, then SQLite performs a search for an appropriate
4722** temporary file directory.
drhab3f9fe2004-08-14 17:10:10 +00004723**
mihailimdc884822008-06-22 08:58:50 +00004724** It is not safe to modify this variable once a [database connection]
drh4ff7fa02007-09-01 18:17:21 +00004725** has been opened. It is intended that this variable be set once
4726** as part of process initialization and before any SQLite interface
4727** routines have been call and remain unchanged thereafter.
drhab3f9fe2004-08-14 17:10:10 +00004728*/
drh73be5012007-08-08 12:11:21 +00004729SQLITE_EXTERN char *sqlite3_temp_directory;
drhab3f9fe2004-08-14 17:10:10 +00004730
danielk19776b456a22005-03-21 04:04:02 +00004731/*
drh9cd29642008-07-23 00:52:55 +00004732** CAPI3REF: Test For Auto-Commit Mode {H12930} <S60200>
mihailim15194222008-06-22 09:55:14 +00004733** KEYWORDS: {autocommit mode}
danielk19776b456a22005-03-21 04:04:02 +00004734**
shane26b34032008-05-23 17:21:09 +00004735** The sqlite3_get_autocommit() interface returns non-zero or
drhf5befa02007-12-06 02:42:07 +00004736** zero if the given database connection is or is not in autocommit mode,
mihailim04bcc002008-06-22 10:21:27 +00004737** respectively. Autocommit mode is on by default.
mihailimdc884822008-06-22 08:58:50 +00004738** Autocommit mode is disabled by a [BEGIN] statement.
shane26b34032008-05-23 17:21:09 +00004739** Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].
drhe30f4422007-08-21 16:15:55 +00004740**
drh7c3472a2007-10-03 20:15:28 +00004741** If certain kinds of errors occur on a statement within a multi-statement
mihailimdc884822008-06-22 08:58:50 +00004742** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR],
drh7c3472a2007-10-03 20:15:28 +00004743** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the
drh33c1be32008-01-30 16:16:14 +00004744** transaction might be rolled back automatically. The only way to
mihailimdc884822008-06-22 08:58:50 +00004745** find out whether SQLite automatically rolled back the transaction after
drh33c1be32008-01-30 16:16:14 +00004746** an error is to use this function.
drh7c3472a2007-10-03 20:15:28 +00004747**
drh33c1be32008-01-30 16:16:14 +00004748** INVARIANTS:
4749**
drh9a247912008-07-22 18:45:08 +00004750** {H12931} The [sqlite3_get_autocommit(D)] interface returns non-zero or
drhafc91042008-02-21 02:09:45 +00004751** zero if the [database connection] D is or is not in autocommit
drh33c1be32008-01-30 16:16:14 +00004752** mode, respectively.
4753**
drh9a247912008-07-22 18:45:08 +00004754** {H12932} Autocommit mode is on by default.
drh33c1be32008-01-30 16:16:14 +00004755**
drh9a247912008-07-22 18:45:08 +00004756** {H12933} Autocommit mode is disabled by a successful [BEGIN] statement.
drh33c1be32008-01-30 16:16:14 +00004757**
drh9a247912008-07-22 18:45:08 +00004758** {H12934} Autocommit mode is enabled by a successful [COMMIT] or [ROLLBACK]
drh33c1be32008-01-30 16:16:14 +00004759** statement.
drh33c1be32008-01-30 16:16:14 +00004760**
drh9a247912008-07-22 18:45:08 +00004761** ASSUMPTIONS:
mihailim04bcc002008-06-22 10:21:27 +00004762**
drh4766b292008-06-26 02:53:02 +00004763** {A12936} If another thread changes the autocommit status of the database
drh33c1be32008-01-30 16:16:14 +00004764** connection while this routine is running, then the return value
4765** is undefined.
drh3e1d8e62005-05-26 16:23:34 +00004766*/
4767int sqlite3_get_autocommit(sqlite3*);
4768
drh51942bc2005-06-12 22:01:42 +00004769/*
drhb25f9d82008-07-23 15:40:06 +00004770** CAPI3REF: Find The Database Handle Of A Prepared Statement {H13120} <S60600>
drh6ed48bf2007-06-14 20:57:18 +00004771**
mihailimdc884822008-06-22 08:58:50 +00004772** The sqlite3_db_handle interface returns the [database connection] handle
4773** to which a [prepared statement] belongs. The database handle returned by
4774** sqlite3_db_handle is the same database handle that was the first argument
4775** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
4776** create the statement in the first place.
drhafc91042008-02-21 02:09:45 +00004777**
4778** INVARIANTS:
4779**
drh9a247912008-07-22 18:45:08 +00004780** {H13123} The [sqlite3_db_handle(S)] interface returns a pointer
mihailimdc884822008-06-22 08:58:50 +00004781** to the [database connection] associated with the
drhafc91042008-02-21 02:09:45 +00004782** [prepared statement] S.
drh51942bc2005-06-12 22:01:42 +00004783*/
4784sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
drh3e1d8e62005-05-26 16:23:34 +00004785
drhbb5a9c32008-06-19 02:52:25 +00004786/*
drhb25f9d82008-07-23 15:40:06 +00004787** CAPI3REF: Find the next prepared statement {H13140} <S60600>
drhbb5a9c32008-06-19 02:52:25 +00004788**
mihailimdc884822008-06-22 08:58:50 +00004789** This interface returns a pointer to the next [prepared statement] after
4790** pStmt associated with the [database connection] pDb. If pStmt is NULL
4791** then this interface returns a pointer to the first prepared statement
4792** associated with the database connection pDb. If no prepared statement
4793** satisfies the conditions of this routine, it returns NULL.
drhbb5a9c32008-06-19 02:52:25 +00004794**
4795** INVARIANTS:
4796**
drh9a247912008-07-22 18:45:08 +00004797** {H13143} If D is a [database connection] that holds one or more
drhbb5a9c32008-06-19 02:52:25 +00004798** unfinalized [prepared statements] and S is a NULL pointer,
4799** then [sqlite3_next_stmt(D, S)] routine shall return a pointer
mihailimdc884822008-06-22 08:58:50 +00004800** to one of the prepared statements associated with D.
drhbb5a9c32008-06-19 02:52:25 +00004801**
drh9a247912008-07-22 18:45:08 +00004802** {H13146} If D is a [database connection] that holds no unfinalized
mihailimdc884822008-06-22 08:58:50 +00004803** [prepared statements] and S is a NULL pointer, then
4804** [sqlite3_next_stmt(D, S)] routine shall return a NULL pointer.
drhbb5a9c32008-06-19 02:52:25 +00004805**
drh9a247912008-07-22 18:45:08 +00004806** {H13149} If S is a [prepared statement] in the [database connection] D
mihailimdc884822008-06-22 08:58:50 +00004807** and S is not the last prepared statement in D, then
drhbb5a9c32008-06-19 02:52:25 +00004808** [sqlite3_next_stmt(D, S)] routine shall return a pointer
mihailimdc884822008-06-22 08:58:50 +00004809** to the next prepared statement in D after S.
drhbb5a9c32008-06-19 02:52:25 +00004810**
drh9a247912008-07-22 18:45:08 +00004811** {H13152} If S is the last [prepared statement] in the
mihailimdc884822008-06-22 08:58:50 +00004812** [database connection] D then the [sqlite3_next_stmt(D, S)]
4813** routine shall return a NULL pointer.
drh74f7eb12008-07-23 18:25:56 +00004814**
4815** ASSUMPTIONS:
4816**
4817** {A13154} The [database connection] pointer D in a call to
4818** [sqlite3_next_stmt(D,S)] must refer to an open database
4819** connection and in particular must not be a NULL pointer.
drhbb5a9c32008-06-19 02:52:25 +00004820*/
4821sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
4822
drhb37df7b2005-10-13 02:09:49 +00004823/*
drh9cd29642008-07-23 00:52:55 +00004824** CAPI3REF: Commit And Rollback Notification Callbacks {H12950} <S60400>
drh6ed48bf2007-06-14 20:57:18 +00004825**
drhafc91042008-02-21 02:09:45 +00004826** The sqlite3_commit_hook() interface registers a callback
drhf5befa02007-12-06 02:42:07 +00004827** function to be invoked whenever a transaction is committed.
drhafc91042008-02-21 02:09:45 +00004828** Any callback set by a previous call to sqlite3_commit_hook()
drhf5befa02007-12-06 02:42:07 +00004829** for the same database connection is overridden.
drhafc91042008-02-21 02:09:45 +00004830** The sqlite3_rollback_hook() interface registers a callback
drhf5befa02007-12-06 02:42:07 +00004831** function to be invoked whenever a transaction is committed.
drhafc91042008-02-21 02:09:45 +00004832** Any callback set by a previous call to sqlite3_commit_hook()
drhf5befa02007-12-06 02:42:07 +00004833** for the same database connection is overridden.
mihailimdc884822008-06-22 08:58:50 +00004834** The pArg argument is passed through to the callback.
4835** If the callback on a commit hook function returns non-zero,
4836** then the commit is converted into a rollback.
drh6ed48bf2007-06-14 20:57:18 +00004837**
drhafc91042008-02-21 02:09:45 +00004838** If another function was previously registered, its
drhf5befa02007-12-06 02:42:07 +00004839** pArg value is returned. Otherwise NULL is returned.
drh6ed48bf2007-06-14 20:57:18 +00004840**
drhafc91042008-02-21 02:09:45 +00004841** Registering a NULL function disables the callback.
drh6ed48bf2007-06-14 20:57:18 +00004842**
mihailimdc884822008-06-22 08:58:50 +00004843** For the purposes of this API, a transaction is said to have been
drh6ed48bf2007-06-14 20:57:18 +00004844** rolled back if an explicit "ROLLBACK" statement is executed, or
drhf5befa02007-12-06 02:42:07 +00004845** an error or constraint causes an implicit rollback to occur.
drhafc91042008-02-21 02:09:45 +00004846** The rollback callback is not invoked if a transaction is
drhf5befa02007-12-06 02:42:07 +00004847** automatically rolled back because the database connection is closed.
drhafc91042008-02-21 02:09:45 +00004848** The rollback callback is not invoked if a transaction is
drhf5befa02007-12-06 02:42:07 +00004849** rolled back because a commit callback returned non-zero.
drhafc91042008-02-21 02:09:45 +00004850** <todo> Check on this </todo>
drh6ed48bf2007-06-14 20:57:18 +00004851**
drhafc91042008-02-21 02:09:45 +00004852** INVARIANTS:
4853**
drh9a247912008-07-22 18:45:08 +00004854** {H12951} The [sqlite3_commit_hook(D,F,P)] interface registers the
drhafc91042008-02-21 02:09:45 +00004855** callback function F to be invoked with argument P whenever
mihailimdc884822008-06-22 08:58:50 +00004856** a transaction commits on the [database connection] D.
drhafc91042008-02-21 02:09:45 +00004857**
drh9a247912008-07-22 18:45:08 +00004858** {H12952} The [sqlite3_commit_hook(D,F,P)] interface returns the P argument
mihailimdc884822008-06-22 08:58:50 +00004859** from the previous call with the same [database connection] D,
4860** or NULL on the first call for a particular database connection D.
drhafc91042008-02-21 02:09:45 +00004861**
drh9a247912008-07-22 18:45:08 +00004862** {H12953} Each call to [sqlite3_commit_hook()] overwrites the callback
drhafc91042008-02-21 02:09:45 +00004863** registered by prior calls.
4864**
drh9a247912008-07-22 18:45:08 +00004865** {H12954} If the F argument to [sqlite3_commit_hook(D,F,P)] is NULL
shane236ce972008-05-30 15:35:30 +00004866** then the commit hook callback is canceled and no callback
drhafc91042008-02-21 02:09:45 +00004867** is invoked when a transaction commits.
4868**
drh9a247912008-07-22 18:45:08 +00004869** {H12955} If the commit callback returns non-zero then the commit is
drhafc91042008-02-21 02:09:45 +00004870** converted into a rollback.
4871**
drh9a247912008-07-22 18:45:08 +00004872** {H12961} The [sqlite3_rollback_hook(D,F,P)] interface registers the
drhafc91042008-02-21 02:09:45 +00004873** callback function F to be invoked with argument P whenever
mihailimdc884822008-06-22 08:58:50 +00004874** a transaction rolls back on the [database connection] D.
drhafc91042008-02-21 02:09:45 +00004875**
drh9a247912008-07-22 18:45:08 +00004876** {H12962} The [sqlite3_rollback_hook(D,F,P)] interface returns the P
mihailimdc884822008-06-22 08:58:50 +00004877** argument from the previous call with the same
4878** [database connection] D, or NULL on the first call
4879** for a particular database connection D.
drhafc91042008-02-21 02:09:45 +00004880**
drh9a247912008-07-22 18:45:08 +00004881** {H12963} Each call to [sqlite3_rollback_hook()] overwrites the callback
drhafc91042008-02-21 02:09:45 +00004882** registered by prior calls.
4883**
drh9a247912008-07-22 18:45:08 +00004884** {H12964} If the F argument to [sqlite3_rollback_hook(D,F,P)] is NULL
shane236ce972008-05-30 15:35:30 +00004885** then the rollback hook callback is canceled and no callback
drhafc91042008-02-21 02:09:45 +00004886** is invoked when a transaction rolls back.
drh6ed48bf2007-06-14 20:57:18 +00004887*/
4888void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
4889void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
4890
4891/*
drh9cd29642008-07-23 00:52:55 +00004892** CAPI3REF: Data Change Notification Callbacks {H12970} <S60400>
drh6ed48bf2007-06-14 20:57:18 +00004893**
mihailimdc884822008-06-22 08:58:50 +00004894** The sqlite3_update_hook() interface registers a callback function
4895** with the [database connection] identified by the first argument
4896** to be invoked whenever a row is updated, inserted or deleted.
4897** Any callback set by a previous call to this function
4898** for the same database connection is overridden.
danielk197794eb6a12005-12-15 15:22:08 +00004899**
mihailimdc884822008-06-22 08:58:50 +00004900** The second argument is a pointer to the function to invoke when a
4901** row is updated, inserted or deleted.
4902** The first argument to the callback is a copy of the third argument
4903** to sqlite3_update_hook().
4904** The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
4905** or [SQLITE_UPDATE], depending on the operation that caused the callback
4906** to be invoked.
4907** The third and fourth arguments to the callback contain pointers to the
4908** database and table name containing the affected row.
4909** The final callback parameter is the rowid of the row. In the case of
4910** an update, this is the rowid after the update takes place.
danielk197794eb6a12005-12-15 15:22:08 +00004911**
drhafc91042008-02-21 02:09:45 +00004912** The update hook is not invoked when internal system tables are
danielk197794eb6a12005-12-15 15:22:08 +00004913** modified (i.e. sqlite_master and sqlite_sequence).
danielk197771fd80b2005-12-16 06:54:01 +00004914**
drhafc91042008-02-21 02:09:45 +00004915** If another function was previously registered, its pArg value
4916** is returned. Otherwise NULL is returned.
4917**
4918** INVARIANTS:
4919**
drh9a247912008-07-22 18:45:08 +00004920** {H12971} The [sqlite3_update_hook(D,F,P)] interface causes the callback
drhafc91042008-02-21 02:09:45 +00004921** function F to be invoked with first parameter P whenever
4922** a table row is modified, inserted, or deleted on
mihailimdc884822008-06-22 08:58:50 +00004923** the [database connection] D.
drhafc91042008-02-21 02:09:45 +00004924**
drh9a247912008-07-22 18:45:08 +00004925** {H12973} The [sqlite3_update_hook(D,F,P)] interface returns the value
drhafc91042008-02-21 02:09:45 +00004926** of P for the previous call on the same [database connection] D,
4927** or NULL for the first call.
4928**
drh9a247912008-07-22 18:45:08 +00004929** {H12975} If the update hook callback F in [sqlite3_update_hook(D,F,P)]
drhafc91042008-02-21 02:09:45 +00004930** is NULL then the no update callbacks are made.
4931**
drh9a247912008-07-22 18:45:08 +00004932** {H12977} Each call to [sqlite3_update_hook(D,F,P)] overrides prior calls
drhafc91042008-02-21 02:09:45 +00004933** to the same interface on the same [database connection] D.
4934**
drh9a247912008-07-22 18:45:08 +00004935** {H12979} The update hook callback is not invoked when internal system
drhafc91042008-02-21 02:09:45 +00004936** tables such as sqlite_master and sqlite_sequence are modified.
4937**
drh9a247912008-07-22 18:45:08 +00004938** {H12981} The second parameter to the update callback
drhafc91042008-02-21 02:09:45 +00004939** is one of [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE],
4940** depending on the operation that caused the callback to be invoked.
4941**
drh9a247912008-07-22 18:45:08 +00004942** {H12983} The third and fourth arguments to the callback contain pointers
drhafc91042008-02-21 02:09:45 +00004943** to zero-terminated UTF-8 strings which are the names of the
4944** database and table that is being updated.
4945
drh9a247912008-07-22 18:45:08 +00004946** {H12985} The final callback parameter is the rowid of the row after
drhafc91042008-02-21 02:09:45 +00004947** the change occurs.
danielk197794eb6a12005-12-15 15:22:08 +00004948*/
danielk197771fd80b2005-12-16 06:54:01 +00004949void *sqlite3_update_hook(
danielk197794eb6a12005-12-15 15:22:08 +00004950 sqlite3*,
drh6d2069d2007-08-14 01:58:53 +00004951 void(*)(void *,int ,char const *,char const *,sqlite3_int64),
danielk197794eb6a12005-12-15 15:22:08 +00004952 void*
4953);
danielk197713a68c32005-12-15 10:11:30 +00004954
danielk1977f3f06bb2005-12-16 15:24:28 +00004955/*
drh9cd29642008-07-23 00:52:55 +00004956** CAPI3REF: Enable Or Disable Shared Pager Cache {H10330} <S30900>
mihailimefc8e8a2008-06-21 16:47:09 +00004957** KEYWORDS: {shared cache} {shared cache mode}
danielk1977f3f06bb2005-12-16 15:24:28 +00004958**
drh6ed48bf2007-06-14 20:57:18 +00004959** This routine enables or disables the sharing of the database cache
mihailimdc884822008-06-22 08:58:50 +00004960** and schema data structures between [database connection | connections]
4961** to the same database. Sharing is enabled if the argument is true
4962** and disabled if the argument is false.
danielk1977f3f06bb2005-12-16 15:24:28 +00004963**
mihailimdc884822008-06-22 08:58:50 +00004964** Cache sharing is enabled and disabled for an entire process. {END}
4965** This is a change as of SQLite version 3.5.0. In prior versions of SQLite,
4966** sharing was enabled or disabled for each thread separately.
drh6ed48bf2007-06-14 20:57:18 +00004967**
drhe30f4422007-08-21 16:15:55 +00004968** The cache sharing mode set by this interface effects all subsequent
4969** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
drhafc91042008-02-21 02:09:45 +00004970** Existing database connections continue use the sharing mode
4971** that was in effect at the time they were opened.
drh6ed48bf2007-06-14 20:57:18 +00004972**
mihailimdc884822008-06-22 08:58:50 +00004973** Virtual tables cannot be used with a shared cache. When shared
drh4ff7fa02007-09-01 18:17:21 +00004974** cache is enabled, the [sqlite3_create_module()] API used to register
drhafc91042008-02-21 02:09:45 +00004975** virtual tables will always return an error.
drh6ed48bf2007-06-14 20:57:18 +00004976**
mihailimdc884822008-06-22 08:58:50 +00004977** This routine returns [SQLITE_OK] if shared cache was enabled or disabled
4978** successfully. An [error code] is returned otherwise.
drh6ed48bf2007-06-14 20:57:18 +00004979**
drhafc91042008-02-21 02:09:45 +00004980** Shared cache is disabled by default. But this might change in
drh4ff7fa02007-09-01 18:17:21 +00004981** future releases of SQLite. Applications that care about shared
4982** cache setting should set it explicitly.
drhafc91042008-02-21 02:09:45 +00004983**
4984** INVARIANTS:
mihailim15194222008-06-22 09:55:14 +00004985**
drh9a247912008-07-22 18:45:08 +00004986** {H10331} A successful invocation of [sqlite3_enable_shared_cache(B)]
drhafc91042008-02-21 02:09:45 +00004987** will enable or disable shared cache mode for any subsequently
4988** created [database connection] in the same process.
4989**
drh9a247912008-07-22 18:45:08 +00004990** {H10336} When shared cache is enabled, the [sqlite3_create_module()]
drhafc91042008-02-21 02:09:45 +00004991** interface will always return an error.
4992**
drh9a247912008-07-22 18:45:08 +00004993** {H10337} The [sqlite3_enable_shared_cache(B)] interface returns
drhafc91042008-02-21 02:09:45 +00004994** [SQLITE_OK] if shared cache was enabled or disabled successfully.
4995**
drh9a247912008-07-22 18:45:08 +00004996** {H10339} Shared cache is disabled by default.
danielk1977aef0bf62005-12-30 16:28:01 +00004997*/
4998int sqlite3_enable_shared_cache(int);
4999
5000/*
drh9cd29642008-07-23 00:52:55 +00005001** CAPI3REF: Attempt To Free Heap Memory {H17340} <S30220>
drh6ed48bf2007-06-14 20:57:18 +00005002**
mihailim04bcc002008-06-22 10:21:27 +00005003** The sqlite3_release_memory() interface attempts to free N bytes
5004** of heap memory by deallocating non-essential memory allocations
5005** held by the database library. {END} Memory used to cache database
5006** pages to improve performance is an example of non-essential memory.
5007** sqlite3_release_memory() returns the number of bytes actually freed,
5008** which might be more or less than the amount requested.
drhafc91042008-02-21 02:09:45 +00005009**
5010** INVARIANTS:
5011**
drh9a247912008-07-22 18:45:08 +00005012** {H17341} The [sqlite3_release_memory(N)] interface attempts to
drhafc91042008-02-21 02:09:45 +00005013** free N bytes of heap memory by deallocating non-essential
shane26b34032008-05-23 17:21:09 +00005014** memory allocations held by the database library.
drhafc91042008-02-21 02:09:45 +00005015**
drh9a247912008-07-22 18:45:08 +00005016** {H16342} The [sqlite3_release_memory(N)] returns the number
drhafc91042008-02-21 02:09:45 +00005017** of bytes actually freed, which might be more or less
5018** than the amount requested.
danielk197752622822006-01-09 09:59:49 +00005019*/
5020int sqlite3_release_memory(int);
5021
5022/*
drh9cd29642008-07-23 00:52:55 +00005023** CAPI3REF: Impose A Limit On Heap Size {H17350} <S30220>
drh6ed48bf2007-06-14 20:57:18 +00005024**
mihailimdc884822008-06-22 08:58:50 +00005025** The sqlite3_soft_heap_limit() interface places a "soft" limit
5026** on the amount of heap memory that may be allocated by SQLite.
5027** If an internal allocation is requested that would exceed the
5028** soft heap limit, [sqlite3_release_memory()] is invoked one or
5029** more times to free up some space before the allocation is performed.
danielk197752622822006-01-09 09:59:49 +00005030**
mihailimdc884822008-06-22 08:58:50 +00005031** The limit is called "soft", because if [sqlite3_release_memory()]
5032** cannot free sufficient memory to prevent the limit from being exceeded,
drhe30f4422007-08-21 16:15:55 +00005033** the memory is allocated anyway and the current operation proceeds.
drh6ed48bf2007-06-14 20:57:18 +00005034**
5035** A negative or zero value for N means that there is no soft heap limit and
drhe30f4422007-08-21 16:15:55 +00005036** [sqlite3_release_memory()] will only be called when memory is exhausted.
drhafc91042008-02-21 02:09:45 +00005037** The default value for the soft heap limit is zero.
drh6ed48bf2007-06-14 20:57:18 +00005038**
mihailim15194222008-06-22 09:55:14 +00005039** SQLite makes a best effort to honor the soft heap limit.
shane26b34032008-05-23 17:21:09 +00005040** But if the soft heap limit cannot be honored, execution will
mihailimdc884822008-06-22 08:58:50 +00005041** continue without error or notification. This is why the limit is
drh6ed48bf2007-06-14 20:57:18 +00005042** called a "soft" limit. It is advisory only.
5043**
drhe30f4422007-08-21 16:15:55 +00005044** Prior to SQLite version 3.5.0, this routine only constrained the memory
5045** allocated by a single thread - the same thread in which this routine
5046** runs. Beginning with SQLite version 3.5.0, the soft heap limit is
drhafc91042008-02-21 02:09:45 +00005047** applied to all threads. The value specified for the soft heap limit
5048** is an upper bound on the total memory allocation for all threads. In
drh8bacf972007-08-25 16:21:29 +00005049** version 3.5.0 there is no mechanism for limiting the heap usage for
5050** individual threads.
drhafc91042008-02-21 02:09:45 +00005051**
5052** INVARIANTS:
5053**
drh9a247912008-07-22 18:45:08 +00005054** {H16351} The [sqlite3_soft_heap_limit(N)] interface places a soft limit
drhafc91042008-02-21 02:09:45 +00005055** of N bytes on the amount of heap memory that may be allocated
5056** using [sqlite3_malloc()] or [sqlite3_realloc()] at any point
5057** in time.
5058**
drh9a247912008-07-22 18:45:08 +00005059** {H16352} If a call to [sqlite3_malloc()] or [sqlite3_realloc()] would
drhafc91042008-02-21 02:09:45 +00005060** cause the total amount of allocated memory to exceed the
5061** soft heap limit, then [sqlite3_release_memory()] is invoked
5062** in an attempt to reduce the memory usage prior to proceeding
5063** with the memory allocation attempt.
5064**
drh9a247912008-07-22 18:45:08 +00005065** {H16353} Calls to [sqlite3_malloc()] or [sqlite3_realloc()] that trigger
drhafc91042008-02-21 02:09:45 +00005066** attempts to reduce memory usage through the soft heap limit
5067** mechanism continue even if the attempt to reduce memory
5068** usage is unsuccessful.
5069**
drh9a247912008-07-22 18:45:08 +00005070** {H16354} A negative or zero value for N in a call to
drhafc91042008-02-21 02:09:45 +00005071** [sqlite3_soft_heap_limit(N)] means that there is no soft
5072** heap limit and [sqlite3_release_memory()] will only be
5073** called when memory is completely exhausted.
5074**
drh9a247912008-07-22 18:45:08 +00005075** {H16355} The default value for the soft heap limit is zero.
drhafc91042008-02-21 02:09:45 +00005076**
drh9a247912008-07-22 18:45:08 +00005077** {H16358} Each call to [sqlite3_soft_heap_limit(N)] overrides the
drhafc91042008-02-21 02:09:45 +00005078** values set by all prior calls.
danielk197752622822006-01-09 09:59:49 +00005079*/
drhd2d4a6b2006-01-10 15:18:27 +00005080void sqlite3_soft_heap_limit(int);
danielk197752622822006-01-09 09:59:49 +00005081
5082/*
drh9cd29642008-07-23 00:52:55 +00005083** CAPI3REF: Extract Metadata About A Column Of A Table {H12850} <S60300>
drh6ed48bf2007-06-14 20:57:18 +00005084**
mihailimdc884822008-06-22 08:58:50 +00005085** This routine returns metadata about a specific column of a specific
5086** database table accessible using the [database connection] handle
5087** passed as the first function argument.
danielk1977deb802c2006-02-09 13:43:28 +00005088**
mihailimdc884822008-06-22 08:58:50 +00005089** The column is identified by the second, third and fourth parameters to
danielk1977deb802c2006-02-09 13:43:28 +00005090** this function. The second parameter is either the name of the database
5091** (i.e. "main", "temp" or an attached database) containing the specified
5092** table or NULL. If it is NULL, then all attached databases are searched
mihailimdc884822008-06-22 08:58:50 +00005093** for the table using the same algorithm used by the database engine to
danielk1977deb802c2006-02-09 13:43:28 +00005094** resolve unqualified table references.
5095**
mihailimdc884822008-06-22 08:58:50 +00005096** The third and fourth parameters to this function are the table and column
5097** name of the desired column, respectively. Neither of these parameters
danielk1977deb802c2006-02-09 13:43:28 +00005098** may be NULL.
5099**
mihailimdc884822008-06-22 08:58:50 +00005100** Metadata is returned by writing to the memory locations passed as the 5th
5101** and subsequent parameters to this function. Any of these arguments may be
5102** NULL, in which case the corresponding element of metadata is omitted.
mihailim15194222008-06-22 09:55:14 +00005103**
mihailimdc884822008-06-22 08:58:50 +00005104** <blockquote>
5105** <table border="1">
5106** <tr><th> Parameter <th> Output<br>Type <th> Description
danielk1977deb802c2006-02-09 13:43:28 +00005107**
mihailimdc884822008-06-22 08:58:50 +00005108** <tr><td> 5th <td> const char* <td> Data type
5109** <tr><td> 6th <td> const char* <td> Name of default collation sequence
5110** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint
5111** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY
5112** <tr><td> 9th <td> int <td> True if column is AUTOINCREMENT
5113** </table>
5114** </blockquote>
danielk1977deb802c2006-02-09 13:43:28 +00005115**
mihailimdc884822008-06-22 08:58:50 +00005116** The memory pointed to by the character pointers returned for the
5117** declaration type and collation sequence is valid only until the next
5118** call to any SQLite API function.
danielk1977deb802c2006-02-09 13:43:28 +00005119**
mihailimdc884822008-06-22 08:58:50 +00005120** If the specified table is actually a view, an [error code] is returned.
danielk1977deb802c2006-02-09 13:43:28 +00005121**
mihailimdc884822008-06-22 08:58:50 +00005122** If the specified column is "rowid", "oid" or "_rowid_" and an
5123** INTEGER PRIMARY KEY column has been explicitly declared, then the output
danielk1977deb802c2006-02-09 13:43:28 +00005124** parameters are set for the explicitly declared column. If there is no
mihailimdc884822008-06-22 08:58:50 +00005125** explicitly declared INTEGER PRIMARY KEY column, then the output
5126** parameters are set as follows:
danielk1977deb802c2006-02-09 13:43:28 +00005127**
drh6ed48bf2007-06-14 20:57:18 +00005128** <pre>
danielk1977deb802c2006-02-09 13:43:28 +00005129** data type: "INTEGER"
5130** collation sequence: "BINARY"
5131** not null: 0
5132** primary key: 1
5133** auto increment: 0
drh6ed48bf2007-06-14 20:57:18 +00005134** </pre>
danielk1977deb802c2006-02-09 13:43:28 +00005135**
5136** This function may load one or more schemas from database files. If an
5137** error occurs during this process, or if the requested table or column
mihailimdc884822008-06-22 08:58:50 +00005138** cannot be found, an [error code] is returned and an error message left
5139** in the [database connection] (to be retrieved using sqlite3_errmsg()).
danielk19774b1ae992006-02-10 03:06:10 +00005140**
5141** This API is only available if the library was compiled with the
drh4ead1482008-06-26 18:16:05 +00005142** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
danielk1977deb802c2006-02-09 13:43:28 +00005143*/
5144int sqlite3_table_column_metadata(
5145 sqlite3 *db, /* Connection handle */
5146 const char *zDbName, /* Database name or NULL */
5147 const char *zTableName, /* Table name */
5148 const char *zColumnName, /* Column name */
5149 char const **pzDataType, /* OUTPUT: Declared data type */
5150 char const **pzCollSeq, /* OUTPUT: Collation sequence name */
5151 int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */
5152 int *pPrimaryKey, /* OUTPUT: True if column part of PK */
drh98c94802007-10-01 13:50:31 +00005153 int *pAutoinc /* OUTPUT: True if column is auto-increment */
danielk1977deb802c2006-02-09 13:43:28 +00005154);
5155
5156/*
drh9cd29642008-07-23 00:52:55 +00005157** CAPI3REF: Load An Extension {H12600} <S20500>
drh1e397f82006-06-08 15:28:43 +00005158**
mihailimdc884822008-06-22 08:58:50 +00005159** This interface loads an SQLite extension library from the named file.
drh1e397f82006-06-08 15:28:43 +00005160**
drh9a247912008-07-22 18:45:08 +00005161** {H12601} The sqlite3_load_extension() interface attempts to load an
mihailimdc884822008-06-22 08:58:50 +00005162** SQLite extension library contained in the file zFile.
drh1e397f82006-06-08 15:28:43 +00005163**
drh9a247912008-07-22 18:45:08 +00005164** {H12602} The entry point is zProc.
mihailimdc884822008-06-22 08:58:50 +00005165**
drh9a247912008-07-22 18:45:08 +00005166** {H12603} zProc may be 0, in which case the name of the entry point
mihailimdc884822008-06-22 08:58:50 +00005167** defaults to "sqlite3_extension_init".
5168**
drh9a247912008-07-22 18:45:08 +00005169** {H12604} The sqlite3_load_extension() interface shall return
mihailimdc884822008-06-22 08:58:50 +00005170** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
5171**
drh9a247912008-07-22 18:45:08 +00005172** {H12605} If an error occurs and pzErrMsg is not 0, then the
mihailim421dfca2008-06-22 16:35:48 +00005173** [sqlite3_load_extension()] interface shall attempt to
5174** fill *pzErrMsg with error message text stored in memory
5175** obtained from [sqlite3_malloc()]. {END} The calling function
5176** should free this memory by calling [sqlite3_free()].
5177**
drh9a247912008-07-22 18:45:08 +00005178** {H12606} Extension loading must be enabled using
mihailimdc884822008-06-22 08:58:50 +00005179** [sqlite3_enable_load_extension()] prior to calling this API,
5180** otherwise an error will be returned.
drh1e397f82006-06-08 15:28:43 +00005181*/
5182int sqlite3_load_extension(
5183 sqlite3 *db, /* Load the extension into this database connection */
5184 const char *zFile, /* Name of the shared library containing extension */
5185 const char *zProc, /* Entry point. Derived from zFile if 0 */
5186 char **pzErrMsg /* Put error message here if not 0 */
5187);
5188
5189/*
drh9cd29642008-07-23 00:52:55 +00005190** CAPI3REF: Enable Or Disable Extension Loading {H12620} <S20500>
drh6ed48bf2007-06-14 20:57:18 +00005191**
drhc2e87a32006-06-27 15:16:14 +00005192** So as not to open security holes in older applications that are
drh6ed48bf2007-06-14 20:57:18 +00005193** unprepared to deal with extension loading, and as a means of disabling
mihailimdc884822008-06-22 08:58:50 +00005194** extension loading while evaluating user-entered SQL, the following API
5195** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
drhc2e87a32006-06-27 15:16:14 +00005196**
mihailimdc884822008-06-22 08:58:50 +00005197** Extension loading is off by default. See ticket #1863.
5198**
drh9a247912008-07-22 18:45:08 +00005199** {H12621} Call the sqlite3_enable_load_extension() routine with onoff==1
mihailimdc884822008-06-22 08:58:50 +00005200** to turn extension loading on and call it with onoff==0 to turn
5201** it back off again.
5202**
drh9a247912008-07-22 18:45:08 +00005203** {H12622} Extension loading is off by default.
drhc2e87a32006-06-27 15:16:14 +00005204*/
5205int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
5206
5207/*
drh9cd29642008-07-23 00:52:55 +00005208** CAPI3REF: Automatically Load An Extensions {H12640} <S20500>
drh9eff6162006-06-12 21:59:13 +00005209**
drh1409be62006-08-23 20:07:20 +00005210** This API can be invoked at program startup in order to register
5211** one or more statically linked extensions that will be available
mihailim04bcc002008-06-22 10:21:27 +00005212** to all new [database connections]. {END}
mihailimdc884822008-06-22 08:58:50 +00005213**
5214** This routine stores a pointer to the extension in an array that is
5215** obtained from [sqlite3_malloc()]. If you run a memory leak checker
5216** on your program and it reports a leak because of this array, invoke
5217** [sqlite3_reset_auto_extension()] prior to shutdown to free the memory.
5218**
drh9a247912008-07-22 18:45:08 +00005219** {H12641} This function registers an extension entry point that is
mihailimdc884822008-06-22 08:58:50 +00005220** automatically invoked whenever a new [database connection]
5221** is opened using [sqlite3_open()], [sqlite3_open16()],
5222** or [sqlite3_open_v2()].
5223**
drh9a247912008-07-22 18:45:08 +00005224** {H12642} Duplicate extensions are detected so calling this routine
mihailimdc884822008-06-22 08:58:50 +00005225** multiple times with the same extension is harmless.
5226**
drh9a247912008-07-22 18:45:08 +00005227** {H12643} This routine stores a pointer to the extension in an array
mihailimdc884822008-06-22 08:58:50 +00005228** that is obtained from [sqlite3_malloc()].
5229**
drh9a247912008-07-22 18:45:08 +00005230** {H12644} Automatic extensions apply across all threads.
drh1409be62006-08-23 20:07:20 +00005231*/
5232int sqlite3_auto_extension(void *xEntryPoint);
5233
drh1409be62006-08-23 20:07:20 +00005234/*
drh9cd29642008-07-23 00:52:55 +00005235** CAPI3REF: Reset Automatic Extension Loading {H12660} <S20500>
drh1409be62006-08-23 20:07:20 +00005236**
mihailim04bcc002008-06-22 10:21:27 +00005237** This function disables all previously registered automatic
5238** extensions. {END} It undoes the effect of all prior
5239** [sqlite3_auto_extension()] calls.
drh6ed48bf2007-06-14 20:57:18 +00005240**
drh9a247912008-07-22 18:45:08 +00005241** {H12661} This function disables all previously registered
mihailimdc884822008-06-22 08:58:50 +00005242** automatic extensions.
5243**
drh9a247912008-07-22 18:45:08 +00005244** {H12662} This function disables automatic extensions in all threads.
drh1409be62006-08-23 20:07:20 +00005245*/
5246void sqlite3_reset_auto_extension(void);
5247
drh1409be62006-08-23 20:07:20 +00005248/*
5249****** EXPERIMENTAL - subject to change without notice **************
5250**
drh9eff6162006-06-12 21:59:13 +00005251** The interface to the virtual-table mechanism is currently considered
5252** to be experimental. The interface might change in incompatible ways.
5253** If this is a problem for you, do not use the interface at this time.
5254**
shane26b34032008-05-23 17:21:09 +00005255** When the virtual-table mechanism stabilizes, we will declare the
drh9eff6162006-06-12 21:59:13 +00005256** interface fixed, support it indefinitely, and remove this comment.
5257*/
5258
5259/*
5260** Structures used by the virtual table interface
drhe09daa92006-06-10 13:29:31 +00005261*/
5262typedef struct sqlite3_vtab sqlite3_vtab;
5263typedef struct sqlite3_index_info sqlite3_index_info;
5264typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;
5265typedef struct sqlite3_module sqlite3_module;
drh9eff6162006-06-12 21:59:13 +00005266
5267/*
drh9cd29642008-07-23 00:52:55 +00005268** CAPI3REF: Virtual Table Object {H18000} <S20400>
drhb4d58ae2008-02-21 20:17:06 +00005269** KEYWORDS: sqlite3_module
drhd5a68d32008-08-04 13:44:57 +00005270** EXPERIMENTAL
drhb4d58ae2008-02-21 20:17:06 +00005271**
drh9eff6162006-06-12 21:59:13 +00005272** A module is a class of virtual tables. Each module is defined
5273** by an instance of the following structure. This structure consists
5274** mostly of methods for the module.
mihailim15194222008-06-22 09:55:14 +00005275**
5276** This interface is experimental and is subject to change or
5277** removal in future releases of SQLite.
drh9eff6162006-06-12 21:59:13 +00005278*/
drhe09daa92006-06-10 13:29:31 +00005279struct sqlite3_module {
5280 int iVersion;
danielk19779da9d472006-06-14 06:58:15 +00005281 int (*xCreate)(sqlite3*, void *pAux,
drhe4102962006-09-11 00:34:22 +00005282 int argc, const char *const*argv,
drh4ca8aac2006-09-10 17:31:58 +00005283 sqlite3_vtab **ppVTab, char**);
danielk19779da9d472006-06-14 06:58:15 +00005284 int (*xConnect)(sqlite3*, void *pAux,
drhe4102962006-09-11 00:34:22 +00005285 int argc, const char *const*argv,
drh4ca8aac2006-09-10 17:31:58 +00005286 sqlite3_vtab **ppVTab, char**);
drhe09daa92006-06-10 13:29:31 +00005287 int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
5288 int (*xDisconnect)(sqlite3_vtab *pVTab);
5289 int (*xDestroy)(sqlite3_vtab *pVTab);
5290 int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);
5291 int (*xClose)(sqlite3_vtab_cursor*);
drh4be8b512006-06-13 23:51:34 +00005292 int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
drhe09daa92006-06-10 13:29:31 +00005293 int argc, sqlite3_value **argv);
5294 int (*xNext)(sqlite3_vtab_cursor*);
danielk1977a298e902006-06-22 09:53:48 +00005295 int (*xEof)(sqlite3_vtab_cursor*);
drhe09daa92006-06-10 13:29:31 +00005296 int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int);
drh6d2069d2007-08-14 01:58:53 +00005297 int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid);
5298 int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *);
drhe09daa92006-06-10 13:29:31 +00005299 int (*xBegin)(sqlite3_vtab *pVTab);
5300 int (*xSync)(sqlite3_vtab *pVTab);
5301 int (*xCommit)(sqlite3_vtab *pVTab);
5302 int (*xRollback)(sqlite3_vtab *pVTab);
drhb7f6f682006-07-08 17:06:43 +00005303 int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
drhe94b0c32006-07-08 18:09:15 +00005304 void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
5305 void **ppArg);
danielk1977182c4ba2007-06-27 15:53:34 +00005306 int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
drhe09daa92006-06-10 13:29:31 +00005307};
drh9eff6162006-06-12 21:59:13 +00005308
5309/*
drh9cd29642008-07-23 00:52:55 +00005310** CAPI3REF: Virtual Table Indexing Information {H18100} <S20400>
drhb4d58ae2008-02-21 20:17:06 +00005311** KEYWORDS: sqlite3_index_info
drhd5a68d32008-08-04 13:44:57 +00005312** EXPERIMENTAL
drhb4d58ae2008-02-21 20:17:06 +00005313**
drh9eff6162006-06-12 21:59:13 +00005314** The sqlite3_index_info structure and its substructures is used to
5315** pass information into and receive the reply from the xBestIndex
5316** method of an sqlite3_module. The fields under **Inputs** are the
5317** inputs to xBestIndex and are read-only. xBestIndex inserts its
5318** results into the **Outputs** fields.
5319**
mihailim15194222008-06-22 09:55:14 +00005320** The aConstraint[] array records WHERE clause constraints of the form:
drh9eff6162006-06-12 21:59:13 +00005321**
mihailim15194222008-06-22 09:55:14 +00005322** <pre>column OP expr</pre>
drh9eff6162006-06-12 21:59:13 +00005323**
mihailim15194222008-06-22 09:55:14 +00005324** where OP is =, &lt;, &lt;=, &gt;, or &gt;=. The particular operator is
5325** stored in aConstraint[].op. The index of the column is stored in
drh9eff6162006-06-12 21:59:13 +00005326** aConstraint[].iColumn. aConstraint[].usable is TRUE if the
5327** expr on the right-hand side can be evaluated (and thus the constraint
5328** is usable) and false if it cannot.
5329**
5330** The optimizer automatically inverts terms of the form "expr OP column"
drh98c94802007-10-01 13:50:31 +00005331** and makes other simplifications to the WHERE clause in an attempt to
drh9eff6162006-06-12 21:59:13 +00005332** get as many WHERE clause terms into the form shown above as possible.
5333** The aConstraint[] array only reports WHERE clause terms in the correct
5334** form that refer to the particular virtual table being queried.
5335**
5336** Information about the ORDER BY clause is stored in aOrderBy[].
5337** Each term of aOrderBy records a column of the ORDER BY clause.
5338**
5339** The xBestIndex method must fill aConstraintUsage[] with information
danielk19775fac9f82006-06-13 14:16:58 +00005340** about what parameters to pass to xFilter. If argvIndex>0 then
drh9eff6162006-06-12 21:59:13 +00005341** the right-hand side of the corresponding aConstraint[] is evaluated
5342** and becomes the argvIndex-th entry in argv. If aConstraintUsage[].omit
5343** is true, then the constraint is assumed to be fully handled by the
5344** virtual table and is not checked again by SQLite.
5345**
drh4be8b512006-06-13 23:51:34 +00005346** The idxNum and idxPtr values are recorded and passed into xFilter.
5347** sqlite3_free() is used to free idxPtr if needToFreeIdxPtr is true.
drh9eff6162006-06-12 21:59:13 +00005348**
5349** The orderByConsumed means that output from xFilter will occur in
5350** the correct order to satisfy the ORDER BY clause so that no separate
5351** sorting step is required.
5352**
5353** The estimatedCost value is an estimate of the cost of doing the
5354** particular lookup. A full scan of a table with N entries should have
5355** a cost of N. A binary search of a table of N entries should have a
5356** cost of approximately log(N).
mihailim15194222008-06-22 09:55:14 +00005357**
5358** This interface is experimental and is subject to change or
5359** removal in future releases of SQLite.
drh9eff6162006-06-12 21:59:13 +00005360*/
drhe09daa92006-06-10 13:29:31 +00005361struct sqlite3_index_info {
5362 /* Inputs */
drh6cca08c2007-09-21 12:43:16 +00005363 int nConstraint; /* Number of entries in aConstraint */
5364 struct sqlite3_index_constraint {
drh9eff6162006-06-12 21:59:13 +00005365 int iColumn; /* Column on left-hand side of constraint */
5366 unsigned char op; /* Constraint operator */
5367 unsigned char usable; /* True if this constraint is usable */
5368 int iTermOffset; /* Used internally - xBestIndex should ignore */
drh6cca08c2007-09-21 12:43:16 +00005369 } *aConstraint; /* Table of WHERE clause constraints */
5370 int nOrderBy; /* Number of terms in the ORDER BY clause */
5371 struct sqlite3_index_orderby {
drh9eff6162006-06-12 21:59:13 +00005372 int iColumn; /* Column number */
5373 unsigned char desc; /* True for DESC. False for ASC. */
drh6cca08c2007-09-21 12:43:16 +00005374 } *aOrderBy; /* The ORDER BY clause */
drhe09daa92006-06-10 13:29:31 +00005375 /* Outputs */
drh9eff6162006-06-12 21:59:13 +00005376 struct sqlite3_index_constraint_usage {
5377 int argvIndex; /* if >0, constraint is part of argv to xFilter */
5378 unsigned char omit; /* Do not code a test for this constraint */
drh6cca08c2007-09-21 12:43:16 +00005379 } *aConstraintUsage;
drh4be8b512006-06-13 23:51:34 +00005380 int idxNum; /* Number used to identify the index */
5381 char *idxStr; /* String, possibly obtained from sqlite3_malloc */
5382 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
drh9eff6162006-06-12 21:59:13 +00005383 int orderByConsumed; /* True if output is already ordered */
5384 double estimatedCost; /* Estimated cost of using this index */
drhe09daa92006-06-10 13:29:31 +00005385};
drh9eff6162006-06-12 21:59:13 +00005386#define SQLITE_INDEX_CONSTRAINT_EQ 2
5387#define SQLITE_INDEX_CONSTRAINT_GT 4
5388#define SQLITE_INDEX_CONSTRAINT_LE 8
5389#define SQLITE_INDEX_CONSTRAINT_LT 16
5390#define SQLITE_INDEX_CONSTRAINT_GE 32
5391#define SQLITE_INDEX_CONSTRAINT_MATCH 64
5392
5393/*
drh9cd29642008-07-23 00:52:55 +00005394** CAPI3REF: Register A Virtual Table Implementation {H18200} <S20400>
drhd5a68d32008-08-04 13:44:57 +00005395** EXPERIMENTAL
drhb4d58ae2008-02-21 20:17:06 +00005396**
mihailim15194222008-06-22 09:55:14 +00005397** This routine is used to register a new module name with a
5398** [database connection]. Module names must be registered before
5399** creating new virtual tables on the module, or before using
5400** preexisting virtual tables of the module.
5401**
5402** This interface is experimental and is subject to change or
5403** removal in future releases of SQLite.
drh9eff6162006-06-12 21:59:13 +00005404*/
shanea79c3cc2008-08-11 17:27:01 +00005405SQLITE_EXPERIMENTAL int sqlite3_create_module(
drh9eff6162006-06-12 21:59:13 +00005406 sqlite3 *db, /* SQLite connection to register module with */
5407 const char *zName, /* Name of the module */
danielk1977d1ab1ba2006-06-15 04:28:13 +00005408 const sqlite3_module *, /* Methods for the module */
5409 void * /* Client data for xCreate/xConnect */
drhb9bb7c12006-06-11 23:41:55 +00005410);
drhe09daa92006-06-10 13:29:31 +00005411
drh9eff6162006-06-12 21:59:13 +00005412/*
drh9cd29642008-07-23 00:52:55 +00005413** CAPI3REF: Register A Virtual Table Implementation {H18210} <S20400>
drhd5a68d32008-08-04 13:44:57 +00005414** EXPERIMENTAL
drhb4d58ae2008-02-21 20:17:06 +00005415**
mihailim15194222008-06-22 09:55:14 +00005416** This routine is identical to the [sqlite3_create_module()] method above,
danielk1977832a58a2007-06-22 15:21:15 +00005417** except that it allows a destructor function to be specified. It is
5418** even more experimental than the rest of the virtual tables API.
5419*/
shanea79c3cc2008-08-11 17:27:01 +00005420SQLITE_EXPERIMENTAL int sqlite3_create_module_v2(
danielk1977832a58a2007-06-22 15:21:15 +00005421 sqlite3 *db, /* SQLite connection to register module with */
5422 const char *zName, /* Name of the module */
5423 const sqlite3_module *, /* Methods for the module */
5424 void *, /* Client data for xCreate/xConnect */
5425 void(*xDestroy)(void*) /* Module destructor function */
5426);
5427
5428/*
drh9cd29642008-07-23 00:52:55 +00005429** CAPI3REF: Virtual Table Instance Object {H18010} <S20400>
drhb4d58ae2008-02-21 20:17:06 +00005430** KEYWORDS: sqlite3_vtab
drhd5a68d32008-08-04 13:44:57 +00005431** EXPERIMENTAL
drhb4d58ae2008-02-21 20:17:06 +00005432**
drh9eff6162006-06-12 21:59:13 +00005433** Every module implementation uses a subclass of the following structure
5434** to describe a particular instance of the module. Each subclass will
mihailim15194222008-06-22 09:55:14 +00005435** be tailored to the specific needs of the module implementation.
5436** The purpose of this superclass is to define certain fields that are
5437** common to all module implementations.
drhfe1368e2006-09-10 17:08:29 +00005438**
5439** Virtual tables methods can set an error message by assigning a
mihailim15194222008-06-22 09:55:14 +00005440** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should
5441** take care that any prior string is freed by a call to [sqlite3_free()]
drhfe1368e2006-09-10 17:08:29 +00005442** prior to assigning a new string to zErrMsg. After the error message
5443** is delivered up to the client application, the string will be automatically
5444** freed by sqlite3_free() and the zErrMsg field will be zeroed. Note
5445** that sqlite3_mprintf() and sqlite3_free() are used on the zErrMsg field
5446** since virtual tables are commonly implemented in loadable extensions which
5447** do not have access to sqlite3MPrintf() or sqlite3Free().
mihailim15194222008-06-22 09:55:14 +00005448**
5449** This interface is experimental and is subject to change or
5450** removal in future releases of SQLite.
drh9eff6162006-06-12 21:59:13 +00005451*/
5452struct sqlite3_vtab {
drha967e882006-06-13 01:04:52 +00005453 const sqlite3_module *pModule; /* The module for this virtual table */
danielk1977be718892006-06-23 08:05:19 +00005454 int nRef; /* Used internally */
drh4ca8aac2006-09-10 17:31:58 +00005455 char *zErrMsg; /* Error message from sqlite3_mprintf() */
drh9eff6162006-06-12 21:59:13 +00005456 /* Virtual table implementations will typically add additional fields */
5457};
5458
drhb4d58ae2008-02-21 20:17:06 +00005459/*
drh9cd29642008-07-23 00:52:55 +00005460** CAPI3REF: Virtual Table Cursor Object {H18020} <S20400>
drhb4d58ae2008-02-21 20:17:06 +00005461** KEYWORDS: sqlite3_vtab_cursor
drhd5a68d32008-08-04 13:44:57 +00005462** EXPERIMENTAL
drhb4d58ae2008-02-21 20:17:06 +00005463**
5464** Every module implementation uses a subclass of the following structure
drh9eff6162006-06-12 21:59:13 +00005465** to describe cursors that point into the virtual table and are used
5466** to loop through the virtual table. Cursors are created using the
5467** xOpen method of the module. Each module implementation will define
5468** the content of a cursor structure to suit its own needs.
5469**
5470** This superclass exists in order to define fields of the cursor that
5471** are common to all implementations.
mihailim15194222008-06-22 09:55:14 +00005472**
5473** This interface is experimental and is subject to change or
5474** removal in future releases of SQLite.
drh9eff6162006-06-12 21:59:13 +00005475*/
5476struct sqlite3_vtab_cursor {
5477 sqlite3_vtab *pVtab; /* Virtual table of this cursor */
5478 /* Virtual table implementations will typically add additional fields */
5479};
5480
5481/*
drh9cd29642008-07-23 00:52:55 +00005482** CAPI3REF: Declare The Schema Of A Virtual Table {H18280} <S20400>
drhd5a68d32008-08-04 13:44:57 +00005483** EXPERIMENTAL
drhb4d58ae2008-02-21 20:17:06 +00005484**
drh9eff6162006-06-12 21:59:13 +00005485** The xCreate and xConnect methods of a module use the following API
5486** to declare the format (the names and datatypes of the columns) of
5487** the virtual tables they implement.
mihailim15194222008-06-22 09:55:14 +00005488**
5489** This interface is experimental and is subject to change or
5490** removal in future releases of SQLite.
drh9eff6162006-06-12 21:59:13 +00005491*/
shanea79c3cc2008-08-11 17:27:01 +00005492SQLITE_EXPERIMENTAL int sqlite3_declare_vtab(sqlite3*, const char *zCreateTable);
drhe09daa92006-06-10 13:29:31 +00005493
5494/*
drh9cd29642008-07-23 00:52:55 +00005495** CAPI3REF: Overload A Function For A Virtual Table {H18300} <S20400>
drhd5a68d32008-08-04 13:44:57 +00005496** EXPERIMENTAL
drhb4d58ae2008-02-21 20:17:06 +00005497**
drhb7481e72006-09-16 21:45:14 +00005498** Virtual tables can provide alternative implementations of functions
5499** using the xFindFunction method. But global versions of those functions
5500** must exist in order to be overloaded.
5501**
5502** This API makes sure a global version of a function with a particular
5503** name and number of parameters exists. If no such function exists
5504** before this API is called, a new function is created. The implementation
5505** of the new function always causes an exception to be thrown. So
5506** the new function is not good for anything by itself. Its only
shane26b34032008-05-23 17:21:09 +00005507** purpose is to be a placeholder function that can be overloaded
drhb7481e72006-09-16 21:45:14 +00005508** by virtual tables.
5509**
5510** This API should be considered part of the virtual table interface,
5511** which is experimental and subject to change.
5512*/
shanea79c3cc2008-08-11 17:27:01 +00005513SQLITE_EXPERIMENTAL int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
drhb7481e72006-09-16 21:45:14 +00005514
5515/*
drh9eff6162006-06-12 21:59:13 +00005516** The interface to the virtual-table mechanism defined above (back up
5517** to a comment remarkably similar to this one) is currently considered
5518** to be experimental. The interface might change in incompatible ways.
5519** If this is a problem for you, do not use the interface at this time.
5520**
drh98c94802007-10-01 13:50:31 +00005521** When the virtual-table mechanism stabilizes, we will declare the
drh9eff6162006-06-12 21:59:13 +00005522** interface fixed, support it indefinitely, and remove this comment.
5523**
5524****** EXPERIMENTAL - subject to change without notice **************
5525*/
5526
danielk19778cbadb02007-05-03 16:31:26 +00005527/*
drh9cd29642008-07-23 00:52:55 +00005528** CAPI3REF: A Handle To An Open BLOB {H17800} <S30230>
mihailim15194222008-06-22 09:55:14 +00005529** KEYWORDS: {BLOB handle} {BLOB handles}
drh6ed48bf2007-06-14 20:57:18 +00005530**
drhb4d58ae2008-02-21 20:17:06 +00005531** An instance of this object represents an open BLOB on which
mihailim1c492652008-06-21 18:02:16 +00005532** [sqlite3_blob_open | incremental BLOB I/O] can be performed.
mihailim15194222008-06-22 09:55:14 +00005533** Objects of this type are created by [sqlite3_blob_open()]
5534** and destroyed by [sqlite3_blob_close()].
drh6ed48bf2007-06-14 20:57:18 +00005535** The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces
mihailim15194222008-06-22 09:55:14 +00005536** can be used to read or write small subsections of the BLOB.
5537** The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes.
danielk19778cbadb02007-05-03 16:31:26 +00005538*/
danielk1977b4e9af92007-05-01 17:49:49 +00005539typedef struct sqlite3_blob sqlite3_blob;
5540
danielk19778cbadb02007-05-03 16:31:26 +00005541/*
drh9cd29642008-07-23 00:52:55 +00005542** CAPI3REF: Open A BLOB For Incremental I/O {H17810} <S30230>
drh6ed48bf2007-06-14 20:57:18 +00005543**
mihailim04bcc002008-06-22 10:21:27 +00005544** This interfaces opens a [BLOB handle | handle] to the BLOB located
drhf84ddc12008-03-24 12:51:46 +00005545** in row iRow, column zColumn, table zTable in database zDb;
mihailim15194222008-06-22 09:55:14 +00005546** in other words, the same BLOB that would be selected by:
danielk19778cbadb02007-05-03 16:31:26 +00005547**
drh6ed48bf2007-06-14 20:57:18 +00005548** <pre>
5549** SELECT zColumn FROM zDb.zTable WHERE rowid = iRow;
drhf5befa02007-12-06 02:42:07 +00005550** </pre> {END}
danielk19778cbadb02007-05-03 16:31:26 +00005551**
mihailim15194222008-06-22 09:55:14 +00005552** If the flags parameter is non-zero, the the BLOB is opened for read
5553** and write access. If it is zero, the BLOB is opened for read access.
danielk19778cbadb02007-05-03 16:31:26 +00005554**
drhf84ddc12008-03-24 12:51:46 +00005555** Note that the database name is not the filename that contains
5556** the database but rather the symbolic name of the database that
5557** is assigned when the database is connected using [ATTACH].
mihailim15194222008-06-22 09:55:14 +00005558** For the main database file, the database name is "main".
5559** For TEMP tables, the database name is "temp".
drhf84ddc12008-03-24 12:51:46 +00005560**
mihailim15194222008-06-22 09:55:14 +00005561** On success, [SQLITE_OK] is returned and the new [BLOB handle] is written
5562** to *ppBlob. Otherwise an [error code] is returned and any value written
5563** to *ppBlob should not be used by the caller.
5564** This function sets the [database connection] error code and message
drh6ed48bf2007-06-14 20:57:18 +00005565** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()].
mihailim15194222008-06-22 09:55:14 +00005566**
drh9de1b352008-06-26 15:04:57 +00005567** If the row that a BLOB handle points to is modified by an
5568** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
5569** then the BLOB handle is marked as "expired".
5570** This is true if any column of the row is changed, even a column
5571** other than the one the BLOB handle is open on.
5572** Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for
5573** a expired BLOB handle fail with an return code of [SQLITE_ABORT].
5574** Changes written into a BLOB prior to the BLOB expiring are not
5575** rollback by the expiration of the BLOB. Such changes will eventually
5576** commit if the transaction continues to completion.
5577**
drhb4d58ae2008-02-21 20:17:06 +00005578** INVARIANTS:
5579**
drh9a247912008-07-22 18:45:08 +00005580** {H17813} A successful invocation of the [sqlite3_blob_open(D,B,T,C,R,F,P)]
drh9de1b352008-06-26 15:04:57 +00005581** interface shall open an [sqlite3_blob] object P on the BLOB
5582** in column C of the table T in the database B on
5583** the [database connection] D.
drhb4d58ae2008-02-21 20:17:06 +00005584**
drh9a247912008-07-22 18:45:08 +00005585** {H17814} A successful invocation of [sqlite3_blob_open(D,...)] shall start
mihailim15194222008-06-22 09:55:14 +00005586** a new transaction on the [database connection] D if that
5587** connection is not already in a transaction.
drhb4d58ae2008-02-21 20:17:06 +00005588**
drh9a247912008-07-22 18:45:08 +00005589** {H17816} The [sqlite3_blob_open(D,B,T,C,R,F,P)] interface shall open
drh9de1b352008-06-26 15:04:57 +00005590** the BLOB for read and write access if and only if the F
5591** parameter is non-zero.
drhb4d58ae2008-02-21 20:17:06 +00005592**
drh9a247912008-07-22 18:45:08 +00005593** {H17819} The [sqlite3_blob_open()] interface shall return [SQLITE_OK] on
drhb4d58ae2008-02-21 20:17:06 +00005594** success and an appropriate [error code] on failure.
5595**
drh9a247912008-07-22 18:45:08 +00005596** {H17821} If an error occurs during evaluation of [sqlite3_blob_open(D,...)]
drhb4d58ae2008-02-21 20:17:06 +00005597** then subsequent calls to [sqlite3_errcode(D)],
drh9de1b352008-06-26 15:04:57 +00005598** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] shall return
shane26b34032008-05-23 17:21:09 +00005599** information appropriate for that error.
drh9de1b352008-06-26 15:04:57 +00005600**
drh9a247912008-07-22 18:45:08 +00005601** {H17824} If any column in the row that a [sqlite3_blob] has open is
drh9de1b352008-06-26 15:04:57 +00005602** changed by a separate [UPDATE] or [DELETE] statement or by
5603** an [ON CONFLICT] side effect, then the [sqlite3_blob] shall
5604** be marked as invalid.
danielk19778cbadb02007-05-03 16:31:26 +00005605*/
danielk1977b4e9af92007-05-01 17:49:49 +00005606int sqlite3_blob_open(
5607 sqlite3*,
5608 const char *zDb,
5609 const char *zTable,
5610 const char *zColumn,
drh6d2069d2007-08-14 01:58:53 +00005611 sqlite3_int64 iRow,
danielk1977b4e9af92007-05-01 17:49:49 +00005612 int flags,
5613 sqlite3_blob **ppBlob
5614);
5615
danielk19778cbadb02007-05-03 16:31:26 +00005616/*
drh9cd29642008-07-23 00:52:55 +00005617** CAPI3REF: Close A BLOB Handle {H17830} <S30230>
drh6ed48bf2007-06-14 20:57:18 +00005618**
mihailim15194222008-06-22 09:55:14 +00005619** Closes an open [BLOB handle].
drh2dd62be2007-12-04 13:22:43 +00005620**
drhb4d58ae2008-02-21 20:17:06 +00005621** Closing a BLOB shall cause the current transaction to commit
drhf5befa02007-12-06 02:42:07 +00005622** if there are no other BLOBs, no pending prepared statements, and the
mihailim15194222008-06-22 09:55:14 +00005623** database connection is in [autocommit mode].
drhb4d58ae2008-02-21 20:17:06 +00005624** If any writes were made to the BLOB, they might be held in cache
drhf5befa02007-12-06 02:42:07 +00005625** until the close operation if they will fit. {END}
mihailim15194222008-06-22 09:55:14 +00005626**
drhf5befa02007-12-06 02:42:07 +00005627** Closing the BLOB often forces the changes
drh2dd62be2007-12-04 13:22:43 +00005628** out to disk and so if any I/O errors occur, they will likely occur
drh9a247912008-07-22 18:45:08 +00005629** at the time when the BLOB is closed. {H17833} Any errors that occur during
drh2dd62be2007-12-04 13:22:43 +00005630** closing are reported as a non-zero return value.
5631**
drhb4d58ae2008-02-21 20:17:06 +00005632** The BLOB is closed unconditionally. Even if this routine returns
drh2dd62be2007-12-04 13:22:43 +00005633** an error code, the BLOB is still closed.
drhb4d58ae2008-02-21 20:17:06 +00005634**
5635** INVARIANTS:
5636**
drh9a247912008-07-22 18:45:08 +00005637** {H17833} The [sqlite3_blob_close(P)] interface closes an [sqlite3_blob]
mihailim04bcc002008-06-22 10:21:27 +00005638** object P previously opened using [sqlite3_blob_open()].
drhb4d58ae2008-02-21 20:17:06 +00005639**
drh9a247912008-07-22 18:45:08 +00005640** {H17836} Closing an [sqlite3_blob] object using
drhb4d58ae2008-02-21 20:17:06 +00005641** [sqlite3_blob_close()] shall cause the current transaction to
5642** commit if there are no other open [sqlite3_blob] objects
5643** or [prepared statements] on the same [database connection] and
mihailim15194222008-06-22 09:55:14 +00005644** the database connection is in [autocommit mode].
drhb4d58ae2008-02-21 20:17:06 +00005645**
drh9a247912008-07-22 18:45:08 +00005646** {H17839} The [sqlite3_blob_close(P)] interfaces shall close the
drhb4d58ae2008-02-21 20:17:06 +00005647** [sqlite3_blob] object P unconditionally, even if
5648** [sqlite3_blob_close(P)] returns something other than [SQLITE_OK].
danielk19778cbadb02007-05-03 16:31:26 +00005649*/
danielk1977b4e9af92007-05-01 17:49:49 +00005650int sqlite3_blob_close(sqlite3_blob *);
5651
danielk19778cbadb02007-05-03 16:31:26 +00005652/*
drh9cd29642008-07-23 00:52:55 +00005653** CAPI3REF: Return The Size Of An Open BLOB {H17840} <S30230>
drh6ed48bf2007-06-14 20:57:18 +00005654**
mihailim15194222008-06-22 09:55:14 +00005655** Returns the size in bytes of the BLOB accessible via the open
5656** []BLOB handle] in its only argument.
drhb4d58ae2008-02-21 20:17:06 +00005657**
5658** INVARIANTS:
5659**
drh9a247912008-07-22 18:45:08 +00005660** {H17843} The [sqlite3_blob_bytes(P)] interface returns the size
drhb4d58ae2008-02-21 20:17:06 +00005661** in bytes of the BLOB that the [sqlite3_blob] object P
5662** refers to.
danielk19778cbadb02007-05-03 16:31:26 +00005663*/
danielk1977b4e9af92007-05-01 17:49:49 +00005664int sqlite3_blob_bytes(sqlite3_blob *);
5665
drh9eff6162006-06-12 21:59:13 +00005666/*
drh9cd29642008-07-23 00:52:55 +00005667** CAPI3REF: Read Data From A BLOB Incrementally {H17850} <S30230>
drh6ed48bf2007-06-14 20:57:18 +00005668**
mihailim15194222008-06-22 09:55:14 +00005669** This function is used to read data from an open [BLOB handle] into a
5670** caller-supplied buffer. N bytes of data are copied into buffer Z
5671** from the open BLOB, starting at offset iOffset.
danielk19778cbadb02007-05-03 16:31:26 +00005672**
mihailim15194222008-06-22 09:55:14 +00005673** If offset iOffset is less than N bytes from the end of the BLOB,
drhb4d58ae2008-02-21 20:17:06 +00005674** [SQLITE_ERROR] is returned and no data is read. If N or iOffset is
mihailim15194222008-06-22 09:55:14 +00005675** less than zero, [SQLITE_ERROR] is returned and no data is read.
drhf5befa02007-12-06 02:42:07 +00005676**
drh9de1b352008-06-26 15:04:57 +00005677** An attempt to read from an expired [BLOB handle] fails with an
5678** error code of [SQLITE_ABORT].
5679**
mihailim15194222008-06-22 09:55:14 +00005680** On success, SQLITE_OK is returned.
5681** Otherwise, an [error code] or an [extended error code] is returned.
drhb4d58ae2008-02-21 20:17:06 +00005682**
5683** INVARIANTS:
5684**
drh9a247912008-07-22 18:45:08 +00005685** {H17853} A successful invocation of [sqlite3_blob_read(P,Z,N,X)]
drh9de1b352008-06-26 15:04:57 +00005686** shall reads N bytes of data out of the BLOB referenced by
5687** [BLOB handle] P beginning at offset X and store those bytes
5688** into buffer Z.
drhb4d58ae2008-02-21 20:17:06 +00005689**
drh9a247912008-07-22 18:45:08 +00005690** {H17856} In [sqlite3_blob_read(P,Z,N,X)] if the size of the BLOB
drh9de1b352008-06-26 15:04:57 +00005691** is less than N+X bytes, then the function shall leave the
5692** Z buffer unchanged and return [SQLITE_ERROR].
drhb4d58ae2008-02-21 20:17:06 +00005693**
drh9a247912008-07-22 18:45:08 +00005694** {H17859} In [sqlite3_blob_read(P,Z,N,X)] if X or N is less than zero
drh9de1b352008-06-26 15:04:57 +00005695** then the function shall leave the Z buffer unchanged
5696** and return [SQLITE_ERROR].
drhb4d58ae2008-02-21 20:17:06 +00005697**
drh9a247912008-07-22 18:45:08 +00005698** {H17862} The [sqlite3_blob_read(P,Z,N,X)] interface shall return [SQLITE_OK]
drh9de1b352008-06-26 15:04:57 +00005699** if N bytes are successfully read into buffer Z.
5700**
drh9a247912008-07-22 18:45:08 +00005701** {H17863} If the [BLOB handle] P is expired and X and N are within bounds
drh9de1b352008-06-26 15:04:57 +00005702** then [sqlite3_blob_read(P,Z,N,X)] shall leave the Z buffer
5703** unchanged and return [SQLITE_ABORT].
drhb4d58ae2008-02-21 20:17:06 +00005704**
drh9a247912008-07-22 18:45:08 +00005705** {H17865} If the requested read could not be completed,
drh9de1b352008-06-26 15:04:57 +00005706** the [sqlite3_blob_read(P,Z,N,X)] interface shall return an
drhb4d58ae2008-02-21 20:17:06 +00005707** appropriate [error code] or [extended error code].
5708**
drh9a247912008-07-22 18:45:08 +00005709** {H17868} If an error occurs during evaluation of [sqlite3_blob_read(P,...)]
drhb4d58ae2008-02-21 20:17:06 +00005710** then subsequent calls to [sqlite3_errcode(D)],
drh9de1b352008-06-26 15:04:57 +00005711** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] shall return
shane26b34032008-05-23 17:21:09 +00005712** information appropriate for that error, where D is the
mihailim15194222008-06-22 09:55:14 +00005713** [database connection] that was used to open the [BLOB handle] P.
danielk19778cbadb02007-05-03 16:31:26 +00005714*/
drhb4d58ae2008-02-21 20:17:06 +00005715int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
danielk19778cbadb02007-05-03 16:31:26 +00005716
5717/*
drh9cd29642008-07-23 00:52:55 +00005718** CAPI3REF: Write Data Into A BLOB Incrementally {H17870} <S30230>
drh6ed48bf2007-06-14 20:57:18 +00005719**
mihailim15194222008-06-22 09:55:14 +00005720** This function is used to write data into an open [BLOB handle] from a
5721** caller-supplied buffer. N bytes of data are copied from the buffer Z
5722** into the open BLOB, starting at offset iOffset.
danielk19778cbadb02007-05-03 16:31:26 +00005723**
mihailim15194222008-06-22 09:55:14 +00005724** If the [BLOB handle] passed as the first argument was not opened for
5725** writing (the flags parameter to [sqlite3_blob_open()] was zero),
5726** this function returns [SQLITE_READONLY].
danielk19778cbadb02007-05-03 16:31:26 +00005727**
mihailim15194222008-06-22 09:55:14 +00005728** This function may only modify the contents of the BLOB; it is
5729** not possible to increase the size of a BLOB using this API.
5730** If offset iOffset is less than N bytes from the end of the BLOB,
5731** [SQLITE_ERROR] is returned and no data is written. If N is
drhf5befa02007-12-06 02:42:07 +00005732** less than zero [SQLITE_ERROR] is returned and no data is written.
danielk19778cbadb02007-05-03 16:31:26 +00005733**
drh9de1b352008-06-26 15:04:57 +00005734** An attempt to write to an expired [BLOB handle] fails with an
5735** error code of [SQLITE_ABORT]. Writes to the BLOB that occurred
5736** before the [BLOB handle] expired are not rolled back by the
5737** expiration of the handle, though of course those changes might
5738** have been overwritten by the statement that expired the BLOB handle
5739** or by other independent statements.
5740**
mihailim15194222008-06-22 09:55:14 +00005741** On success, SQLITE_OK is returned.
5742** Otherwise, an [error code] or an [extended error code] is returned.
drhb4d58ae2008-02-21 20:17:06 +00005743**
5744** INVARIANTS:
5745**
drh9a247912008-07-22 18:45:08 +00005746** {H17873} A successful invocation of [sqlite3_blob_write(P,Z,N,X)]
drh9de1b352008-06-26 15:04:57 +00005747** shall write N bytes of data from buffer Z into the BLOB
5748** referenced by [BLOB handle] P beginning at offset X into
5749** the BLOB.
drhb4d58ae2008-02-21 20:17:06 +00005750**
drh9a247912008-07-22 18:45:08 +00005751** {H17874} In the absence of other overridding changes, the changes
drh9de1b352008-06-26 15:04:57 +00005752** written to a BLOB by [sqlite3_blob_write()] shall
5753** remain in effect after the associated [BLOB handle] expires.
drhb4d58ae2008-02-21 20:17:06 +00005754**
drh9a247912008-07-22 18:45:08 +00005755** {H17875} If the [BLOB handle] P was opened for reading only then
drh9de1b352008-06-26 15:04:57 +00005756** an invocation of [sqlite3_blob_write(P,Z,N,X)] shall leave
5757** the referenced BLOB unchanged and return [SQLITE_READONLY].
drhb4d58ae2008-02-21 20:17:06 +00005758**
drh9a247912008-07-22 18:45:08 +00005759** {H17876} If the size of the BLOB referenced by [BLOB handle] P is
drh9de1b352008-06-26 15:04:57 +00005760** less than N+X bytes then [sqlite3_blob_write(P,Z,N,X)] shall
5761** leave the BLOB unchanged and return [SQLITE_ERROR].
drhb4d58ae2008-02-21 20:17:06 +00005762**
drh9a247912008-07-22 18:45:08 +00005763** {H17877} If the [BLOB handle] P is expired and X and N are within bounds
drh9de1b352008-06-26 15:04:57 +00005764** then [sqlite3_blob_read(P,Z,N,X)] shall leave the BLOB
5765** unchanged and return [SQLITE_ABORT].
5766**
drh9a247912008-07-22 18:45:08 +00005767** {H17879} If X or N are less than zero then [sqlite3_blob_write(P,Z,N,X)]
drh9de1b352008-06-26 15:04:57 +00005768** shall leave the BLOB referenced by [BLOB handle] P unchanged
5769** and return [SQLITE_ERROR].
5770**
drh9a247912008-07-22 18:45:08 +00005771** {H17882} The [sqlite3_blob_write(P,Z,N,X)] interface shall return
drh9de1b352008-06-26 15:04:57 +00005772** [SQLITE_OK] if N bytes where successfully written into the BLOB.
drhb4d58ae2008-02-21 20:17:06 +00005773**
drh9a247912008-07-22 18:45:08 +00005774** {H17885} If the requested write could not be completed,
drh9de1b352008-06-26 15:04:57 +00005775** the [sqlite3_blob_write(P,Z,N,X)] interface shall return an
drhb4d58ae2008-02-21 20:17:06 +00005776** appropriate [error code] or [extended error code].
5777**
drh9a247912008-07-22 18:45:08 +00005778** {H17888} If an error occurs during evaluation of [sqlite3_blob_write(D,...)]
drhb4d58ae2008-02-21 20:17:06 +00005779** then subsequent calls to [sqlite3_errcode(D)],
drh9de1b352008-06-26 15:04:57 +00005780** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] shall return
shane26b34032008-05-23 17:21:09 +00005781** information appropriate for that error.
danielk19778cbadb02007-05-03 16:31:26 +00005782*/
5783int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
5784
drhd84f9462007-08-15 11:28:56 +00005785/*
drh9cd29642008-07-23 00:52:55 +00005786** CAPI3REF: Virtual File System Objects {H11200} <S20100>
drhd84f9462007-08-15 11:28:56 +00005787**
5788** A virtual filesystem (VFS) is an [sqlite3_vfs] object
5789** that SQLite uses to interact
drhb4d58ae2008-02-21 20:17:06 +00005790** with the underlying operating system. Most SQLite builds come with a
drhd84f9462007-08-15 11:28:56 +00005791** single default VFS that is appropriate for the host computer.
5792** New VFSes can be registered and existing VFSes can be unregistered.
5793** The following interfaces are provided.
5794**
mihailim15194222008-06-22 09:55:14 +00005795** The sqlite3_vfs_find() interface returns a pointer to a VFS given its name.
5796** Names are case sensitive.
drhb4d58ae2008-02-21 20:17:06 +00005797** Names are zero-terminated UTF-8 strings.
mihailim15194222008-06-22 09:55:14 +00005798** If there is no match, a NULL pointer is returned.
5799** If zVfsName is NULL then the default VFS is returned.
drhd84f9462007-08-15 11:28:56 +00005800**
drhb4d58ae2008-02-21 20:17:06 +00005801** New VFSes are registered with sqlite3_vfs_register().
5802** Each new VFS becomes the default VFS if the makeDflt flag is set.
5803** The same VFS can be registered multiple times without injury.
5804** To make an existing VFS into the default VFS, register it again
5805** with the makeDflt flag set. If two different VFSes with the
5806** same name are registered, the behavior is undefined. If a
drhb6f5cf32007-08-28 15:21:45 +00005807** VFS is registered with a name that is NULL or an empty string,
5808** then the behavior is undefined.
mihailim15194222008-06-22 09:55:14 +00005809**
drhb4d58ae2008-02-21 20:17:06 +00005810** Unregister a VFS with the sqlite3_vfs_unregister() interface.
5811** If the default VFS is unregistered, another VFS is chosen as
drhd84f9462007-08-15 11:28:56 +00005812** the default. The choice for the new VFS is arbitrary.
drhb4d58ae2008-02-21 20:17:06 +00005813**
5814** INVARIANTS:
5815**
drh9a247912008-07-22 18:45:08 +00005816** {H11203} The [sqlite3_vfs_find(N)] interface returns a pointer to the
drhb4d58ae2008-02-21 20:17:06 +00005817** registered [sqlite3_vfs] object whose name exactly matches
5818** the zero-terminated UTF-8 string N, or it returns NULL if
5819** there is no match.
5820**
drh9a247912008-07-22 18:45:08 +00005821** {H11206} If the N parameter to [sqlite3_vfs_find(N)] is NULL then
drhb4d58ae2008-02-21 20:17:06 +00005822** the function returns a pointer to the default [sqlite3_vfs]
mihailim15194222008-06-22 09:55:14 +00005823** object if there is one, or NULL if there is no default
drhb4d58ae2008-02-21 20:17:06 +00005824** [sqlite3_vfs] object.
5825**
drh9a247912008-07-22 18:45:08 +00005826** {H11209} The [sqlite3_vfs_register(P,F)] interface registers the
drhb4d58ae2008-02-21 20:17:06 +00005827** well-formed [sqlite3_vfs] object P using the name given
5828** by the zName field of the object.
5829**
drh9a247912008-07-22 18:45:08 +00005830** {H11212} Using the [sqlite3_vfs_register(P,F)] interface to register
drhb4d58ae2008-02-21 20:17:06 +00005831** the same [sqlite3_vfs] object multiple times is a harmless no-op.
5832**
drh9a247912008-07-22 18:45:08 +00005833** {H11215} The [sqlite3_vfs_register(P,F)] interface makes the [sqlite3_vfs]
mihailim15194222008-06-22 09:55:14 +00005834** object P the default [sqlite3_vfs] object if F is non-zero.
drhb4d58ae2008-02-21 20:17:06 +00005835**
drh9a247912008-07-22 18:45:08 +00005836** {H11218} The [sqlite3_vfs_unregister(P)] interface unregisters the
drhb4d58ae2008-02-21 20:17:06 +00005837** [sqlite3_vfs] object P so that it is no longer returned by
5838** subsequent calls to [sqlite3_vfs_find()].
drhd84f9462007-08-15 11:28:56 +00005839*/
drhd677b3d2007-08-20 22:48:41 +00005840sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName);
drhd677b3d2007-08-20 22:48:41 +00005841int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
5842int sqlite3_vfs_unregister(sqlite3_vfs*);
drhd84f9462007-08-15 11:28:56 +00005843
5844/*
drh9cd29642008-07-23 00:52:55 +00005845** CAPI3REF: Mutexes {H17000} <S20000>
drhd84f9462007-08-15 11:28:56 +00005846**
5847** The SQLite core uses these routines for thread
danielk19774a9d1f62008-06-19 08:51:23 +00005848** synchronization. Though they are intended for internal
drhd84f9462007-08-15 11:28:56 +00005849** use by SQLite, code that links against SQLite is
5850** permitted to use any of these routines.
5851**
mihailim15194222008-06-22 09:55:14 +00005852** The SQLite source code contains multiple implementations
drh8bacf972007-08-25 16:21:29 +00005853** of these mutex routines. An appropriate implementation
5854** is selected automatically at compile-time. The following
5855** implementations are available in the SQLite core:
drhd84f9462007-08-15 11:28:56 +00005856**
5857** <ul>
drhc7ce76a2007-08-30 14:10:30 +00005858** <li> SQLITE_MUTEX_OS2
drhd84f9462007-08-15 11:28:56 +00005859** <li> SQLITE_MUTEX_PTHREAD
drhc7ce76a2007-08-30 14:10:30 +00005860** <li> SQLITE_MUTEX_W32
drhd84f9462007-08-15 11:28:56 +00005861** <li> SQLITE_MUTEX_NOOP
drhd84f9462007-08-15 11:28:56 +00005862** </ul>
5863**
mihailim15194222008-06-22 09:55:14 +00005864** The SQLITE_MUTEX_NOOP implementation is a set of routines
5865** that does no real locking and is appropriate for use in
drhc7ce76a2007-08-30 14:10:30 +00005866** a single-threaded application. The SQLITE_MUTEX_OS2,
5867** SQLITE_MUTEX_PTHREAD, and SQLITE_MUTEX_W32 implementations
shane26b34032008-05-23 17:21:09 +00005868** are appropriate for use on OS/2, Unix, and Windows.
mihailim15194222008-06-22 09:55:14 +00005869**
drh8bacf972007-08-25 16:21:29 +00005870** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
5871** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
danielk19774a9d1f62008-06-19 08:51:23 +00005872** implementation is included with the library. In this case the
5873** application must supply a custom mutex implementation using the
5874** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
mihailim15194222008-06-22 09:55:14 +00005875** before calling sqlite3_initialize() or any other public sqlite3_
danielk19774a9d1f62008-06-19 08:51:23 +00005876** function that calls sqlite3_initialize().
drhcb041342008-06-12 00:07:29 +00005877**
drh9a247912008-07-22 18:45:08 +00005878** {H17011} The sqlite3_mutex_alloc() routine allocates a new
5879** mutex and returns a pointer to it. {H17012} If it returns NULL
5880** that means that a mutex could not be allocated. {H17013} SQLite
5881** will unwind its stack and return an error. {H17014} The argument
drh6bdec4a2007-08-16 19:40:16 +00005882** to sqlite3_mutex_alloc() is one of these integer constants:
5883**
5884** <ul>
5885** <li> SQLITE_MUTEX_FAST
5886** <li> SQLITE_MUTEX_RECURSIVE
5887** <li> SQLITE_MUTEX_STATIC_MASTER
5888** <li> SQLITE_MUTEX_STATIC_MEM
drh86f8c192007-08-22 00:39:19 +00005889** <li> SQLITE_MUTEX_STATIC_MEM2
drh6bdec4a2007-08-16 19:40:16 +00005890** <li> SQLITE_MUTEX_STATIC_PRNG
danielk19779f61c2f2007-08-27 17:27:49 +00005891** <li> SQLITE_MUTEX_STATIC_LRU
danielk1977dfb316d2008-03-26 18:34:43 +00005892** <li> SQLITE_MUTEX_STATIC_LRU2
mihailim04bcc002008-06-22 10:21:27 +00005893** </ul>
drh6bdec4a2007-08-16 19:40:16 +00005894**
drh9a247912008-07-22 18:45:08 +00005895** {H17015} The first two constants cause sqlite3_mutex_alloc() to create
drh6bdec4a2007-08-16 19:40:16 +00005896** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
drhf5befa02007-12-06 02:42:07 +00005897** is used but not necessarily so when SQLITE_MUTEX_FAST is used. {END}
drh6bdec4a2007-08-16 19:40:16 +00005898** The mutex implementation does not need to make a distinction
5899** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
drh9a247912008-07-22 18:45:08 +00005900** not want to. {H17016} But SQLite will only request a recursive mutex in
drhf5befa02007-12-06 02:42:07 +00005901** cases where it really needs one. {END} If a faster non-recursive mutex
drh6bdec4a2007-08-16 19:40:16 +00005902** implementation is available on the host platform, the mutex subsystem
5903** might return such a mutex in response to SQLITE_MUTEX_FAST.
5904**
drh9a247912008-07-22 18:45:08 +00005905** {H17017} The other allowed parameters to sqlite3_mutex_alloc() each return
drhf5befa02007-12-06 02:42:07 +00005906** a pointer to a static preexisting mutex. {END} Four static mutexes are
drh6bdec4a2007-08-16 19:40:16 +00005907** used by the current version of SQLite. Future versions of SQLite
5908** may add additional static mutexes. Static mutexes are for internal
5909** use by SQLite only. Applications that use SQLite mutexes should
5910** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
5911** SQLITE_MUTEX_RECURSIVE.
5912**
drh9a247912008-07-22 18:45:08 +00005913** {H17018} Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
drh6bdec4a2007-08-16 19:40:16 +00005914** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
drh9a247912008-07-22 18:45:08 +00005915** returns a different mutex on every call. {H17034} But for the static
drh6bdec4a2007-08-16 19:40:16 +00005916** mutex types, the same mutex is returned on every call that has
mihailim04bcc002008-06-22 10:21:27 +00005917** the same type number.
drhd84f9462007-08-15 11:28:56 +00005918**
drh9a247912008-07-22 18:45:08 +00005919** {H17019} The sqlite3_mutex_free() routine deallocates a previously
5920** allocated dynamic mutex. {H17020} SQLite is careful to deallocate every
drh4766b292008-06-26 02:53:02 +00005921** dynamic mutex that it allocates. {A17021} The dynamic mutexes must not be in
5922** use when they are deallocated. {A17022} Attempting to deallocate a static
drh9a247912008-07-22 18:45:08 +00005923** mutex results in undefined behavior. {H17023} SQLite never deallocates
drhf5befa02007-12-06 02:42:07 +00005924** a static mutex. {END}
drhd84f9462007-08-15 11:28:56 +00005925**
drh6bdec4a2007-08-16 19:40:16 +00005926** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
drh9a247912008-07-22 18:45:08 +00005927** to enter a mutex. {H17024} If another thread is already within the mutex,
drh6bdec4a2007-08-16 19:40:16 +00005928** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
drh9a247912008-07-22 18:45:08 +00005929** SQLITE_BUSY. {H17025} The sqlite3_mutex_try() interface returns [SQLITE_OK]
5930** upon successful entry. {H17026} Mutexes created using
drhf5befa02007-12-06 02:42:07 +00005931** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
drh9a247912008-07-22 18:45:08 +00005932** {H17027} In such cases the,
drh6bdec4a2007-08-16 19:40:16 +00005933** mutex must be exited an equal number of times before another thread
drh4766b292008-06-26 02:53:02 +00005934** can enter. {A17028} If the same thread tries to enter any other
drhf5befa02007-12-06 02:42:07 +00005935** kind of mutex more than once, the behavior is undefined.
drh9a247912008-07-22 18:45:08 +00005936** {H17029} SQLite will never exhibit
drhcb041342008-06-12 00:07:29 +00005937** such behavior in its own use of mutexes.
drhd84f9462007-08-15 11:28:56 +00005938**
mihailim15194222008-06-22 09:55:14 +00005939** Some systems (for example, Windows 95) do not support the operation
5940** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try()
drh9a247912008-07-22 18:45:08 +00005941** will always return SQLITE_BUSY. {H17030} The SQLite core only ever uses
drhcb041342008-06-12 00:07:29 +00005942** sqlite3_mutex_try() as an optimization so this is acceptable behavior.
drhca49cba2007-09-04 22:31:36 +00005943**
drh9a247912008-07-22 18:45:08 +00005944** {H17031} The sqlite3_mutex_leave() routine exits a mutex that was
drh4766b292008-06-26 02:53:02 +00005945** previously entered by the same thread. {A17032} The behavior
drh8bacf972007-08-25 16:21:29 +00005946** is undefined if the mutex is not currently entered by the
drh9a247912008-07-22 18:45:08 +00005947** calling thread or is not currently allocated. {H17033} SQLite will
drhf5befa02007-12-06 02:42:07 +00005948** never do either. {END}
drh8bacf972007-08-25 16:21:29 +00005949**
drh40257ff2008-06-13 18:24:27 +00005950** If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
5951** sqlite3_mutex_leave() is a NULL pointer, then all three routines
5952** behave as no-ops.
5953**
drh8bacf972007-08-25 16:21:29 +00005954** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].
5955*/
5956sqlite3_mutex *sqlite3_mutex_alloc(int);
5957void sqlite3_mutex_free(sqlite3_mutex*);
5958void sqlite3_mutex_enter(sqlite3_mutex*);
5959int sqlite3_mutex_try(sqlite3_mutex*);
5960void sqlite3_mutex_leave(sqlite3_mutex*);
5961
drh56a40a82008-06-18 13:47:03 +00005962/*
drh9cd29642008-07-23 00:52:55 +00005963** CAPI3REF: Mutex Methods Object {H17120} <S20130>
drhd5a68d32008-08-04 13:44:57 +00005964** EXPERIMENTAL
drh56a40a82008-06-18 13:47:03 +00005965**
5966** An instance of this structure defines the low-level routines
danielk19774a9d1f62008-06-19 08:51:23 +00005967** used to allocate and use mutexes.
5968**
5969** Usually, the default mutex implementations provided by SQLite are
mihailim15194222008-06-22 09:55:14 +00005970** sufficient, however the user has the option of substituting a custom
5971** implementation for specialized deployments or systems for which SQLite
danielk19774a9d1f62008-06-19 08:51:23 +00005972** does not provide a suitable implementation. In this case, the user
5973** creates and populates an instance of this structure to pass
mihailim15194222008-06-22 09:55:14 +00005974** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
danielk19774a9d1f62008-06-19 08:51:23 +00005975** Additionally, an instance of this structure can be used as an
5976** output variable when querying the system for the current mutex
5977** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
5978**
5979** The xMutexInit method defined by this structure is invoked as
5980** part of system initialization by the sqlite3_initialize() function.
drh9a247912008-07-22 18:45:08 +00005981** {H17001} The xMutexInit routine shall be called by SQLite once for each
mihailim15194222008-06-22 09:55:14 +00005982** effective call to [sqlite3_initialize()].
danielk19774a9d1f62008-06-19 08:51:23 +00005983**
5984** The xMutexEnd method defined by this structure is invoked as
5985** part of system shutdown by the sqlite3_shutdown() function. The
5986** implementation of this method is expected to release all outstanding
5987** resources obtained by the mutex methods implementation, especially
drh9a247912008-07-22 18:45:08 +00005988** those obtained by the xMutexInit method. {H17003} The xMutexEnd()
mihailim15194222008-06-22 09:55:14 +00005989** interface shall be invoked once for each call to [sqlite3_shutdown()].
danielk19774a9d1f62008-06-19 08:51:23 +00005990**
5991** The remaining seven methods defined by this structure (xMutexAlloc,
5992** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and
5993** xMutexNotheld) implement the following interfaces (respectively):
drh56a40a82008-06-18 13:47:03 +00005994**
5995** <ul>
danielk19774a9d1f62008-06-19 08:51:23 +00005996** <li> [sqlite3_mutex_alloc()] </li>
5997** <li> [sqlite3_mutex_free()] </li>
5998** <li> [sqlite3_mutex_enter()] </li>
5999** <li> [sqlite3_mutex_try()] </li>
6000** <li> [sqlite3_mutex_leave()] </li>
6001** <li> [sqlite3_mutex_held()] </li>
6002** <li> [sqlite3_mutex_notheld()] </li>
drh56a40a82008-06-18 13:47:03 +00006003** </ul>
danielk19774a9d1f62008-06-19 08:51:23 +00006004**
6005** The only difference is that the public sqlite3_XXX functions enumerated
6006** above silently ignore any invocations that pass a NULL pointer instead
6007** of a valid mutex handle. The implementations of the methods defined
6008** by this structure are not required to handle this case, the results
6009** of passing a NULL pointer instead of a valid mutex handle are undefined
6010** (i.e. it is acceptable to provide an implementation that segfaults if
6011** it is passed a NULL pointer).
drh56a40a82008-06-18 13:47:03 +00006012*/
danielk19776d2ab0e2008-06-17 17:21:18 +00006013typedef struct sqlite3_mutex_methods sqlite3_mutex_methods;
6014struct sqlite3_mutex_methods {
6015 int (*xMutexInit)(void);
danielk19774a9d1f62008-06-19 08:51:23 +00006016 int (*xMutexEnd)(void);
danielk19776d2ab0e2008-06-17 17:21:18 +00006017 sqlite3_mutex *(*xMutexAlloc)(int);
6018 void (*xMutexFree)(sqlite3_mutex *);
6019 void (*xMutexEnter)(sqlite3_mutex *);
6020 int (*xMutexTry)(sqlite3_mutex *);
6021 void (*xMutexLeave)(sqlite3_mutex *);
danielk19776d2ab0e2008-06-17 17:21:18 +00006022 int (*xMutexHeld)(sqlite3_mutex *);
6023 int (*xMutexNotheld)(sqlite3_mutex *);
6024};
6025
drh8bacf972007-08-25 16:21:29 +00006026/*
drh9cd29642008-07-23 00:52:55 +00006027** CAPI3REF: Mutex Verification Routines {H17080} <S20130> <S30800>
drhd677b3d2007-08-20 22:48:41 +00006028**
6029** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
drh9a247912008-07-22 18:45:08 +00006030** are intended for use inside assert() statements. {H17081} The SQLite core
drhf77a2ff2007-08-25 14:49:36 +00006031** never uses these routines except inside an assert() and applications
drh9a247912008-07-22 18:45:08 +00006032** are advised to follow the lead of the core. {H17082} The core only
drh8bacf972007-08-25 16:21:29 +00006033** provides implementations for these routines when it is compiled
drh4766b292008-06-26 02:53:02 +00006034** with the SQLITE_DEBUG flag. {A17087} External mutex implementations
drh8bacf972007-08-25 16:21:29 +00006035** are only required to provide these routines if SQLITE_DEBUG is
6036** defined and if NDEBUG is not defined.
6037**
drh9a247912008-07-22 18:45:08 +00006038** {H17083} These routines should return true if the mutex in their argument
mihailim04bcc002008-06-22 10:21:27 +00006039** is held or not held, respectively, by the calling thread.
drh8bacf972007-08-25 16:21:29 +00006040**
drhfddfa2d2007-12-05 18:05:16 +00006041** {X17084} The implementation is not required to provided versions of these
mihailim04bcc002008-06-22 10:21:27 +00006042** routines that actually work. If the implementation does not provide working
6043** versions of these routines, it should at least provide stubs that always
6044** return true so that one does not get spurious assertion failures.
drhd677b3d2007-08-20 22:48:41 +00006045**
drh9a247912008-07-22 18:45:08 +00006046** {H17085} If the argument to sqlite3_mutex_held() is a NULL pointer then
drhfddfa2d2007-12-05 18:05:16 +00006047** the routine should return 1. {END} This seems counter-intuitive since
drhd677b3d2007-08-20 22:48:41 +00006048** clearly the mutex cannot be held if it does not exist. But the
6049** the reason the mutex does not exist is because the build is not
6050** using mutexes. And we do not want the assert() containing the
6051** call to sqlite3_mutex_held() to fail, so a non-zero return is
drh9a247912008-07-22 18:45:08 +00006052** the appropriate thing to do. {H17086} The sqlite3_mutex_notheld()
drhd677b3d2007-08-20 22:48:41 +00006053** interface should also return 1 when given a NULL pointer.
drhd84f9462007-08-15 11:28:56 +00006054*/
drhd677b3d2007-08-20 22:48:41 +00006055int sqlite3_mutex_held(sqlite3_mutex*);
6056int sqlite3_mutex_notheld(sqlite3_mutex*);
drh32bc3f62007-08-21 20:25:39 +00006057
6058/*
drh9cd29642008-07-23 00:52:55 +00006059** CAPI3REF: Mutex Types {H17001} <H17000>
drh32bc3f62007-08-21 20:25:39 +00006060**
drhd5a68d32008-08-04 13:44:57 +00006061** The [sqlite3_mutex_alloc()] interface takes a single argument
mihailim04bcc002008-06-22 10:21:27 +00006062** which is one of these integer constants.
drhd5a68d32008-08-04 13:44:57 +00006063**
6064** The set of static mutexes may change from one SQLite release to the
6065** next. Applications that override the built-in mutex logic must be
6066** prepared to accommodate additional static mutexes.
drh32bc3f62007-08-21 20:25:39 +00006067*/
drh6bdec4a2007-08-16 19:40:16 +00006068#define SQLITE_MUTEX_FAST 0
6069#define SQLITE_MUTEX_RECURSIVE 1
6070#define SQLITE_MUTEX_STATIC_MASTER 2
drh86f8c192007-08-22 00:39:19 +00006071#define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */
6072#define SQLITE_MUTEX_STATIC_MEM2 4 /* sqlite3_release_memory() */
6073#define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */
danielk19779f61c2f2007-08-27 17:27:49 +00006074#define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
danielk1977dfb316d2008-03-26 18:34:43 +00006075#define SQLITE_MUTEX_STATIC_LRU2 7 /* lru page list */
drh6d2069d2007-08-14 01:58:53 +00006076
drhcc6bb3e2007-08-31 16:11:35 +00006077/*
drh9cd29642008-07-23 00:52:55 +00006078** CAPI3REF: Low-Level Control Of Database Files {H11300} <S30800>
drhcc6bb3e2007-08-31 16:11:35 +00006079**
drh9a247912008-07-22 18:45:08 +00006080** {H11301} The [sqlite3_file_control()] interface makes a direct call to the
drhcc6bb3e2007-08-31 16:11:35 +00006081** xFileControl method for the [sqlite3_io_methods] object associated
drh9a247912008-07-22 18:45:08 +00006082** with a particular database identified by the second argument. {H11302} The
drhcc6bb3e2007-08-31 16:11:35 +00006083** name of the database is the name assigned to the database by the
6084** <a href="lang_attach.html">ATTACH</a> SQL command that opened the
drh9a247912008-07-22 18:45:08 +00006085** database. {H11303} To control the main database file, use the name "main"
6086** or a NULL pointer. {H11304} The third and fourth parameters to this routine
drhcc6bb3e2007-08-31 16:11:35 +00006087** are passed directly through to the second and third parameters of
drh9a247912008-07-22 18:45:08 +00006088** the xFileControl method. {H11305} The return value of the xFileControl
drhcc6bb3e2007-08-31 16:11:35 +00006089** method becomes the return value of this routine.
6090**
drh9a247912008-07-22 18:45:08 +00006091** {H11306} If the second parameter (zDbName) does not match the name of any
6092** open database file, then SQLITE_ERROR is returned. {H11307} This error
drhcc6bb3e2007-08-31 16:11:35 +00006093** code is not remembered and will not be recalled by [sqlite3_errcode()]
drh4766b292008-06-26 02:53:02 +00006094** or [sqlite3_errmsg()]. {A11308} The underlying xFileControl method might
6095** also return SQLITE_ERROR. {A11309} There is no way to distinguish between
drhcc6bb3e2007-08-31 16:11:35 +00006096** an incorrect zDbName and an SQLITE_ERROR return from the underlying
drhfddfa2d2007-12-05 18:05:16 +00006097** xFileControl method. {END}
drh4ff7fa02007-09-01 18:17:21 +00006098**
6099** See also: [SQLITE_FCNTL_LOCKSTATE]
drhcc6bb3e2007-08-31 16:11:35 +00006100*/
6101int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
drh6d2069d2007-08-14 01:58:53 +00006102
danielk19778cbadb02007-05-03 16:31:26 +00006103/*
drh9cd29642008-07-23 00:52:55 +00006104** CAPI3REF: Testing Interface {H11400} <S30800>
drhed13d982008-01-31 14:43:24 +00006105**
6106** The sqlite3_test_control() interface is used to read out internal
6107** state of SQLite and to inject faults into SQLite for testing
shane26b34032008-05-23 17:21:09 +00006108** purposes. The first parameter is an operation code that determines
drhed13d982008-01-31 14:43:24 +00006109** the number, meaning, and operation of all subsequent parameters.
6110**
6111** This interface is not for use by applications. It exists solely
6112** for verifying the correct operation of the SQLite library. Depending
6113** on how the SQLite library is compiled, this interface might not exist.
6114**
6115** The details of the operation codes, their meanings, the parameters
6116** they take, and what they do are all subject to change without notice.
6117** Unlike most of the SQLite API, this function is not guaranteed to
6118** operate consistently from one release to the next.
6119*/
6120int sqlite3_test_control(int op, ...);
6121
6122/*
drh9cd29642008-07-23 00:52:55 +00006123** CAPI3REF: Testing Interface Operation Codes {H11410} <H11400>
drhed13d982008-01-31 14:43:24 +00006124**
6125** These constants are the valid operation code parameters used
6126** as the first argument to [sqlite3_test_control()].
6127**
shane26b34032008-05-23 17:21:09 +00006128** These parameters and their meanings are subject to change
drhed13d982008-01-31 14:43:24 +00006129** without notice. These values are for testing purposes only.
6130** Applications should not use any of these parameters or the
6131** [sqlite3_test_control()] interface.
6132*/
drh2fa18682008-03-19 14:15:34 +00006133#define SQLITE_TESTCTRL_PRNG_SAVE 5
6134#define SQLITE_TESTCTRL_PRNG_RESTORE 6
6135#define SQLITE_TESTCTRL_PRNG_RESET 7
drh3088d592008-03-21 16:45:47 +00006136#define SQLITE_TESTCTRL_BITVEC_TEST 8
danielk1977d09414c2008-06-19 18:17:49 +00006137#define SQLITE_TESTCTRL_FAULT_INSTALL 9
danielk19772d1d86f2008-06-20 14:59:51 +00006138#define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10
drhed13d982008-01-31 14:43:24 +00006139
drhf7141992008-06-19 00:16:08 +00006140/*
drh9cd29642008-07-23 00:52:55 +00006141** CAPI3REF: SQLite Runtime Status {H17200} <S60200>
drhd5a68d32008-08-04 13:44:57 +00006142** EXPERIMENTAL
drhf7141992008-06-19 00:16:08 +00006143**
mihailim15194222008-06-22 09:55:14 +00006144** This interface is used to retrieve runtime status information
drhf7141992008-06-19 00:16:08 +00006145** about the preformance of SQLite, and optionally to reset various
6146** highwater marks. The first argument is an integer code for
6147** the specific parameter to measure. Recognized integer codes
6148** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...].
6149** The current value of the parameter is returned into *pCurrent.
6150** The highest recorded value is returned in *pHighwater. If the
6151** resetFlag is true, then the highest record value is reset after
6152** *pHighwater is written. Some parameters do not record the highest
6153** value. For those parameters
6154** nothing is written into *pHighwater and the resetFlag is ignored.
6155** Other parameters record only the highwater mark and not the current
6156** value. For these latter parameters nothing is written into *pCurrent.
6157**
6158** This routine returns SQLITE_OK on success and a non-zero
6159** [error code] on failure.
6160**
6161** This routine is threadsafe but is not atomic. This routine can
6162** called while other threads are running the same or different SQLite
6163** interfaces. However the values returned in *pCurrent and
6164** *pHighwater reflect the status of SQLite at different points in time
6165** and it is possible that another thread might change the parameter
6166** in between the times when *pCurrent and *pHighwater are written.
6167**
drh2462e322008-07-31 14:47:54 +00006168** See also: [sqlite3_db_status()]
drhf7141992008-06-19 00:16:08 +00006169*/
shanea79c3cc2008-08-11 17:27:01 +00006170SQLITE_EXPERIMENTAL int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
drh2462e322008-07-31 14:47:54 +00006171
6172/*
6173** CAPI3REF: Database Connection Status {H17201} <S60200>
drhd5a68d32008-08-04 13:44:57 +00006174** EXPERIMENTAL
drh2462e322008-07-31 14:47:54 +00006175**
6176** This interface is used to retrieve runtime status information
6177** about a single [database connection]. The first argument is the
6178** database connection object to be interrogated. The second argument
6179** is the parameter to interrogate. Currently, the only allowed value
6180** for the second parameter is [SQLITE_DBSTATUS_LOOKASIDE_USED].
6181** Additional options will likely appear in future releases of SQLite.
6182**
6183** The current value of the request parameter is written into *pCur
6184** and the highest instantaneous value is written into *pHiwtr. If
6185** the resetFlg is true, then the highest instantaneous value is
6186** reset back down to the current value.
6187**
6188** See also: [sqlite3_status()].
drh2462e322008-07-31 14:47:54 +00006189*/
shanea79c3cc2008-08-11 17:27:01 +00006190SQLITE_EXPERIMENTAL int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
drhf7141992008-06-19 00:16:08 +00006191
6192/*
drh9cd29642008-07-23 00:52:55 +00006193** CAPI3REF: Status Parameters {H17250} <H17200>
drhd5a68d32008-08-04 13:44:57 +00006194** EXPERIMENTAL
drhf7141992008-06-19 00:16:08 +00006195**
6196** These integer constants designate various run-time status parameters
6197** that can be returned by [sqlite3_status()].
6198**
6199** <dl>
6200** <dt>SQLITE_STATUS_MEMORY_USED</dt>
6201** <dd>This parameter is the current amount of memory checked out
mihailim15194222008-06-22 09:55:14 +00006202** using [sqlite3_malloc()], either directly or indirectly. The
drhf7141992008-06-19 00:16:08 +00006203** figure includes calls made to [sqlite3_malloc()] by the application
6204** and internal memory usage by the SQLite library. Scratch memory
6205** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
6206** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
6207** this parameter. The amount returned is the sum of the allocation
mihailim15194222008-06-22 09:55:14 +00006208** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>
drhf7141992008-06-19 00:16:08 +00006209**
drhe50135e2008-08-05 17:53:22 +00006210** <dt>SQLITE_STATUS_MALLOC_SIZE</dt>
6211** <dd>This parameter records the largest memory allocation request
6212** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
6213** internal equivalents). Only the value returned in the
6214** *pHighwater parameter to [sqlite3_status()] is of interest.
6215** The value written into the *pCurrent parameter is undefined.</dd>
6216**
drhf7141992008-06-19 00:16:08 +00006217** <dt>SQLITE_STATUS_PAGECACHE_USED</dt>
6218** <dd>This parameter returns the number of pages used out of the
drhe50135e2008-08-05 17:53:22 +00006219** [pagecache memory allocator] that was configured using
6220** [SQLITE_CONFIG_PAGECACHE]. The
drhf7141992008-06-19 00:16:08 +00006221** value returned is in pages, not in bytes.</dd>
6222**
6223** <dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
6224** <dd>This parameter returns the number of bytes of page cache
6225** allocation which could not be statisfied by the [SQLITE_CONFIG_PAGECACHE]
drhe50135e2008-08-05 17:53:22 +00006226** buffer and where forced to overflow to [sqlite3_malloc()]. The
6227** returned value includes allocations that overflowed because they
6228** where too large (they were larger than the "sz" parameter to
6229** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
6230** no space was left in the page cache.</dd>
6231**
6232** <dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
6233** <dd>This parameter records the largest memory allocation request
6234** handed to [pagecache memory allocator]. Only the value returned in the
6235** *pHighwater parameter to [sqlite3_status()] is of interest.
6236** The value written into the *pCurrent parameter is undefined.</dd>
drhf7141992008-06-19 00:16:08 +00006237**
6238** <dt>SQLITE_STATUS_SCRATCH_USED</dt>
6239** <dd>This parameter returns the number of allocations used out of the
drhe50135e2008-08-05 17:53:22 +00006240** [scratch memory allocator] configured using
drhf7141992008-06-19 00:16:08 +00006241** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
drhe50135e2008-08-05 17:53:22 +00006242** in bytes. Since a single thread may only have one scratch allocation
drhf7141992008-06-19 00:16:08 +00006243** outstanding at time, this parameter also reports the number of threads
6244** using scratch memory at the same time.</dd>
6245**
drh71f48622008-07-13 03:55:03 +00006246** <dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
drhf7141992008-06-19 00:16:08 +00006247** <dd>This parameter returns the number of bytes of scratch memory
6248** allocation which could not be statisfied by the [SQLITE_CONFIG_SCRATCH]
drhe50135e2008-08-05 17:53:22 +00006249** buffer and where forced to overflow to [sqlite3_malloc()]. The values
6250** returned include overflows because the requested allocation was too
6251** larger (that is, because the requested allocation was larger than the
6252** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
6253** slots were available.
6254** </dd>
drhf7141992008-06-19 00:16:08 +00006255**
drhe50135e2008-08-05 17:53:22 +00006256** <dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
drhf7141992008-06-19 00:16:08 +00006257** <dd>This parameter records the largest memory allocation request
drhe50135e2008-08-05 17:53:22 +00006258** handed to [scratch memory allocator]. Only the value returned in the
6259** *pHighwater parameter to [sqlite3_status()] is of interest.
6260** The value written into the *pCurrent parameter is undefined.</dd>
drhec424a52008-07-25 15:39:03 +00006261**
6262** <dt>SQLITE_STATUS_PARSER_STACK</dt>
6263** <dd>This parameter records the deepest parser stack. It is only
drh0a60a382008-07-31 17:16:05 +00006264** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>
drhf7141992008-06-19 00:16:08 +00006265** </dl>
6266**
6267** New status parameters may be added from time to time.
6268*/
6269#define SQLITE_STATUS_MEMORY_USED 0
6270#define SQLITE_STATUS_PAGECACHE_USED 1
6271#define SQLITE_STATUS_PAGECACHE_OVERFLOW 2
6272#define SQLITE_STATUS_SCRATCH_USED 3
6273#define SQLITE_STATUS_SCRATCH_OVERFLOW 4
6274#define SQLITE_STATUS_MALLOC_SIZE 5
drhec424a52008-07-25 15:39:03 +00006275#define SQLITE_STATUS_PARSER_STACK 6
drhe50135e2008-08-05 17:53:22 +00006276#define SQLITE_STATUS_PAGECACHE_SIZE 7
6277#define SQLITE_STATUS_SCRATCH_SIZE 8
drhf7141992008-06-19 00:16:08 +00006278
drh633e6d52008-07-28 19:34:53 +00006279/*
6280** CAPI3REF: Status Parameters for database connections {H17275} <H17200>
drhd5a68d32008-08-04 13:44:57 +00006281** EXPERIMENTAL
drh633e6d52008-07-28 19:34:53 +00006282**
6283** Status verbs for [sqlite3_db_status()].
6284**
6285** <dl>
6286** <dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
6287** <dd>This parameter returns the number of lookaside memory slots currently
6288** checked out.</dd>
6289** </dl>
6290*/
6291#define SQLITE_DBSTATUS_LOOKASIDE_USED 0
drhed13d982008-01-31 14:43:24 +00006292
6293/*
drhb37df7b2005-10-13 02:09:49 +00006294** Undo the hack that converts floating point types to integer for
6295** builds on processors without floating point support.
6296*/
6297#ifdef SQLITE_OMIT_FLOATING_POINT
6298# undef double
6299#endif
6300
drh382c0242001-10-06 16:33:02 +00006301#ifdef __cplusplus
6302} /* End of the 'extern "C"' block */
6303#endif
danielk19774adee202004-05-08 08:23:19 +00006304#endif