15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 2001 September 15 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The author disclaims copyright to this source code. In place of 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a legal notice, here is a blessing: 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** May you do good and not evil. 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** May you find forgiveness for yourself and forgive others. 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** May you share freely, never taking more than you give. 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)************************************************************************* 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This header file defines the interface that the SQLite library 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** presents to client programs. If a C-function, structure, datatype, 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or constant definition does not appear in this file, then it is 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** not a published API of SQLite, is subject to change without 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** notice, and should not be referenced by programs that use SQLite. 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Some of the definitions that are in this file are marked as 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** "experimental". Experimental interfaces are normally new 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** features recently added to SQLite. We do not anticipate changes 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to experimental interfaces but reserve the right to make minor changes 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** if experience from use "in the wild" suggest such changes are prudent. 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The official C-language API documentation for SQLite is derived 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** from comments in this file. This file is the authoritative source 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** on how SQLite interfaces are suppose to operate. 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The name of this file under configuration management is "sqlite.h.in". 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The makefile makes some minor changes to this file (such as inserting 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the version number) and changes its name to "sqlite3.h" as 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** part of the build process. 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef _SQLITE3_H_ 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define _SQLITE3_H_ 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <stdarg.h> /* Needed for the definition of va_list */ 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Make sure we can call this stuff from C++. 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef __cplusplus 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)extern "C" { 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Add the ability to override 'extern' 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef SQLITE_EXTERN 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define SQLITE_EXTERN extern 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These no-op macros are used in front of interfaces to mark those 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interfaces as either deprecated or experimental. New applications 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** should not use deprecated interfaces - they are support for backwards 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** compatibility only. Application writers should be aware that 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** experimental interfaces are subject to change in point releases. 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These macros used to resolve to various kinds of compiler magic that 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** would generate warning messages when they were used. But that 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** compiler magic ended up generating such a flurry of bug reports 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that we have taken it all out and gone back to using simple 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** noop macros. 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DEPRECATED 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_EXPERIMENTAL 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Ensure these symbols were not defined by some previous header file. 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef SQLITE_VERSION 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# undef SQLITE_VERSION 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef SQLITE_VERSION_NUMBER 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# undef SQLITE_VERSION_NUMBER 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Compile-Time Library Version Numbers 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** evaluates to a string literal that is the SQLite version in the 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** format "X.Y.Z" where X is the major version number (always 3 for 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite3) and Y is the minor version number and Z is the release number.)^ 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** numbers used in [SQLITE_VERSION].)^ 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The SQLITE_VERSION_NUMBER for any given release of SQLite will also 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** be larger than the release from which it is derived. Either Y will 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** be held constant and Z will be incremented or else Y will be incremented 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and Z will be reset to zero. 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Since version 3.6.18, SQLite source code has been stored in the 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <a href="http://www.fossil-scm.org/">Fossil configuration management 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a string which identifies a particular check-in of SQLite 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** within its configuration management system. ^The SQLITE_SOURCE_ID 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** string contains the date and time of the check-in (UTC) and an SHA1 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** hash of the entire source tree. 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also: [sqlite3_libversion()], 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_libversion_number()], [sqlite3_sourceid()], 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite_version()] and [sqlite_source_id()]. 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_VERSION "--VERS--" 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_VERSION_NUMBER --VERSION-NUMBER-- 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_SOURCE_ID "--SOURCE-ID--" 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Run-Time Library Version Numbers 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: sqlite3_version, sqlite3_sourceid 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These interfaces provide the same information as the [SQLITE_VERSION], 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** but are associated with the library instead of the header file. ^(Cautious 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** programmers might include assert() statements in their application to 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** verify that values returned by these interfaces match the macros in 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the header, and thus insure that the application is 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** compiled with matching library and header files. 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <blockquote><pre> 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER ); 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 ); 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 ); 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </pre></blockquote>)^ 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION] 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** macro. ^The sqlite3_libversion() function returns a pointer to the 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to the sqlite3_version[] string constant. The sqlite3_libversion() 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function is provided for use in DLLs since DLL users usually do not have 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** direct access to string constants within the DLL. ^The 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_libversion_number() function returns an integer equal to 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_VERSION_NUMBER]. ^The sqlite3_sourceid() function returns 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a pointer to a string constant whose value is the same as the 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_SOURCE_ID] C preprocessor macro. 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also: [sqlite_version()] and [sqlite_source_id()]. 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)SQLITE_EXTERN const char sqlite3_version[]; 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char *sqlite3_libversion(void); 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char *sqlite3_sourceid(void); 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_libversion_number(void); 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Run-Time Library Compilation Options Diagnostics 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_compileoption_used() function returns 0 or 1 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** indicating whether the specified option was defined at 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** compile time. ^The SQLITE_ prefix may be omitted from the 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** option name passed to sqlite3_compileoption_used(). 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_compileoption_get() function allows iterating 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** over the list of options that were defined at compile time by 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** returning the N-th compile time option string. ^If N is out of range, 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_compileoption_get() returns a NULL pointer. ^The SQLITE_ 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** prefix is omitted from any strings returned by 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_compileoption_get(). 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Support for the diagnostic functions sqlite3_compileoption_used() 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and sqlite3_compileoption_get() may be omitted by specifying the 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time. 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also: SQL functions [sqlite_compileoption_used()] and 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite_compileoption_get()] and the [compile_options pragma]. 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_compileoption_used(const char *zOptName); 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char *sqlite3_compileoption_get(int N); 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Test To See If The Library Is Threadsafe 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_threadsafe() function returns zero if and only if 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite was compiled mutexing code omitted due to the 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_THREADSAFE] compile-time option being set to 0. 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite can be compiled with or without mutexes. When 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are enabled and SQLite is threadsafe. When the 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_THREADSAFE] macro is 0, 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the mutexes are omitted. Without the mutexes, it is not safe 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to use SQLite concurrently from more than one thread. 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Enabling mutexes incurs a measurable performance penalty. 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** So if speed is of utmost importance, it makes sense to disable 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the mutexes. But for maximum safety, mutexes should be enabled. 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The default behavior is for mutexes to be enabled. 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This interface can be used by an application to make sure that the 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** version of SQLite that it is linking against was compiled with 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the desired setting of the [SQLITE_THREADSAFE] macro. 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This interface only reports on the compile-time mutex setting 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** can be fully or partially disabled using a call to [sqlite3_config()] 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD], 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or [SQLITE_CONFIG_MUTEX]. ^(The return value of the 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_threadsafe() function shows only the compile-time setting of 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** thread safety, not any run-time changes to that setting made by 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_config(). In other words, the return value from sqlite3_threadsafe() 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is unchanged by calls to sqlite3_config().)^ 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See the [threading mode] documentation for additional information. 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_threadsafe(void); 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Database Connection Handle 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: {database connection} {database connections} 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Each open SQLite database is represented by a pointer to an instance of 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the opaque structure named "sqlite3". It is useful to think of an sqlite3 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()] 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is its destructor. There are many other interfaces (such as 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_prepare_v2()], [sqlite3_create_function()], and 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_busy_timeout()] to name but three) that are methods on an 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3 object. 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct sqlite3 sqlite3; 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: 64-Bit Integer Types 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: sqlite_int64 sqlite_uint64 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Because there is no cross-platform way to specify 64-bit integer types 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite includes typedefs for 64-bit signed and unsigned integers. 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions. 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The sqlite_int64 and sqlite_uint64 types are supported for backwards 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** compatibility only. 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_int64 and sqlite_int64 types can store integer values 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** between -9223372036854775808 and +9223372036854775807 inclusive. ^The 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_uint64 and sqlite_uint64 types can store integer values 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** between 0 and +18446744073709551615 inclusive. 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef SQLITE_INT64_TYPE 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef SQLITE_INT64_TYPE sqlite_int64; 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#elif defined(_MSC_VER) || defined(__BORLANDC__) 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef __int64 sqlite_int64; 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef unsigned __int64 sqlite_uint64; 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef long long int sqlite_int64; 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef unsigned long long int sqlite_uint64; 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef sqlite_int64 sqlite3_int64; 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef sqlite_uint64 sqlite3_uint64; 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If compiling for a processor that lacks floating point support, 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** substitute integer for floating-point. 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef SQLITE_OMIT_FLOATING_POINT 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define double sqlite3_int64 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Closing A Database Connection 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_close() routine is the destructor for the [sqlite3] object. 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Calls to sqlite3_close() return SQLITE_OK if the [sqlite3] object is 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** successfully destroyed and all associated resources are deallocated. 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Applications must [sqlite3_finalize | finalize] all [prepared statements] 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and [sqlite3_blob_close | close] all [BLOB handles] associated with 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the [sqlite3] object prior to attempting to close the object. ^If 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_close() is called on a [database connection] that still has 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** outstanding [prepared statements] or [BLOB handles], then it returns 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLITE_BUSY. 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If [sqlite3_close()] is invoked while a transaction is open, 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the transaction is automatically rolled back. 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The C parameter to [sqlite3_close(C)] must be either a NULL 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** pointer or an [sqlite3] object pointer obtained 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** from [sqlite3_open()], [sqlite3_open16()], or 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_open_v2()], and not previously closed. 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Calling sqlite3_close() with a NULL pointer argument is a 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** harmless no-op. 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_close(sqlite3 *); 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The type for a callback function. 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This is legacy and deprecated. It is included for historical 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** compatibility and is not documented. 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef int (*sqlite3_callback)(void*,int,char**, char**); 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: One-Step Query Execution Interface 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The sqlite3_exec() interface is a convenience wrapper around 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()], 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that allows an application to run multiple statements of SQL 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** without having to use a lot of C code. 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded, 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** semicolon-separate SQL statements passed into its 2nd argument, 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in the context of the [database connection] passed in as its 1st 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** argument. ^If the callback function of the 3rd argument to 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_exec() is not NULL, then it is invoked for each result row 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** coming out of the evaluated SQL statements. ^The 4th argument to 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to sqlite3_exec() is relayed through to the 1st argument of each 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** callback invocation. ^If the callback pointer to sqlite3_exec() 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is NULL, then no callback is ever invoked and result rows are 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ignored. 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If an error occurs while evaluating the SQL statements passed into 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_exec(), then execution of the current statement stops and 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec() 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is not NULL then any error message is written into memory obtained 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** from [sqlite3_malloc()] and passed back through the 5th parameter. 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** To avoid memory leaks, the application should invoke [sqlite3_free()] 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** on error message strings returned through the 5th parameter of 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of sqlite3_exec() after the error message string is no longer needed. 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** occur, then sqlite3_exec() sets the pointer in its 5th parameter to 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** NULL before returning. 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec() 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** routine returns SQLITE_ABORT without invoking the callback again and 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** without running any subsequent SQL statements. 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The 2nd argument to the sqlite3_exec() callback function is the 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** number of columns in the result. ^The 3rd argument to the sqlite3_exec() 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** callback is an array of pointers to strings obtained as if from 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_column_text()], one for each column. ^If an element of a 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** result row is NULL then the corresponding string pointer for the 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_exec() callback is an array of pointers to strings where each 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** entry represents the name of corresponding result column as obtained 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** from [sqlite3_column_name()]. 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to an empty string, or a pointer that contains only whitespace and/or 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQL comments, then no SQL statements are evaluated and the database 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is not changed. 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Restrictions: 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <ul> 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> The application must insure that the 1st parameter to sqlite3_exec() 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is a valid and open [database connection]. 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> The application must not close [database connection] specified by 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running. 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> The application must not modify the SQL statement text passed into 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running. 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </ul> 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_exec( 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3*, /* An open database */ 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *sql, /* SQL to be evaluated */ 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*callback)(void*,int,char**,char**), /* Callback function */ 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void *, /* 1st argument to callback */ 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) char **errmsg /* Error msg written here */ 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Result Codes 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: SQLITE_OK {error code} {error codes} 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: {result code} {result codes} 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Many SQLite functions return an integer result code from the set shown 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** here in order to indicates success or failure. 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** New error codes may be added in future versions of SQLite. 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also: [SQLITE_IOERR_READ | extended result codes] 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_OK 0 /* Successful result */ 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* beginning-of-error-codes */ 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_ERROR 1 /* SQL error or missing database */ 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ 3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_PERM 3 /* Access permission denied */ 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_ABORT 4 /* Callback routine requested an abort */ 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_BUSY 5 /* The database file is locked */ 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_LOCKED 6 /* A table in the database is locked */ 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_NOMEM 7 /* A malloc() failed */ 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_READONLY 8 /* Attempt to write a readonly database */ 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/ 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ 3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CORRUPT 11 /* The database disk image is malformed */ 3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */ 3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_FULL 13 /* Insertion failed because database is full */ 3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CANTOPEN 14 /* Unable to open the database file */ 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_PROTOCOL 15 /* Database lock protocol error */ 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_EMPTY 16 /* Database is empty */ 3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_SCHEMA 17 /* The database schema changed */ 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */ 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */ 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_MISMATCH 20 /* Data type mismatch */ 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_MISUSE 21 /* Library used incorrectly */ 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */ 3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_AUTH 23 /* Authorization denied */ 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_FORMAT 24 /* Auxiliary database format error */ 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */ 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_NOTADB 26 /* File opened that is not a database file */ 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */ 4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* end-of-error-codes */ 4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Extended Result Codes 4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: {extended error code} {extended error codes} 4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: {extended result code} {extended result codes} 4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** In its default configuration, SQLite API routines return one of 26 integer 4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_OK | result codes]. However, experience has shown that many of 4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** these result codes are too coarse-grained. They do not provide as 4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** much information about problems as programmers might like. In an effort to 4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** address this, newer versions of SQLite (version 3.3.8 and later) include 4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** support for additional result codes that provide more detailed information 4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** about errors. The extended result codes are enabled or disabled 4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** on a per database connection basis using the 4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_extended_result_codes()] API. 4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Some of the available extended result codes are listed here. 4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** One may expect the number of extended result codes will be expand 4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** over time. Software that uses extended result codes should expect 4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to see new result codes in future releases of SQLite. 4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The SQLITE_OK result code will never be extended. It will always 4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** be exactly zero. 4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) 4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) 4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) 4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) 4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) 4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) 4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) 4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) 4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) 4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) 4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) 4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) 4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8)) 4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8)) 4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8)) 4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8)) 4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8)) 4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) 4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) 4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) 4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) 4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) 4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) 4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Flags For File Open Operations 4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These bit values are intended for use in the 4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 3rd parameter to the [sqlite3_open_v2()] interface and 4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in the 4th parameter to the xOpen method of the 4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_vfs] object. 4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ 4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ 4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ 4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ 4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ 4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ 4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ 4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ 4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ 4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ 4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ 4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */ 4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ 4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */ 4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ 4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ 4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ 4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ 4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* Reserved: 0x00F00000 */ 4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Device Characteristics 4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The xDeviceCharacteristics method of the [sqlite3_io_methods] 4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** object returns an integer which is a vector of the these 4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** bit values expressing I/O characteristics of the mass storage 4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** device that holds the file that the [sqlite3_io_methods] 4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** refers to. 4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The SQLITE_IOCAP_ATOMIC property means that all writes of 4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values 4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** mean that writes of blocks that are nnn bytes in size and 4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are aligned to an address which is an integer multiple of 4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means 4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that when data is appended to a file, the data is appended 4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** first then the size of the file is extended, never the other 4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** way around. The SQLITE_IOCAP_SEQUENTIAL property means that 5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** information is written to disk in the same order as calls 5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to xWrite(). 5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOCAP_ATOMIC 0x00000001 5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOCAP_ATOMIC512 0x00000002 5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOCAP_ATOMIC1K 0x00000004 5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOCAP_ATOMIC2K 0x00000008 5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOCAP_ATOMIC4K 0x00000010 5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOCAP_ATOMIC8K 0x00000020 5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOCAP_ATOMIC16K 0x00000040 5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOCAP_ATOMIC32K 0x00000080 5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOCAP_ATOMIC64K 0x00000100 5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOCAP_SAFE_APPEND 0x00000200 5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOCAP_SEQUENTIAL 0x00000400 5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800 5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: File Locking Levels 5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite uses one of these integer values as the second 5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** argument to calls it makes to the xLock() and xUnlock() methods 5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of an [sqlite3_io_methods] object. 5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_LOCK_NONE 0 5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_LOCK_SHARED 1 5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_LOCK_RESERVED 2 5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_LOCK_PENDING 3 5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_LOCK_EXCLUSIVE 4 5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Synchronization Type Flags 5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** When SQLite invokes the xSync() method of an 5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_io_methods] object it uses a combination of 5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** these integer values as the second argument. 5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** When the SQLITE_SYNC_DATAONLY flag is used, it means that the 5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sync operation only needs to flush data to mass storage. Inode 5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** information need not be flushed. If the lower four bits of the flag 5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics. 5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If the lower four bits equal SQLITE_SYNC_FULL, that means 5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to use Mac OS X style fullsync instead of fsync(). 5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags 5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL 5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** settings. The [synchronous pragma] determines when calls to the 5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** xSync VFS method occur and applies uniformly across all platforms. 5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how 5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** energetic or rigorous or forceful the sync operations are and 5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** only make a difference on Mac OSX for the default SQLite code. 5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** (Third-party VFS implementations might also make the distinction 5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the 5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** operating systems natively supported by SQLite, only Mac OSX 5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** cares about the difference.) 5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_SYNC_NORMAL 0x00002 5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_SYNC_FULL 0x00003 5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_SYNC_DATAONLY 0x00010 5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: OS Interface Open File Handle 5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** An [sqlite3_file] object represents an open file in the 5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_vfs | OS interface layer]. Individual OS interface 5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** implementations will 5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** want to subclass this object by appending additional fields 5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for their own use. The pMethods entry is a pointer to an 5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_io_methods] object that defines methods for performing 5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** I/O operations on the open file. 5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct sqlite3_file sqlite3_file; 5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct sqlite3_file { 5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const struct sqlite3_io_methods *pMethods; /* Methods for an open file */ 5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: OS Interface File Virtual Methods Object 5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Every file opened by the [sqlite3_vfs] xOpen method populates an 5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_file] object (or, more commonly, a subclass of the 5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_file] object) with a pointer to an instance of this object. 5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This object defines the methods used to perform various operations 5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** against the open file represented by the [sqlite3_file] object. 5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If the xOpen method sets the sqlite3_file.pMethods element 5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to a non-NULL pointer, then the sqlite3_io_methods.xClose method 5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** may be invoked even if the xOpen reported that it failed. The 5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** only way to prevent a call to xClose following a failed xOpen 5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is for the xOpen to set the sqlite3_file.pMethods element to NULL. 5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or 5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_SYNC_FULL]. The first choice is the normal fsync(). 5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY] 5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** flag may be ORed in to indicate that only the data of the file 5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and not its inode needs to be synced. 5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The integer values to xLock() and xUnlock() are one of 5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <ul> 5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_LOCK_NONE], 5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_LOCK_SHARED], 6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_LOCK_RESERVED], 6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_LOCK_PENDING], or 6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_LOCK_EXCLUSIVE]. 6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </ul> 6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** xLock() increases the lock. xUnlock() decreases the lock. 6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The xCheckReservedLock() method checks whether any database connection, 6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** either in this process or in some other process, is holding a RESERVED, 6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** PENDING, or EXCLUSIVE lock on the file. It returns true 6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** if such a lock exists and false otherwise. 6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The xFileControl() method is a generic interface that allows custom 6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** VFS implementations to directly control an open file using the 6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_file_control()] interface. The second "op" argument is an 6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** integer opcode. The third argument is a generic pointer intended to 6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** point to a structure that may contain arguments or space in which to 6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** write return values. Potential uses for xFileControl() might be 6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** functions to enable blocking locks with timeouts, to change the 6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** locking strategy (for example to use dot-file locks), to inquire 6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** about the status of a lock, or to break stale locks. The SQLite 6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** core reserves all opcodes less than 100 for its own use. 6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available. 6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Applications that define a custom xFileControl method should use opcodes 6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** greater than 100 to avoid conflicts. VFS implementations should 6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** return [SQLITE_NOTFOUND] for file control opcodes that they do not 6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** recognize. 6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The xSectorSize() method returns the sector size of the 6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** device that underlies the file. The sector size is the 6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** minimum write that can be performed without disturbing 6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** other bytes in the file. The xDeviceCharacteristics() 6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** method returns a bit vector describing behaviors of the 6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** underlying device: 6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <ul> 6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_IOCAP_ATOMIC] 6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_IOCAP_ATOMIC512] 6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_IOCAP_ATOMIC1K] 6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_IOCAP_ATOMIC2K] 6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_IOCAP_ATOMIC4K] 6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_IOCAP_ATOMIC8K] 6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_IOCAP_ATOMIC16K] 6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_IOCAP_ATOMIC32K] 6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_IOCAP_ATOMIC64K] 6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_IOCAP_SAFE_APPEND] 6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_IOCAP_SEQUENTIAL] 6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </ul> 6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The SQLITE_IOCAP_ATOMIC property means that all writes of 6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values 6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** mean that writes of blocks that are nnn bytes in size and 6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are aligned to an address which is an integer multiple of 6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means 6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that when data is appended to a file, the data is appended 6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** first then the size of the file is extended, never the other 6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** way around. The SQLITE_IOCAP_SEQUENTIAL property means that 6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** information is written to disk in the same order as calls 6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to xWrite(). 6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill 6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in the unread portions of the buffer with zeros. A VFS that 6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** fails to zero-fill short reads might seem to work. However, 6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** failure to zero-fill short reads will eventually lead to 6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database corruption. 6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct sqlite3_io_methods sqlite3_io_methods; 6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct sqlite3_io_methods { 6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int iVersion; 6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xClose)(sqlite3_file*); 6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); 6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst); 6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xTruncate)(sqlite3_file*, sqlite3_int64 size); 6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xSync)(sqlite3_file*, int flags); 6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize); 6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xLock)(sqlite3_file*, int); 6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xUnlock)(sqlite3_file*, int); 6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xCheckReservedLock)(sqlite3_file*, int *pResOut); 6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xFileControl)(sqlite3_file*, int op, void *pArg); 6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xSectorSize)(sqlite3_file*); 6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xDeviceCharacteristics)(sqlite3_file*); 6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /* Methods above are valid for version 1 */ 6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**); 6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xShmLock)(sqlite3_file*, int offset, int n, int flags); 6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xShmBarrier)(sqlite3_file*); 6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xShmUnmap)(sqlite3_file*, int deleteFlag); 6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /* Methods above are valid for version 2 */ 6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /* Additional methods may be added in future releases */ 6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Standard File Control Opcodes 6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These integer constants are opcodes for the xFileControl method 6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()] 6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interface. 6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This 6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** opcode causes the xFileControl method to write the current state of 6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED], 6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE]) 6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** into an integer that the pArg argument points to. This capability 7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is used during testing and only needs to be supported when SQLITE_TEST 7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is defined. 7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS 7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** layer a hint of how large the database file will grow to be during the 7055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** current transaction. This hint is not guaranteed to be accurate but it 7065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is often close. The underlying VFS might choose to preallocate database 7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** file space based on this hint in order to help writes to the database 7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** file run faster. 7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS 7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** extends and truncates the database file in chunks of a size specified 7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by the user. The fourth argument to [sqlite3_file_control()] should 7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** point to an integer (type int) containing the new chunk-size to use 7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for the nominated database. Allocating database file space in large 7155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** chunks (say 1MB at a time), may reduce file-system fragmentation and 7165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** improve performance on some systems. 7175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 7185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer 7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to the [sqlite3_file] object associated with a particular database 7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** connection. See the [sqlite3_file_control()] documentation for 7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** additional information. 7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by 7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite and sent to all VFSes in place of a call to the xSync method 7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** when the database connection has [PRAGMA synchronous] set to OFF.)^ 7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Some specialized VFSes need this signal in order to operate correctly 7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most 7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** VFSes do not need this signal and should silently ignore this opcode. 7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Applications should not call [sqlite3_file_control()] with this 7305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** opcode as doing so may disrupt the operation of the specialized VFSes 7315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that do require it. 7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_FCNTL_LOCKSTATE 1 7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_GET_LOCKPROXYFILE 2 7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_SET_LOCKPROXYFILE 3 7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_LAST_ERRNO 4 7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_FCNTL_SIZE_HINT 5 7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_FCNTL_CHUNK_SIZE 6 7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_FCNTL_FILE_POINTER 7 7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_FCNTL_SYNC_OMITTED 8 7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Mutex Handle 7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The mutex module within SQLite defines [sqlite3_mutex] to be an 7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** abstract type for a mutex object. The SQLite core never looks 7485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** at the internal representation of an [sqlite3_mutex]. It only 7495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** deals with pointers to the [sqlite3_mutex] object. 7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Mutexes are created using [sqlite3_mutex_alloc()]. 7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct sqlite3_mutex sqlite3_mutex; 7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: OS Interface Object 7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** An instance of the sqlite3_vfs object defines the interface between 7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the SQLite core and the underlying operating system. The "vfs" 7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in the name of the object stands for "virtual file system". 7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The value of the iVersion field is initially 1 but may be larger in 7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** future versions of SQLite. Additional fields may be appended to this 7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** object when the iVersion value is increased. Note that the structure 7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of the sqlite3_vfs object changes in the transaction between 7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not 7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** modified. 7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The szOsFile field is the size of the subclassed [sqlite3_file] 7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** structure used by this VFS. mxPathname is the maximum length of 7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a pathname in this VFS. 7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Registered sqlite3_vfs objects are kept on a linked list formed by 7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the pNext pointer. The [sqlite3_vfs_register()] 7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and [sqlite3_vfs_unregister()] interfaces manage this list 7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in a thread-safe way. The [sqlite3_vfs_find()] interface 7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** searches the list. Neither the application code nor the VFS 7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** implementation should use the pNext pointer. 7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The pNext field is the only field in the sqlite3_vfs 7815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** structure that SQLite will ever modify. SQLite will only access 7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or modify this field while holding a particular static mutex. 7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The application should never modify anything within the sqlite3_vfs 7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** object once the object has been registered. 7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The zName field holds the name of the VFS module. The name must 7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** be unique across all VFS modules. 7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 7895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^SQLite guarantees that the zFilename parameter to xOpen 7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is either a NULL pointer or string obtained 7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** from xFullPathname() with an optional suffix added. 7925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If a suffix is added to the zFilename parameter, it will 7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** consist of a single "-" character followed by no more than 7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 10 alphanumeric and/or "-" characters. 7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^SQLite further guarantees that 7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the string will be valid and unchanged until xClose() is 7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** called. Because of the previous sentence, 7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the [sqlite3_file] can safely store a pointer to the 7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** filename if it needs to remember the filename for some reason. 8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If the zFilename parameter to xOpen is a NULL pointer then xOpen 8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** must invent its own temporary name for the file. ^Whenever the 8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** xFilename parameter is NULL it will also be the case that the 8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE]. 8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 8055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The flags argument to xOpen() includes all bits set in 8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()] 8075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or [sqlite3_open16()] is used, then flags includes at least 8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]. 8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If xOpen() opens a file read-only then it sets *pOutFlags to 8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set. 8115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(SQLite will also add one of the following flags to the xOpen() 8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** call, depending on the object being opened: 8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <ul> 8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_OPEN_MAIN_DB] 8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_OPEN_MAIN_JOURNAL] 8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_OPEN_TEMP_DB] 8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_OPEN_TEMP_JOURNAL] 8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_OPEN_TRANSIENT_DB] 8215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_OPEN_SUBJOURNAL] 8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_OPEN_MASTER_JOURNAL] 8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_OPEN_WAL] 8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </ul>)^ 8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The file I/O implementation can use the object type flags to 8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** change the way it deals with files. For example, an application 8285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that does not care about crash recovery or rollback might make 8295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the open of a journal file a no-op. Writes to this journal would 8305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** also be no-ops, and any attempt to read the journal would return 8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLITE_IOERR. Or the implementation might recognize that a database 8325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** file will be doing page-aligned sector reads and writes in a random 8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** order and set up its I/O subsystem accordingly. 8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 8355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite might also add one of the following flags to the xOpen method: 8365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 8375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <ul> 8385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_OPEN_DELETEONCLOSE] 8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_OPEN_EXCLUSIVE] 8405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </ul> 8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 8425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be 8435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE] 8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** will be set for TEMP databases and their journals, transient 8455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** databases, and subjournals. 8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 8475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction 8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** with the [SQLITE_OPEN_CREATE] flag, which are both directly 8495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** analogous to the O_EXCL and O_CREAT flags of the POSIX open() 8505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the 8515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLITE_OPEN_CREATE, is used to indicate that file should always 8525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** be created, and that it is an error if it already exists. 8535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** It is <i>not</i> used to indicate the file should be opened 8545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for exclusive access. 8555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 8565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^At least szOsFile bytes of memory are allocated by SQLite 8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to hold the [sqlite3_file] structure passed as the third 8585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** argument to xOpen. The xOpen method does not have to 8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** allocate the structure; it should just fill it in. Note that 8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the xOpen method must set the sqlite3_file.pMethods to either 8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a valid [sqlite3_io_methods] object or to NULL. xOpen must do 8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** this even if the open fails. SQLite expects that the sqlite3_file.pMethods 8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** element will be valid after xOpen returns regardless of the success 8645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or failure of the xOpen call. 8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 8665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] 8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to 8685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** test whether a file is readable and writable, or [SQLITE_ACCESS_READ] 8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to test whether a file is at least readable. The file can be a 8705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** directory. 8715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 8725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^SQLite will always allocate at least mxPathname+1 bytes for the 8735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** output buffer xFullPathname. The exact size of the output buffer 8745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is also passed as a parameter to both methods. If the output buffer 8755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is 8765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** handled as a fatal error by SQLite, vfs implementations should endeavor 8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to prevent this by setting mxPathname to a sufficiently large value. 8785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 8795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64() 8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interfaces are not strictly a part of the filesystem, but they are 8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** included in the VFS structure for completeness. 8825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The xRandomness() function attempts to return nBytes bytes 8835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of good-quality randomness into zOut. The return value is 8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the actual number of bytes of randomness obtained. 8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The xSleep() method causes the calling thread to sleep for at 8865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** least the number of microseconds given. ^The xCurrentTime() 8875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** method returns a Julian Day Number for the current date and time as 8885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a floating point value. 8895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The xCurrentTimeInt64() method returns, as an integer, the Julian 8905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Day Number multipled by 86400000 (the number of milliseconds in 8915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a 24-hour day). 8925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^SQLite will use the xCurrentTimeInt64() method to get the current 8935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** date and time if that method is available (if iVersion is 2 or 8945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** greater and the function pointer is not NULL) and will fall back 8955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to xCurrentTime() if xCurrentTimeInt64() is unavailable. 8965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 8975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces 8985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are not used by the SQLite core. These optional interfaces are provided 8995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by some VFSes to facilitate testing of the VFS code. By overriding 9005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** system calls with functions under its control, a test program can 9015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** simulate faults and error conditions that would otherwise be difficult 9025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or impossible to induce. The set of system calls that can be overridden 9035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** varies from one VFS to another, and from one version of the same VFS to the 9045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** next. Applications that use these interfaces must be prepared for any 9055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or all of these interfaces to be NULL or for their behavior to change 9065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** from one release to the next. Applications must not attempt to access 9075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** any of these methods if the iVersion of the VFS is less than 3. 9085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 9095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct sqlite3_vfs sqlite3_vfs; 9105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef void (*sqlite3_syscall_ptr)(void); 9115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct sqlite3_vfs { 9125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int iVersion; /* Structure version number (currently 3) */ 9135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int szOsFile; /* Size of subclassed sqlite3_file */ 9145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int mxPathname; /* Maximum file pathname length */ 9155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3_vfs *pNext; /* Next registered VFS */ 9165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zName; /* Name of this virtual file system */ 9175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void *pAppData; /* Pointer to application-specific data */ 9185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*, 9195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int flags, int *pOutFlags); 9205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir); 9215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut); 9225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut); 9235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename); 9245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg); 9255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void); 9265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xDlClose)(sqlite3_vfs*, void*); 9275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut); 9285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xSleep)(sqlite3_vfs*, int microseconds); 9295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xCurrentTime)(sqlite3_vfs*, double*); 9305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xGetLastError)(sqlite3_vfs*, int, char *); 9315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /* 9325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ** The methods above are in version 1 of the sqlite_vfs object 9335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ** definition. Those that follow are added in version 2 or later 9345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 9355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*); 9365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /* 9375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ** The methods above are in versions 1 and 2 of the sqlite_vfs object. 9385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ** Those below are for version 3 and greater. 9395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 9405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr); 9415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName); 9425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName); 9435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /* 9445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ** The methods above are in versions 1 through 3 of the sqlite_vfs object. 9455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ** New fields may be appended in figure versions. The iVersion 9465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ** value will increment whenever this happens. 9475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 9485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 9495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 9515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Flags for the xAccess VFS method 9525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 9535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These integer constants can be used as the third parameter to 9545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the xAccess method of an [sqlite3_vfs] object. They determine 9555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** what kind of permissions the xAccess method is looking for. 9565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** With SQLITE_ACCESS_EXISTS, the xAccess method 9575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** simply checks whether the file exists. 9585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** With SQLITE_ACCESS_READWRITE, the xAccess method 9595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** checks whether the named directory is both readable and writable 9605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** (in other words, if files can be added, removed, and renamed within 9615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the directory). 9625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The SQLITE_ACCESS_READWRITE constant is currently used only by the 9635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [temp_store_directory pragma], though this could change in a future 9645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** release of SQLite. 9655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** With SQLITE_ACCESS_READ, the xAccess method 9665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** checks whether the file is readable. The SQLITE_ACCESS_READ constant is 9675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** currently unused, though it might be used in a future release of 9685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite. 9695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 9705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_ACCESS_EXISTS 0 9715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */ 9725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_ACCESS_READ 2 /* Unused */ 9735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 9755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Flags for the xShmLock VFS method 9765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 9775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These integer constants define the various locking operations 9785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** allowed by the xShmLock method of [sqlite3_io_methods]. The 9795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** following are the only legal combinations of flags to the 9805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** xShmLock method: 9815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 9825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <ul> 9835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> SQLITE_SHM_LOCK | SQLITE_SHM_SHARED 9845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE 9855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED 9865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE 9875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </ul> 9885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 9895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as 9905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** was given no the corresponding lock. 9915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 9925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The xShmLock method can transition between unlocked and SHARED or 9935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** between unlocked and EXCLUSIVE. It cannot transition between SHARED 9945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and EXCLUSIVE. 9955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 9965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_SHM_UNLOCK 1 9975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_SHM_LOCK 2 9985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_SHM_SHARED 4 9995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_SHM_EXCLUSIVE 8 10005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 10025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Maximum xShmLock index 10035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 10045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The xShmLock method on [sqlite3_io_methods] may use values 10055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** between 0 and this upper bound as its "offset" argument. 10065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The SQLite core will never attempt to acquire or release a 10075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** lock outside of this range 10085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 10095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_SHM_NLOCK 8 10105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 10135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Initialize The SQLite Library 10145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 10155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_initialize() routine initializes the 10165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite library. ^The sqlite3_shutdown() routine 10175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** deallocates any resources that were allocated by sqlite3_initialize(). 10185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These routines are designed to aid in process initialization and 10195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** shutdown on embedded systems. Workstation applications using 10205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite normally do not need to invoke either of these routines. 10215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 10225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** A call to sqlite3_initialize() is an "effective" call if it is 10235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the first time sqlite3_initialize() is invoked during the lifetime of 10245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the process, or if it is the first time sqlite3_initialize() is invoked 10255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** following a call to sqlite3_shutdown(). ^(Only an effective call 10265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of sqlite3_initialize() does any initialization. All other calls 10275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are harmless no-ops.)^ 10285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 10295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** A call to sqlite3_shutdown() is an "effective" call if it is the first 10305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** call to sqlite3_shutdown() since the last sqlite3_initialize(). ^(Only 10315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** an effective call to sqlite3_shutdown() does any deinitialization. 10325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^ 10335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 10345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown() 10355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is not. The sqlite3_shutdown() interface must only be called from a 10365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** single thread. All open [database connections] must be closed and all 10375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** other SQLite resources must be deallocated prior to invoking 10385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_shutdown(). 10395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 10405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Among other things, ^sqlite3_initialize() will invoke 10415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_os_init(). Similarly, ^sqlite3_shutdown() 10425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** will invoke sqlite3_os_end(). 10435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 10445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success. 10455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If for some reason, sqlite3_initialize() is unable to initialize 10465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the library (perhaps it is unable to allocate a needed resource such 10475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** as a mutex) it returns an [error code] other than [SQLITE_OK]. 10485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 10495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_initialize() routine is called internally by many other 10505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite interfaces so that an application usually does not need to 10515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** invoke sqlite3_initialize() directly. For example, [sqlite3_open()] 10525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** calls sqlite3_initialize() so the SQLite library will be automatically 10535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** initialized when [sqlite3_open()] is called if it has not be initialized 10545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT] 10555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** compile-time option, then the automatic calls to sqlite3_initialize() 10565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are omitted and the application must call sqlite3_initialize() directly 10575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** prior to using any other SQLite interface. For maximum portability, 10585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** it is recommended that applications always invoke sqlite3_initialize() 10595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** directly prior to using any other SQLite interface. Future releases 10605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of SQLite may require this. In other words, the behavior exhibited 10615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the 10625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** default behavior in some future release of SQLite. 10635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 10645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The sqlite3_os_init() routine does operating-system specific 10655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** initialization of the SQLite library. The sqlite3_os_end() 10665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** routine undoes the effect of sqlite3_os_init(). Typical tasks 10675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** performed by these routines include allocation or deallocation 10685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of static resources, initialization of global variables, 10695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** setting up a default [sqlite3_vfs] module, or setting up 10705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a default configuration using [sqlite3_config()]. 10715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 10725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The application should never invoke either sqlite3_os_init() 10735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or sqlite3_os_end() directly. The application should only invoke 10745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init() 10755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interface is called automatically by sqlite3_initialize() and 10765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate 10775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** implementations for sqlite3_os_init() and sqlite3_os_end() 10785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are built into SQLite when it is compiled for Unix, Windows, or OS/2. 10795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** When [custom builds | built for other platforms] 10805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** (using the [SQLITE_OS_OTHER=1] compile-time 10815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** option) the application must supply a suitable implementation for 10825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_os_init() and sqlite3_os_end(). An application-supplied 10835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** implementation of sqlite3_os_init() or sqlite3_os_end() 10845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** must return [SQLITE_OK] on success and some other [error code] upon 10855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** failure. 10865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 10875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_initialize(void); 10885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_shutdown(void); 10895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_os_init(void); 10905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_os_end(void); 10915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 10935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Configuring The SQLite Library 10945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 10955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The sqlite3_config() interface is used to make global configuration 10965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** changes to SQLite in order to tune SQLite to the specific needs of 10975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the application. The default configuration is recommended for most 10985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** applications and so this routine is usually not necessary. It is 10995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** provided to support rare applications with unusual needs. 11005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 11015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The sqlite3_config() interface is not threadsafe. The application 11025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** must insure that no other SQLite interfaces are invoked by other 11035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** threads while sqlite3_config() is running. Furthermore, sqlite3_config() 11045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** may only be invoked prior to library initialization using 11055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. 11065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If sqlite3_config() is called after [sqlite3_initialize()] and before 11075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. 11085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Note, however, that ^sqlite3_config() can be called as part of the 11095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** implementation of an application-defined [sqlite3_os_init()]. 11105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 11115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The first argument to sqlite3_config() is an integer 11125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_CONFIG_SINGLETHREAD | configuration option] that determines 11135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** what property of SQLite is to be configured. Subsequent arguments 11145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option] 11155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in the first argument. 11165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 11175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. 11185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the option is unknown or SQLite is unable to set the option 11195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then this routine returns a non-zero [error code]. 11205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 11215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_config(int, ...); 11225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 11245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Configure database connections 11255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 11265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The sqlite3_db_config() interface is used to make configuration 11275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** changes to a [database connection]. The interface is similar to 11285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_config()] except that the changes apply to a single 11295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [database connection] (specified in the first argument). 11305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 11315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The second argument to sqlite3_db_config(D,V,...) is the 11325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code 11335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that indicates what aspect of the [database connection] is being configured. 11345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Subsequent arguments vary depending on the configuration verb. 11355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 11365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if 11375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the call is considered successful. 11385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 11395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_db_config(sqlite3*, int op, ...); 11405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 11425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Memory Allocation Routines 11435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 11445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** An instance of this object defines the interface between SQLite 11455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and low-level memory allocation routines. 11465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 11475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This object is used in only one place in the SQLite interface. 11485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** A pointer to an instance of this object is the argument to 11495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_config()] when the configuration option is 11505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC]. 11515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** By creating an instance of this object 11525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC]) 11535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** during configuration, an application can specify an alternative 11545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** memory allocation subsystem for SQLite to use for all of its 11555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** dynamic memory needs. 11565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 11575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Note that SQLite comes with several [built-in memory allocators] 11585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that are perfectly adequate for the overwhelming majority of applications 11595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and that this object is only useful to a tiny minority of applications 11605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** with specialized memory allocation requirements. This object is 11615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** also used during testing of SQLite in order to specify an alternative 11625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** memory allocator that simulates memory out-of-memory conditions in 11635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** order to verify that SQLite recovers gracefully from such 11645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** conditions. 11655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 11665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The xMalloc and xFree methods must work like the 11675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** malloc() and free() functions from the standard C library. 11685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The xRealloc method must work like realloc() from the standard C library 11695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** with the exception that if the second argument to xRealloc is zero, 11705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** xRealloc must be a no-op - it must not perform any allocation or 11715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** deallocation. ^SQLite guarantees that the second argument to 11725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** xRealloc is always a value returned by a prior call to xRoundup. 11735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** And so in cases where xRoundup always returns a positive number, 11745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** xRealloc can perform exactly as the standard library realloc() and 11755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** still be in compliance with this specification. 11765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 11775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** xSize should return the allocated size of a memory allocation 11785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** previously obtained from xMalloc or xRealloc. The allocated size 11795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is always at least as big as the requested size but may be larger. 11805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 11815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The xRoundup method returns what would be the allocated size of 11825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a memory allocation given a particular requested size. Most memory 11835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** allocators round up memory allocations at least to the next multiple 11845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of 8. Some allocators round up to a larger multiple or to a power of 2. 11855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Every memory allocation request coming in through [sqlite3_malloc()] 11865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0, 11875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that causes the corresponding memory allocation to fail. 11885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 11895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The xInit method initializes the memory allocator. (For example, 11905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** it might allocate any require mutexes or initialize internal data 11915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** structures. The xShutdown method is invoked (indirectly) by 11925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_shutdown()] and should deallocate any resources acquired 11935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by xInit. The pAppData pointer is used as the only parameter to 11945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** xInit and xShutdown. 11955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 11965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes 11975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the xInit method, so the xInit method need not be threadsafe. The 11985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** xShutdown method is only called from [sqlite3_shutdown()] so it does 11995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** not need to be threadsafe either. For all other methods, SQLite 12005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the 12015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which 12025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** it is by default) and so the methods are automatically serialized. 12035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other 12045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** methods must be threadsafe or else make their own arrangements for 12055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** serialization. 12065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 12075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite will never invoke xInit() more than once without an intervening 12085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** call to xShutdown(). 12095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 12105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct sqlite3_mem_methods sqlite3_mem_methods; 12115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct sqlite3_mem_methods { 12125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void *(*xMalloc)(int); /* Memory allocation function */ 12135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xFree)(void*); /* Free a prior allocation */ 12145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void *(*xRealloc)(void*,int); /* Resize an allocation */ 12155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xSize)(void*); /* Return the size of an allocation */ 12165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xRoundup)(int); /* Round up request size to allocation size */ 12175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xInit)(void*); /* Initialize the memory allocator */ 12185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xShutdown)(void*); /* Deinitialize the memory allocator */ 12195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void *pAppData; /* Argument to xInit() and xShutdown() */ 12205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 12215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 12225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 12235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Configuration Options 12245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 12255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These constants are the available integer configuration options that 12265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** can be passed as the first argument to the [sqlite3_config()] interface. 12275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 12285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** New configuration options may be added in future releases of SQLite. 12295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Existing configuration options might be discontinued. Applications 12305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** should check the return code from [sqlite3_config()] to make sure that 12315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the call worked. The [sqlite3_config()] interface will return a 12325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** non-zero [error code] if a discontinued or unsupported configuration option 12335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is invoked. 12345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 12355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dl> 12365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_CONFIG_SINGLETHREAD</dt> 12375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>There are no arguments to this option. ^This option sets the 12385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [threading mode] to Single-thread. In other words, it disables 12395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** all mutexing and puts SQLite into a mode where it can only be used 12405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by a single thread. ^If SQLite is compiled with 12415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 12425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** it is not possible to change the [threading mode] from its default 12435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** value of Single-thread and so [sqlite3_config()] will return 12445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD 12455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** configuration option.</dd> 12465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 12475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_CONFIG_MULTITHREAD</dt> 12485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>There are no arguments to this option. ^This option sets the 12495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [threading mode] to Multi-thread. In other words, it disables 12505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** mutexing on [database connection] and [prepared statement] objects. 12515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The application is responsible for serializing access to 12525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [database connections] and [prepared statements]. But other mutexes 12535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are enabled so that SQLite will be safe to use in a multi-threaded 12545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** environment as long as no two threads attempt to use the same 12555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [database connection] at the same time. ^If SQLite is compiled with 12565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 12575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** it is not possible to set the Multi-thread [threading mode] and 12585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_config()] will return [SQLITE_ERROR] if called with the 12595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLITE_CONFIG_MULTITHREAD configuration option.</dd> 12605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 12615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_CONFIG_SERIALIZED</dt> 12625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>There are no arguments to this option. ^This option sets the 12635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [threading mode] to Serialized. In other words, this option enables 12645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** all mutexes including the recursive 12655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** mutexes on [database connection] and [prepared statement] objects. 12665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** In this mode (which is the default when SQLite is compiled with 12675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access 12685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to [database connections] and [prepared statements] so that the 12695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** application is free to use the same [database connection] or the 12705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** same [prepared statement] in different threads at the same time. 12715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If SQLite is compiled with 12725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 12735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** it is not possible to set the Serialized [threading mode] and 12745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_config()] will return [SQLITE_ERROR] if called with the 12755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLITE_CONFIG_SERIALIZED configuration option.</dd> 12765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 12775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_CONFIG_MALLOC</dt> 12785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd> ^(This option takes a single argument which is a pointer to an 12795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** instance of the [sqlite3_mem_methods] structure. The argument specifies 12805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** alternative low-level memory allocation routines to be used in place of 12815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the memory allocation routines built into SQLite.)^ ^SQLite makes 12825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** its own private copy of the content of the [sqlite3_mem_methods] structure 12835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** before the [sqlite3_config()] call returns.</dd> 12845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 12855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_CONFIG_GETMALLOC</dt> 12865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd> ^(This option takes a single argument which is a pointer to an 12875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods] 12885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** structure is filled with the currently defined memory allocation routines.)^ 12895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This option can be used to overload the default memory allocation 12905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** routines with a wrapper that simulations memory allocation failure or 12915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** tracks memory usage, for example. </dd> 12925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 12935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_CONFIG_MEMSTATUS</dt> 12945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd> ^This option takes single argument of type int, interpreted as a 12955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** boolean, which enables or disables the collection of memory allocation 12965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** statistics. ^(When memory allocation statistics are disabled, the 12975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** following SQLite interfaces become non-operational: 12985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <ul> 12995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [sqlite3_memory_used()] 13005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [sqlite3_memory_highwater()] 13015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [sqlite3_soft_heap_limit64()] 13025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [sqlite3_status()] 13035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </ul>)^ 13045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Memory allocation statistics are enabled by default unless SQLite is 13055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory 13065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** allocation statistics are disabled by default. 13075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </dd> 13085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 13095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_CONFIG_SCRATCH</dt> 13105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd> ^This option specifies a static memory buffer that SQLite can use for 13115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** scratch memory. There are three arguments: A pointer an 8-byte 13125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** aligned memory buffer from which the scratch allocations will be 13135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** drawn, the size of each scratch allocation (sz), 13145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and the maximum number of scratch allocations (N). The sz 13155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** argument must be a multiple of 16. 13165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The first argument must be a pointer to an 8-byte aligned buffer 13175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of at least sz*N bytes of memory. 13185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^SQLite will use no more than two scratch buffers per thread. So 13195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** N should be set to twice the expected maximum number of threads. 13205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^SQLite will never require a scratch buffer that is more than 6 13215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** times the database page size. ^If SQLite needs needs additional 13225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** scratch memory beyond what is provided by this configuration option, then 13235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_malloc()] will be used to obtain the memory needed.</dd> 13245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 13255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_CONFIG_PAGECACHE</dt> 13265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd> ^This option specifies a static memory buffer that SQLite can use for 13275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the database page cache with the default page cache implemenation. 13285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This configuration should not be used if an application-define page 13295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option. 13305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** There are three arguments to this option: A pointer to 8-byte aligned 13315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** memory, the size of each page buffer (sz), and the number of pages (N). 13325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The sz argument should be the size of the largest database page 13335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** (a power of two between 512 and 32768) plus a little extra for each 13345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** page header. ^The page header size is 20 to 40 bytes depending on 13355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the host architecture. ^It is harmless, apart from the wasted memory, 13365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to make sz a little too large. The first 13375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** argument should point to an allocation of at least sz*N bytes of memory. 13385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^SQLite will use the memory provided by the first argument to satisfy its 13395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** memory needs for the first N pages that it adds to cache. ^If additional 13405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** page cache memory is needed beyond what is provided by this option, then 13415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite goes to [sqlite3_malloc()] for the additional storage space. 13425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The pointer in the first argument must 13435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** be aligned to an 8-byte boundary or subsequent behavior of SQLite 13445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** will be undefined.</dd> 13455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 13465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_CONFIG_HEAP</dt> 13475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd> ^This option specifies a static memory buffer that SQLite will use 13485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for all of its dynamic memory allocation needs beyond those provided 13495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. 13505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** There are three arguments: An 8-byte aligned pointer to the memory, 13515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the number of bytes in the memory buffer, and the minimum allocation size. 13525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts 13535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to using its default memory allocator (the system malloc() implementation), 13545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the 13555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or 13565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory 13575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** allocator is engaged to handle all of SQLites memory allocation needs. 13585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The first pointer (the memory pointer) must be aligned to an 8-byte 13595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** boundary or subsequent behavior of SQLite will be undefined. 13605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The minimum allocation size is capped at 2^12. Reasonable values 13615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for the minimum allocation size are 2^5 through 2^8.</dd> 13625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 13635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_CONFIG_MUTEX</dt> 13645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd> ^(This option takes a single argument which is a pointer to an 13655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** instance of the [sqlite3_mutex_methods] structure. The argument specifies 13665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** alternative low-level mutex routines to be used in place 13675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the 13685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** content of the [sqlite3_mutex_methods] structure before the call to 13695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_config()] returns. ^If SQLite is compiled with 13705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 13715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the entire mutexing subsystem is omitted from the build and hence calls to 13725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will 13735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** return [SQLITE_ERROR].</dd> 13745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 13755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_CONFIG_GETMUTEX</dt> 13765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd> ^(This option takes a single argument which is a pointer to an 13775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** instance of the [sqlite3_mutex_methods] structure. The 13785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_mutex_methods] 13795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** structure is filled with the currently defined mutex routines.)^ 13805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This option can be used to overload the default mutex allocation 13815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** routines with a wrapper used to track mutex usage for performance 13825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** profiling or testing, for example. ^If SQLite is compiled with 13835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 13845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the entire mutexing subsystem is omitted from the build and hence calls to 13855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will 13865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** return [SQLITE_ERROR].</dd> 13875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 13885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_CONFIG_LOOKASIDE</dt> 13895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd> ^(This option takes two arguments that determine the default 13905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** memory allocation for the lookaside memory allocator on each 13915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [database connection]. The first argument is the 13925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** size of each lookaside buffer slot and the second is the number of 13935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** slots allocated to each database connection.)^ ^(This option sets the 13945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] 13955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** verb to [sqlite3_db_config()] can be used to change the lookaside 13965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** configuration on individual connections.)^ </dd> 13975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 13985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_CONFIG_PCACHE</dt> 13995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd> ^(This option takes a single argument which is a pointer to 14005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** an [sqlite3_pcache_methods] object. This object specifies the interface 14015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to a custom page cache implementation.)^ ^SQLite makes a copy of the 14025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** object and uses it for page cache memory allocations.</dd> 14035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 14045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_CONFIG_GETPCACHE</dt> 14055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd> ^(This option takes a single argument which is a pointer to an 14065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_pcache_methods] object. SQLite copies of the current 14075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** page cache implementation into that object.)^ </dd> 14085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 14095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_CONFIG_LOG</dt> 14105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a 14115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function with a call signature of void(*)(void*,int,const char*), 14125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and a pointer to void. ^If the function pointer is not NULL, it is 14135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** invoked by [sqlite3_log()] to process each logging event. ^If the 14145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op. 14155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is 14165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** passed through as the first parameter to the application-defined logger 14175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function whenever that function is invoked. ^The second parameter to 14185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the logger function is a copy of the first parameter to the corresponding 14195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_log()] call and is intended to be a [result code] or an 14205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [extended result code]. ^The third parameter passed to the logger is 14215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** log message after formatting via [sqlite3_snprintf()]. 14225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The SQLite logging interface is not reentrant; the logger function 14235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** supplied by the application must not invoke any SQLite interface. 14245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** In a multi-threaded application, the application-defined logger 14255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function must be threadsafe. </dd> 14265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 14275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </dl> 14285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 14295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ 14305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ 14315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CONFIG_SERIALIZED 3 /* nil */ 14325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ 14335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ 14345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */ 14355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ 14365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ 14375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ 14385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ 14395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ 14405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ 14415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ 14425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */ 14435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */ 14445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ 14455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 14475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Database Connection Configuration Options 14485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 14495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These constants are the available integer configuration options that 14505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** can be passed as the second argument to the [sqlite3_db_config()] interface. 14515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 14525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** New configuration options may be added in future releases of SQLite. 14535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Existing configuration options might be discontinued. Applications 14545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** should check the return code from [sqlite3_db_config()] to make sure that 14555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the call worked. ^The [sqlite3_db_config()] interface will return a 14565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** non-zero [error code] if a discontinued or unsupported configuration option 14575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is invoked. 14585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 14595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dl> 14605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt> 14615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd> ^This option takes three additional arguments that determine the 14625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [lookaside memory allocator] configuration for the [database connection]. 14635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The first argument (the third parameter to [sqlite3_db_config()] is a 14645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** pointer to a memory buffer to use for lookaside memory. 14655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb 14665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** may be NULL in which case SQLite will allocate the 14675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the 14685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** size of each lookaside buffer slot. ^The third argument is the number of 14695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** slots. The size of the buffer in the first argument must be greater than 14705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or equal to the product of the second and third arguments. The buffer 14715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** must be aligned to an 8-byte boundary. ^If the second argument to 14725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally 14735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** rounded down to the next smaller multiple of 8. ^(The lookaside memory 14745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** configuration for a database connection can only be changed when that 14755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** connection is not currently using lookaside memory, or in other words 14765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** when the "current value" returned by 14775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero. 14785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Any attempt to change the lookaside memory configuration when lookaside 14795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** memory is in use leaves the configuration unchanged and returns 14805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_BUSY].)^</dd> 14815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 14825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt> 14835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd> ^This option is used to enable or disable the enforcement of 14845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [foreign key constraints]. There should be two additional arguments. 14855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The first argument is an integer which is 0 to disable FK enforcement, 14865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** positive to enable FK enforcement or negative to leave FK enforcement 14875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** unchanged. The second parameter is a pointer to an integer into which 14885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is written 0 or 1 to indicate whether FK enforcement is off or on 14895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** following this call. The second parameter may be a NULL pointer, in 14905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** which case the FK enforcement setting is not reported back. </dd> 14915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 14925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt> 14935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers]. 14945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** There should be two additional arguments. 14955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The first argument is an integer which is 0 to disable triggers, 14965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** positive to enable triggers or negative to leave the setting unchanged. 14975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The second parameter is a pointer to an integer into which 14985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is written 0 or 1 to indicate whether triggers are disabled or enabled 14995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** following this call. The second parameter may be a NULL pointer, in 15005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** which case the trigger setting is not reported back. </dd> 15015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 15025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </dl> 15035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 15045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */ 15055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */ 15065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */ 15075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 15105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Enable Or Disable Extended Result Codes 15115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 15125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_extended_result_codes() routine enables or disables the 15135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [extended result codes] feature of SQLite. ^The extended result 15145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** codes are disabled by default for historical compatibility. 15155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 15165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_extended_result_codes(sqlite3*, int onoff); 15175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 15195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Last Insert Rowid 15205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 15215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Each entry in an SQLite table has a unique 64-bit signed 15225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** integer key called the [ROWID | "rowid"]. ^The rowid is always available 15235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** as an undeclared column named ROWID, OID, or _ROWID_ as long as those 15245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** names are not also used by explicitly declared columns. ^If 15255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the table has a column of type [INTEGER PRIMARY KEY] then that column 15265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is another alias for the rowid. 15275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 15285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This routine returns the [rowid] of the most recent 15295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** successful [INSERT] into the database from the [database connection] 15305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in the first argument. ^If no successful [INSERT]s 15315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** have ever occurred on that database connection, zero is returned. 15325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 15335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(If an [INSERT] occurs within a trigger, then the [rowid] of the inserted 15345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** row is returned by this routine as long as the trigger is running. 15355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** But once the trigger terminates, the value returned by this routine 15365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** reverts to the last value inserted before the trigger fired.)^ 15375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 15385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^An [INSERT] that fails due to a constraint violation is not a 15395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** successful [INSERT] and does not change the value returned by this 15405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, 15415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and INSERT OR ABORT make no changes to the return value of this 15425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** routine when their insertion fails. ^(When INSERT OR REPLACE 15435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** encounters a constraint violation, it does not fail. The 15445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** INSERT continues to completion after deleting rows that caused 15455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the constraint problem so INSERT OR REPLACE will always change 15465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the return value of this interface.)^ 15475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 15485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^For the purposes of this routine, an [INSERT] is considered to 15495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** be successful even if it is subsequently rolled back. 15505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 15515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This function is accessible to SQL statements via the 15525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [last_insert_rowid() SQL function]. 15535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 15545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If a separate thread performs a new [INSERT] on the same 15555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database connection while the [sqlite3_last_insert_rowid()] 15565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function is running and thus changes the last insert [rowid], 15575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then the value returned by [sqlite3_last_insert_rowid()] is 15585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** unpredictable and might not equal either the old or the new 15595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** last insert [rowid]. 15605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 15615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); 15625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 15645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Count The Number Of Rows Modified 15655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 15665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This function returns the number of database rows that were changed 15675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or inserted or deleted by the most recently completed SQL statement 15685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** on the [database connection] specified by the first parameter. 15695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(Only changes that are directly specified by the [INSERT], [UPDATE], 15705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or [DELETE] statement are counted. Auxiliary changes caused by 15715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** triggers or [foreign key actions] are not counted.)^ Use the 15725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_total_changes()] function to find the total number of changes 15735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** including changes caused by triggers and foreign key actions. 15745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 15755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Changes to a view that are simulated by an [INSTEAD OF trigger] 15765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are not counted. Only real table changes are counted. 15775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 15785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(A "row change" is a change to a single row of a single table 15795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** caused by an INSERT, DELETE, or UPDATE statement. Rows that 15805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are changed as side effects of [REPLACE] constraint resolution, 15815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** rollback, ABORT processing, [DROP TABLE], or by any other 15825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** mechanisms do not count as direct row changes.)^ 15835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 15845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** A "trigger context" is a scope of execution that begins and 15855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ends with the script of a [CREATE TRIGGER | trigger]. 15865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Most SQL statements are 15875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** evaluated outside of any trigger. This is the "top level" 15885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** trigger context. If a trigger fires from the top level, a 15895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** new trigger context is entered for the duration of that one 15905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** trigger. Subtriggers create subcontexts for their duration. 15915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 15925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does 15935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** not create a new trigger context. 15945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 15955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This function returns the number of direct row changes in the 15965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** most recent INSERT, UPDATE, or DELETE statement within the same 15975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** trigger context. 15985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 15995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Thus, when called from the top level, this function returns the 16005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** number of changes in the most recent INSERT, UPDATE, or DELETE 16015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that also occurred at the top level. ^(Within the body of a trigger, 16025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the sqlite3_changes() interface can be called to find the number of 16035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** changes in the most recently completed INSERT, UPDATE, or DELETE 16045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** statement within the body of the same trigger. 16055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** However, the number returned does not include changes 16065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** caused by subtriggers since those have their own context.)^ 16075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 16085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also the [sqlite3_total_changes()] interface, the 16095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [count_changes pragma], and the [changes() SQL function]. 16105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 16115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If a separate thread makes changes on the same database connection 16125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** while [sqlite3_changes()] is running then the value returned 16135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is unpredictable and not meaningful. 16145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 16155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_changes(sqlite3*); 16165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 16175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 16185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Total Number Of Rows Modified 16195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 16205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This function returns the number of row changes caused by [INSERT], 16215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [UPDATE] or [DELETE] statements since the [database connection] was opened. 16225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The count returned by sqlite3_total_changes() includes all changes 16235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** from all [CREATE TRIGGER | trigger] contexts and changes made by 16245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [foreign key actions]. However, 16255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the count does not include changes used to implement [REPLACE] constraints, 16265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** do rollbacks or ABORT processing, or [DROP TABLE] processing. The 16275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** count does not include rows of views that fire an [INSTEAD OF trigger], 16285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** though if the INSTEAD OF trigger makes changes of its own, those changes 16295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are counted.)^ 16305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_total_changes() function counts the changes as soon as 16315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the statement that makes them is completed (when the statement handle 16325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is passed to [sqlite3_reset()] or [sqlite3_finalize()]). 16335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 16345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also the [sqlite3_changes()] interface, the 16355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [count_changes pragma], and the [total_changes() SQL function]. 16365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 16375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If a separate thread makes changes on the same database connection 16385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** while [sqlite3_total_changes()] is running then the value 16395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** returned is unpredictable and not meaningful. 16405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 16415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_total_changes(sqlite3*); 16425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 16435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 16445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Interrupt A Long-Running Query 16455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 16465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This function causes any pending database operation to abort and 16475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** return at its earliest opportunity. This routine is typically 16485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** called in response to a user action such as pressing "Cancel" 16495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or Ctrl-C where the user wants a long query operation to halt 16505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** immediately. 16515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 16525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^It is safe to call this routine from a thread different from the 16535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** thread that is currently running the database operation. But it 16545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is not safe to call this routine with a [database connection] that 16555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is closed or might close before sqlite3_interrupt() returns. 16565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 16575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If an SQL operation is very nearly finished at the time when 16585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_interrupt() is called, then it might not have an opportunity 16595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to be interrupted and might continue to completion. 16605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 16615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT]. 16625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE 16635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that is inside an explicit transaction, then the entire transaction 16645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** will be rolled back automatically. 16655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 16665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_interrupt(D) call is in effect until all currently running 16675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQL statements on [database connection] D complete. ^Any new SQL statements 16685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that are started after the sqlite3_interrupt() call and before the 16695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** running statements reaches zero are interrupted as if they had been 16705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** running prior to the sqlite3_interrupt() call. ^New SQL statements 16715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that are started after the running statement count reaches zero are 16725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** not effected by the sqlite3_interrupt(). 16735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^A call to sqlite3_interrupt(D) that occurs when there are no running 16745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQL statements is a no-op and has no effect on SQL statements 16755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that are started after the sqlite3_interrupt() call returns. 16765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 16775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If the database connection closes while [sqlite3_interrupt()] 16785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is running then bad things will likely happen. 16795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 16805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_interrupt(sqlite3*); 16815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 16825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 16835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Determine If An SQL Statement Is Complete 16845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 16855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These routines are useful during command-line input to determine if the 16865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** currently entered text seems to form a complete SQL statement or 16875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** if additional input is needed before sending the text into 16885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite for parsing. ^These routines return 1 if the input string 16895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** appears to be a complete SQL statement. ^A statement is judged to be 16905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** complete if it ends with a semicolon token and is not a prefix of a 16915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within 16925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** string literals or quoted identifier names or comments are not 16935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** independent tokens (they are part of the token in which they are 16945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** embedded) and thus do not count as a statement terminator. ^Whitespace 16955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and comments that follow the final semicolon are ignored. 16965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 16975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^These routines return 0 if the statement is incomplete. ^If a 16985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** memory allocation fails, then SQLITE_NOMEM is returned. 16995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 17005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^These routines do not parse the SQL statements thus 17015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** will not detect syntactically incorrect SQL. 17025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 17035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior 17045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked 17055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** automatically by sqlite3_complete16(). If that initialization fails, 17065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then the return value from sqlite3_complete16() will be non-zero 17075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** regardless of whether or not the input SQL is complete.)^ 17085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 17095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The input to [sqlite3_complete()] must be a zero-terminated 17105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** UTF-8 string. 17115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 17125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The input to [sqlite3_complete16()] must be a zero-terminated 17135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** UTF-16 string in native byte order. 17145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 17155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_complete(const char *sql); 17165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_complete16(const void *sql); 17175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 17185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 17195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors 17205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 17215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This routine sets a callback function that might be invoked whenever 17225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** an attempt is made to open a database table that another thread 17235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or process has locked. 17245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 17255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] 17265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is returned immediately upon encountering the lock. ^If the busy callback 17275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is not NULL, then the callback might be invoked with two arguments. 17285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 17295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The first argument to the busy handler is a copy of the void* pointer which 17305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is the third argument to sqlite3_busy_handler(). ^The second argument to 17315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the busy handler callback is the number of times that the busy handler has 17325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** been invoked for this locking event. ^If the 17335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** busy callback returns 0, then no additional attempts are made to 17345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned. 17355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the callback returns non-zero, then another attempt 17365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is made to open the database for reading and the cycle repeats. 17375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 17385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The presence of a busy handler does not guarantee that it will be invoked 17395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** when there is lock contention. ^If SQLite determines that invoking the busy 17405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY] 17415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler. 17425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Consider a scenario where one process is holding a read lock that 17435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** it is trying to promote to a reserved lock and 17445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a second process is holding a reserved lock that it is trying 17455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to promote to an exclusive lock. The first process cannot proceed 17465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** because it is blocked by the second and the second process cannot 17475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** proceed because it is blocked by the first. If both processes 17485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** invoke the busy handlers, neither will make any progress. Therefore, 17495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite returns [SQLITE_BUSY] for the first process, hoping that this 17505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** will induce the first process to release its read lock and allow 17515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the second process to proceed. 17525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 17535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The default busy callback is NULL. 17545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 17555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED] 17565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** when SQLite is in the middle of a large transaction where all the 17575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** changes will not fit into the in-memory cache. SQLite will 17585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** already hold a RESERVED lock on the database file, but it needs 17595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to promote this lock to EXCLUSIVE so that it can spill cache 17605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** pages into the database file without harm to concurrent 17615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** readers. ^If it is unable to promote the lock, then the in-memory 17625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** cache will be left in an inconsistent state and so the error 17635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** code is promoted from the relatively benign [SQLITE_BUSY] to 17645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the more severe [SQLITE_IOERR_BLOCKED]. ^This error code promotion 17655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** forces an automatic rollback of the changes. See the 17665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <a href="/cvstrac/wiki?p=CorruptionFollowingBusyError"> 17675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CorruptionFollowingBusyError</a> wiki page for a discussion of why 17685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** this is important. 17695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 17705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(There can only be a single busy handler defined for each 17715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [database connection]. Setting a new busy handler clears any 17725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()] 17735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** will also set or clear the busy handler. 17745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 17755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The busy callback should not take any actions which modify the 17765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database connection that invoked the busy handler. Any such actions 17775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** result in undefined behavior. 17785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 17795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** A busy handler must not close the database connection 17805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or [prepared statement] that invoked the busy handler. 17815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 17825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*); 17835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 17845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 17855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Set A Busy Timeout 17865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 17875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps 17885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for a specified amount of time when a table is locked. ^The handler 17895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** will sleep multiple times until at least "ms" milliseconds of sleeping 17905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** have accumulated. ^After at least "ms" milliseconds of sleeping, 17915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the handler returns 0 which causes [sqlite3_step()] to return 17925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]. 17935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 17945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Calling this routine with an argument less than or equal to zero 17955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** turns off all busy handlers. 17965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 17975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(There can only be a single busy handler for a particular 17985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [database connection] any any given moment. If another busy handler 17995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** was defined (using [sqlite3_busy_handler()]) prior to calling 18005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** this routine, that other busy handler is cleared.)^ 18015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 18025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_busy_timeout(sqlite3*, int ms); 18035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 18045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 18055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Convenience Routines For Running Queries 18065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 18075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This is a legacy interface that is preserved for backwards compatibility. 18085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Use of this interface is not recommended. 18095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 18105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Definition: A <b>result table</b> is memory data structure created by the 18115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_get_table()] interface. A result table records the 18125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** complete query results from one or more queries. 18135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 18145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The table conceptually has a number of rows and columns. But 18155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** these numbers are not part of the result table itself. These 18165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** numbers are obtained separately. Let N be the number of rows 18175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and M be the number of columns. 18185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 18195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** A result table is an array of pointers to zero-terminated UTF-8 strings. 18205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** There are (N+1)*M elements in the array. The first M pointers point 18215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to zero-terminated strings that contain the names of the columns. 18225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The remaining entries all point to query results. NULL values result 18235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in NULL pointers. All other values are in their UTF-8 zero-terminated 18245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** string representation as returned by [sqlite3_column_text()]. 18255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 18265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** A result table might consist of one or more memory allocations. 18275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** It is not safe to pass a result table directly to [sqlite3_free()]. 18285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** A result table should be deallocated using [sqlite3_free_table()]. 18295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 18305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(As an example of the result table format, suppose a query result 18315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is as follows: 18325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 18335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <blockquote><pre> 18345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Name | Age 18355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ----------------------- 18365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Alice | 43 18375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Bob | 28 18385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Cindy | 21 18395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </pre></blockquote> 18405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 18415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** There are two column (M==2) and three rows (N==3). Thus the 18425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** result table has 8 entries. Suppose the result table is stored 18435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in an array names azResult. Then azResult holds this content: 18445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 18455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <blockquote><pre> 18465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** azResult[0] = "Name"; 18475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** azResult[1] = "Age"; 18485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** azResult[2] = "Alice"; 18495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** azResult[3] = "43"; 18505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** azResult[4] = "Bob"; 18515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** azResult[5] = "28"; 18525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** azResult[6] = "Cindy"; 18535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** azResult[7] = "21"; 18545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </pre></blockquote>)^ 18555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 18565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_get_table() function evaluates one or more 18575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** semicolon-separated SQL statements in the zero-terminated UTF-8 18585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** string of its 2nd parameter and returns a result table to the 18595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** pointer given in its 3rd parameter. 18605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 18615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** After the application has finished with the result from sqlite3_get_table(), 18625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** it must pass the result table pointer to sqlite3_free_table() in order to 18635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** release the memory that was malloced. Because of the way the 18645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling 18655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function must not try to call [sqlite3_free()] directly. Only 18665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_free_table()] is able to release the memory properly and safely. 18675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 18685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The sqlite3_get_table() interface is implemented as a wrapper around 18695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access 18705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to any internal data structures of SQLite. It uses only the public 18715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interface defined here. As a consequence, errors that occur in the 18725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** wrapper layer outside of the internal [sqlite3_exec()] call are not 18735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** reflected in subsequent calls to [sqlite3_errcode()] or 18745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_errmsg()]. 18755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 18765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_get_table( 18775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3 *db, /* An open database */ 18785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zSql, /* SQL to be evaluated */ 18795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) char ***pazResult, /* Results of the query */ 18805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int *pnRow, /* Number of result rows written here */ 18815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int *pnColumn, /* Number of result columns written here */ 18825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) char **pzErrmsg /* Error msg written here */ 18835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 18845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_free_table(char **result); 18855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 18865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 18875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Formatted String Printing Functions 18885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 18895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These routines are work-alikes of the "printf()" family of functions 18905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** from the standard C library. 18915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 18925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their 18935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** results into memory obtained from [sqlite3_malloc()]. 18945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The strings returned by these two routines should be 18955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** released by [sqlite3_free()]. ^Both routines return a 18965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** NULL pointer if [sqlite3_malloc()] is unable to allocate enough 18975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** memory to hold the resulting string. 18985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 18995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from 19005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the standard C library. The result is written into the 19015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** buffer supplied as the second parameter whose size is given by 19025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the first parameter. Note that the order of the 19035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** first two parameters is reversed from snprintf().)^ This is an 19045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** historical accident that cannot be fixed without breaking 19055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** backwards compatibility. ^(Note also that sqlite3_snprintf() 19065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** returns a pointer to its buffer instead of the number of 19075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** characters actually written into the buffer.)^ We admit that 19085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the number of characters written would be a more useful return 19095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** value but we cannot change the implementation of sqlite3_snprintf() 19105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** now without breaking compatibility. 19115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 19125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^As long as the buffer size is greater than zero, sqlite3_snprintf() 19135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** guarantees that the buffer is always zero-terminated. ^The first 19145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** parameter "n" is the total size of the buffer, including space for 19155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the zero terminator. So the longest string that can be completely 19165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** written will be n-1 characters. 19175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 19185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf(). 19195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 19205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These routines all implement some additional formatting 19215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** options that are useful for constructing SQL statements. 19225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** All of the usual printf() formatting options apply. In addition, there 19235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is are "%q", "%Q", and "%z" options. 19245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 19255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The %q option works like %s in that it substitutes a null-terminated 19265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** string from the argument list. But %q also doubles every '\'' character. 19275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** %q is designed for use inside a string literal.)^ By doubling each '\'' 19285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** character it escapes that character and allows it to be inserted into 19295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the string. 19305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 19315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** For example, assume the string variable zText contains text as follows: 19325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 19335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <blockquote><pre> 19345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** char *zText = "It's a happy day!"; 19355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </pre></blockquote> 19365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 19375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** One can use this text in an SQL statement as follows: 19385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 19395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <blockquote><pre> 19405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText); 19415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_exec(db, zSQL, 0, 0, 0); 19425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_free(zSQL); 19435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </pre></blockquote> 19445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 19455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Because the %q format string is used, the '\'' character in zText 19465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is escaped and the SQL generated is as follows: 19475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 19485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <blockquote><pre> 19495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** INSERT INTO table1 VALUES('It''s a happy day!') 19505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </pre></blockquote> 19515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 19525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This is correct. Had we used %s instead of %q, the generated SQL 19535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** would have looked like this: 19545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 19555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <blockquote><pre> 19565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** INSERT INTO table1 VALUES('It's a happy day!'); 19575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </pre></blockquote> 19585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 19595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This second example is an SQL syntax error. As a general rule you should 19605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** always use %q instead of %s when inserting text into a string literal. 19615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 19625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The %Q option works like %q except it also adds single quotes around 19635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the outside of the total string. Additionally, if the parameter in the 19645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** argument list is a NULL pointer, %Q substitutes the text "NULL" (without 19655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** single quotes).)^ So, for example, one could say: 19665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 19675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <blockquote><pre> 19685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText); 19695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_exec(db, zSQL, 0, 0, 0); 19705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_free(zSQL); 19715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </pre></blockquote> 19725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 19735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The code above will render a correct SQL statement in the zSQL 19745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** variable even if the zText variable is a NULL pointer. 19755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 19765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The "%z" formatting option works like "%s" but with the 19775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** addition that after the string has been read and copied into 19785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the result, [sqlite3_free()] is called on the input string.)^ 19795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 19805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)char *sqlite3_mprintf(const char*,...); 19815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)char *sqlite3_vmprintf(const char*, va_list); 19825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)char *sqlite3_snprintf(int,char*,const char*, ...); 19835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)char *sqlite3_vsnprintf(int,char*,const char*, va_list); 19845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 19855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 19865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Memory Allocation Subsystem 19875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 19885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The SQLite core uses these three routines for all of its own 19895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** internal memory allocation needs. "Core" in the previous sentence 19905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** does not include operating-system specific VFS implementation. The 19915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Windows VFS uses native malloc() and free() for some operations. 19925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 19935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_malloc() routine returns a pointer to a block 19945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of memory at least N bytes in length, where N is the parameter. 19955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If sqlite3_malloc() is unable to obtain sufficient free 19965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** memory, it returns a NULL pointer. ^If the parameter N to 19975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns 19985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a NULL pointer. 19995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 20005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Calling sqlite3_free() with a pointer previously returned 20015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by sqlite3_malloc() or sqlite3_realloc() releases that memory so 20025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that it might be reused. ^The sqlite3_free() routine is 20035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a no-op if is called with a NULL pointer. Passing a NULL pointer 20045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to sqlite3_free() is harmless. After being freed, memory 20055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** should neither be read nor written. Even reading previously freed 20065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** memory might result in a segmentation fault or other severe error. 20075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Memory corruption, a segmentation fault, or other severe error 20085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** might result if sqlite3_free() is called with a non-NULL pointer that 20095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** was not obtained from sqlite3_malloc() or sqlite3_realloc(). 20105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 20115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The sqlite3_realloc() interface attempts to resize a 20125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** prior memory allocation to be at least N bytes, where N is the 20135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** second parameter. The memory allocation to be resized is the first 20145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** parameter.)^ ^ If the first parameter to sqlite3_realloc() 20155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is a NULL pointer then its behavior is identical to calling 20165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc(). 20175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the second parameter to sqlite3_realloc() is zero or 20185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** negative then the behavior is exactly the same as calling 20195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_free(P) where P is the first parameter to sqlite3_realloc(). 20205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^sqlite3_realloc() returns a pointer to a memory allocation 20215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of at least N bytes in size or NULL if sufficient memory is unavailable. 20225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If M is the size of the prior allocation, then min(N,M) bytes 20235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of the prior allocation are copied into the beginning of buffer returned 20245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by sqlite3_realloc() and the prior allocation is freed. 20255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If sqlite3_realloc() returns NULL, then the prior allocation 20265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is not freed. 20275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 20285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The memory returned by sqlite3_malloc() and sqlite3_realloc() 20295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is always aligned to at least an 8 byte boundary, or to a 20305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time 20315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** option is used. 20325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 20335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** In SQLite version 3.5.0 and 3.5.1, it was possible to define 20345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in 20355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** implementation of these routines to be omitted. That capability 20365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is no longer provided. Only built-in memory allocators can be used. 20375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 20385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The Windows OS interface layer calls 20395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the system malloc() and free() directly when converting 20405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** filenames between the UTF-8 encoding used by SQLite 20415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and whatever filename encoding is used by the particular Windows 20425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** installation. Memory allocation errors are detected, but 20435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** they are reported back as [SQLITE_CANTOPEN] or 20445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_IOERR] rather than [SQLITE_NOMEM]. 20455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 20465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()] 20475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** must be either NULL or else pointers obtained from a prior 20485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have 20495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** not yet been released. 20505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 20515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The application must not read or write any part of 20525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a block of memory after it has been released using 20535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_free()] or [sqlite3_realloc()]. 20545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 20555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void *sqlite3_malloc(int); 20565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void *sqlite3_realloc(void*, int); 20575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_free(void*); 20585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 20595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 20605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Memory Allocator Statistics 20615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 20625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite provides these two interfaces for reporting on the status 20635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()] 20645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** routines, which form the built-in memory allocation subsystem. 20655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 20665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [sqlite3_memory_used()] routine returns the number of bytes 20675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of memory currently outstanding (malloced but not freed). 20685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [sqlite3_memory_highwater()] routine returns the maximum 20695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** value of [sqlite3_memory_used()] since the high-water mark 20705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** was last reset. ^The values returned by [sqlite3_memory_used()] and 20715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_memory_highwater()] include any overhead 20725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** added by SQLite in its implementation of [sqlite3_malloc()], 20735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** but not overhead added by the any underlying system library 20745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** routines that [sqlite3_malloc()] may call. 20755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 20765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The memory high-water mark is reset to the current value of 20775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_memory_used()] if and only if the parameter to 20785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_memory_highwater()] is true. ^The value returned 20795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by [sqlite3_memory_highwater(1)] is the high-water mark 20805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** prior to the reset. 20815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 20825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)sqlite3_int64 sqlite3_memory_used(void); 20835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)sqlite3_int64 sqlite3_memory_highwater(int resetFlag); 20845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 20855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 20865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Pseudo-Random Number Generator 20875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 20885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite contains a high-quality pseudo-random number generator (PRNG) used to 20895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** select random [ROWID | ROWIDs] when inserting new records into a table that 20905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** already uses the largest possible [ROWID]. The PRNG is also used for 20915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the build-in random() and randomblob() SQL functions. This interface allows 20925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** applications to access the same PRNG for other purposes. 20935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 20945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^A call to this routine stores N bytes of randomness into buffer P. 20955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 20965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The first time this routine is invoked (either internally or by 20975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the application) the PRNG is seeded using randomness obtained 20985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** from the xRandomness method of the default [sqlite3_vfs] object. 20995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^On all subsequent invocations, the pseudo-randomness is generated 21005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** internally and without recourse to the [sqlite3_vfs] xRandomness 21015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** method. 21025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 21035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_randomness(int N, void *P); 21045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 21055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 21065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Compile-Time Authorization Callbacks 21075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 21085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This routine registers an authorizer callback with a particular 21095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [database connection], supplied in the first argument. 21105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The authorizer callback is invoked as SQL statements are being compiled 21115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], 21125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()]. ^At various 21135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** points during the compilation process, as logic is being created 21145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to perform various actions, the authorizer callback is invoked to 21155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** see if those actions are allowed. ^The authorizer callback should 21165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the 21175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** specific action but allow the SQL statement to continue to be 21185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be 21195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** rejected with an error. ^If the authorizer callback returns 21205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY] 21215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then the [sqlite3_prepare_v2()] or equivalent call that triggered 21225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the authorizer will fail with an error message. 21235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 21245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** When the callback returns [SQLITE_OK], that means the operation 21255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** requested is ok. ^When the callback returns [SQLITE_DENY], the 21265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_prepare_v2()] or equivalent call that triggered the 21275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** authorizer will fail with an error message explaining that 21285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** access is denied. 21295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 21305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The first parameter to the authorizer callback is a copy of the third 21315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** parameter to the sqlite3_set_authorizer() interface. ^The second parameter 21325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to the callback is an integer [SQLITE_COPY | action code] that specifies 21335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the particular action to be authorized. ^The third through sixth parameters 21345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to the callback are zero-terminated strings that contain additional 21355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** details about the action to be authorized. 21365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 21375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the action code is [SQLITE_READ] 21385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and the callback returns [SQLITE_IGNORE] then the 21395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [prepared statement] statement is constructed to substitute 21405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a NULL value in place of the table column that would have 21415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE] 21425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** return can be used to deny an untrusted user access to individual 21435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** columns of a table. 21445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the action code is [SQLITE_DELETE] and the callback returns 21455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the 21465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [truncate optimization] is disabled and all rows are deleted individually. 21475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 21485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** An authorizer is used when [sqlite3_prepare | preparing] 21495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQL statements from an untrusted source, to ensure that the SQL statements 21505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** do not try to access data they are not allowed to see, or that they do not 21515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** try to execute malicious statements that damage the database. For 21525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** example, an application may allow a user to enter arbitrary 21535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQL queries for evaluation by a database. But the application does 21545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** not want the user to be able to make arbitrary changes to the 21555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database. An authorizer could then be put in place while the 21565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** user-entered SQL is being [sqlite3_prepare | prepared] that 21575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** disallows everything except [SELECT] statements. 21585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 21595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Applications that need to process SQL from untrusted sources 21605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** might also consider lowering resource limits using [sqlite3_limit()] 21615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and limiting database size using the [max_page_count] [PRAGMA] 21625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in addition to using an authorizer. 21635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 21645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(Only a single authorizer can be in place on a database connection 21655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** at a time. Each call to sqlite3_set_authorizer overrides the 21665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** previous call.)^ ^Disable the authorizer by installing a NULL callback. 21675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The authorizer is disabled by default. 21685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 21695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The authorizer callback must not do anything that will modify 21705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the database connection that invoked the authorizer callback. 21715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 21725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database connections for the meaning of "modify" in this paragraph. 21735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 21745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the 21755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** statement might be re-prepared during [sqlite3_step()] due to a 21765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** schema change. Hence, the application should ensure that the 21775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** correct authorizer callback remains in place during the [sqlite3_step()]. 21785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 21795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Note that the authorizer callback is invoked only during 21805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_prepare()] or its variants. Authorization is not 21815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** performed during statement evaluation in [sqlite3_step()], unless 21825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** as stated in the previous paragraph, sqlite3_step() invokes 21835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_prepare_v2() to reprepare a statement after a schema change. 21845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 21855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_set_authorizer( 21865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3*, 21875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), 21885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void *pUserData 21895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 21905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 21915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 21925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Authorizer Return Codes 21935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 21945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The [sqlite3_set_authorizer | authorizer callback function] must 21955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** return either [SQLITE_OK] or one of these two constants in order 21965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to signal SQLite whether or not the action is permitted. See the 21975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_set_authorizer | authorizer documentation] for additional 21985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** information. 21995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 22005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DENY 1 /* Abort the SQL statement with an error */ 22015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ 22025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 22035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 22045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Authorizer Action Codes 22055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 22065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The [sqlite3_set_authorizer()] interface registers a callback function 22075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that is invoked to authorize certain SQL statement actions. The 22085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** second parameter to the callback is an integer code that specifies 22095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** what action is being authorized. These are the integer action codes that 22105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the authorizer callback may be passed. 22115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 22125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These action code values signify what kind of operation is to be 22135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** authorized. The 3rd and 4th parameters to the authorization 22145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** callback function will be parameters or NULL depending on which of these 22155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** codes is used as the second parameter. ^(The 5th parameter to the 22165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** authorizer callback is the name of the database ("main", "temp", 22175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback 22185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is the name of the inner-most trigger or view that is responsible for 22195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the access attempt or NULL if this access attempt is directly from 22205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** top-level SQL code. 22215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 22225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/******************************************* 3rd ************ 4th ***********/ 22235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */ 22245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CREATE_TABLE 2 /* Table Name NULL */ 22255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */ 22265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */ 22275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */ 22285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */ 22295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */ 22305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CREATE_VIEW 8 /* View Name NULL */ 22315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DELETE 9 /* Table Name NULL */ 22325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DROP_INDEX 10 /* Index Name Table Name */ 22335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DROP_TABLE 11 /* Table Name NULL */ 22345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */ 22355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */ 22365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */ 22375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */ 22385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */ 22395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DROP_VIEW 17 /* View Name NULL */ 22405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_INSERT 18 /* Table Name NULL */ 22415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */ 22425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_READ 20 /* Table Name Column Name */ 22435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_SELECT 21 /* NULL NULL */ 22445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_TRANSACTION 22 /* Operation NULL */ 22455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_UPDATE 23 /* Table Name Column Name */ 22465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_ATTACH 24 /* Filename NULL */ 22475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DETACH 25 /* Database Name NULL */ 22485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */ 22495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_REINDEX 27 /* Index Name NULL */ 22505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_ANALYZE 28 /* Table Name NULL */ 22515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */ 22525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */ 22535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_FUNCTION 31 /* NULL Function Name */ 22545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */ 22555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_COPY 0 /* No longer used */ 22565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 22575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 22585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Tracing And Profiling Functions 22595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 22605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These routines register callback functions that can be used for 22615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** tracing and profiling the execution of SQL statements. 22625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 22635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The callback function registered by sqlite3_trace() is invoked at 22645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** various times when an SQL statement is being run by [sqlite3_step()]. 22655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the 22665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQL statement text as the statement first begins executing. 22675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(Additional sqlite3_trace() callbacks might occur 22685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** as each triggered subprogram is entered. The callbacks for triggers 22695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** contain a UTF-8 SQL comment that identifies the trigger.)^ 22705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 22715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The callback function registered by sqlite3_profile() is invoked 22725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** as each SQL statement finishes. ^The profile callback contains 22735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the original statement text and an estimate of wall-clock time 22745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of how long that statement took to run. ^The profile callback 22755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** time is in units of nanoseconds, however the current implementation 22765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is only capable of millisecond resolution so the six least significant 22775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** digits in the time are meaningless. Future versions of SQLite 22785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** might provide greater resolution on the profiler callback. The 22795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_profile() function is considered experimental and is 22805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** subject to change in future versions of SQLite. 22815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 22825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*); 22835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*, 22845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void(*xProfile)(void*,const char*,sqlite3_uint64), void*); 22855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 22865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 22875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Query Progress Callbacks 22885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 22895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback 22905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function X to be invoked periodically during long running calls to 22915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for 22925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database connection D. An example use for this 22935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interface is to keep a GUI updated during a large query. 22945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 22955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The parameter P is passed through as the only parameter to the 22965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** callback function X. ^The parameter N is the number of 22975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [virtual machine instructions] that are evaluated between successive 22985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** invocations of the callback X. 22995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 23005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Only a single progress handler may be defined at one time per 23015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [database connection]; setting a new progress handler cancels the 23025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** old one. ^Setting parameter X to NULL disables the progress handler. 23035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The progress handler is also disabled by setting N to a value less 23045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** than 1. 23055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 23065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the progress callback returns non-zero, the operation is 23075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interrupted. This feature can be used to implement a 23085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** "Cancel" button on a GUI progress dialog box. 23095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 23105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The progress handler callback must not do anything that will modify 23115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the database connection that invoked the progress handler. 23125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 23135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database connections for the meaning of "modify" in this paragraph. 23145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 23155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 23165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); 23175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 23185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 23195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Opening A New Database Connection 23205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 23215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^These routines open an SQLite database file whose name is given by the 23225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** filename argument. ^The filename argument is interpreted as UTF-8 for 23235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte 23245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** order for sqlite3_open16(). ^(A [database connection] handle is usually 23255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** returned in *ppDb, even if an error occurs. The only exception is that 23265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** if SQLite is unable to allocate memory to hold the [sqlite3] object, 23275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a NULL will be written into *ppDb instead of a pointer to the [sqlite3] 23285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** object.)^ ^(If the database is opened (and/or created) successfully, then 23295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The 23305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain 23315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** an English language description of the error following a failure of any 23325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of the sqlite3_open() routines. 23335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 23345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The default encoding for the database will be UTF-8 if 23355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_open() or sqlite3_open_v2() is called and 23365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** UTF-16 in the native byte order if sqlite3_open16() is used. 23375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 23385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Whether or not an error occurs when it is opened, resources 23395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** associated with the [database connection] handle should be released by 23405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** passing it to [sqlite3_close()] when it is no longer required. 23415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 23425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The sqlite3_open_v2() interface works like sqlite3_open() 23435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** except that it accepts two additional parameters for additional control 23445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** over the new database connection. ^(The flags parameter to 23455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_open_v2() can take one of 23465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the following three values, optionally combined with the 23475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE], 23485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and/or [SQLITE_OPEN_PRIVATECACHE] flags:)^ 23495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 23505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dl> 23515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>[SQLITE_OPEN_READONLY]</dt> 23525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>The database is opened in read-only mode. If the database does not 23535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** already exist, an error is returned.</dd>)^ 23545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 23555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>[SQLITE_OPEN_READWRITE]</dt> 23565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>The database is opened for reading and writing if possible, or reading 23575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** only if the file is write protected by the operating system. In either 23585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** case the database must already exist, otherwise an error is returned.</dd>)^ 23595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 23605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt> 23615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>The database is opened for reading and writing, and is created if 23625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** it does not already exist. This is the behavior that is always used for 23635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_open() and sqlite3_open16().</dd>)^ 23645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </dl> 23655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 23665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If the 3rd parameter to sqlite3_open_v2() is not one of the 23675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** combinations shown above or one of the combinations shown above combined 23685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], 23695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_PRIVATECACHE] flags, 23705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then the behavior is undefined. 23715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 23725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection 23735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** opens in the multi-thread [threading mode] as long as the single-thread 23745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** mode has not been set at compile-time or start-time. ^If the 23755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens 23765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in the serialized [threading mode] unless single-thread was 23775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** previously selected at compile-time or start-time. 23785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be 23795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** eligible to use [shared cache mode], regardless of whether or not shared 23805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** cache is enabled using [sqlite3_enable_shared_cache()]. ^The 23815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not 23825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** participate in [shared cache mode] even if it is enabled. 23835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 23845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the filename is ":memory:", then a private, temporary in-memory database 23855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is created for the connection. ^This in-memory database will vanish when 23865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the database connection is closed. Future versions of SQLite might 23875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** make use of additional special filenames that begin with the ":" character. 23885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** It is recommended that when a database filename actually does begin with 23895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a ":" character you should prefix the filename with a pathname such as 23905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** "./" to avoid ambiguity. 23915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 23925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the filename is an empty string, then a private, temporary 23935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** on-disk database will be created. ^This private database will be 23945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** automatically deleted as soon as the database connection is closed. 23955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 23965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The fourth parameter to sqlite3_open_v2() is the name of the 23975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_vfs] object that defines the operating system interface that 23985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the new database connection should use. ^If the fourth parameter is 23995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a NULL pointer then the default [sqlite3_vfs] object is used. 24005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 24015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <b>Note to Windows users:</b> The encoding used for the filename argument 24025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever 24035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** codepage is currently defined. Filenames containing international 24045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** characters must be converted to UTF-8 prior to passing them into 24055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_open() or sqlite3_open_v2(). 24065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 24075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_open( 24085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *filename, /* Database filename (UTF-8) */ 24095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3 **ppDb /* OUT: SQLite db handle */ 24105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 24115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_open16( 24125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const void *filename, /* Database filename (UTF-16) */ 24135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3 **ppDb /* OUT: SQLite db handle */ 24145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 24155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_open_v2( 24165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *filename, /* Database filename (UTF-8) */ 24175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3 **ppDb, /* OUT: SQLite db handle */ 24185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int flags, /* Flags */ 24195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zVfs /* Name of VFS module to use */ 24205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 24215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 24225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 24235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Error Codes And Messages 24245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 24255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_errcode() interface returns the numeric [result code] or 24265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [extended result code] for the most recent failed sqlite3_* API call 24275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** associated with a [database connection]. If a prior API call failed 24285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** but the most recent API call succeeded, the return value from 24295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_errcode() is undefined. ^The sqlite3_extended_errcode() 24305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interface is the same except that it always returns the 24315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [extended result code] even when extended result codes are 24325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** disabled. 24335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 24345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language 24355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** text that describes the error, as either UTF-8 or UTF-16 respectively. 24365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(Memory to hold the error message string is managed internally. 24375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The application does not need to worry about freeing the result. 24385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** However, the error string might be overwritten or deallocated by 24395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** subsequent calls to other SQLite interface functions.)^ 24405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 24415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** When the serialized [threading mode] is in use, it might be the 24425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** case that a second error occurs on a separate thread in between 24435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the time of the first error and the call to these interfaces. 24445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** When that happens, the second error will be reported since these 24455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interfaces always report the most recent result. To avoid 24465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** this, each thread can obtain exclusive use of the [database connection] D 24475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning 24485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after 24495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** all calls to the interfaces listed here are completed. 24505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 24515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If an interface fails with SQLITE_MISUSE, that means the interface 24525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** was invoked incorrectly by the application. In that case, the 24535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** error code and message may or may not be set. 24545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 24555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_errcode(sqlite3 *db); 24565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_extended_errcode(sqlite3 *db); 24575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char *sqlite3_errmsg(sqlite3*); 24585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const void *sqlite3_errmsg16(sqlite3*); 24595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 24605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 24615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: SQL Statement Object 24625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: {prepared statement} {prepared statements} 24635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 24645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** An instance of this object represents a single SQL statement. 24655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This object is variously known as a "prepared statement" or a 24665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** "compiled SQL statement" or simply as a "statement". 24675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 24685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The life of a statement object goes something like this: 24695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 24705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <ol> 24715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> Create the object using [sqlite3_prepare_v2()] or a related 24725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function. 24735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> Bind values to [host parameters] using the sqlite3_bind_*() 24745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interfaces. 24755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> Run the SQL by calling [sqlite3_step()] one or more times. 24765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> Reset the statement using [sqlite3_reset()] then go back 24775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to step 2. Do this zero or more times. 24785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> Destroy the object using [sqlite3_finalize()]. 24795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </ol> 24805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 24815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Refer to documentation on individual methods above for additional 24825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** information. 24835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 24845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct sqlite3_stmt sqlite3_stmt; 24855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 24865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 24875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Run-time Limits 24885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 24895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(This interface allows the size of various constructs to be limited 24905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** on a connection by connection basis. The first parameter is the 24915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [database connection] whose limit is to be set or queried. The 24925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** second parameter is one of the [limit categories] that define a 24935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** class of constructs to be size limited. The third parameter is the 24945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** new limit for that construct.)^ 24955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 24965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the new limit is a negative number, the limit is unchanged. 24975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a 24985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [limits | hard upper bound] 24995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** set at compile-time by a C preprocessor macro called 25005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [limits | SQLITE_MAX_<i>NAME</i>]. 25015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** (The "_LIMIT_" in the name is changed to "_MAX_".))^ 25025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Attempts to increase a limit above its hard upper bound are 25035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** silently truncated to the hard upper bound. 25045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 25055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Regardless of whether or not the limit was changed, the 25065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_limit()] interface returns the prior value of the limit. 25075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Hence, to find the current value of a limit without changing it, 25085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** simply invoke this interface with the third parameter set to -1. 25095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 25105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Run-time limits are intended for use in applications that manage 25115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** both their own internal database and also databases that are controlled 25125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by untrusted external sources. An example application might be a 25135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** web browser that has its own databases for storing history and 25145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** separate databases controlled by JavaScript applications downloaded 25155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** off the Internet. The internal databases can be given the 25165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** large, default limits. Databases managed by external sources can 25175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** be given much smaller limits designed to prevent a denial of service 25185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** attack. Developers might also want to use the [sqlite3_set_authorizer()] 25195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interface to further control untrusted SQL. The size of the database 25205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** created by an untrusted script can be contained using the 25215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [max_page_count] [PRAGMA]. 25225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 25235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** New run-time limit categories may be added in future releases. 25245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 25255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_limit(sqlite3*, int id, int newVal); 25265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 25275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 25285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Run-Time Limit Categories 25295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: {limit category} {*limit categories} 25305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 25315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These constants define various performance limits 25325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that can be lowered at run-time using [sqlite3_limit()]. 25335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The synopsis of the meanings of the various limits is shown below. 25345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Additional information is available at [limits | Limits in SQLite]. 25355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 25365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dl> 25375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_LIMIT_LENGTH</dt> 25385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^ 25395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 25405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt> 25415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>The maximum length of an SQL statement, in bytes.</dd>)^ 25425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 25435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_LIMIT_COLUMN</dt> 25445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>The maximum number of columns in a table definition or in the 25455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** result set of a [SELECT] or the maximum number of columns in an index 25465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or in an ORDER BY or GROUP BY clause.</dd>)^ 25475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 25485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> 25495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>The maximum depth of the parse tree on any expression.</dd>)^ 25505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 25515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt> 25525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^ 25535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 25545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt> 25555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>The maximum number of instructions in a virtual machine program 25565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** used to implement an SQL statement. This limit is not currently 25575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** enforced, though that might be added in some future release of 25585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite.</dd>)^ 25595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 25605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt> 25615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>The maximum number of arguments on a function.</dd>)^ 25625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 25635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_LIMIT_ATTACHED</dt> 25645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>The maximum number of [ATTACH | attached databases].)^</dd> 25655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 25665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt> 25675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>The maximum length of the pattern argument to the [LIKE] or 25685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [GLOB] operators.</dd>)^ 25695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 25705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> 25715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>The maximum index number of any [parameter] in an SQL statement.)^ 25725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 25735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> 25745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>The maximum depth of recursion for triggers.</dd>)^ 25755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </dl> 25765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 25775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_LIMIT_LENGTH 0 25785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_LIMIT_SQL_LENGTH 1 25795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_LIMIT_COLUMN 2 25805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_LIMIT_EXPR_DEPTH 3 25815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_LIMIT_COMPOUND_SELECT 4 25825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_LIMIT_VDBE_OP 5 25835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_LIMIT_FUNCTION_ARG 6 25845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_LIMIT_ATTACHED 7 25855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8 25865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_LIMIT_VARIABLE_NUMBER 9 25875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_LIMIT_TRIGGER_DEPTH 10 25885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 25895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 25905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Compiling An SQL Statement 25915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: {SQL statement compiler} 25925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 25935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** To execute an SQL query, it must first be compiled into a byte-code 25945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** program using one of these routines. 25955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 25965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The first argument, "db", is a [database connection] obtained from a 25975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or 25985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_open16()]. The database connection must not have been closed. 25995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 26005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The second argument, "zSql", is the statement to be compiled, encoded 26015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2() 26025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2() 26035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** use UTF-16. 26045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 26055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the nByte argument is less than zero, then zSql is read up to the 26065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** first zero terminator. ^If nByte is non-negative, then it is the maximum 26075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** number of bytes read from zSql. ^When nByte is non-negative, the 26085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** zSql string ends at either the first '\000' or '\u0000' character or 26095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the nByte-th byte, whichever comes first. If the caller knows 26105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that the supplied string is nul-terminated, then there is a small 26115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** performance advantage to be gained by passing an nByte parameter that 26125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is equal to the number of bytes in the input string <i>including</i> 26135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the nul-terminator bytes. 26145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 26155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If pzTail is not NULL then *pzTail is made to point to the first byte 26165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** past the end of the first SQL statement in zSql. These routines only 26175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** compile the first statement in zSql, so *pzTail is left pointing to 26185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** what remains uncompiled. 26195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 26205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^*ppStmt is left pointing to a compiled [prepared statement] that can be 26215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set 26225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to NULL. ^If the input text contains no SQL (if the input is an empty 26235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** string or a comment) then *ppStmt is set to NULL. 26245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The calling procedure is responsible for deleting the compiled 26255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQL statement using [sqlite3_finalize()] after it has finished with it. 26265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ppStmt may not be NULL. 26275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 26285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK]; 26295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** otherwise an [error code] is returned. 26305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 26315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are 26325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** recommended for all new programs. The two older interfaces are retained 26335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for backwards compatibility, but their use is discouraged. 26345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^In the "v2" interfaces, the prepared statement 26355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that is returned (the [sqlite3_stmt] object) contains a copy of the 26365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** original SQL text. This causes the [sqlite3_step()] interface to 26375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** behave differently in three ways: 26385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 26395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <ol> 26405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> 26415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it 26425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** always used to do, [sqlite3_step()] will automatically recompile the SQL 26435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** statement and try to run it again. 26445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </li> 26455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 26465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> 26475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^When an error occurs, [sqlite3_step()] will return one of the detailed 26485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [error codes] or [extended error codes]. ^The legacy behavior was that 26495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code 26505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and the application would have to make a second call to [sqlite3_reset()] 26515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in order to find the underlying cause of the problem. With the "v2" prepare 26525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interfaces, the underlying reason for the error is returned immediately. 26535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </li> 26545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 26555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> 26565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the specific value bound to [parameter | host parameter] in the 26575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** WHERE clause might influence the choice of query plan for a statement, 26585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then the statement will be automatically recompiled, as if there had been 26595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a schema change, on the first [sqlite3_step()] call following any change 26605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to the [sqlite3_bind_text | bindings] of that [parameter]. 26615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The specific value of WHERE-clause [parameter] might influence the 26625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** choice of query plan if the parameter is the left-hand side of a [LIKE] 26635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or [GLOB] operator or if the parameter is compared to an indexed column 26645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and the [SQLITE_ENABLE_STAT2] compile-time option is enabled. 26655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the 26665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </li> 26675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </ol> 26685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 26695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_prepare( 26705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3 *db, /* Database handle */ 26715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zSql, /* SQL statement, UTF-8 encoded */ 26725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int nByte, /* Maximum length of zSql in bytes. */ 26735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 26745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char **pzTail /* OUT: Pointer to unused portion of zSql */ 26755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 26765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_prepare_v2( 26775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3 *db, /* Database handle */ 26785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zSql, /* SQL statement, UTF-8 encoded */ 26795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int nByte, /* Maximum length of zSql in bytes. */ 26805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 26815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char **pzTail /* OUT: Pointer to unused portion of zSql */ 26825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 26835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_prepare16( 26845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3 *db, /* Database handle */ 26855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const void *zSql, /* SQL statement, UTF-16 encoded */ 26865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int nByte, /* Maximum length of zSql in bytes. */ 26875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 26885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const void **pzTail /* OUT: Pointer to unused portion of zSql */ 26895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 26905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_prepare16_v2( 26915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3 *db, /* Database handle */ 26925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const void *zSql, /* SQL statement, UTF-16 encoded */ 26935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int nByte, /* Maximum length of zSql in bytes. */ 26945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 26955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const void **pzTail /* OUT: Pointer to unused portion of zSql */ 26965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 26975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 26985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 26995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Retrieving Statement SQL 27005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 27015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This interface can be used to retrieve a saved copy of the original 27025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQL text used to create a [prepared statement] if that statement was 27035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()]. 27045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 27055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char *sqlite3_sql(sqlite3_stmt *pStmt); 27065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 27075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 27085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Determine If An SQL Statement Writes The Database 27095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 27105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if 27115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and only if the [prepared statement] X makes no direct changes to 27125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the content of the database file. 27135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 27145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Note that [application-defined SQL functions] or 27155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [virtual tables] might change the database indirectly as a side effect. 27165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(For example, if an application defines a function "eval()" that 27175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** calls [sqlite3_exec()], then the following SQL statement would 27185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** change the database file through side-effects: 27195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 27205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <blockquote><pre> 27215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SELECT eval('DELETE FROM t1') FROM t2; 27225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </pre></blockquote> 27235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 27245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** But because the [SELECT] statement does not change the database file 27255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** directly, sqlite3_stmt_readonly() would still return true.)^ 27265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 27275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK], 27285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true, 27295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** since the statements themselves do not actually modify the database but 27305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** rather they control the timing of when other statements modify the 27315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database. ^The [ATTACH] and [DETACH] statements also cause 27325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_stmt_readonly() to return true since, while those statements 27335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** change the configuration of a database connection, they do not make 27345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** changes to the content of the database files on disk. 27355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 27365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); 27375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 27385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 27395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Dynamically Typed Value Object 27405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value} 27415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 27425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite uses the sqlite3_value object to represent all values 27435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that can be stored in a database table. SQLite uses dynamic typing 27445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for the values it stores. ^Values stored in sqlite3_value objects 27455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** can be integers, floating point values, strings, BLOBs, or NULL. 27465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 27475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** An sqlite3_value object may be either "protected" or "unprotected". 27485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Some interfaces require a protected sqlite3_value. Other interfaces 27495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** will accept either a protected or an unprotected sqlite3_value. 27505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Every interface that accepts sqlite3_value arguments specifies 27515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** whether or not it requires a protected sqlite3_value. 27525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 27535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The terms "protected" and "unprotected" refer to whether or not 27545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a mutex is held. An internal mutex is held for a protected 27555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_value object but no mutex is held for an unprotected 27565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_value object. If SQLite is compiled to be single-threaded 27575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0) 27585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or if SQLite is run in one of reduced mutex modes 27595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD] 27605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then there is no distinction between protected and unprotected 27615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_value objects and they can be used interchangeably. However, 27625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for maximum code portability it is recommended that applications 27635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** still make the distinction between protected and unprotected 27645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_value objects even when not strictly required. 27655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 27665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_value objects that are passed as parameters into the 27675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** implementation of [application-defined SQL functions] are protected. 27685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_value object returned by 27695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_column_value()] is unprotected. 27705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Unprotected sqlite3_value objects may only be used with 27715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_result_value()] and [sqlite3_bind_value()]. 27725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The [sqlite3_value_blob | sqlite3_value_type()] family of 27735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interfaces require protected sqlite3_value objects. 27745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 27755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct Mem sqlite3_value; 27765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 27775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 27785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: SQL Function Context Object 27795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 27805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The context in which an SQL function executes is stored in an 27815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_context object. ^A pointer to an sqlite3_context object 27825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is always first parameter to [application-defined SQL functions]. 27835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The application-defined SQL function implementation will pass this 27845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** pointer through into calls to [sqlite3_result_int | sqlite3_result()], 27855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_aggregate_context()], [sqlite3_user_data()], 27865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()], 27875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and/or [sqlite3_set_auxdata()]. 27885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 27895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct sqlite3_context sqlite3_context; 27905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 27915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 27925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Binding Values To Prepared Statements 27935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: {host parameter} {host parameters} {host parameter name} 27945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} 27955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 27965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants, 27975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** literals may be replaced by a [parameter] that matches one of following 27985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** templates: 27995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 28005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <ul> 28015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> ? 28025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> ?NNN 28035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> :VVV 28045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> @VVV 28055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> $VVV 28065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </ul> 28075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 28085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** In the templates above, NNN represents an integer literal, 28095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and VVV represents an alphanumeric identifier.)^ ^The values of these 28105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** parameters (also called "host parameter names" or "SQL parameters") 28115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** can be set using the sqlite3_bind_*() routines defined here. 28125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 28135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The first argument to the sqlite3_bind_*() routines is always 28145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a pointer to the [sqlite3_stmt] object returned from 28155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_prepare_v2()] or its variants. 28165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 28175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The second argument is the index of the SQL parameter to be set. 28185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The leftmost SQL parameter has an index of 1. ^When the same named 28195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQL parameter is used more than once, second and subsequent 28205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** occurrences have the same index as the first occurrence. 28215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The index for named parameters can be looked up using the 28225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_bind_parameter_index()] API if desired. ^The index 28235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for "?NNN" parameters is the value of NNN. 28245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The NNN value must be between 1 and the [sqlite3_limit()] 28255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999). 28265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 28275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The third argument is the value to bind to the parameter. 28285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 28295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(In those routines that have a fourth argument, its value is the 28305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** number of bytes in the parameter. To be clear: the value is the 28315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** number of <u>bytes</u> in the value, not the number of characters.)^ 28325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the fourth parameter is negative, the length of the string is 28335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the number of bytes up to the first zero terminator. 28345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 28355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and 28365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or 28375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** string after SQLite has finished with it. ^The destructor is called 28385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(), 28395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_bind_text(), or sqlite3_bind_text16() fails. 28405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the fifth argument is 28415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the special value [SQLITE_STATIC], then SQLite assumes that the 28425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** information is in static, unmanaged space and does not need to be freed. 28435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the fifth argument has the value [SQLITE_TRANSIENT], then 28445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite makes its own private copy of the data immediately, before 28455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the sqlite3_bind_*() routine returns. 28465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 28475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that 28485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is filled with zeroes. ^A zeroblob uses a fixed amount of memory 28495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** (just an integer to hold its size) while it is being processed. 28505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Zeroblobs are intended to serve as placeholders for BLOBs whose 28515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** content is later written using 28525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_blob_open | incremental BLOB I/O] routines. 28535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^A negative value for the zeroblob results in a zero-length BLOB. 28545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 28555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer 28565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for the [prepared statement] or with a prepared statement for which 28575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_step()] has been called more recently than [sqlite3_reset()], 28585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_() 28595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** routine is passed a [prepared statement] that has been finalized, the 28605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** result is undefined and probably harmful. 28615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 28625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Bindings are not cleared by the [sqlite3_reset()] routine. 28635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Unbound parameters are interpreted as NULL. 28645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 28655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an 28665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [error code] if anything goes wrong. 28675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^[SQLITE_RANGE] is returned if the parameter 28685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails. 28695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 28705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also: [sqlite3_bind_parameter_count()], 28715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()]. 28725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 28735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); 28745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_bind_double(sqlite3_stmt*, int, double); 28755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_bind_int(sqlite3_stmt*, int, int); 28765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); 28775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_bind_null(sqlite3_stmt*, int); 28785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*)); 28795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*)); 28805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); 28815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); 28825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 28835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 28845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Number Of SQL Parameters 28855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 28865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This routine can be used to find the number of [SQL parameters] 28875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in a [prepared statement]. SQL parameters are tokens of the 28885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as 28895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** placeholders for values that are [sqlite3_bind_blob | bound] 28905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to the parameters at a later time. 28915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 28925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(This routine actually returns the index of the largest (rightmost) 28935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** parameter. For all forms except ?NNN, this will correspond to the 28945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** number of unique parameters. If parameters of the ?NNN form are used, 28955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** there may be gaps in the list.)^ 28965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 28975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also: [sqlite3_bind_blob|sqlite3_bind()], 28985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_bind_parameter_name()], and 28995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_bind_parameter_index()]. 29005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 29015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_bind_parameter_count(sqlite3_stmt*); 29025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 29035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 29045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Name Of A Host Parameter 29055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 29065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_bind_parameter_name(P,N) interface returns 29075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the name of the N-th [SQL parameter] in the [prepared statement] P. 29085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA" 29095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA" 29105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** respectively. 29115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** In other words, the initial ":" or "$" or "@" or "?" 29125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is included as part of the name.)^ 29135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Parameters of the form "?" without a following integer have no name 29145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and are referred to as "nameless" or "anonymous parameters". 29155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 29165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The first host parameter has an index of 1, not 0. 29175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 29185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the value N is out of range or if the N-th parameter is 29195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** nameless, then NULL is returned. ^The returned string is 29205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** always in UTF-8 encoding even if the named parameter was 29215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** originally specified as UTF-16 in [sqlite3_prepare16()] or 29225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_prepare16_v2()]. 29235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 29245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also: [sqlite3_bind_blob|sqlite3_bind()], 29255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_bind_parameter_count()], and 29265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_bind_parameter_index()]. 29275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 29285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); 29295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 29305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 29315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Index Of A Parameter With A Given Name 29325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 29335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Return the index of an SQL parameter given its name. ^The 29345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** index value returned is suitable for use as the second 29355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero 29365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is returned if no matching parameter is found. ^The parameter 29375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** name must be given in UTF-8 even if the original statement 29385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** was prepared from UTF-16 text using [sqlite3_prepare16_v2()]. 29395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 29405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also: [sqlite3_bind_blob|sqlite3_bind()], 29415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_bind_parameter_count()], and 29425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_bind_parameter_index()]. 29435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 29445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); 29455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 29465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 29475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Reset All Bindings On A Prepared Statement 29485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 29495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset 29505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the [sqlite3_bind_blob | bindings] on a [prepared statement]. 29515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Use this routine to reset all host parameters to NULL. 29525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 29535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_clear_bindings(sqlite3_stmt*); 29545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 29555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 29565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Number Of Columns In A Result Set 29575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 29585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Return the number of columns in the result set returned by the 29595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [prepared statement]. ^This routine returns 0 if pStmt is an SQL 29605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** statement that does not return data (for example an [UPDATE]). 29615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 29625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also: [sqlite3_data_count()] 29635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 29645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_column_count(sqlite3_stmt *pStmt); 29655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 29665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 29675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Column Names In A Result Set 29685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 29695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^These routines return the name assigned to a particular column 29705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in the result set of a [SELECT] statement. ^The sqlite3_column_name() 29715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interface returns a pointer to a zero-terminated UTF-8 string 29725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and sqlite3_column_name16() returns a pointer to a zero-terminated 29735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** UTF-16 string. ^The first parameter is the [prepared statement] 29745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that implements the [SELECT] statement. ^The second parameter is the 29755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** column number. ^The leftmost column is number 0. 29765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 29775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The returned string pointer is valid until either the [prepared statement] 29785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is destroyed by [sqlite3_finalize()] or until the statement is automatically 29795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** reprepared by the first call to [sqlite3_step()] for a particular run 29805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or until the next call to 29815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_column_name() or sqlite3_column_name16() on the same column. 29825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 29835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If sqlite3_malloc() fails during the processing of either routine 29845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** (for example during a conversion from UTF-8 to UTF-16) then a 29855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** NULL pointer is returned. 29865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 29875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The name of a result column is the value of the "AS" clause for 29885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that column, if there is an AS clause. If there is no AS clause 29895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then the name of the column is unspecified and may change from 29905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** one release of SQLite to the next. 29915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 29925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char *sqlite3_column_name(sqlite3_stmt*, int N); 29935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const void *sqlite3_column_name16(sqlite3_stmt*, int N); 29945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 29955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 29965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Source Of Data In A Query Result 29975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 29985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^These routines provide a means to determine the database, table, and 29995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** table column that is the origin of a particular result column in 30005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SELECT] statement. 30015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The name of the database or table or column can be returned as 30025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** either a UTF-8 or UTF-16 string. ^The _database_ routines return 30035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the database name, the _table_ routines return the table name, and 30045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the origin_ routines return the column name. 30055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The returned string is valid until the [prepared statement] is destroyed 30065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** using [sqlite3_finalize()] or until the statement is automatically 30075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** reprepared by the first call to [sqlite3_step()] for a particular run 30085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or until the same information is requested 30095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** again in a different encoding. 30105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 30115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The names returned are the original un-aliased names of the 30125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database, table, and column. 30135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 30145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The first argument to these interfaces is a [prepared statement]. 30155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^These functions return information about the Nth result column returned by 30165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the statement, where N is the second function argument. 30175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The left-most column is column 0 for these routines. 30185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 30195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the Nth column returned by the statement is an expression or 30205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** subquery and is not a column value, then all of these functions return 30215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** NULL. ^These routine might also return NULL if a memory allocation error 30225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** occurs. ^Otherwise, they return the name of the attached database, table, 30235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or column that query result column was extracted from. 30245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 30255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^As with all other SQLite APIs, those whose names end with "16" return 30265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** UTF-16 encoded strings and the other functions return UTF-8. 30275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 30285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^These APIs are only available if the library was compiled with the 30295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol. 30305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 30315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If two or more threads call one or more of these routines against the same 30325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** prepared statement and column at the same time then the results are 30335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** undefined. 30345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 30355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If two or more threads call one or more 30365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_column_database_name | column metadata interfaces] 30375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for the same [prepared statement] and result column 30385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** at the same time then the results are undefined. 30395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 30405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char *sqlite3_column_database_name(sqlite3_stmt*,int); 30415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const void *sqlite3_column_database_name16(sqlite3_stmt*,int); 30425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char *sqlite3_column_table_name(sqlite3_stmt*,int); 30435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const void *sqlite3_column_table_name16(sqlite3_stmt*,int); 30445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char *sqlite3_column_origin_name(sqlite3_stmt*,int); 30455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); 30465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 30475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 30485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Declared Datatype Of A Query Result 30495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 30505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The first parameter is a [prepared statement]. 30515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If this statement is a [SELECT] statement and the Nth column of the 30525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** returned result set of that [SELECT] is a table column (not an 30535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** expression or subquery) then the declared type of the table 30545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** column is returned.)^ ^If the Nth column of the result set is an 30555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** expression or subquery, then a NULL pointer is returned. 30565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The returned string is always UTF-8 encoded. 30575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 30585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(For example, given the database schema: 30595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 30605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CREATE TABLE t1(c1 VARIANT); 30615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 30625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and the following statement to be compiled: 30635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 30645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SELECT c1 + 1, c1 FROM t1; 30655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 30665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** this routine would return the string "VARIANT" for the second result 30675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** column (i==1), and a NULL pointer for the first result column (i==0).)^ 30685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 30695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^SQLite uses dynamic run-time typing. ^So just because a column 30705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is declared to contain a particular type does not mean that the 30715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** data stored in that column is of the declared type. SQLite is 30725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** strongly typed, but the typing is dynamic not static. ^Type 30735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is associated with individual values, not with the containers 30745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** used to hold those values. 30755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 30765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char *sqlite3_column_decltype(sqlite3_stmt*,int); 30775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const void *sqlite3_column_decltype16(sqlite3_stmt*,int); 30785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 30795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 30805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Evaluate An SQL Statement 30815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 30825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** After a [prepared statement] has been prepared using either 30835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy 30845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function 30855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** must be called one or more times to evaluate the statement. 30865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 30875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The details of the behavior of the sqlite3_step() interface depend 30885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** on whether the statement was prepared using the newer "v2" interface 30895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy 30905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interface [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the 30915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** new "v2" interface is recommended for new applications but the legacy 30925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interface will continue to be supported. 30935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 30945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^In the legacy interface, the return value will be either [SQLITE_BUSY], 30955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE]. 30965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^With the "v2" interface, any of the other [result codes] or 30975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [extended result codes] might be returned as well. 30985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 30995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^[SQLITE_BUSY] means that the database engine was unable to acquire the 31005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database locks it needs to do its job. ^If the statement is a [COMMIT] 31015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or occurs outside of an explicit transaction, then you can retry the 31025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** statement. If the statement is not a [COMMIT] and occurs within a 31035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** explicit transaction then you should rollback the transaction before 31045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** continuing. 31055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 31065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^[SQLITE_DONE] means that the statement has finished executing 31075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** successfully. sqlite3_step() should not be called again on this virtual 31085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** machine without first calling [sqlite3_reset()] to reset the virtual 31095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** machine back to its initial state. 31105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 31115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the SQL statement being executed returns any data, then [SQLITE_ROW] 31125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is returned each time a new row of data is ready for processing by the 31135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** caller. The values may be accessed using the [column access functions]. 31145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_step() is called again to retrieve the next row of data. 31155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 31165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^[SQLITE_ERROR] means that a run-time error (such as a constraint 31175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** violation) has occurred. sqlite3_step() should not be called again on 31185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the VM. More information may be found by calling [sqlite3_errmsg()]. 31195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^With the legacy interface, a more specific error code (for example, 31205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth) 31215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** can be obtained by calling [sqlite3_reset()] on the 31225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [prepared statement]. ^In the "v2" interface, 31235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the more specific error code is returned directly by sqlite3_step(). 31245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 31255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_MISUSE] means that the this routine was called inappropriately. 31265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Perhaps it was called on a [prepared statement] that has 31275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** already been [sqlite3_finalize | finalized] or on one that had 31285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could 31295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** be the case that the same database connection is being used by two or 31305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** more threads at the same moment in time. 31315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 31325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** For all versions of SQLite up to and including 3.6.23.1, a call to 31335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_reset()] was required after sqlite3_step() returned anything 31345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** other than [SQLITE_ROW] before any subsequent invocation of 31355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_step(). Failure to reset the prepared statement using 31365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from 31375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_step(). But after version 3.6.23.1, sqlite3_step() began 31385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** calling [sqlite3_reset()] automatically in this circumstance rather 31395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** than returning [SQLITE_MISUSE]. This is not considered a compatibility 31405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** break because any application that ever receives an SQLITE_MISUSE error 31415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option 31425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** can be used to restore the legacy behavior. 31435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 31445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step() 31455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** API always returns a generic error code, [SQLITE_ERROR], following any 31465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call 31475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the 31485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** specific [error codes] that better describes the error. 31495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** We admit that this is a goofy design. The problem has been fixed 31505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** with the "v2" interface. If you prepare all of your SQL statements 31515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead 31525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces, 31535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then the more specific [error codes] are returned directly 31545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by sqlite3_step(). The use of the "v2" interface is recommended. 31555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 31565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_step(sqlite3_stmt*); 31575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 31585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 31595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Number of columns in a result set 31605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 31615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_data_count(P) interface returns the number of columns in the 31625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** current row of the result set of [prepared statement] P. 31635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If prepared statement P does not have results ready to return 31645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of 31655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interfaces) then sqlite3_data_count(P) returns 0. 31665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer. 31675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 31685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also: [sqlite3_column_count()] 31695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 31705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_data_count(sqlite3_stmt *pStmt); 31715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 31725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 31735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Fundamental Datatypes 31745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: SQLITE_TEXT 31755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 31765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(Every value in SQLite has one of five fundamental datatypes: 31775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 31785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <ul> 31795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> 64-bit signed integer 31805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> 64-bit IEEE floating point number 31815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> string 31825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> BLOB 31835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> NULL 31845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </ul>)^ 31855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 31865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These constants are codes for each of those types. 31875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 31885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Note that the SQLITE_TEXT constant was also used in SQLite version 2 31895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for a completely different meaning. Software that links against both 31905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not 31915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLITE_TEXT. 31925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 31935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_INTEGER 1 31945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_FLOAT 2 31955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_BLOB 4 31965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_NULL 5 31975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef SQLITE_TEXT 31985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# undef SQLITE_TEXT 31995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else 32005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define SQLITE_TEXT 3 32015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 32025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE3_TEXT 3 32035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 32045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 32055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Result Values From A Query 32065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: {column access functions} 32075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 32085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These routines form the "result set" interface. 32095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 32105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^These routines return information about a single column of the current 32115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** result row of a query. ^In every case the first argument is a pointer 32125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*] 32135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that was returned from [sqlite3_prepare_v2()] or one of its variants) 32145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and the second argument is the index of the column for which information 32155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** should be returned. ^The leftmost column of the result set has the index 0. 32165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The number of columns in the result can be determined using 32175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_column_count()]. 32185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 32195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If the SQL statement does not currently point to a valid row, or if the 32205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** column index is out of range, the result is undefined. 32215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These routines may only be called when the most recent call to 32225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_step()] has returned [SQLITE_ROW] and neither 32235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently. 32245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If any of these routines are called after [sqlite3_reset()] or 32255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_finalize()] or after [sqlite3_step()] has returned 32265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** something other than [SQLITE_ROW], the results are undefined. 32275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()] 32285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are called from a different thread while any of these routines 32295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are pending, then the results are undefined. 32305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 32315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_column_type() routine returns the 32325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_INTEGER | datatype code] for the initial data type 32335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of the result column. ^The returned value is one of [SQLITE_INTEGER], 32345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. The value 32355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** returned by sqlite3_column_type() is only meaningful if no type 32365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** conversions have occurred as described below. After a type conversion, 32375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the value returned by sqlite3_column_type() is undefined. Future 32385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** versions of SQLite may change the behavior of sqlite3_column_type() 32395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** following a type conversion. 32405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 32415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes() 32425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** routine returns the number of bytes in that BLOB or string. 32435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts 32445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the string to UTF-8 and then returns the number of bytes. 32455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the result is a numeric value then sqlite3_column_bytes() uses 32465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns 32475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the number of bytes in that string. 32485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the result is NULL, then sqlite3_column_bytes() returns zero. 32495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 32505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16() 32515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** routine returns the number of bytes in that BLOB or string. 32525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts 32535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the string to UTF-16 and then returns the number of bytes. 32545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the result is a numeric value then sqlite3_column_bytes16() uses 32555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns 32565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the number of bytes in that string. 32575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the result is NULL, then sqlite3_column_bytes16() returns zero. 32585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 32595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The values returned by [sqlite3_column_bytes()] and 32605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_column_bytes16()] do not include the zero terminators at the end 32615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of the string. ^For clarity: the values returned by 32625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of 32635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** bytes in the string, not the number of characters. 32645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 32655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(), 32665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** even empty strings, are always zero terminated. ^The return 32675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer. 32685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 32695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The object returned by [sqlite3_column_value()] is an 32705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [unprotected sqlite3_value] object. An unprotected sqlite3_value object 32715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()]. 32725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If the [unprotected sqlite3_value] object returned by 32735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_column_value()] is used in any other way, including calls 32745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to routines like [sqlite3_value_int()], [sqlite3_value_text()], 32755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or [sqlite3_value_bytes()], then the behavior is undefined. 32765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 32775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These routines attempt to convert the value where appropriate. ^For 32785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** example, if the internal representation is FLOAT and a text result 32795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is requested, [sqlite3_snprintf()] is used internally to perform the 32805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** conversion automatically. ^(The following table details the conversions 32815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that are applied: 32825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 32835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <blockquote> 32845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <table border="1"> 32855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion 32865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 32875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> NULL <td> INTEGER <td> Result is 0 32885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> NULL <td> FLOAT <td> Result is 0.0 32895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> NULL <td> TEXT <td> Result is NULL pointer 32905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> NULL <td> BLOB <td> Result is NULL pointer 32915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float 32925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer 32935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT 32945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> FLOAT <td> INTEGER <td> Convert from float to integer 32955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float 32965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> FLOAT <td> BLOB <td> Same as FLOAT->TEXT 32975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> TEXT <td> INTEGER <td> Use atoi() 32985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> TEXT <td> FLOAT <td> Use atof() 32995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> TEXT <td> BLOB <td> No change 33005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> BLOB <td> INTEGER <td> Convert to TEXT then use atoi() 33015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> BLOB <td> FLOAT <td> Convert to TEXT then use atof() 33025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed 33035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </table> 33045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </blockquote>)^ 33055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 33065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The table above makes reference to standard C library functions atoi() 33075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and atof(). SQLite does not really use these functions. It has its 33085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** own equivalent internal routines. The atoi() and atof() names are 33095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** used in the table for brevity and because they are familiar to most 33105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** C programmers. 33115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 33125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Note that when type conversions occur, pointers returned by prior 33135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or 33145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_column_text16() may be invalidated. 33155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Type conversions and pointer invalidations might occur 33165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in the following cases: 33175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 33185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <ul> 33195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> The initial content is a BLOB and sqlite3_column_text() or 33205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_column_text16() is called. A zero-terminator might 33215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** need to be added to the string.</li> 33225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or 33235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_column_text16() is called. The content must be converted 33245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to UTF-16.</li> 33255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or 33265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_column_text() is called. The content must be converted 33275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to UTF-8.</li> 33285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </ul> 33295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 33305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Conversions between UTF-16be and UTF-16le are always done in place and do 33315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** not invalidate a prior pointer, though of course the content of the buffer 33325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that the prior pointer references will have been modified. Other kinds 33335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of conversion are done in place when it is possible, but sometimes they 33345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are not possible and in those cases prior pointers are invalidated. 33355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 33365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The safest and easiest to remember policy is to invoke these routines 33375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in one of the following ways: 33385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 33395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <ul> 33405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li> 33415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li> 33425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li> 33435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </ul> 33445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 33455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** In other words, you should call sqlite3_column_text(), 33465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result 33475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** into the desired format, then invoke sqlite3_column_bytes() or 33485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_column_bytes16() to find the size of the result. Do not mix calls 33495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to sqlite3_column_text() or sqlite3_column_blob() with calls to 33505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16() 33515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** with calls to sqlite3_column_bytes(). 33525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 33535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The pointers returned are valid until a type conversion occurs as 33545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** described above, or until [sqlite3_step()] or [sqlite3_reset()] or 33555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_finalize()] is called. ^The memory space used to hold strings 33565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned 33575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into 33585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_free()]. 33595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 33605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(If a memory allocation error occurs during the evaluation of any 33615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of these routines, a default value is returned. The default value 33625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is either the integer 0, the floating point number 0.0, or a NULL 33635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** pointer. Subsequent calls to [sqlite3_errcode()] will return 33645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_NOMEM].)^ 33655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 33665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); 33675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_column_bytes(sqlite3_stmt*, int iCol); 33685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_column_bytes16(sqlite3_stmt*, int iCol); 33695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)double sqlite3_column_double(sqlite3_stmt*, int iCol); 33705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_column_int(sqlite3_stmt*, int iCol); 33715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol); 33725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); 33735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const void *sqlite3_column_text16(sqlite3_stmt*, int iCol); 33745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_column_type(sqlite3_stmt*, int iCol); 33755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol); 33765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 33775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 33785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Destroy A Prepared Statement Object 33795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 33805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_finalize() function is called to delete a [prepared statement]. 33815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the most recent evaluation of the statement encountered no errors or 33825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or if the statement is never been evaluated, then sqlite3_finalize() returns 33835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLITE_OK. ^If the most recent evaluation of statement S failed, then 33845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_finalize(S) returns the appropriate [error code] or 33855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [extended error code]. 33865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 33875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_finalize(S) routine can be called at any point during 33885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the life cycle of [prepared statement] S: 33895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** before statement S is ever evaluated, after 33905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** one or more calls to [sqlite3_reset()], or after any call 33915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to [sqlite3_step()] regardless of whether or not the statement has 33925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** completed execution. 33935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 33945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op. 33955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 33965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The application must finalize every [prepared statement] in order to avoid 33975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** resource leaks. It is a grievous error for the application to try to use 33985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a prepared statement after it has been finalized. Any use of a prepared 33995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** statement after it has been finalized can result in undefined and 34005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** undesirable behavior such as segfaults and heap corruption. 34015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 34025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_finalize(sqlite3_stmt *pStmt); 34035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 34045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 34055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Reset A Prepared Statement Object 34065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 34075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The sqlite3_reset() function is called to reset a [prepared statement] 34085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** object back to its initial state, ready to be re-executed. 34095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Any SQL statement variables that had values bound to them using 34105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values. 34115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Use [sqlite3_clear_bindings()] to reset the bindings. 34125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 34135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S 34145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** back to the beginning of its program. 34155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 34165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the most recent call to [sqlite3_step(S)] for the 34175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE], 34185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or if [sqlite3_step(S)] has never before been called on S, 34195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then [sqlite3_reset(S)] returns [SQLITE_OK]. 34205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 34215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the most recent call to [sqlite3_step(S)] for the 34225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [prepared statement] S indicated an error, then 34235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_reset(S)] returns an appropriate [error code]. 34245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 34255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [sqlite3_reset(S)] interface does not change the values 34265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S. 34275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 34285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_reset(sqlite3_stmt *pStmt); 34295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 34305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 34315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Create Or Redefine SQL Functions 34325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: {function creation routines} 34335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: {application-defined SQL function} 34345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: {application-defined SQL functions} 34355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 34365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^These functions (collectively known as "function creation routines") 34375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are used to add SQL functions or aggregates or to redefine the behavior 34385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of existing SQL functions or aggregates. The only differences between 34395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** these routines are the text encoding expected for 34405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the second parameter (the name of the function being created) 34415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and the presence or absence of a destructor callback for 34425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the application data pointer. 34435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 34445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The first parameter is the [database connection] to which the SQL 34455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function is to be added. ^If an application uses more than one database 34465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** connection then application-defined SQL functions must be added 34475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to each database connection separately. 34485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 34495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The second parameter is the name of the SQL function to be created or 34505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** redefined. ^The length of the name is limited to 255 bytes in a UTF-8 34515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** representation, exclusive of the zero-terminator. ^Note that the name 34525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes. 34535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Any attempt to create a function with a longer name 34545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** will result in [SQLITE_MISUSE] being returned. 34555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 34565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The third parameter (nArg) 34575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is the number of arguments that the SQL function or 34585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** aggregate takes. ^If this parameter is -1, then the SQL function or 34595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** aggregate may take any number of arguments between 0 and the limit 34605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third 34615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** parameter is less than -1 or greater than 127 then the behavior is 34625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** undefined. 34635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 34645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The fourth parameter, eTextRep, specifies what 34655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_UTF8 | text encoding] this SQL function prefers for 34665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** its parameters. Every SQL function implementation must be able to work 34675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be 34685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** more efficient with one encoding than another. ^An application may 34695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** invoke sqlite3_create_function() or sqlite3_create_function16() multiple 34705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** times with the same function but with different values of eTextRep. 34715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^When multiple implementations of the same function are available, SQLite 34725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** will pick the one that involves the least amount of data conversion. 34735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If there is only a single implementation which does not care what text 34745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** encoding is used, then the fourth argument should be [SQLITE_ANY]. 34755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 34765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The fifth parameter is an arbitrary pointer. The implementation of the 34775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function can gain access to this pointer using [sqlite3_user_data()].)^ 34785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 34795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are 34805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** pointers to C-language functions that implement the SQL function or 34815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** aggregate. ^A scalar SQL function requires an implementation of the xFunc 34825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** callback only; NULL pointers must be passed as the xStep and xFinal 34835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** parameters. ^An aggregate SQL function requires an implementation of xStep 34845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing 34855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQL function or aggregate, pass NULL pointers for all three function 34865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** callbacks. 34875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 34885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(If the ninth parameter to sqlite3_create_function_v2() is not NULL, 34895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then it is destructor for the application data pointer. 34905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The destructor is invoked when the function is deleted, either by being 34915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** overloaded or when the database connection closes.)^ 34925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The destructor is also invoked if the call to 34935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_create_function_v2() fails. 34945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^When the destructor callback of the tenth parameter is invoked, it 34955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is passed a single argument which is a copy of the application data 34965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** pointer which was the fifth parameter to sqlite3_create_function_v2(). 34975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 34985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^It is permitted to register multiple implementations of the same 34995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** functions with the same name but with either differing numbers of 35005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** arguments or differing preferred text encodings. ^SQLite will use 35015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the implementation that most closely matches the way in which the 35025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQL function is used. ^A function implementation with a non-negative 35035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** nArg parameter is a better match than a function implementation with 35045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a negative nArg. ^A function where the preferred text encoding 35055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** matches the database encoding is a better 35065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** match than a function where the encoding is different. 35075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^A function where the encoding difference is between UTF16le and UTF16be 35085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is a closer match than a function where the encoding difference is 35095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** between UTF8 and UTF16. 35105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 35115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Built-in functions may be overloaded by new application-defined functions. 35125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 35135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^An application-defined function is permitted to call other 35145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite interfaces. However, such calls must not 35155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** close the database connection nor finalize or reset the prepared 35165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** statement in which the function is running. 35175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 35185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_create_function( 35195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3 *db, 35205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zFunctionName, 35215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int nArg, 35225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int eTextRep, 35235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void *pApp, 35245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 35255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xStep)(sqlite3_context*,int,sqlite3_value**), 35265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xFinal)(sqlite3_context*) 35275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 35285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_create_function16( 35295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3 *db, 35305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const void *zFunctionName, 35315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int nArg, 35325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int eTextRep, 35335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void *pApp, 35345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 35355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xStep)(sqlite3_context*,int,sqlite3_value**), 35365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xFinal)(sqlite3_context*) 35375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 35385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_create_function_v2( 35395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3 *db, 35405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zFunctionName, 35415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int nArg, 35425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int eTextRep, 35435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void *pApp, 35445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 35455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xStep)(sqlite3_context*,int,sqlite3_value**), 35465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xFinal)(sqlite3_context*), 35475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void(*xDestroy)(void*) 35485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 35495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 35505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 35515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Text Encodings 35525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 35535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These constant define integer codes that represent the various 35545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** text encodings supported by SQLite. 35555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 35565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_UTF8 1 35575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_UTF16LE 2 35585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_UTF16BE 3 35595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_UTF16 4 /* Use native byte order */ 35605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_ANY 5 /* sqlite3_create_function only */ 35615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ 35625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 35635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 35645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Deprecated Functions 35655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** DEPRECATED 35665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 35675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These functions are [deprecated]. In order to maintain 35685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** backwards compatibility with older code, these functions continue 35695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to be supported. However, new applications should avoid 35705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the use of these functions. To help encourage people to avoid 35715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** using these functions, we are not going to tell you what they do. 35725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 35735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef SQLITE_OMIT_DEPRECATED 35745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*); 35755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*); 35765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*); 35775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)SQLITE_DEPRECATED int sqlite3_global_recover(void); 35785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)SQLITE_DEPRECATED void sqlite3_thread_cleanup(void); 35795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64); 35805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 35815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 35825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 35835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Obtaining SQL Function Parameter Values 35845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 35855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The C-language implementation of SQL functions and aggregates uses 35865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** this set of interface routines to access the parameter values on 35875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the function or aggregate. 35885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 35895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The xFunc (for scalar functions) or xStep (for aggregates) parameters 35905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to [sqlite3_create_function()] and [sqlite3_create_function16()] 35915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** define callbacks that implement the SQL functions and aggregates. 35925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The 3rd parameter to these callbacks is an array of pointers to 35935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [protected sqlite3_value] objects. There is one [sqlite3_value] object for 35945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** each parameter to the SQL function. These routines are used to 35955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** extract values from the [sqlite3_value] objects. 35965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 35975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These routines work only with [protected sqlite3_value] objects. 35985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Any attempt to use these routines on an [unprotected sqlite3_value] 35995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** object results in undefined behavior. 36005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 36015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^These routines work just like the corresponding [column access functions] 36025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** except that these routines take a single [protected sqlite3_value] object 36035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** pointer instead of a [sqlite3_stmt*] pointer and an integer column number. 36045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 36055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_value_text16() interface extracts a UTF-16 string 36065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in the native byte-order of the host machine. ^The 36075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces 36085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** extract UTF-16 strings as big-endian and little-endian respectively. 36095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 36105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The sqlite3_value_numeric_type() interface attempts to apply 36115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** numeric affinity to the value. This means that an attempt is 36125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** made to convert the value to an integer or floating point. If 36135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** such a conversion is possible without loss of information (in other 36145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** words, if the value is a string that looks like a number) 36155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then the conversion is performed. Otherwise no conversion occurs. 36165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The [SQLITE_INTEGER | datatype] after conversion is returned.)^ 36175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 36185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Please pay particular attention to the fact that the pointer returned 36195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** from [sqlite3_value_blob()], [sqlite3_value_text()], or 36205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_value_text16()] can be invalidated by a subsequent call to 36215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()], 36225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or [sqlite3_value_text16()]. 36235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 36245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These routines must be called from the same thread as 36255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the SQL function that supplied the [sqlite3_value*] parameters. 36265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 36275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const void *sqlite3_value_blob(sqlite3_value*); 36285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_value_bytes(sqlite3_value*); 36295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_value_bytes16(sqlite3_value*); 36305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)double sqlite3_value_double(sqlite3_value*); 36315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_value_int(sqlite3_value*); 36325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)sqlite3_int64 sqlite3_value_int64(sqlite3_value*); 36335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const unsigned char *sqlite3_value_text(sqlite3_value*); 36345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const void *sqlite3_value_text16(sqlite3_value*); 36355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const void *sqlite3_value_text16le(sqlite3_value*); 36365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const void *sqlite3_value_text16be(sqlite3_value*); 36375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_value_type(sqlite3_value*); 36385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_value_numeric_type(sqlite3_value*); 36395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 36405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 36415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Obtain Aggregate Function Context 36425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 36435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Implementations of aggregate SQL functions use this 36445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** routine to allocate memory for storing their state. 36455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 36465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The first time the sqlite3_aggregate_context(C,N) routine is called 36475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for a particular aggregate function, SQLite 36485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** allocates N of memory, zeroes out that memory, and returns a pointer 36495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to the new memory. ^On second and subsequent calls to 36505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_aggregate_context() for the same aggregate function instance, 36515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the same buffer is returned. Sqlite3_aggregate_context() is normally 36525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** called once for each invocation of the xStep callback and then one 36535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** last time when the xFinal callback is invoked. ^(When no rows match 36545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** an aggregate query, the xStep() callback of the aggregate function 36555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** implementation is never called and xFinal() is called exactly once. 36565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** In those cases, sqlite3_aggregate_context() might be called for the 36575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** first time from within xFinal().)^ 36585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 36595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer if N is 36605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** less than or equal to zero or if a memory allocate error occurs. 36615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 36625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is 36635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** determined by the N parameter on first successful call. Changing the 36645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** value of N in subsequent call to sqlite3_aggregate_context() within 36655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the same aggregate function instance will not resize the memory 36665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** allocation.)^ 36675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 36685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^SQLite automatically frees the memory allocated by 36695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_aggregate_context() when the aggregate query concludes. 36705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 36715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The first parameter must be a copy of the 36725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_context | SQL function context] that is the first parameter 36735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to the xStep or xFinal callback routine that implements the aggregate 36745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function. 36755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 36765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This routine must be called from the same thread in which 36775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the aggregate SQL function is running. 36785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 36795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); 36805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 36815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 36825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: User Data For Functions 36835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 36845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_user_data() interface returns a copy of 36855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the pointer that was the pUserData parameter (the 5th parameter) 36865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of the [sqlite3_create_function()] 36875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and [sqlite3_create_function16()] routines that originally 36885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** registered the application defined function. 36895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 36905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This routine must be called from the same thread in which 36915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the application-defined function is running. 36925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 36935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void *sqlite3_user_data(sqlite3_context*); 36945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 36955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 36965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Database Connection For Functions 36975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 36985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_context_db_handle() interface returns a copy of 36995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the pointer to the [database connection] (the 1st parameter) 37005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of the [sqlite3_create_function()] 37015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and [sqlite3_create_function16()] routines that originally 37025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** registered the application defined function. 37035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 37045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)sqlite3 *sqlite3_context_db_handle(sqlite3_context*); 37055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 37065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 37075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Function Auxiliary Data 37085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 37095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The following two functions may be used by scalar SQL functions to 37105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** associate metadata with argument values. If the same value is passed to 37115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** multiple invocations of the same SQL function during query execution, under 37125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** some circumstances the associated metadata may be preserved. This may 37135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** be used, for example, to add a regular-expression matching scalar 37145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function. The compiled version of the regular expression is stored as 37155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** metadata associated with the SQL value passed as the regular expression 37165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** pattern. The compiled regular expression can be reused on multiple 37175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** invocations of the same function so that the original pattern string 37185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** does not need to be recompiled on each invocation. 37195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 37205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata 37215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** associated by the sqlite3_set_auxdata() function with the Nth argument 37225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** value to the application-defined function. ^If no metadata has been ever 37235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** been set for the Nth argument of the function, or if the corresponding 37245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function parameter has changed since the meta-data was set, 37255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then sqlite3_get_auxdata() returns a NULL pointer. 37265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 37275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_set_auxdata() interface saves the metadata 37285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** pointed to by its 3rd parameter as the metadata for the N-th 37295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** argument of the application-defined function. Subsequent 37305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** calls to sqlite3_get_auxdata() might return this data, if it has 37315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** not been destroyed. 37325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If it is not NULL, SQLite will invoke the destructor 37335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function given by the 4th parameter to sqlite3_set_auxdata() on 37345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the metadata when the corresponding function parameter changes 37355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or when the SQL statement completes, whichever comes first. 37365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 37375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite is free to call the destructor and drop metadata on any 37385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** parameter of any function at any time. ^The only guarantee is that 37395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the destructor will be called before the metadata is dropped. 37405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 37415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(In practice, metadata is preserved between function calls for 37425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** expressions that are constant at compile time. This includes literal 37435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** values and [parameters].)^ 37445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 37455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These routines must be called from the same thread in which 37465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the SQL function is running. 37475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 37485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void *sqlite3_get_auxdata(sqlite3_context*, int N); 37495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*)); 37505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 37515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 37525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 37535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Constants Defining Special Destructor Behavior 37545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 37555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These are special values for the destructor that is passed in as the 37565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** final argument to routines like [sqlite3_result_blob()]. ^If the destructor 37575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** argument is SQLITE_STATIC, it means that the content pointer is constant 37585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and will never change. It does not need to be destroyed. ^The 37595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLITE_TRANSIENT value means that the content will likely change in 37605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the near future and that SQLite should make its own private copy of 37615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the content before returning. 37625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 37635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The typedef is necessary to work around problems in certain 37645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** C++ compilers. See ticket #2191. 37655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 37665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef void (*sqlite3_destructor_type)(void*); 37675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_STATIC ((sqlite3_destructor_type)0) 37685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) 37695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 37705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 37715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Setting The Result Of An SQL Function 37725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 37735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These routines are used by the xFunc or xFinal callbacks that 37745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** implement SQL functions and aggregates. See 37755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_create_function()] and [sqlite3_create_function16()] 37765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for additional information. 37775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 37785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These functions work very much like the [parameter binding] family of 37795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** functions used to bind values to host parameters in prepared statements. 37805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Refer to the [SQL parameter] documentation for additional information. 37815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 37825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_result_blob() interface sets the result from 37835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** an application-defined function to be the BLOB whose content is pointed 37845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to by the second parameter and which is N bytes long where N is the 37855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** third parameter. 37865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 37875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_result_zeroblob() interfaces set the result of 37885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the application-defined function to be a BLOB containing all zero 37895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** bytes and N bytes in size, where N is the value of the 2nd parameter. 37905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 37915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_result_double() interface sets the result from 37925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** an application-defined function to be a floating point value specified 37935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by its 2nd argument. 37945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 37955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_result_error() and sqlite3_result_error16() functions 37965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** cause the implemented SQL function to throw an exception. 37975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^SQLite uses the string pointed to by the 37985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16() 37995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** as the text of an error message. ^SQLite interprets the error 38005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** message string from sqlite3_result_error() as UTF-8. ^SQLite 38015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interprets the string from sqlite3_result_error16() as UTF-16 in native 38025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** byte order. ^If the third parameter to sqlite3_result_error() 38035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or sqlite3_result_error16() is negative then SQLite takes as the error 38045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** message all text up through the first zero character. 38055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the third parameter to sqlite3_result_error() or 38065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_result_error16() is non-negative then SQLite takes that many 38075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** bytes (not characters) from the 2nd parameter as the error message. 38085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_result_error() and sqlite3_result_error16() 38095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** routines make a private copy of the error message text before 38105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** they return. Hence, the calling function can deallocate or 38115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** modify the text after they return without harm. 38125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_result_error_code() function changes the error code 38135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** returned by SQLite as a result of an error in a function. ^By default, 38145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error() 38155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or sqlite3_result_error16() resets the error code to SQLITE_ERROR. 38165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 38175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_result_toobig() interface causes SQLite to throw an error 38185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** indicating that a string or BLOB is too long to represent. 38195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 38205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_result_nomem() interface causes SQLite to throw an error 38215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** indicating that a memory allocation failed. 38225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 38235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_result_int() interface sets the return value 38245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of the application-defined function to be the 32-bit signed integer 38255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** value given in the 2nd argument. 38265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_result_int64() interface sets the return value 38275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of the application-defined function to be the 64-bit signed integer 38285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** value given in the 2nd argument. 38295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 38305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_result_null() interface sets the return value 38315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of the application-defined function to be NULL. 38325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 38335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_result_text(), sqlite3_result_text16(), 38345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces 38355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** set the return value of the application-defined function to be 38365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a text string which is represented as UTF-8, UTF-16 native byte order, 38375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** UTF-16 little endian, or UTF-16 big endian, respectively. 38385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^SQLite takes the text result from the application from 38395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the 2nd parameter of the sqlite3_result_text* interfaces. 38405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the 3rd parameter to the sqlite3_result_text* interfaces 38415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is negative, then SQLite takes result text from the 2nd parameter 38425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** through the first zero character. 38435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the 3rd parameter to the sqlite3_result_text* interfaces 38445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is non-negative, then as many bytes (not characters) of the text 38455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** pointed to by the 2nd parameter are taken as the application-defined 38465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function result. 38475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the 4th parameter to the sqlite3_result_text* interfaces 38485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that 38495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function as the destructor on the text or BLOB result when it has 38505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** finished using that result. 38515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the 4th parameter to the sqlite3_result_text* interfaces or to 38525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite 38535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** assumes that the text or BLOB result is in constant space and does not 38545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** copy the content of the parameter nor call a destructor on the content 38555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** when it has finished using that result. 38565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the 4th parameter to the sqlite3_result_text* interfaces 38575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT 38585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then SQLite makes a copy of the result into space obtained from 38595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** from [sqlite3_malloc()] before it returns. 38605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 38615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_result_value() interface sets the result of 38625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the application-defined function to be a copy the 38635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The 38645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_result_value() interface makes a copy of the [sqlite3_value] 38655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** so that the [sqlite3_value] specified in the parameter may change or 38665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** be deallocated after sqlite3_result_value() returns without harm. 38675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^A [protected sqlite3_value] object may always be used where an 38685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [unprotected sqlite3_value] object is required, so either 38695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** kind of [sqlite3_value] object can be used with this interface. 38705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 38715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If these routines are called from within the different thread 38725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** than the one containing the application-defined function that received 38735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the [sqlite3_context] pointer, the results are undefined. 38745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 38755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); 38765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_result_double(sqlite3_context*, double); 38775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_result_error(sqlite3_context*, const char*, int); 38785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_result_error16(sqlite3_context*, const void*, int); 38795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_result_error_toobig(sqlite3_context*); 38805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_result_error_nomem(sqlite3_context*); 38815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_result_error_code(sqlite3_context*, int); 38825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_result_int(sqlite3_context*, int); 38835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_result_int64(sqlite3_context*, sqlite3_int64); 38845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_result_null(sqlite3_context*); 38855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*)); 38865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*)); 38875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*)); 38885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*)); 38895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_result_value(sqlite3_context*, sqlite3_value*); 38905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_result_zeroblob(sqlite3_context*, int n); 38915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 38925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 38935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Define New Collating Sequences 38945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 38955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^These functions add, remove, or modify a [collation] associated 38965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** with the [database connection] specified as the first argument. 38975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 38985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The name of the collation is a UTF-8 string 38995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for sqlite3_create_collation() and sqlite3_create_collation_v2() 39005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and a UTF-16 string in native byte order for sqlite3_create_collation16(). 39015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Collation names that compare equal according to [sqlite3_strnicmp()] are 39025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** considered to be the same name. 39035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 39045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The third argument (eTextRep) must be one of the constants: 39055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <ul> 39065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_UTF8], 39075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_UTF16LE], 39085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_UTF16BE], 39095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_UTF16], or 39105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [SQLITE_UTF16_ALIGNED]. 39115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </ul>)^ 39125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The eTextRep argument determines the encoding of strings passed 39135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to the collating function callback, xCallback. 39145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep 39155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** force strings to be UTF16 with native byte order. 39165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin 39175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** on an even byte address. 39185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 39195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The fourth argument, pArg, is an application data pointer that is passed 39205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** through as the first argument to the collating function callback. 39215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 39225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The fifth argument, xCallback, is a pointer to the collating function. 39235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Multiple collating functions can be registered using the same name but 39245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** with different eTextRep parameters and SQLite will use whichever 39255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function requires the least amount of data transformation. 39265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the xCallback argument is NULL then the collating function is 39275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** deleted. ^When all collating functions having the same name are deleted, 39285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that collation is no longer usable. 39295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 39305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The collating function callback is invoked with a copy of the pArg 39315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** application data pointer and with two strings in the encoding specified 39325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by the eTextRep argument. The collating function must return an 39335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** integer that is negative, zero, or positive 39345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** if the first string is less than, equal to, or greater than the second, 39355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** respectively. A collating function must always return the same answer 39365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** given the same inputs. If two or more collating functions are registered 39375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to the same collation name (using different eTextRep values) then all 39385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** must give an equivalent answer when invoked with equivalent strings. 39395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The collating function must obey the following properties for all 39405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** strings A, B, and C: 39415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 39425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <ol> 39435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> If A==B then B==A. 39445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> If A==B and B==C then A==C. 39455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> If A<B THEN B>A. 39465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> If A<B and B<C then A<C. 39475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </ol> 39485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 39495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If a collating function fails any of the above constraints and that 39505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** collating function is registered and used, then the behavior of SQLite 39515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is undefined. 39525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 39535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation() 39545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** with the addition that the xDestroy callback is invoked on pArg when 39555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the collating function is deleted. 39565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Collating functions are deleted when they are overridden by later 39575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** calls to the collation creation functions or when the 39585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [database connection] is closed using [sqlite3_close()]. 39595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 39605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The xDestroy callback is <u>not</u> called if the 39615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_create_collation_v2() function fails. Applications that invoke 39625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should 39635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** check the return code and dispose of the application data pointer 39645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** themselves rather than expecting SQLite to deal with it for them. 39655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This is different from every other SQLite interface. The inconsistency 39665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is unfortunate but cannot be changed without breaking backwards 39675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** compatibility. 39685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 39695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()]. 39705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 39715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_create_collation( 39725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3*, 39735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zName, 39745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int eTextRep, 39755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void *pArg, 39765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int(*xCompare)(void*,int,const void*,int,const void*) 39775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 39785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_create_collation_v2( 39795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3*, 39805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zName, 39815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int eTextRep, 39825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void *pArg, 39835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int(*xCompare)(void*,int,const void*,int,const void*), 39845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void(*xDestroy)(void*) 39855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 39865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_create_collation16( 39875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3*, 39885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const void *zName, 39895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int eTextRep, 39905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void *pArg, 39915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int(*xCompare)(void*,int,const void*,int,const void*) 39925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 39935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 39945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 39955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Collation Needed Callbacks 39965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 39975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^To avoid having to register all collation sequences before a database 39985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** can be used, a single callback function may be registered with the 39995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [database connection] to be invoked whenever an undefined collation 40005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sequence is required. 40015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 40025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the function is registered using the sqlite3_collation_needed() API, 40035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then it is passed the names of undefined collation sequences as strings 40045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** encoded in UTF-8. ^If sqlite3_collation_needed16() is used, 40055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the names are passed as UTF-16 in machine native byte order. 40065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^A call to either function replaces the existing collation-needed callback. 40075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 40085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(When the callback is invoked, the first argument passed is a copy 40095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of the second argument to sqlite3_collation_needed() or 40105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_collation_needed16(). The second argument is the database 40115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE], 40125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or [SQLITE_UTF16LE], indicating the most desirable form of the collation 40135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sequence function required. The fourth parameter is the name of the 40145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** required collation sequence.)^ 40155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 40165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The callback function should register the desired collation using 40175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_create_collation()], [sqlite3_create_collation16()], or 40185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_create_collation_v2()]. 40195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 40205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_collation_needed( 40215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3*, 40225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void*, 40235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void(*)(void*,sqlite3*,int eTextRep,const char*) 40245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 40255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_collation_needed16( 40265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3*, 40275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void*, 40285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void(*)(void*,sqlite3*,int eTextRep,const void*) 40295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 40305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 40315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef SQLITE_HAS_CODEC 40325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 40335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Specify the key for an encrypted database. This routine should be 40345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** called right after sqlite3_open(). 40355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 40365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The code to implement this API is not available in the public release 40375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of SQLite. 40385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 40395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_key( 40405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3 *db, /* Database to be rekeyed */ 40415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const void *pKey, int nKey /* The key */ 40425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 40435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 40445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 40455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Change the key on an open database. If the current database is not 40465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the 40475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database is decrypted. 40485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 40495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The code to implement this API is not available in the public release 40505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of SQLite. 40515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 40525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_rekey( 40535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3 *db, /* Database to be rekeyed */ 40545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const void *pKey, int nKey /* The new key */ 40555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 40565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 40575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 40585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Specify the activation key for a SEE database. Unless 40595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** activated, none of the SEE routines will work. 40605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 40615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_activate_see( 40625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zPassPhrase /* Activation phrase */ 40635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 40645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 40655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 40665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef SQLITE_ENABLE_CEROD 40675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 40685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Specify the activation key for a CEROD database. Unless 40695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** activated, none of the CEROD routines will work. 40705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 40715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_activate_cerod( 40725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zPassPhrase /* Activation phrase */ 40735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 40745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 40755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 40765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 40775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Suspend Execution For A Short Time 40785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 40795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The sqlite3_sleep() function causes the current thread to suspend execution 40805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for at least a number of milliseconds specified in its parameter. 40815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 40825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If the operating system does not support sleep requests with 40835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** millisecond time resolution, then the time will be rounded up to 40845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the nearest second. The number of milliseconds of sleep actually 40855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** requested from the operating system is returned. 40865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 40875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^SQLite implements this interface by calling the xSleep() 40885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** method of the default [sqlite3_vfs] object. If the xSleep() method 40895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of the default VFS is not implemented correctly, or not implemented at 40905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** all, then the behavior of sqlite3_sleep() may deviate from the description 40915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in the previous paragraphs. 40925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 40935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_sleep(int); 40945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 40955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 40965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Name Of The Folder Holding Temporary Files 40975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 40985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(If this global variable is made to point to a string which is 40995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the name of a folder (a.k.a. directory), then all temporary files 41005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** created by SQLite when using a built-in [sqlite3_vfs | VFS] 41015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** will be placed in that directory.)^ ^If this variable 41025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is a NULL pointer, then SQLite performs a search for an appropriate 41035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** temporary file directory. 41045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 41055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** It is not safe to read or modify this variable in more than one 41065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** thread at a time. It is not safe to read or modify this variable 41075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** if a [database connection] is being used at the same time in a separate 41085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** thread. 41095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** It is intended that this variable be set once 41105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** as part of process initialization and before any SQLite interface 41115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** routines have been called and that this variable remain unchanged 41125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** thereafter. 41135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 41145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [temp_store_directory pragma] may modify this variable and cause 41155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore, 41165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the [temp_store_directory pragma] always assumes that any string 41175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that this variable points to is held in memory obtained from 41185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_malloc] and the pragma may attempt to free that memory 41195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** using [sqlite3_free]. 41205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Hence, if this variable is modified directly, either it should be 41215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** made NULL or made to point to memory obtained from [sqlite3_malloc] 41225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or else the use of the [temp_store_directory pragma] should be avoided. 41235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 41245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)SQLITE_EXTERN char *sqlite3_temp_directory; 41255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 41265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 41275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Test For Auto-Commit Mode 41285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: {autocommit mode} 41295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 41305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_get_autocommit() interface returns non-zero or 41315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** zero if the given database connection is or is not in autocommit mode, 41325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** respectively. ^Autocommit mode is on by default. 41335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Autocommit mode is disabled by a [BEGIN] statement. 41345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK]. 41355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 41365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If certain kinds of errors occur on a statement within a multi-statement 41375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR], 41385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the 41395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** transaction might be rolled back automatically. The only way to 41405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** find out whether SQLite automatically rolled back the transaction after 41415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** an error is to use this function. 41425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 41435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If another thread changes the autocommit status of the database 41445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** connection while this routine is running, then the return value 41455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is undefined. 41465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 41475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_get_autocommit(sqlite3*); 41485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 41495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 41505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Find The Database Handle Of A Prepared Statement 41515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 41525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_db_handle interface returns the [database connection] handle 41535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to which a [prepared statement] belongs. ^The [database connection] 41545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** returned by sqlite3_db_handle is the same [database connection] 41555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that was the first argument 41565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to the [sqlite3_prepare_v2()] call (or its variants) that was used to 41575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** create the statement in the first place. 41585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 41595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)sqlite3 *sqlite3_db_handle(sqlite3_stmt*); 41605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 41615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 41625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Find the next prepared statement 41635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 41645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This interface returns a pointer to the next [prepared statement] after 41655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** pStmt associated with the [database connection] pDb. ^If pStmt is NULL 41665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then this interface returns a pointer to the first prepared statement 41675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** associated with the database connection pDb. ^If no prepared statement 41685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** satisfies the conditions of this routine, it returns NULL. 41695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 41705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The [database connection] pointer D in a call to 41715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_next_stmt(D,S)] must refer to an open database 41725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** connection and in particular must not be a NULL pointer. 41735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 41745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); 41755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 41765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 41775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Commit And Rollback Notification Callbacks 41785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 41795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_commit_hook() interface registers a callback 41805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function to be invoked whenever a transaction is [COMMIT | committed]. 41815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Any callback set by a previous call to sqlite3_commit_hook() 41825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for the same database connection is overridden. 41835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_rollback_hook() interface registers a callback 41845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function to be invoked whenever a transaction is [ROLLBACK | rolled back]. 41855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Any callback set by a previous call to sqlite3_rollback_hook() 41865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for the same database connection is overridden. 41875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The pArg argument is passed through to the callback. 41885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the callback on a commit hook function returns non-zero, 41895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then the commit is converted into a rollback. 41905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 41915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions 41925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** return the P argument from the previous call of the same function 41935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** on the same [database connection] D, or NULL for 41945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the first call for each function on D. 41955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 41965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The callback implementation must not do anything that will modify 41975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the database connection that invoked the callback. Any actions 41985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to modify the database connection must be deferred until after the 41995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** completion of the [sqlite3_step()] call that triggered the commit 42005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or rollback hook in the first place. 42015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 42025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database connections for the meaning of "modify" in this paragraph. 42035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 42045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Registering a NULL function disables the callback. 42055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 42065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^When the commit hook callback routine returns zero, the [COMMIT] 42075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** operation is allowed to continue normally. ^If the commit hook 42085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK]. 42095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The rollback hook is invoked on a rollback that results from a commit 42105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** hook returning non-zero, just as it would be with any other rollback. 42115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 42125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^For the purposes of this API, a transaction is said to have been 42135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** rolled back if an explicit "ROLLBACK" statement is executed, or 42145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** an error or constraint causes an implicit rollback to occur. 42155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The rollback callback is not invoked if a transaction is 42165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** automatically rolled back because the database connection is closed. 42175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 42185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also the [sqlite3_update_hook()] interface. 42195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 42205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); 42215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); 42225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 42235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 42245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Data Change Notification Callbacks 42255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 42265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_update_hook() interface registers a callback function 42275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** with the [database connection] identified by the first argument 42285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to be invoked whenever a row is updated, inserted or deleted. 42295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Any callback set by a previous call to this function 42305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for the same database connection is overridden. 42315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 42325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The second argument is a pointer to the function to invoke when a 42335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** row is updated, inserted or deleted. 42345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The first argument to the callback is a copy of the third argument 42355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to sqlite3_update_hook(). 42365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE], 42375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or [SQLITE_UPDATE], depending on the operation that caused the callback 42385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to be invoked. 42395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The third and fourth arguments to the callback contain pointers to the 42405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database and table name containing the affected row. 42415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The final callback parameter is the [rowid] of the row. 42425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^In the case of an update, this is the [rowid] after the update takes place. 42435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 42445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The update hook is not invoked when internal system tables are 42455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** modified (i.e. sqlite_master and sqlite_sequence).)^ 42465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 42475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^In the current implementation, the update hook 42485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is not invoked when duplication rows are deleted because of an 42495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook 42505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** invoked when rows are deleted using the [truncate optimization]. 42515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The exceptions defined in this paragraph might change in a future 42525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** release of SQLite. 42535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 42545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The update hook implementation must not do anything that will modify 42555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the database connection that invoked the update hook. Any actions 42565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to modify the database connection must be deferred until after the 42575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** completion of the [sqlite3_step()] call that triggered the update hook. 42585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 42595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database connections for the meaning of "modify" in this paragraph. 42605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 42615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_update_hook(D,C,P) function 42625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** returns the P argument from the previous call 42635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** on the same [database connection] D, or NULL for 42645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the first call on D. 42655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 42665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also the [sqlite3_commit_hook()] and [sqlite3_rollback_hook()] 42675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interfaces. 42685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 42695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void *sqlite3_update_hook( 42705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3*, 42715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void(*)(void *,int ,char const *,char const *,sqlite3_int64), 42725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void* 42735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 42745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 42755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 42765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Enable Or Disable Shared Pager Cache 42775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: {shared cache} 42785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 42795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(This routine enables or disables the sharing of the database cache 42805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and schema data structures between [database connection | connections] 42815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to the same database. Sharing is enabled if the argument is true 42825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and disabled if the argument is false.)^ 42835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 42845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Cache sharing is enabled and disabled for an entire process. 42855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This is a change as of SQLite version 3.5.0. In prior versions of SQLite, 42865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sharing was enabled or disabled for each thread separately. 42875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 42885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The cache sharing mode set by this interface effects all subsequent 42895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()]. 42905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Existing database connections continue use the sharing mode 42915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that was in effect at the time they were opened.)^ 42925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 42935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled 42945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** successfully. An [error code] is returned otherwise.)^ 42955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 42965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Shared cache is disabled by default. But this might change in 42975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** future releases of SQLite. Applications that care about shared 42985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** cache setting should set it explicitly. 42995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 43005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See Also: [SQLite Shared-Cache Mode] 43015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 43025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_enable_shared_cache(int); 43035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 43045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 43055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Attempt To Free Heap Memory 43065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 43075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_release_memory() interface attempts to free N bytes 43085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of heap memory by deallocating non-essential memory allocations 43095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** held by the database library. Memory used to cache database 43105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** pages to improve performance is an example of non-essential memory. 43115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^sqlite3_release_memory() returns the number of bytes actually freed, 43125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** which might be more or less than the amount requested. 43135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_release_memory() routine is a no-op returning zero 43145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT]. 43155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 43165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_release_memory(int); 43175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 43185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 43195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Impose A Limit On Heap Size 43205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 43215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the 43225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** soft limit on the amount of heap memory that may be allocated by SQLite. 43235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^SQLite strives to keep heap memory utilization below the soft heap 43245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** limit by reducing the number of pages held in the page cache 43255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** as heap memory usages approaches the limit. 43265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The soft heap limit is "soft" because even though SQLite strives to stay 43275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** below the limit, it will exceed the limit rather than generate 43285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** an [SQLITE_NOMEM] error. In other words, the soft heap limit 43295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is advisory only. 43305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 43315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The return value from sqlite3_soft_heap_limit64() is the size of 43325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the soft heap limit prior to the call. ^If the argument N is negative 43335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then no change is made to the soft heap limit. Hence, the current 43345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** size of the soft heap limit can be determined by invoking 43355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_soft_heap_limit64() with a negative argument. 43365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 43375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the argument N is zero then the soft heap limit is disabled. 43385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 43395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The soft heap limit is not enforced in the current implementation 43405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** if one or more of following conditions are true: 43415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 43425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <ul> 43435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> The soft heap limit is set to zero. 43445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> Memory accounting is disabled using a combination of the 43455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and 43465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option. 43475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> An alternative page cache implementation is specified using 43485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_config]([SQLITE_CONFIG_PCACHE],...). 43495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> The page cache allocates from its own memory pool supplied 43505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than 43515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** from the heap. 43525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </ul>)^ 43535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 43545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Beginning with SQLite version 3.7.3, the soft heap limit is enforced 43555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT] 43565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** compile-time option is invoked. With [SQLITE_ENABLE_MEMORY_MANAGEMENT], 43575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the soft heap limit is enforced on every memory allocation. Without 43585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced 43595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** when memory is allocated by the page cache. Testing suggests that because 43605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the page cache is the predominate memory user in SQLite, most 43615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** applications will achieve adequate soft heap limit enforcement without 43625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT]. 43635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 43645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The circumstances under which SQLite will enforce the soft heap limit may 43655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** changes in future releases of SQLite. 43665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 43675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N); 43685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 43695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 43705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Deprecated Soft Heap Limit Interface 43715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** DEPRECATED 43725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 43735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This is a deprecated version of the [sqlite3_soft_heap_limit64()] 43745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interface. This routine is provided for historical compatibility 43755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** only. All new applications should use the 43765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_soft_heap_limit64()] interface rather than this one. 43775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 43785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N); 43795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 43805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 43815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 43825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Extract Metadata About A Column Of A Table 43835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 43845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This routine returns metadata about a specific column of a specific 43855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database table accessible using the [database connection] handle 43865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** passed as the first function argument. 43875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 43885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The column is identified by the second, third and fourth parameters to 43895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** this function. ^The second parameter is either the name of the database 43905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** (i.e. "main", "temp", or an attached database) containing the specified 43915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** table or NULL. ^If it is NULL, then all attached databases are searched 43925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for the table using the same algorithm used by the database engine to 43935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** resolve unqualified table references. 43945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 43955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The third and fourth parameters to this function are the table and column 43965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** name of the desired column, respectively. Neither of these parameters 43975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** may be NULL. 43985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 43995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Metadata is returned by writing to the memory locations passed as the 5th 44005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and subsequent parameters to this function. ^Any of these arguments may be 44015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** NULL, in which case the corresponding element of metadata is omitted. 44025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 44035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<blockquote> 44045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <table border="1"> 44055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><th> Parameter <th> Output<br>Type <th> Description 44065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 44075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> 5th <td> const char* <td> Data type 44085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> 6th <td> const char* <td> Name of default collation sequence 44095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint 44105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY 44115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT] 44125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </table> 44135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </blockquote>)^ 44145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 44155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The memory pointed to by the character pointers returned for the 44165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** declaration type and collation sequence is valid only until the next 44175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** call to any SQLite API function. 44185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 44195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the specified table is actually a view, an [error code] is returned. 44205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 44215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the specified column is "rowid", "oid" or "_rowid_" and an 44225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output 44235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** parameters are set for the explicitly declared column. ^(If there is no 44245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** explicitly declared [INTEGER PRIMARY KEY] column, then the output 44255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** parameters are set as follows: 44265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 44275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <pre> 44285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** data type: "INTEGER" 44295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** collation sequence: "BINARY" 44305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** not null: 0 44315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** primary key: 1 44325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** auto increment: 0 44335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </pre>)^ 44345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 44355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(This function may load one or more schemas from database files. If an 44365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** error occurs during this process, or if the requested table or column 44375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** cannot be found, an [error code] is returned and an error message left 44385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in the [database connection] (to be retrieved using sqlite3_errmsg()).)^ 44395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 44405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This API is only available if the library was compiled with the 44415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined. 44425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 44435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_table_column_metadata( 44445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3 *db, /* Connection handle */ 44455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zDbName, /* Database name or NULL */ 44465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zTableName, /* Table name */ 44475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zColumnName, /* Column name */ 44485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) char const **pzDataType, /* OUTPUT: Declared data type */ 44495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) char const **pzCollSeq, /* OUTPUT: Collation sequence name */ 44505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */ 44515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int *pPrimaryKey, /* OUTPUT: True if column part of PK */ 44525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int *pAutoinc /* OUTPUT: True if column is auto-increment */ 44535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 44545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 44555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 44565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Load An Extension 44575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 44585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This interface loads an SQLite extension library from the named file. 44595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 44605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_load_extension() interface attempts to load an 44615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite extension library contained in the file zFile. 44625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 44635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The entry point is zProc. 44645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^zProc may be 0, in which case the name of the entry point 44655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** defaults to "sqlite3_extension_init". 44665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_load_extension() interface returns 44675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong. 44685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If an error occurs and pzErrMsg is not 0, then the 44695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_load_extension()] interface shall attempt to 44705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** fill *pzErrMsg with error message text stored in memory 44715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** obtained from [sqlite3_malloc()]. The calling function 44725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** should free this memory by calling [sqlite3_free()]. 44735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 44745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Extension loading must be enabled using 44755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_enable_load_extension()] prior to calling this API, 44765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** otherwise an error will be returned. 44775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 44785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also the [load_extension() SQL function]. 44795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 44805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_load_extension( 44815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3 *db, /* Load the extension into this database connection */ 44825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zFile, /* Name of the shared library containing extension */ 44835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zProc, /* Entry point. Derived from zFile if 0 */ 44845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) char **pzErrMsg /* Put error message here if not 0 */ 44855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 44865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 44875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 44885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Enable Or Disable Extension Loading 44895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 44905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^So as not to open security holes in older applications that are 44915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** unprepared to deal with extension loading, and as a means of disabling 44925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** extension loading while evaluating user-entered SQL, the following API 44935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is provided to turn the [sqlite3_load_extension()] mechanism on and off. 44945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 44955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Extension loading is off by default. See ticket #1863. 44965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Call the sqlite3_enable_load_extension() routine with onoff==1 44975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to turn extension loading on and call it with onoff==0 to turn 44985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** it back off again. 44995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 45005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_enable_load_extension(sqlite3 *db, int onoff); 45015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 45025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 45035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Automatically Load Statically Linked Extensions 45045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 45055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This interface causes the xEntryPoint() function to be invoked for 45065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** each new [database connection] that is created. The idea here is that 45075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** xEntryPoint() is the entry point for a statically linked SQLite extension 45085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that is to be automatically loaded into all new database connections. 45095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 45105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(Even though the function prototype shows that xEntryPoint() takes 45115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** no arguments and returns void, SQLite invokes xEntryPoint() with three 45125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** arguments and expects and integer result as if the signature of the 45135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** entry point where as follows: 45145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 45155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <blockquote><pre> 45165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** int xEntryPoint( 45175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3 *db, 45185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** const char **pzErrMsg, 45195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** const struct sqlite3_api_routines *pThunk 45205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ); 45215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </pre></blockquote>)^ 45225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 45235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If the xEntryPoint routine encounters an error, it should make *pzErrMsg 45245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** point to an appropriate error message (obtained from [sqlite3_mprintf()]) 45255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg 45265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is NULL before calling the xEntryPoint(). ^SQLite will invoke 45275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any 45285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()], 45295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail. 45305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 45315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Calling sqlite3_auto_extension(X) with an entry point X that is already 45325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** on the list of automatic extensions is a harmless no-op. ^No entry point 45335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** will be called more than once for each database connection that is opened. 45345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 45355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also: [sqlite3_reset_auto_extension()]. 45365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 45375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_auto_extension(void (*xEntryPoint)(void)); 45385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 45395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 45405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Reset Automatic Extension Loading 45415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 45425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This interface disables all automatic extensions previously 45435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** registered using [sqlite3_auto_extension()]. 45445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 45455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_reset_auto_extension(void); 45465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 45475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 45485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The interface to the virtual-table mechanism is currently considered 45495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to be experimental. The interface might change in incompatible ways. 45505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If this is a problem for you, do not use the interface at this time. 45515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 45525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** When the virtual-table mechanism stabilizes, we will declare the 45535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interface fixed, support it indefinitely, and remove this comment. 45545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 45555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 45565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 45575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Structures used by the virtual table interface 45585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 45595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct sqlite3_vtab sqlite3_vtab; 45605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct sqlite3_index_info sqlite3_index_info; 45615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor; 45625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct sqlite3_module sqlite3_module; 45635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 45645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 45655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Virtual Table Object 45665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: sqlite3_module {virtual table module} 45675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 45685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This structure, sometimes called a "virtual table module", 45695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** defines the implementation of a [virtual tables]. 45705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This structure consists mostly of methods for the module. 45715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 45725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^A virtual table module is created by filling in a persistent 45735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** instance of this structure and passing a pointer to that instance 45745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to [sqlite3_create_module()] or [sqlite3_create_module_v2()]. 45755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The registration remains valid until it is replaced by a different 45765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** module or until the [database connection] closes. The content 45775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of this structure must not change while it is registered with 45785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** any database connection. 45795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 45805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct sqlite3_module { 45815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int iVersion; 45825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xCreate)(sqlite3*, void *pAux, 45835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int argc, const char *const*argv, 45845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3_vtab **ppVTab, char**); 45855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xConnect)(sqlite3*, void *pAux, 45865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int argc, const char *const*argv, 45875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3_vtab **ppVTab, char**); 45885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*); 45895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xDisconnect)(sqlite3_vtab *pVTab); 45905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xDestroy)(sqlite3_vtab *pVTab); 45915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor); 45925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xClose)(sqlite3_vtab_cursor*); 45935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr, 45945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int argc, sqlite3_value **argv); 45955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xNext)(sqlite3_vtab_cursor*); 45965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xEof)(sqlite3_vtab_cursor*); 45975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int); 45985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid); 45995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *); 46005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xBegin)(sqlite3_vtab *pVTab); 46015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xSync)(sqlite3_vtab *pVTab); 46025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xCommit)(sqlite3_vtab *pVTab); 46035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xRollback)(sqlite3_vtab *pVTab); 46045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName, 46055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), 46065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void **ppArg); 46075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xRename)(sqlite3_vtab *pVtab, const char *zNew); 46085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 46095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 46105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 46115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Virtual Table Indexing Information 46125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: sqlite3_index_info 46135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 46145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The sqlite3_index_info structure and its substructures is used as part 46155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of the [virtual table] interface to 46165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** pass information into and receive the reply from the [xBestIndex] 46175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** method of a [virtual table module]. The fields under **Inputs** are the 46185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** inputs to xBestIndex and are read-only. xBestIndex inserts its 46195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** results into the **Outputs** fields. 46205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 46215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The aConstraint[] array records WHERE clause constraints of the form: 46225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 46235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <blockquote>column OP expr</blockquote> 46245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 46255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** where OP is =, <, <=, >, or >=.)^ ^(The particular operator is 46265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** stored in aConstraint[].op using one of the 46275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^ 46285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The index of the column is stored in 46295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the 46305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** expr on the right-hand side can be evaluated (and thus the constraint 46315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is usable) and false if it cannot.)^ 46325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 46335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The optimizer automatically inverts terms of the form "expr OP column" 46345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and makes other simplifications to the WHERE clause in an attempt to 46355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** get as many WHERE clause terms into the form shown above as possible. 46365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The aConstraint[] array only reports WHERE clause terms that are 46375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** relevant to the particular virtual table being queried. 46385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 46395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Information about the ORDER BY clause is stored in aOrderBy[]. 46405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Each term of aOrderBy records a column of the ORDER BY clause. 46415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 46425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The [xBestIndex] method must fill aConstraintUsage[] with information 46435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** about what parameters to pass to xFilter. ^If argvIndex>0 then 46445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the right-hand side of the corresponding aConstraint[] is evaluated 46455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit 46465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is true, then the constraint is assumed to be fully handled by the 46475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** virtual table and is not checked again by SQLite.)^ 46485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 46495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The idxNum and idxPtr values are recorded and passed into the 46505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [xFilter] method. 46515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^[sqlite3_free()] is used to free idxPtr if and only if 46525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** needToFreeIdxPtr is true. 46535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 46545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in 46555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the correct order to satisfy the ORDER BY clause so that no separate 46565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sorting step is required. 46575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 46585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The estimatedCost value is an estimate of the cost of doing the 46595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** particular lookup. A full scan of a table with N entries should have 46605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a cost of N. A binary search of a table of N entries should have a 46615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** cost of approximately log(N). 46625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 46635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct sqlite3_index_info { 46645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /* Inputs */ 46655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int nConstraint; /* Number of entries in aConstraint */ 46665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) struct sqlite3_index_constraint { 46675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int iColumn; /* Column on left-hand side of constraint */ 46685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned char op; /* Constraint operator */ 46695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned char usable; /* True if this constraint is usable */ 46705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int iTermOffset; /* Used internally - xBestIndex should ignore */ 46715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } *aConstraint; /* Table of WHERE clause constraints */ 46725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int nOrderBy; /* Number of terms in the ORDER BY clause */ 46735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) struct sqlite3_index_orderby { 46745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int iColumn; /* Column number */ 46755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned char desc; /* True for DESC. False for ASC. */ 46765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } *aOrderBy; /* The ORDER BY clause */ 46775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /* Outputs */ 46785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) struct sqlite3_index_constraint_usage { 46795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int argvIndex; /* if >0, constraint is part of argv to xFilter */ 46805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned char omit; /* Do not code a test for this constraint */ 46815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } *aConstraintUsage; 46825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int idxNum; /* Number used to identify the index */ 46835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) char *idxStr; /* String, possibly obtained from sqlite3_malloc */ 46845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */ 46855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int orderByConsumed; /* True if output is already ordered */ 46865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) double estimatedCost; /* Estimated cost of using this index */ 46875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 46885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 46895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 46905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Virtual Table Constraint Operator Codes 46915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 46925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These macros defined the allowed values for the 46935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_index_info].aConstraint[].op field. Each value represents 46945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** an operator that is part of a constraint term in the wHERE clause of 46955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a query that uses a [virtual table]. 46965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 46975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_INDEX_CONSTRAINT_EQ 2 46985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_INDEX_CONSTRAINT_GT 4 46995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_INDEX_CONSTRAINT_LE 8 47005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_INDEX_CONSTRAINT_LT 16 47015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_INDEX_CONSTRAINT_GE 32 47025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_INDEX_CONSTRAINT_MATCH 64 47035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 47045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 47055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Register A Virtual Table Implementation 47065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 47075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^These routines are used to register a new [virtual table module] name. 47085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Module names must be registered before 47095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** creating a new [virtual table] using the module and before using a 47105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** preexisting [virtual table] for the module. 47115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 47125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The module name is registered on the [database connection] specified 47135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by the first parameter. ^The name of the module is given by the 47145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** second parameter. ^The third parameter is a pointer to 47155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the implementation of the [virtual table module]. ^The fourth 47165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** parameter is an arbitrary client data pointer that is passed through 47175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** into the [xCreate] and [xConnect] methods of the virtual table module 47185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** when a new virtual table is be being created or reinitialized. 47195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 47205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_create_module_v2() interface has a fifth parameter which 47215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is a pointer to a destructor for the pClientData. ^SQLite will 47225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** invoke the destructor function (if it is not NULL) when SQLite 47235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** no longer needs the pClientData pointer. ^The destructor will also 47245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** be invoked if the call to sqlite3_create_module_v2() fails. 47255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_create_module() 47265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interface is equivalent to sqlite3_create_module_v2() with a NULL 47275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** destructor. 47285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 47295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_create_module( 47305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3 *db, /* SQLite connection to register module with */ 47315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zName, /* Name of the module */ 47325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const sqlite3_module *p, /* Methods for the module */ 47335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void *pClientData /* Client data for xCreate/xConnect */ 47345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 47355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_create_module_v2( 47365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3 *db, /* SQLite connection to register module with */ 47375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zName, /* Name of the module */ 47385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const sqlite3_module *p, /* Methods for the module */ 47395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void *pClientData, /* Client data for xCreate/xConnect */ 47405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void(*xDestroy)(void*) /* Module destructor function */ 47415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 47425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 47435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 47445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Virtual Table Instance Object 47455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: sqlite3_vtab 47465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 47475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Every [virtual table module] implementation uses a subclass 47485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of this object to describe a particular instance 47495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of the [virtual table]. Each subclass will 47505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** be tailored to the specific needs of the module implementation. 47515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The purpose of this superclass is to define certain fields that are 47525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** common to all module implementations. 47535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 47545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Virtual tables methods can set an error message by assigning a 47555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should 47565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** take care that any prior string is freed by a call to [sqlite3_free()] 47575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** prior to assigning a new string to zErrMsg. ^After the error message 47585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is delivered up to the client application, the string will be automatically 47595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** freed by sqlite3_free() and the zErrMsg field will be zeroed. 47605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 47615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct sqlite3_vtab { 47625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const sqlite3_module *pModule; /* The module for this virtual table */ 47635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int nRef; /* NO LONGER USED */ 47645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) char *zErrMsg; /* Error message from sqlite3_mprintf() */ 47655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /* Virtual table implementations will typically add additional fields */ 47665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 47675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 47685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 47695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Virtual Table Cursor Object 47705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor} 47715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 47725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Every [virtual table module] implementation uses a subclass of the 47735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** following structure to describe cursors that point into the 47745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [virtual table] and are used 47755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to loop through the virtual table. Cursors are created using the 47765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed 47775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by the [sqlite3_module.xClose | xClose] method. Cursors are used 47785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods 47795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of the module. Each module implementation will define 47805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the content of a cursor structure to suit its own needs. 47815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 47825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This superclass exists in order to define fields of the cursor that 47835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are common to all implementations. 47845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 47855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct sqlite3_vtab_cursor { 47865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3_vtab *pVtab; /* Virtual table of this cursor */ 47875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /* Virtual table implementations will typically add additional fields */ 47885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 47895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 47905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 47915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Declare The Schema Of A Virtual Table 47925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 47935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [xCreate] and [xConnect] methods of a 47945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [virtual table module] call this interface 47955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to declare the format (the names and datatypes of the columns) of 47965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the virtual tables they implement. 47975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 47985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_declare_vtab(sqlite3*, const char *zSQL); 47995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 48005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 48015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Overload A Function For A Virtual Table 48025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 48035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(Virtual tables can provide alternative implementations of functions 48045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** using the [xFindFunction] method of the [virtual table module]. 48055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** But global versions of those functions 48065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** must exist in order to be overloaded.)^ 48075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 48085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(This API makes sure a global version of a function with a particular 48095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** name and number of parameters exists. If no such function exists 48105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** before this API is called, a new function is created.)^ ^The implementation 48115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of the new function always causes an exception to be thrown. So 48125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the new function is not good for anything by itself. Its only 48135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** purpose is to be a placeholder function that can be overloaded 48145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by a [virtual table]. 48155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 48165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg); 48175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 48185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 48195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The interface to the virtual-table mechanism defined above (back up 48205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to a comment remarkably similar to this one) is currently considered 48215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to be experimental. The interface might change in incompatible ways. 48225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If this is a problem for you, do not use the interface at this time. 48235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 48245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** When the virtual-table mechanism stabilizes, we will declare the 48255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interface fixed, support it indefinitely, and remove this comment. 48265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 48275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 48285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 48295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: A Handle To An Open BLOB 48305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: {BLOB handle} {BLOB handles} 48315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 48325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** An instance of this object represents an open BLOB on which 48335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_blob_open | incremental BLOB I/O] can be performed. 48345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Objects of this type are created by [sqlite3_blob_open()] 48355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and destroyed by [sqlite3_blob_close()]. 48365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces 48375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** can be used to read or write small subsections of the BLOB. 48385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes. 48395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 48405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct sqlite3_blob sqlite3_blob; 48415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 48425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 48435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Open A BLOB For Incremental I/O 48445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 48455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located 48465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in row iRow, column zColumn, table zTable in database zDb; 48475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in other words, the same BLOB that would be selected by: 48485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 48495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <pre> 48505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow; 48515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </pre>)^ 48525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 48535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the flags parameter is non-zero, then the BLOB is opened for read 48545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and write access. ^If it is zero, the BLOB is opened for read access. 48555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^It is not possible to open a column that is part of an index or primary 48565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** key for writing. ^If [foreign key constraints] are enabled, it is 48575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** not possible to open a column that is part of a [child key] for writing. 48585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 48595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Note that the database name is not the filename that contains 48605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the database but rather the symbolic name of the database that 48615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** appears after the AS keyword when the database is connected using [ATTACH]. 48625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^For the main database file, the database name is "main". 48635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^For TEMP tables, the database name is "temp". 48645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 48655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written 48665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set 48675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to be a null pointer.)^ 48685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This function sets the [database connection] error code and message 48695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related 48705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** functions. ^Note that the *ppBlob variable is always initialized in a 48715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob 48725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** regardless of the success or failure of this routine. 48735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 48745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(If the row that a BLOB handle points to is modified by an 48755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects 48765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then the BLOB handle is marked as "expired". 48775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This is true if any column of the row is changed, even a column 48785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** other than the one the BLOB handle is open on.)^ 48795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for 48805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** an expired BLOB handle fail with a return code of [SQLITE_ABORT]. 48815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(Changes written into a BLOB prior to the BLOB expiring are not 48825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** rolled back by the expiration of the BLOB. Such changes will eventually 48835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** commit if the transaction continues to completion.)^ 48845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 48855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Use the [sqlite3_blob_bytes()] interface to determine the size of 48865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the opened blob. ^The size of a blob may not be changed by this 48875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interface. Use the [UPDATE] SQL command to change the size of a 48885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** blob. 48895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 48905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces 48915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and the built-in [zeroblob] SQL function can be used, if desired, 48925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to create an empty, zero-filled blob in which to read or write using 48935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** this interface. 48945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 48955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** To avoid a resource leak, every open [BLOB handle] should eventually 48965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** be released by a call to [sqlite3_blob_close()]. 48975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 48985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_blob_open( 48995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3*, 49005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zDb, 49015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zTable, 49025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zColumn, 49035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3_int64 iRow, 49045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int flags, 49055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3_blob **ppBlob 49065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 49075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 49085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 49095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Move a BLOB Handle to a New Row 49105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 49115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This function is used to move an existing blob handle so that it points 49125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to a different row of the same database table. ^The new row is identified 49135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by the rowid value passed as the second argument. Only the row can be 49145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** changed. ^The database, table and column on which the blob handle is open 49155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** remain the same. Moving an existing blob handle to a new row can be 49165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** faster than closing the existing handle and opening a new one. 49175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 49185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] - 49195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** it must exist and there must be either a blob or text value stored in 49205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the nominated column.)^ ^If the new row is not present in the table, or if 49215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** it does not contain a blob or text value, or if another error occurs, an 49225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite error code is returned and the blob handle is considered aborted. 49235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or 49245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_blob_reopen()] on an aborted blob handle immediately return 49255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle 49265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** always returns zero. 49275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 49285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This function sets the database handle error code and message. 49295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 49305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); 49315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 49325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 49335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Close A BLOB Handle 49345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 49355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Closes an open [BLOB handle]. 49365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 49375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Closing a BLOB shall cause the current transaction to commit 49385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** if there are no other BLOBs, no pending prepared statements, and the 49395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database connection is in [autocommit mode]. 49405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If any writes were made to the BLOB, they might be held in cache 49415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** until the close operation if they will fit. 49425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 49435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(Closing the BLOB often forces the changes 49445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** out to disk and so if any I/O errors occur, they will likely occur 49455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** at the time when the BLOB is closed. Any errors that occur during 49465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** closing are reported as a non-zero return value.)^ 49475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 49485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The BLOB is closed unconditionally. Even if this routine returns 49495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** an error code, the BLOB is still closed.)^ 49505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 49515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Calling this routine with a null pointer (such as would be returned 49525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by a failed call to [sqlite3_blob_open()]) is a harmless no-op. 49535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 49545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_blob_close(sqlite3_blob *); 49555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 49565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 49575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Return The Size Of An Open BLOB 49585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 49595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Returns the size in bytes of the BLOB accessible via the 49605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** successfully opened [BLOB handle] in its only argument. ^The 49615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** incremental blob I/O routines can only read or overwriting existing 49625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** blob content; they cannot change the size of a blob. 49635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 49645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This routine only works on a [BLOB handle] which has been created 49655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by a prior successful call to [sqlite3_blob_open()] and which has not 49665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** been closed by [sqlite3_blob_close()]. Passing any other pointer in 49675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to this routine results in undefined and probably undesirable behavior. 49685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 49695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_blob_bytes(sqlite3_blob *); 49705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 49715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 49725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Read Data From A BLOB Incrementally 49735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 49745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(This function is used to read data from an open [BLOB handle] into a 49755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** caller-supplied buffer. N bytes of data are copied into buffer Z 49765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** from the open BLOB, starting at offset iOffset.)^ 49775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 49785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If offset iOffset is less than N bytes from the end of the BLOB, 49795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_ERROR] is returned and no data is read. ^If N or iOffset is 49805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** less than zero, [SQLITE_ERROR] is returned and no data is read. 49815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The size of the blob (and hence the maximum value of N+iOffset) 49825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** can be determined using the [sqlite3_blob_bytes()] interface. 49835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 49845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^An attempt to read from an expired [BLOB handle] fails with an 49855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** error code of [SQLITE_ABORT]. 49865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 49875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(On success, sqlite3_blob_read() returns SQLITE_OK. 49885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Otherwise, an [error code] or an [extended error code] is returned.)^ 49895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 49905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This routine only works on a [BLOB handle] which has been created 49915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by a prior successful call to [sqlite3_blob_open()] and which has not 49925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** been closed by [sqlite3_blob_close()]. Passing any other pointer in 49935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to this routine results in undefined and probably undesirable behavior. 49945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 49955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also: [sqlite3_blob_write()]. 49965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 49975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); 49985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 49995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 50005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Write Data Into A BLOB Incrementally 50015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 50025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This function is used to write data into an open [BLOB handle] from a 50035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** caller-supplied buffer. ^N bytes of data are copied from the buffer Z 50045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** into the open BLOB, starting at offset iOffset. 50055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 50065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the [BLOB handle] passed as the first argument was not opened for 50075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** writing (the flags parameter to [sqlite3_blob_open()] was zero), 50085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** this function returns [SQLITE_READONLY]. 50095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 50105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This function may only modify the contents of the BLOB; it is 50115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** not possible to increase the size of a BLOB using this API. 50125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If offset iOffset is less than N bytes from the end of the BLOB, 50135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_ERROR] is returned and no data is written. ^If N is 50145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** less than zero [SQLITE_ERROR] is returned and no data is written. 50155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The size of the BLOB (and hence the maximum value of N+iOffset) 50165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** can be determined using the [sqlite3_blob_bytes()] interface. 50175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 50185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^An attempt to write to an expired [BLOB handle] fails with an 50195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred 50205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** before the [BLOB handle] expired are not rolled back by the 50215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** expiration of the handle, though of course those changes might 50225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** have been overwritten by the statement that expired the BLOB handle 50235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or by other independent statements. 50245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 50255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(On success, sqlite3_blob_write() returns SQLITE_OK. 50265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Otherwise, an [error code] or an [extended error code] is returned.)^ 50275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 50285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This routine only works on a [BLOB handle] which has been created 50295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by a prior successful call to [sqlite3_blob_open()] and which has not 50305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** been closed by [sqlite3_blob_close()]. Passing any other pointer in 50315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to this routine results in undefined and probably undesirable behavior. 50325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 50335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also: [sqlite3_blob_read()]. 50345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 50355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset); 50365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 50375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 50385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Virtual File System Objects 50395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 50405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** A virtual filesystem (VFS) is an [sqlite3_vfs] object 50415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that SQLite uses to interact 50425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** with the underlying operating system. Most SQLite builds come with a 50435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** single default VFS that is appropriate for the host computer. 50445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** New VFSes can be registered and existing VFSes can be unregistered. 50455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The following interfaces are provided. 50465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 50475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name. 50485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Names are case sensitive. 50495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Names are zero-terminated UTF-8 strings. 50505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If there is no match, a NULL pointer is returned. 50515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If zVfsName is NULL then the default VFS is returned. 50525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 50535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^New VFSes are registered with sqlite3_vfs_register(). 50545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Each new VFS becomes the default VFS if the makeDflt flag is set. 50555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The same VFS can be registered multiple times without injury. 50565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^To make an existing VFS into the default VFS, register it again 50575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** with the makeDflt flag set. If two different VFSes with the 50585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** same name are registered, the behavior is undefined. If a 50595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** VFS is registered with a name that is NULL or an empty string, 50605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then the behavior is undefined. 50615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 50625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Unregister a VFS with the sqlite3_vfs_unregister() interface. 50635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(If the default VFS is unregistered, another VFS is chosen as 50645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the default. The choice for the new VFS is arbitrary.)^ 50655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 50665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName); 50675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt); 50685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_vfs_unregister(sqlite3_vfs*); 50695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 50705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 50715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Mutexes 50725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 50735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The SQLite core uses these routines for thread 50745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** synchronization. Though they are intended for internal 50755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** use by SQLite, code that links against SQLite is 50765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** permitted to use any of these routines. 50775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 50785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The SQLite source code contains multiple implementations 50795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of these mutex routines. An appropriate implementation 50805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is selected automatically at compile-time. ^(The following 50815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** implementations are available in the SQLite core: 50825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 50835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <ul> 50845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> SQLITE_MUTEX_OS2 50855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> SQLITE_MUTEX_PTHREAD 50865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> SQLITE_MUTEX_W32 50875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> SQLITE_MUTEX_NOOP 50885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </ul>)^ 50895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 50905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The SQLITE_MUTEX_NOOP implementation is a set of routines 50915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that does no real locking and is appropriate for use in 50925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a single-threaded application. ^The SQLITE_MUTEX_OS2, 50935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLITE_MUTEX_PTHREAD, and SQLITE_MUTEX_W32 implementations 50945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are appropriate for use on OS/2, Unix, and Windows. 50955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 50965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor 50975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex 50985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** implementation is included with the library. In this case the 50995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** application must supply a custom mutex implementation using the 51005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function 51015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** before calling sqlite3_initialize() or any other public sqlite3_ 51025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function that calls sqlite3_initialize().)^ 51035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 51045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_mutex_alloc() routine allocates a new 51055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** mutex and returns a pointer to it. ^If it returns NULL 51065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that means that a mutex could not be allocated. ^SQLite 51075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** will unwind its stack and return an error. ^(The argument 51085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to sqlite3_mutex_alloc() is one of these integer constants: 51095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 51105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <ul> 51115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> SQLITE_MUTEX_FAST 51125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> SQLITE_MUTEX_RECURSIVE 51135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> SQLITE_MUTEX_STATIC_MASTER 51145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> SQLITE_MUTEX_STATIC_MEM 51155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> SQLITE_MUTEX_STATIC_MEM2 51165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> SQLITE_MUTEX_STATIC_PRNG 51175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> SQLITE_MUTEX_STATIC_LRU 51185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> SQLITE_MUTEX_STATIC_LRU2 51195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </ul>)^ 51205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 51215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) 51225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** cause sqlite3_mutex_alloc() to create 51235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE 51245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is used but not necessarily so when SQLITE_MUTEX_FAST is used. 51255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The mutex implementation does not need to make a distinction 51265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does 51275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** not want to. ^SQLite will only request a recursive mutex in 51285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** cases where it really needs one. ^If a faster non-recursive mutex 51295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** implementation is available on the host platform, the mutex subsystem 51305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** might return such a mutex in response to SQLITE_MUTEX_FAST. 51315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 51325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other 51335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return 51345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a pointer to a static preexisting mutex. ^Six static mutexes are 51355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** used by the current version of SQLite. Future versions of SQLite 51365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** may add additional static mutexes. Static mutexes are for internal 51375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** use by SQLite only. Applications that use SQLite mutexes should 51385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or 51395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLITE_MUTEX_RECURSIVE. 51405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 51415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST 51425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc() 51435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** returns a different mutex on every call. ^But for the static 51445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** mutex types, the same mutex is returned on every call that has 51455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the same type number. 51465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 51475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_mutex_free() routine deallocates a previously 51485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** allocated dynamic mutex. ^SQLite is careful to deallocate every 51495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** dynamic mutex that it allocates. The dynamic mutexes must not be in 51505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** use when they are deallocated. Attempting to deallocate a static 51515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** mutex results in undefined behavior. ^SQLite never deallocates 51525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a static mutex. 51535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 51545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt 51555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to enter a mutex. ^If another thread is already within the mutex, 51565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return 51575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK] 51585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** upon successful entry. ^(Mutexes created using 51595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread. 51605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** In such cases the, 51615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** mutex must be exited an equal number of times before another thread 51625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** can enter.)^ ^(If the same thread tries to enter any other 51635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** kind of mutex more than once, the behavior is undefined. 51645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite will never exhibit 51655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** such behavior in its own use of mutexes.)^ 51665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 51675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(Some systems (for example, Windows 95) do not support the operation 51685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try() 51695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** will always return SQLITE_BUSY. The SQLite core only ever uses 51705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_mutex_try() as an optimization so this is acceptable behavior.)^ 51715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 51725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_mutex_leave() routine exits a mutex that was 51735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** previously entered by the same thread. ^(The behavior 51745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is undefined if the mutex is not currently entered by the 51755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** calling thread or is not currently allocated. SQLite will 51765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** never do either.)^ 51775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 51785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or 51795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_mutex_leave() is a NULL pointer, then all three routines 51805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** behave as no-ops. 51815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 51825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()]. 51835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 51845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)sqlite3_mutex *sqlite3_mutex_alloc(int); 51855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_mutex_free(sqlite3_mutex*); 51865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_mutex_enter(sqlite3_mutex*); 51875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_mutex_try(sqlite3_mutex*); 51885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_mutex_leave(sqlite3_mutex*); 51895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 51905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 51915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Mutex Methods Object 51925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 51935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** An instance of this structure defines the low-level routines 51945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** used to allocate and use mutexes. 51955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 51965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Usually, the default mutex implementations provided by SQLite are 51975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sufficient, however the user has the option of substituting a custom 51985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** implementation for specialized deployments or systems for which SQLite 51995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** does not provide a suitable implementation. In this case, the user 52005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** creates and populates an instance of this structure to pass 52015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option. 52025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Additionally, an instance of this structure can be used as an 52035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** output variable when querying the system for the current mutex 52045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** implementation, using the [SQLITE_CONFIG_GETMUTEX] option. 52055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 52065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The xMutexInit method defined by this structure is invoked as 52075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** part of system initialization by the sqlite3_initialize() function. 52085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The xMutexInit routine is called by SQLite exactly once for each 52095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** effective call to [sqlite3_initialize()]. 52105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 52115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The xMutexEnd method defined by this structure is invoked as 52125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** part of system shutdown by the sqlite3_shutdown() function. The 52135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** implementation of this method is expected to release all outstanding 52145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** resources obtained by the mutex methods implementation, especially 52155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** those obtained by the xMutexInit method. ^The xMutexEnd() 52165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interface is invoked exactly once for each call to [sqlite3_shutdown()]. 52175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 52185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The remaining seven methods defined by this structure (xMutexAlloc, 52195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and 52205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** xMutexNotheld) implement the following interfaces (respectively): 52215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 52225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <ul> 52235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [sqlite3_mutex_alloc()] </li> 52245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [sqlite3_mutex_free()] </li> 52255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [sqlite3_mutex_enter()] </li> 52265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [sqlite3_mutex_try()] </li> 52275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [sqlite3_mutex_leave()] </li> 52285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [sqlite3_mutex_held()] </li> 52295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> [sqlite3_mutex_notheld()] </li> 52305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </ul>)^ 52315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 52325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The only difference is that the public sqlite3_XXX functions enumerated 52335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** above silently ignore any invocations that pass a NULL pointer instead 52345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of a valid mutex handle. The implementations of the methods defined 52355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by this structure are not required to handle this case, the results 52365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of passing a NULL pointer instead of a valid mutex handle are undefined 52375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** (i.e. it is acceptable to provide an implementation that segfaults if 52385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** it is passed a NULL pointer). 52395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 52405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The xMutexInit() method must be threadsafe. ^It must be harmless to 52415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** invoke xMutexInit() multiple times within the same process and without 52425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** intervening calls to xMutexEnd(). Second and subsequent calls to 52435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** xMutexInit() must be no-ops. 52445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 52455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()] 52465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and its associates). ^Similarly, xMutexAlloc() must not use SQLite memory 52475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** allocation for a static mutex. ^However xMutexAlloc() may use SQLite 52485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** memory allocation for a fast or recursive mutex. 52495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 52505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is 52515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** called, but only if the prior call to xMutexInit returned SQLITE_OK. 52525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If xMutexInit fails in any way, it is expected to clean up after itself 52535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** prior to returning. 52545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 52555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct sqlite3_mutex_methods sqlite3_mutex_methods; 52565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct sqlite3_mutex_methods { 52575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xMutexInit)(void); 52585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xMutexEnd)(void); 52595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3_mutex *(*xMutexAlloc)(int); 52605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xMutexFree)(sqlite3_mutex *); 52615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xMutexEnter)(sqlite3_mutex *); 52625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xMutexTry)(sqlite3_mutex *); 52635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xMutexLeave)(sqlite3_mutex *); 52645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xMutexHeld)(sqlite3_mutex *); 52655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xMutexNotheld)(sqlite3_mutex *); 52665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 52675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 52685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 52695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Mutex Verification Routines 52705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 52715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines 52725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are intended for use inside assert() statements. ^The SQLite core 52735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** never uses these routines except inside an assert() and applications 52745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are advised to follow the lead of the core. ^The SQLite core only 52755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** provides implementations for these routines when it is compiled 52765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** with the SQLITE_DEBUG flag. ^External mutex implementations 52775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are only required to provide these routines if SQLITE_DEBUG is 52785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** defined and if NDEBUG is not defined. 52795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 52805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^These routines should return true if the mutex in their argument 52815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is held or not held, respectively, by the calling thread. 52825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 52835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The implementation is not required to provided versions of these 52845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** routines that actually work. If the implementation does not provide working 52855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** versions of these routines, it should at least provide stubs that always 52865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** return true so that one does not get spurious assertion failures. 52875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 52885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the argument to sqlite3_mutex_held() is a NULL pointer then 52895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the routine should return 1. This seems counter-intuitive since 52905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** clearly the mutex cannot be held if it does not exist. But the 52915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the reason the mutex does not exist is because the build is not 52925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** using mutexes. And we do not want the assert() containing the 52935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** call to sqlite3_mutex_held() to fail, so a non-zero return is 52945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the appropriate thing to do. ^The sqlite3_mutex_notheld() 52955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interface should also return 1 when given a NULL pointer. 52965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 52975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef NDEBUG 52985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_mutex_held(sqlite3_mutex*); 52995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_mutex_notheld(sqlite3_mutex*); 53005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 53015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 53025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 53035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Mutex Types 53045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 53055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The [sqlite3_mutex_alloc()] interface takes a single argument 53065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** which is one of these integer constants. 53075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 53085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The set of static mutexes may change from one SQLite release to the 53095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** next. Applications that override the built-in mutex logic must be 53105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** prepared to accommodate additional static mutexes. 53115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 53125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_MUTEX_FAST 0 53135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_MUTEX_RECURSIVE 1 53145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_MUTEX_STATIC_MASTER 2 53155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */ 53165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */ 53175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */ 53185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */ 53195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */ 53205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */ 53215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */ 53225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 53235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 53245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Retrieve the mutex for a database connection 53255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 53265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This interface returns a pointer the [sqlite3_mutex] object that 53275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** serializes access to the [database connection] given in the argument 53285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** when the [threading mode] is Serialized. 53295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the [threading mode] is Single-thread or Multi-thread then this 53305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** routine returns a NULL pointer. 53315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 53325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)sqlite3_mutex *sqlite3_db_mutex(sqlite3*); 53335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 53345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 53355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Low-Level Control Of Database Files 53365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 53375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [sqlite3_file_control()] interface makes a direct call to the 53385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** xFileControl method for the [sqlite3_io_methods] object associated 53395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** with a particular database identified by the second argument. ^The 53405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** name of the database is "main" for the main database or "temp" for the 53415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** TEMP database, or the name that appears after the AS keyword for 53425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** databases that are added using the [ATTACH] SQL command. 53435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^A NULL pointer can be used in place of "main" to refer to the 53445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** main database file. 53455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The third and fourth parameters to this routine 53465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are passed directly through to the second and third parameters of 53475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the xFileControl method. ^The return value of the xFileControl 53485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** method becomes the return value of this routine. 53495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 53505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The SQLITE_FCNTL_FILE_POINTER value for the op parameter causes 53515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a pointer to the underlying [sqlite3_file] object to be written into 53525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the space pointed to by the 4th parameter. ^The SQLITE_FCNTL_FILE_POINTER 53535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** case is a short-circuit path which does not actually invoke the 53545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** underlying sqlite3_io_methods.xFileControl method. 53555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 53565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the second parameter (zDbName) does not match the name of any 53575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** open database file, then SQLITE_ERROR is returned. ^This error 53585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** code is not remembered and will not be recalled by [sqlite3_errcode()] 53595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or [sqlite3_errmsg()]. The underlying xFileControl method might 53605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** also return SQLITE_ERROR. There is no way to distinguish between 53615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** an incorrect zDbName and an SQLITE_ERROR return from the underlying 53625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** xFileControl method. 53635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 53645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also: [SQLITE_FCNTL_LOCKSTATE] 53655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 53665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*); 53675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 53685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 53695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Testing Interface 53705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 53715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_test_control() interface is used to read out internal 53725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** state of SQLite and to inject faults into SQLite for testing 53735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** purposes. ^The first parameter is an operation code that determines 53745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the number, meaning, and operation of all subsequent parameters. 53755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 53765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This interface is not for use by applications. It exists solely 53775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for verifying the correct operation of the SQLite library. Depending 53785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** on how the SQLite library is compiled, this interface might not exist. 53795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 53805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The details of the operation codes, their meanings, the parameters 53815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** they take, and what they do are all subject to change without notice. 53825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Unlike most of the SQLite API, this function is not guaranteed to 53835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** operate consistently from one release to the next. 53845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 53855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_test_control(int op, ...); 53865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 53875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 53885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Testing Interface Operation Codes 53895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 53905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These constants are the valid operation code parameters used 53915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** as the first argument to [sqlite3_test_control()]. 53925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 53935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These parameters and their meanings are subject to change 53945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** without notice. These values are for testing purposes only. 53955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Applications should not use any of these parameters or the 53965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_test_control()] interface. 53975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 53985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_TESTCTRL_FIRST 5 53995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_TESTCTRL_PRNG_SAVE 5 54005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_TESTCTRL_PRNG_RESTORE 6 54015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_TESTCTRL_PRNG_RESET 7 54025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_TESTCTRL_BITVEC_TEST 8 54035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_TESTCTRL_FAULT_INSTALL 9 54045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10 54055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_TESTCTRL_PENDING_BYTE 11 54065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_TESTCTRL_ASSERT 12 54075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_TESTCTRL_ALWAYS 13 54085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_TESTCTRL_RESERVE 14 54095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_TESTCTRL_OPTIMIZATIONS 15 54105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_TESTCTRL_ISKEYWORD 16 54115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_TESTCTRL_PGHDRSZ 17 54125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_TESTCTRL_SCRATCHMALLOC 18 54135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_TESTCTRL_LAST 18 54145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 54155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 54165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: SQLite Runtime Status 54175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 54185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This interface is used to retrieve runtime status information 54195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** about the performance of SQLite, and optionally to reset various 54205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** highwater marks. ^The first argument is an integer code for 54215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the specific parameter to measure. ^(Recognized integer codes 54225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...].)^ 54235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The current value of the parameter is returned into *pCurrent. 54245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The highest recorded value is returned in *pHighwater. ^If the 54255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** resetFlag is true, then the highest record value is reset after 54265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** *pHighwater is written. ^(Some parameters do not record the highest 54275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** value. For those parameters 54285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** nothing is written into *pHighwater and the resetFlag is ignored.)^ 54295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(Other parameters record only the highwater mark and not the current 54305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** value. For these latter parameters nothing is written into *pCurrent.)^ 54315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 54325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_status() routine returns SQLITE_OK on success and a 54335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** non-zero [error code] on failure. 54345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 54355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This routine is threadsafe but is not atomic. This routine can be 54365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** called while other threads are running the same or different SQLite 54375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interfaces. However the values returned in *pCurrent and 54385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** *pHighwater reflect the status of SQLite at different points in time 54395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and it is possible that another thread might change the parameter 54405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in between the times when *pCurrent and *pHighwater are written. 54415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 54425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also: [sqlite3_db_status()] 54435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 54445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); 54455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 54465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 54475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 54485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Status Parameters 54495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 54505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These integer constants designate various run-time status parameters 54515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that can be returned by [sqlite3_status()]. 54525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 54535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dl> 54545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_STATUS_MEMORY_USED</dt> 54555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>This parameter is the current amount of memory checked out 54565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** using [sqlite3_malloc()], either directly or indirectly. The 54575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** figure includes calls made to [sqlite3_malloc()] by the application 54585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and internal memory usage by the SQLite library. Scratch memory 54595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache 54605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in 54615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** this parameter. The amount returned is the sum of the allocation 54625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^ 54635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 54645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt> 54655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>This parameter records the largest memory allocation request 54665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their 54675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** internal equivalents). Only the value returned in the 54685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** *pHighwater parameter to [sqlite3_status()] is of interest. 54695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The value written into the *pCurrent parameter is undefined.</dd>)^ 54705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 54715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt> 54725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>This parameter records the number of separate memory allocations 54735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** currently checked out.</dd>)^ 54745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 54755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt> 54765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>This parameter returns the number of pages used out of the 54775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [pagecache memory allocator] that was configured using 54785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_CONFIG_PAGECACHE]. The 54795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** value returned is in pages, not in bytes.</dd>)^ 54805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 54815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt> 54825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>This parameter returns the number of bytes of page cache 54835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE] 54845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** buffer and where forced to overflow to [sqlite3_malloc()]. The 54855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** returned value includes allocations that overflowed because they 54865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** where too large (they were larger than the "sz" parameter to 54875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because 54885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** no space was left in the page cache.</dd>)^ 54895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 54905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt> 54915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>This parameter records the largest memory allocation request 54925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** handed to [pagecache memory allocator]. Only the value returned in the 54935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** *pHighwater parameter to [sqlite3_status()] is of interest. 54945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The value written into the *pCurrent parameter is undefined.</dd>)^ 54955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 54965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt> 54975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>This parameter returns the number of allocations used out of the 54985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [scratch memory allocator] configured using 54995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not 55005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in bytes. Since a single thread may only have one scratch allocation 55015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** outstanding at time, this parameter also reports the number of threads 55025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** using scratch memory at the same time.</dd>)^ 55035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 55045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt> 55055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>This parameter returns the number of bytes of scratch memory 55065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH] 55075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** buffer and where forced to overflow to [sqlite3_malloc()]. The values 55085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** returned include overflows because the requested allocation was too 55095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** larger (that is, because the requested allocation was larger than the 55105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer 55115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** slots were available. 55125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </dd>)^ 55135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 55145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt> 55155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>This parameter records the largest memory allocation request 55165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** handed to [scratch memory allocator]. Only the value returned in the 55175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** *pHighwater parameter to [sqlite3_status()] is of interest. 55185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The value written into the *pCurrent parameter is undefined.</dd>)^ 55195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 55205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_STATUS_PARSER_STACK</dt> 55215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>This parameter records the deepest parser stack. It is only 55225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^ 55235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </dl> 55245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 55255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** New status parameters may be added from time to time. 55265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 55275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_STATUS_MEMORY_USED 0 55285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_STATUS_PAGECACHE_USED 1 55295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_STATUS_PAGECACHE_OVERFLOW 2 55305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_STATUS_SCRATCH_USED 3 55315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_STATUS_SCRATCH_OVERFLOW 4 55325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_STATUS_MALLOC_SIZE 5 55335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_STATUS_PARSER_STACK 6 55345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_STATUS_PAGECACHE_SIZE 7 55355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_STATUS_SCRATCH_SIZE 8 55365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_STATUS_MALLOC_COUNT 9 55375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 55395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Database Connection Status 55405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 55415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This interface is used to retrieve runtime status information 55425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** about a single [database connection]. ^The first argument is the 55435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database connection object to be interrogated. ^The second argument 55445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is an integer constant, taken from the set of 55455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that 55465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** determines the parameter to interrogate. The set of 55475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely 55485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to grow in future releases of SQLite. 55495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 55505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The current value of the requested parameter is written into *pCur 55515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and the highest instantaneous value is written into *pHiwtr. ^If 55525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the resetFlg is true, then the highest instantaneous value is 55535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** reset back down to the current value. 55545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 55555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a 55565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** non-zero [error code] on failure. 55575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 55585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also: [sqlite3_status()] and [sqlite3_stmt_status()]. 55595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 55605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); 55615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 55635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Status Parameters for database connections 55645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 55655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These constants are the available integer "verbs" that can be passed as 55665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the second argument to the [sqlite3_db_status()] interface. 55675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 55685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** New verbs may be added in future releases of SQLite. Existing verbs 55695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** might be discontinued. Applications should check the return code from 55705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_db_status()] to make sure that the call worked. 55715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The [sqlite3_db_status()] interface will return a non-zero error code 55725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** if a discontinued or unsupported verb is invoked. 55735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 55745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dl> 55755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt> 55765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>This parameter returns the number of lookaside memory slots currently 55775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** checked out.</dd>)^ 55785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 55795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt> 55805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>This parameter returns the number malloc attempts that were 55815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** satisfied using lookaside memory. Only the high-water value is meaningful; 55825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the current value is always zero.)^ 55835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 55845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt> 55855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>This parameter returns the number malloc attempts that might have 55865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** been satisfied using lookaside memory but failed due to the amount of 55875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** memory requested being larger than the lookaside slot size. 55885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Only the high-water value is meaningful; 55895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the current value is always zero.)^ 55905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 55915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt> 55925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>This parameter returns the number malloc attempts that might have 55935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** been satisfied using lookaside memory but failed due to all lookaside 55945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** memory already being in use. 55955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Only the high-water value is meaningful; 55965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the current value is always zero.)^ 55975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 55985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt> 55995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>This parameter returns the approximate number of of bytes of heap 56005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** memory used by all pager caches associated with the database connection.)^ 56015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0. 56025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 56035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt> 56045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>This parameter returns the approximate number of of bytes of heap 56055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** memory used to store the schema for all databases associated 56065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** with the connection - main, temp, and any [ATTACH]-ed databases.)^ 56075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The full amount of memory used by the schemas is reported, even if the 56085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** schema memory is shared with other database connections due to 56095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [shared cache mode] being enabled. 56105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0. 56115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 56125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt> 56135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>This parameter returns the approximate number of of bytes of heap 56145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and lookaside memory used by all prepared statements associated with 56155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the database connection.)^ 56165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0. 56175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </dd> 56185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </dl> 56195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 56205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DBSTATUS_LOOKASIDE_USED 0 56215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DBSTATUS_CACHE_USED 1 56225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DBSTATUS_SCHEMA_USED 2 56235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DBSTATUS_STMT_USED 3 56245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DBSTATUS_LOOKASIDE_HIT 4 56255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5 56265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6 56275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_DBSTATUS_MAX 6 /* Largest defined DBSTATUS */ 56285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 56295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 56305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 56315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Prepared Statement Status 56325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 56335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(Each prepared statement maintains various 56345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_STMTSTATUS_SORT | counters] that measure the number 56355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of times it has performed specific operations.)^ These counters can 56365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** be used to monitor the performance characteristics of the prepared 56375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** statements. For example, if the number of table steps greatly exceeds 56385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the number of table searches or result rows, that would tend to indicate 56395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that the prepared statement is using a full table scan rather than 56405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** an index. 56415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 56425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(This interface is used to retrieve and reset counter values from 56435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a [prepared statement]. The first argument is the prepared statement 56445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** object to be interrogated. The second argument 56455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter] 56465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to be interrogated.)^ 56475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The current value of the requested counter is returned. 56485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the resetFlg is true, then the counter is reset to zero after this 56495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interface call returns. 56505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 56515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also: [sqlite3_status()] and [sqlite3_db_status()]. 56525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 56535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); 56545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 56555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 56565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Status Parameters for prepared statements 56575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 56585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These preprocessor macros define integer codes that name counter 56595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** values associated with the [sqlite3_stmt_status()] interface. 56605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The meanings of the various counters are as follows: 56615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 56625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dl> 56635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt> 56645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>^This is the number of times that SQLite has stepped forward in 56655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a table as part of a full table scan. Large numbers for this counter 56665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** may indicate opportunities for performance improvement through 56675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** careful use of indices.</dd> 56685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 56695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_STMTSTATUS_SORT</dt> 56705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>^This is the number of sort operations that have occurred. 56715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** A non-zero value in this counter may indicate an opportunity to 56725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** improvement performance through careful use of indices.</dd> 56735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 56745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt> 56755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dd>^This is the number of rows inserted into transient indices that 56765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** were created automatically in order to help joins run faster. 56775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** A non-zero value in this counter may indicate an opportunity to 56785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** improvement performance by adding permanent indices that do not 56795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** need to be reinitialized each time the statement is run.</dd> 56805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 56815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </dl> 56825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 56835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_STMTSTATUS_FULLSCAN_STEP 1 56845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_STMTSTATUS_SORT 2 56855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_STMTSTATUS_AUTOINDEX 3 56865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 56875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 56885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Custom Page Cache Object 56895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 56905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The sqlite3_pcache type is opaque. It is implemented by 56915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the pluggable module. The SQLite core has no knowledge of 56925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** its size or internal structure and never deals with the 56935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_pcache object except by holding and passing pointers 56945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to the object. 56955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 56965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See [sqlite3_pcache_methods] for additional information. 56975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 56985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct sqlite3_pcache sqlite3_pcache; 56995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 57005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 57015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Application Defined Page Cache. 57025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** KEYWORDS: {page cache} 57035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 57045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can 57055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** register an alternative page cache implementation by passing in an 57065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** instance of the sqlite3_pcache_methods structure.)^ 57075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** In many applications, most of the heap memory allocated by 57085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite is used for the page cache. 57095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** By implementing a 57105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** custom page cache using this API, an application can better control 57115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the amount of memory consumed by SQLite, the way in which 57125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that memory is allocated and released, and the policies used to 57135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** determine exactly which parts of a database file are cached and for 57145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** how long. 57155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 57165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The alternative page cache mechanism is an 57175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** extreme measure that is only needed by the most demanding applications. 57185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The built-in page cache is recommended for most uses. 57195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 57205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The contents of the sqlite3_pcache_methods structure are copied to an 57215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** internal buffer by SQLite within the call to [sqlite3_config]. Hence 57225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the application may discard the parameter after the call to 57235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_config()] returns.)^ 57245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 57255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The xInit() method is called once for each effective 57265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** call to [sqlite3_initialize()])^ 57275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** (usually only once during the lifetime of the process). ^(The xInit() 57285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^ 57295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The intent of the xInit() method is to set up global data structures 57305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** required by the custom page cache implementation. 57315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(If the xInit() method is NULL, then the 57325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** built-in default page cache is used instead of the application defined 57335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** page cache.)^ 57345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 57355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The xShutdown() method is called by [sqlite3_shutdown()]. 57365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** It can be used to clean up 57375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** any outstanding resources before process shutdown, if required. 57385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The xShutdown() method may be NULL. 57395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 57405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^SQLite automatically serializes calls to the xInit method, 57415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** so the xInit method need not be threadsafe. ^The 57425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** xShutdown method is only called from [sqlite3_shutdown()] so it does 57435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** not need to be threadsafe either. All other methods must be threadsafe 57445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** in multithreaded applications. 57455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 57465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^SQLite will never invoke xInit() more than once without an intervening 57475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** call to xShutdown(). 57485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 57495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^SQLite invokes the xCreate() method to construct a new cache instance. 57505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite will typically create one cache instance for each open database file, 57515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** though this is not guaranteed. ^The 57525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** first parameter, szPage, is the size in bytes of the pages that must 57535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** be allocated by the cache. ^szPage will not be a power of two. ^szPage 57545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** will the page size of the database file that is to be cached plus an 57555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** increment (here called "R") of less than 250. SQLite will use the 57565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** extra R bytes on each page to store metadata about the underlying 57575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database page on disk. The value of R depends 57585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** on the SQLite version, the target platform, and how SQLite was compiled. 57595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(R is constant for a particular build of SQLite. Except, there are two 57605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** distinct values of R when SQLite is compiled with the proprietary 57615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ZIPVFS extension.)^ ^The second argument to 57625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** xCreate(), bPurgeable, is true if the cache being created will 57635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** be used to cache database pages of a file stored on disk, or 57645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** false if it is used for an in-memory database. The cache implementation 57655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** does not have to do anything special based with the value of bPurgeable; 57665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will 57675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** never invoke xUnpin() except to deliberately delete a page. 57685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^In other words, calls to xUnpin() on a cache with bPurgeable set to 57695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** false will always have the "discard" flag set to true. 57705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Hence, a cache created with bPurgeable false will 57715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** never contain any unpinned pages. 57725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 57735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The xCachesize() method may be called at any time by SQLite to set the 57745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** suggested maximum cache-size (number of pages stored by) the cache 57755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** instance passed as the first argument. This is the value configured using 57765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable 57775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** parameter, the implementation is not required to do anything with this 57785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** value; it is advisory only. 57795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 57805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The xPagecount() method must return the number of pages currently 57815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** stored in the cache, both pinned and unpinned. 57825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 57835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The xFetch() method locates a page in the cache and returns a pointer to 57845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the page, or a NULL pointer. 57855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** A "page", in this context, means a buffer of szPage bytes aligned at an 57865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 8-byte boundary. The page to be fetched is determined by the key. ^The 57875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** mimimum key value is 1. After it has been retrieved using xFetch, the page 57885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is considered to be "pinned". 57895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 57905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If the requested page is already in the page cache, then the page cache 57915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** implementation must return a pointer to the page buffer with its content 57925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** intact. If the requested page is not already in the cache, then the 57935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** cache implementation should use the value of the createFlag 57945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** parameter to help it determined what action to take: 57955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 57965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <table border=1 width=85% align=center> 57975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><th> createFlag <th> Behaviour when page is not already in cache 57985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> 0 <td> Do not allocate a new page. Return NULL. 57995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so. 58005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Otherwise return NULL. 58015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <tr><td> 2 <td> Make every effort to allocate a new page. Only return 58025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** NULL if allocating a new page is effectively impossible. 58035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </table> 58045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 58055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite 58065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** will only use a createFlag of 2 after a prior call with a createFlag of 1 58075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** failed.)^ In between the to xFetch() calls, SQLite may 58085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** attempt to unpin one or more cache pages by spilling the content of 58095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** pinned pages to disk and synching the operating system disk cache. 58105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 58115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^xUnpin() is called by SQLite with a pointer to a currently pinned page 58125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** as its second argument. If the third parameter, discard, is non-zero, 58135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then the page must be evicted from the cache. 58145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the discard parameter is 58155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** zero, then the page may be discarded or retained at the discretion of 58165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** page cache implementation. ^The page cache implementation 58175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** may choose to evict unpinned pages at any time. 58185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 58195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The cache must not perform any reference counting. A single 58205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** call to xUnpin() unpins the page regardless of the number of prior calls 58215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to xFetch(). 58225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 58235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The xRekey() method is used to change the key value associated with the 58245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** page passed as the second argument. If the cache 58255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** previously contains an entry associated with newKey, it must be 58265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** discarded. ^Any prior cache entry associated with newKey is guaranteed not 58275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to be pinned. 58285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 58295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** When SQLite calls the xTruncate() method, the cache must discard all 58305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** existing cache entries with page numbers (keys) greater than or equal 58315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to the value of the iLimit parameter passed to xTruncate(). If any 58325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** of these pages are pinned, they are implicitly unpinned, meaning that 58335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** they can be safely discarded. 58345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 58355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The xDestroy() method is used to delete a cache allocated by xCreate(). 58365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** All resources associated with the specified cache should be freed. ^After 58375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*] 58385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** handle invalid, and will not use it with any other sqlite3_pcache_methods 58395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** functions. 58405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 58415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct sqlite3_pcache_methods sqlite3_pcache_methods; 58425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct sqlite3_pcache_methods { 58435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void *pArg; 58445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xInit)(void*); 58455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xShutdown)(void*); 58465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable); 58475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xCachesize)(sqlite3_pcache*, int nCachesize); 58485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int (*xPagecount)(sqlite3_pcache*); 58495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag); 58505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xUnpin)(sqlite3_pcache*, void*, int discard); 58515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey); 58525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xTruncate)(sqlite3_pcache*, unsigned iLimit); 58535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xDestroy)(sqlite3_pcache*); 58545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 58555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 58565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 58575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Online Backup Object 58585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 58595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The sqlite3_backup object records state information about an ongoing 58605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** online backup operation. ^The sqlite3_backup object is created by 58615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a call to [sqlite3_backup_init()] and is destroyed by a call to 58625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_backup_finish()]. 58635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 58645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See Also: [Using the SQLite Online Backup API] 58655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 58665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct sqlite3_backup sqlite3_backup; 58675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 58685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 58695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Online Backup API. 58705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 58715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The backup API copies the content of one database into another. 58725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** It is useful either for creating backups of databases or 58735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for copying in-memory databases to or from persistent files. 58745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 58755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See Also: [Using the SQLite Online Backup API] 58765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 58775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^SQLite holds a write transaction open on the destination database file 58785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for the duration of the backup operation. 58795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The source database is read-locked only while it is being read; 58805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** it is not locked continuously for the entire backup operation. 58815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Thus, the backup may be performed on a live source database without 58825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** preventing other database connections from 58835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** reading or writing to the source database while the backup is underway. 58845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 58855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(To perform a backup operation: 58865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <ol> 58875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li><b>sqlite3_backup_init()</b> is called once to initialize the 58885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** backup, 58895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li><b>sqlite3_backup_step()</b> is called one or more times to transfer 58905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the data between the two databases, and finally 58915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li><b>sqlite3_backup_finish()</b> is called to release all resources 58925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** associated with the backup operation. 58935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </ol>)^ 58945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** There should be exactly one call to sqlite3_backup_finish() for each 58955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** successful call to sqlite3_backup_init(). 58965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 58975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <b>sqlite3_backup_init()</b> 58985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 58995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the 59005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [database connection] associated with the destination database 59015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and the database name, respectively. 59025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The database name is "main" for the main database, "temp" for the 59035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** temporary database, or the name specified after the AS keyword in 59045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** an [ATTACH] statement for an attached database. 59055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The S and M arguments passed to 59065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_backup_init(D,N,S,M) identify the [database connection] 59075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and database name of the source database, respectively. 59085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The source and destination [database connections] (parameters S and D) 59095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** must be different or else sqlite3_backup_init(D,N,S,M) will fail with 59105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** an error. 59115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 59125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is 59135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** returned and an error code and error message are stored in the 59145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** destination [database connection] D. 59155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The error code and message for the failed call to sqlite3_backup_init() 59165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or 59175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_errmsg16()] functions. 59185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^A successful call to sqlite3_backup_init() returns a pointer to an 59195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_backup] object. 59205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and 59215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_backup_finish() functions to perform the specified backup 59225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** operation. 59235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 59245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <b>sqlite3_backup_step()</b> 59255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 59265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Function sqlite3_backup_step(B,N) will copy up to N pages between 59275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the source and destination databases specified by [sqlite3_backup] object B. 59285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If N is negative, all remaining source pages are copied. 59295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If sqlite3_backup_step(B,N) successfully copies N pages and there 59305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are still more pages to be copied, then the function returns [SQLITE_OK]. 59315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages 59325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** from source to destination, then it returns [SQLITE_DONE]. 59335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If an error occurs while running sqlite3_backup_step(B,N), 59345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then an [error code] is returned. ^As well as [SQLITE_OK] and 59355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY], 59365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an 59375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code. 59385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 59395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if 59405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <ol> 59415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> the destination database was opened read-only, or 59425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> the destination database is using write-ahead-log journaling 59435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and the destination and source page sizes differ, or 59445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <li> the destination database is an in-memory database and the 59455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** destination and source page sizes differ. 59465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </ol>)^ 59475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 59485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then 59495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the [sqlite3_busy_handler | busy-handler function] 59505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is invoked (if one is specified). ^If the 59515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** busy-handler returns non-zero before the lock is available, then 59525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_BUSY] is returned to the caller. ^In this case the call to 59535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_backup_step() can be retried later. ^If the source 59545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [database connection] 59555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is being used to write to the source database when sqlite3_backup_step() 59565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this 59575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** case the call to sqlite3_backup_step() can be retried later on. ^(If 59585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or 59595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_READONLY] is returned, then 59605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** there is no point in retrying the call to sqlite3_backup_step(). These 59615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** errors are considered fatal.)^ The application must accept 59625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that the backup operation has failed and pass the backup operation handle 59635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to the sqlite3_backup_finish() to release associated resources. 59645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 59655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The first call to sqlite3_backup_step() obtains an exclusive lock 59665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** on the destination file. ^The exclusive lock is not released until either 59675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_backup_finish() is called or the backup operation is complete 59685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and sqlite3_backup_step() returns [SQLITE_DONE]. ^Every call to 59695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_backup_step() obtains a [shared lock] on the source database that 59705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** lasts for the duration of the sqlite3_backup_step() call. 59715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Because the source database is not locked between calls to 59725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_backup_step(), the source database may be modified mid-way 59735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** through the backup process. ^If the source database is modified by an 59745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** external process or via a database connection other than the one being 59755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** used by the backup operation, then the backup will be automatically 59765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** restarted by the next call to sqlite3_backup_step(). ^If the source 59775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database is modified by the using the same database connection as is used 59785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by the backup operation, then the backup database is automatically 59795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** updated at the same time. 59805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 59815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <b>sqlite3_backup_finish()</b> 59825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 59835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the 59845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** application wishes to abandon the backup operation, the application 59855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish(). 59865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The sqlite3_backup_finish() interfaces releases all 59875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** resources associated with the [sqlite3_backup] object. 59885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any 59895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** active write-transaction on the destination database is rolled back. 59905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The [sqlite3_backup] object is invalid 59915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and may not be used following a call to sqlite3_backup_finish(). 59925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 59935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no 59945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_backup_step() errors occurred, regardless or whether or not 59955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_backup_step() completed. 59965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If an out-of-memory condition or IO error occurred during any prior 59975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_backup_step() call on the same [sqlite3_backup] object, then 59985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_backup_finish() returns the corresponding [error code]. 59995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 60005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step() 60015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is not a permanent error and does not affect the return value of 60025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_backup_finish(). 60035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 60045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <b>sqlite3_backup_remaining(), sqlite3_backup_pagecount()</b> 60055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 60065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Each call to sqlite3_backup_step() sets two values inside 60075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the [sqlite3_backup] object: the number of pages still to be backed 60085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** up and the total number of pages in the source database file. 60095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces 60105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** retrieve these two values, respectively. 60115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 60125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The values returned by these functions are only updated by 60135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_backup_step(). ^If the source database is modified during a backup 60145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** operation, then the values are not updated to account for any extra 60155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** pages that need to be updated or the size of the source database file 60165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** changing. 60175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 60185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <b>Concurrent Usage of Database Handles</b> 60195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 60205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The source [database connection] may be used by the application for other 60215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** purposes while a backup operation is underway or being initialized. 60225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If SQLite is compiled and configured to support threadsafe database 60235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** connections, then the source database connection may be used concurrently 60245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** from within other threads. 60255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 60265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** However, the application must guarantee that the destination 60275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [database connection] is not passed to any other API (by any thread) after 60285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_backup_init() is called and before the corresponding call to 60295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_backup_finish(). SQLite does not currently check to see 60305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** if the application incorrectly accesses the destination [database connection] 60315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and so no error code is reported, but the operations may malfunction 60325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** nevertheless. Use of the destination database connection while a 60335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** backup is in progress might also also cause a mutex deadlock. 60345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 60355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If running in [shared cache mode], the application must 60365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** guarantee that the shared cache used by the destination database 60375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is not accessed while the backup is running. In practice this means 60385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that the application must guarantee that the disk file being 60395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** backed up to is not accessed by any connection within the process, 60405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** not just the specific connection that was passed to sqlite3_backup_init(). 60415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 60425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The [sqlite3_backup] object itself is partially threadsafe. Multiple 60435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** threads may safely make multiple concurrent calls to sqlite3_backup_step(). 60445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount() 60455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** APIs are not strictly speaking threadsafe. If they are invoked at the 60465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** same time as another thread is invoking sqlite3_backup_step() it is 60475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** possible that they return invalid values. 60485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 60495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)sqlite3_backup *sqlite3_backup_init( 60505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3 *pDest, /* Destination database handle */ 60515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zDestName, /* Destination database name */ 60525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3 *pSource, /* Source database handle */ 60535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zSourceName /* Source database name */ 60545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 60555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_backup_step(sqlite3_backup *p, int nPage); 60565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_backup_finish(sqlite3_backup *p); 60575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_backup_remaining(sqlite3_backup *p); 60585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_backup_pagecount(sqlite3_backup *p); 60595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 60605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 60615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Unlock Notification 60625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 60635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^When running in shared-cache mode, a database operation may fail with 60645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** an [SQLITE_LOCKED] error if the required locks on the shared-cache or 60655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** individual tables within the shared-cache cannot be obtained. See 60665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLite Shared-Cache Mode] for a description of shared-cache locking. 60675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This API may be used to register a callback that SQLite will invoke 60685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** when the connection currently holding the required lock relinquishes it. 60695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^This API is only available if the library was compiled with the 60705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined. 60715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 60725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See Also: [Using the SQLite Unlock Notification Feature]. 60735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 60745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Shared-cache locks are released when a database connection concludes 60755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** its current transaction, either by committing it or rolling it back. 60765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 60775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^When a connection (known as the blocked connection) fails to obtain a 60785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** shared-cache lock and SQLITE_LOCKED is returned to the caller, the 60795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** identity of the database connection (the blocking connection) that 60805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** has locked the required resource is stored internally. ^After an 60815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** application receives an SQLITE_LOCKED error, it may call the 60825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_unlock_notify() method with the blocked connection handle as 60835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the first argument to register for a callback that will be invoked 60845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** when the blocking connections current transaction is concluded. ^The 60855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** callback is invoked from within the [sqlite3_step] or [sqlite3_close] 60865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** call that concludes the blocking connections transaction. 60875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 60885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(If sqlite3_unlock_notify() is called in a multi-threaded application, 60895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** there is a chance that the blocking connection will have already 60905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** concluded its transaction by the time sqlite3_unlock_notify() is invoked. 60915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If this happens, then the specified callback is invoked immediately, 60925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** from within the call to sqlite3_unlock_notify().)^ 60935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 60945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If the blocked connection is attempting to obtain a write-lock on a 60955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** shared-cache table, and more than one other connection currently holds 60965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a read-lock on the same table, then SQLite arbitrarily selects one of 60975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the other connections to use as the blocking connection. 60985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 60995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^(There may be at most one unlock-notify callback registered by a 61005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** blocked connection. If sqlite3_unlock_notify() is called when the 61015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** blocked connection already has a registered unlock-notify callback, 61025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is 61035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** called with a NULL pointer as its second argument, then any existing 61045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** unlock-notify callback is canceled. ^The blocked connections 61055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** unlock-notify callback may also be canceled by closing the blocked 61065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** connection using [sqlite3_close()]. 61075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 61085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The unlock-notify callback is not reentrant. If an application invokes 61095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** any sqlite3_xxx API functions from within an unlock-notify callback, a 61105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** crash or deadlock may be the result. 61115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 61125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always 61135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** returns SQLITE_OK. 61145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 61155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <b>Callback Invocation Details</b> 61165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 61175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** When an unlock-notify callback is registered, the application provides a 61185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** single void* pointer that is passed to the callback when it is invoked. 61195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** However, the signature of the callback function allows SQLite to pass 61205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** it an array of void* context pointers. The first argument passed to 61215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** an unlock-notify callback is a pointer to an array of void* pointers, 61225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and the second is the number of entries in the array. 61235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 61245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** When a blocking connections transaction is concluded, there may be 61255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** more than one blocked connection that has registered for an unlock-notify 61265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** callback. ^If two or more such blocked connections have specified the 61275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** same callback function, then instead of invoking the callback function 61285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** multiple times, it is invoked once with the set of void* context pointers 61295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** specified by the blocked connections bundled together into an array. 61305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This gives the application an opportunity to prioritize any actions 61315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** related to the set of unblocked database connections. 61325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 61335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <b>Deadlock Detection</b> 61345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 61355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Assuming that after registering for an unlock-notify callback a 61365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database waits for the callback to be issued before taking any further 61375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** action (a reasonable assumption), then using this API may cause the 61385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** application to deadlock. For example, if connection X is waiting for 61395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** connection Y's transaction to be concluded, and similarly connection 61405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Y is waiting on connection X's transaction, then neither connection 61415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** will proceed and the system may remain deadlocked indefinitely. 61425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 61435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock 61445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** detection. ^If a given call to sqlite3_unlock_notify() would put the 61455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** system in a deadlocked state, then SQLITE_LOCKED is returned and no 61465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** unlock-notify callback is registered. The system is said to be in 61475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a deadlocked state if connection A has registered for an unlock-notify 61485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** callback on the conclusion of connection B's transaction, and connection 61495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** B has itself registered for an unlock-notify callback when connection 61505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** A's transaction is concluded. ^Indirect deadlock is also detected, so 61515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the system is also considered to be deadlocked if connection B has 61525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** registered for an unlock-notify callback on the conclusion of connection 61535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** C's transaction, where connection C is waiting on connection A. ^Any 61545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** number of levels of indirection are allowed. 61555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 61565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <b>The "DROP TABLE" Exception</b> 61575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 61585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost 61595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** always appropriate to call sqlite3_unlock_notify(). There is however, 61605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement, 61615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite checks if there are any currently executing SELECT statements 61625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that belong to the same connection. If there are, SQLITE_LOCKED is 61635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** returned. In this case there is no "blocking connection", so invoking 61645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_unlock_notify() results in the unlock-notify callback being 61655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** invoked immediately. If the application then re-attempts the "DROP TABLE" 61665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** or "DROP INDEX" query, an infinite loop might be the result. 61675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 61685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** One way around this problem is to check the extended error code returned 61695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** by an sqlite3_step() call. ^(If there is a blocking connection, then the 61705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in 61715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the special "DROP TABLE/INDEX" case, the extended error code is just 61725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLITE_LOCKED.)^ 61735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 61745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_unlock_notify( 61755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3 *pBlocked, /* Waiting connection */ 61765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */ 61775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void *pNotifyArg /* Argument to pass to xNotify */ 61785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 61795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 61805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 61815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 61825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: String Comparison 61835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 61845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [sqlite3_strnicmp()] API allows applications and extensions to 61855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** compare the contents of two buffers containing UTF-8 strings in a 61865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** case-independent fashion, using the same definition of case independence 61875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that SQLite uses internally when comparing identifiers. 61885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 61895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_strnicmp(const char *, const char *, int); 61905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 61915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 61925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Error Logging Interface 61935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 61945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [sqlite3_log()] interface writes a message into the error log 61955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()]. 61965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^If logging is enabled, the zFormat string and subsequent arguments are 61975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** used with [sqlite3_snprintf()] to generate the final output string. 61985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 61995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The sqlite3_log() interface is intended for use by extensions such as 62005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** virtual tables, collating functions, and SQL functions. While there is 62015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** nothing to prevent an application from calling sqlite3_log(), doing so 62025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is considered bad form. 62035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 62045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The zFormat string must not be NULL. 62055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 62065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** To avoid deadlocks and other threading problems, the sqlite3_log() routine 62075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** will not use dynamically allocated memory. The log message is stored in 62085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a fixed-length buffer on the stack. If the log message is longer than 62095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a few hundred characters, it will be truncated to the length of the 62105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** buffer. 62115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 62125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void sqlite3_log(int iErrCode, const char *zFormat, ...); 62135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 62145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 62155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Write-Ahead Log Commit Hook 62165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 62175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [sqlite3_wal_hook()] function is used to register a callback that 62185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** will be invoked each time a database connection commits data to a 62195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [write-ahead log] (i.e. whenever a transaction is committed in 62205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [journal_mode | journal_mode=WAL mode]). 62215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 62225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The callback is invoked by SQLite after the commit has taken place and 62235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the associated write-lock on the database released, so the implementation 62245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** may read, write or [checkpoint] the database as required. 62255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 62265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The first parameter passed to the callback function when it is invoked 62275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is a copy of the third parameter passed to sqlite3_wal_hook() when 62285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** registering the callback. ^The second is a copy of the database handle. 62295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The third parameter is the name of the database that was written to - 62305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter 62315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is the number of pages currently in the write-ahead log file, 62325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** including those that were just committed. 62335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 62345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The callback function should normally return [SQLITE_OK]. ^If an error 62355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** code is returned, that error will propagate back up through the 62365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLite code base to cause the statement that provoked the callback 62375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to report an error, though the commit will have still occurred. If the 62385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value 62395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that does not correspond to any valid SQLite error code, the results 62405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are undefined. 62415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 62425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** A single database handle may have at most a single write-ahead log callback 62435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any 62445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** previously registered write-ahead log callback. ^Note that the 62455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_wal_autocheckpoint()] interface and the 62465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will 62475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** those overwrite any prior [sqlite3_wal_hook()] settings. 62485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 62495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void *sqlite3_wal_hook( 62505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3*, 62515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int(*)(void *,sqlite3*,const char*,int), 62525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void* 62535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 62545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 62555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 62565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Configure an auto-checkpoint 62575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 62585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around 62595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_wal_hook()] that causes any database on [database connection] D 62605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to automatically [checkpoint] 62615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** after committing a transaction if there are N or 62625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** more frames in the [write-ahead log] file. ^Passing zero or 62635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** a negative value as the nFrame parameter disables automatic 62645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** checkpoints entirely. 62655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 62665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The callback registered by this function replaces any existing callback 62675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback 62685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism 62695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** configured by this function. 62705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 62715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [wal_autocheckpoint pragma] can be used to invoke this interface 62725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** from SQL. 62735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 62745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^Every new [database connection] defaults to having the auto-checkpoint 62755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT] 62765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** pages. The use of this interface 62775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is only necessary if the default setting is found to be suboptimal 62785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** for a particular application. 62795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 62805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_wal_autocheckpoint(sqlite3 *db, int N); 62815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 62825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 62835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Checkpoint a database 62845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 62855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X 62865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** on [database connection] D to be [checkpointed]. ^If X is NULL or an 62875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** empty string, then a checkpoint is run on all databases of 62885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** connection D. ^If the database connection D is not in 62895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [WAL | write-ahead log mode] then this interface is a harmless no-op. 62905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 62915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** ^The [wal_checkpoint pragma] can be used to invoke this interface 62925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the 62935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [wal_autocheckpoint pragma] can be used to cause this interface to be 62945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** run whenever the WAL reaches a certain size threshold. 62955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 62965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** See also: [sqlite3_wal_checkpoint_v2()] 62975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 62985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); 62995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 63005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 63015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Checkpoint a database 63025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 63035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Run a checkpoint operation on WAL database zDb attached to database 63045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** handle db. The specific operation is determined by the value of the 63055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** eMode parameter: 63065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 63075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dl> 63085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_CHECKPOINT_PASSIVE<dd> 63095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Checkpoint as many frames as possible without waiting for any database 63105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** readers or writers to finish. Sync the db file if all frames in the log 63115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** are checkpointed. This mode is the same as calling 63125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** sqlite3_wal_checkpoint(). The busy-handler callback is never invoked. 63135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 63145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_CHECKPOINT_FULL<dd> 63155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This mode blocks (calls the busy-handler callback) until there is no 63165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database writer and all readers are reading from the most recent database 63175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** snapshot. It then checkpoints all frames in the log file and syncs the 63185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database file. This call blocks database writers while it is running, 63195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** but not database readers. 63205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 63215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** <dt>SQLITE_CHECKPOINT_RESTART<dd> 63225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after 63235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** checkpointing the log file it blocks (calls the busy-handler callback) 63245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** until all readers are reading from the database file only. This ensures 63255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that the next client to write to the database file restarts the log file 63265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** from the beginning. This call blocks database writers while it is running, 63275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** but not database readers. 63285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** </dl> 63295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 63305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If pnLog is not NULL, then *pnLog is set to the total number of frames in 63315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the log file before returning. If pnCkpt is not NULL, then *pnCkpt is set to 63325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the total number of checkpointed frames (including any that were already 63335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** checkpointed when this function is called). *pnLog and *pnCkpt may be 63345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** populated even if sqlite3_wal_checkpoint_v2() returns other than SQLITE_OK. 63355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If no values are available because of an error, they are both set to -1 63365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** before returning to communicate this to the caller. 63375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 63385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** All calls obtain an exclusive "checkpoint" lock on the database file. If 63395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** any other process is running a checkpoint operation at the same time, the 63405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** lock cannot be obtained and SQLITE_BUSY is returned. Even if there is a 63415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** busy-handler configured, it will not be invoked in this case. 63425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 63435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The SQLITE_CHECKPOINT_FULL and RESTART modes also obtain the exclusive 63445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** "writer" lock on the database file. If the writer lock cannot be obtained 63455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** immediately, and a busy-handler is configured, it is invoked and the writer 63465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** lock retried until either the busy-handler returns 0 or the lock is 63475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** successfully obtained. The busy-handler is also invoked while waiting for 63485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** database readers as described above. If the busy-handler returns 0 before 63495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the writer lock is obtained or while waiting for database readers, the 63505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** checkpoint operation proceeds from that point in the same way as 63515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible 63525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** without blocking any further. SQLITE_BUSY is returned in this case. 63535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 63545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If parameter zDb is NULL or points to a zero length string, then the 63555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** specified operation is attempted on all WAL databases. In this case the 63565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** values written to output parameters *pnLog and *pnCkpt are undefined. If 63575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** an SQLITE_BUSY error is encountered when processing one or more of the 63585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** attached WAL databases, the operation is still attempted on any remaining 63595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** attached databases and SQLITE_BUSY is returned to the caller. If any other 63605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** error occurs while processing an attached database, processing is abandoned 63615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** and the error code returned to the caller immediately. If no error 63625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** (SQLITE_BUSY or otherwise) is encountered while processing the attached 63635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** databases, SQLITE_OK is returned. 63645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 63655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If database zDb is the name of an attached database that is not in WAL 63665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. If 63675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** zDb is not NULL (or a zero length string) and is not the name of any 63685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** attached database, SQLITE_ERROR is returned to the caller. 63695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 63705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int sqlite3_wal_checkpoint_v2( 63715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sqlite3 *db, /* Database handle */ 63725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *zDb, /* Name of attached database (or NULL) */ 63735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int eMode, /* SQLITE_CHECKPOINT_* value */ 63745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int *pnLog, /* OUT: Size of WAL log in frames */ 63755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int *pnCkpt /* OUT: Total number of frames checkpointed */ 63765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)); 63775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 63785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 63795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** CAPI3REF: Checkpoint operation parameters 63805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 63815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These constants can be used as the 3rd parameter to 63825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** [sqlite3_wal_checkpoint_v2()]. See the [sqlite3_wal_checkpoint_v2()] 63835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** documentation for additional information about the meaning and use of 63845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** each of these values. 63855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 63865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CHECKPOINT_PASSIVE 0 63875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CHECKPOINT_FULL 1 63885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SQLITE_CHECKPOINT_RESTART 2 63895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 63905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6391ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch/* Begin recover.patch for Chromium */ 6392ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch/* 6393ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch** Call to initialize the recover virtual-table modules (see recover.c). 6394ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch** 6395ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch** This could be loaded by default in main.c, but that would make the 6396ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch** virtual table available to Web SQL. Breaking it out allows only 6397ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch** selected users to enable it (currently sql/recovery.cc). 6398ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch*/ 6399ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochint recoverVtableInit(sqlite3 *db); 6400ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch/* End recover.patch for Chromium */ 6401ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 64025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 64035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Undo the hack that converts floating point types to integer for 64045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** builds on processors without floating point support. 64055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 64065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef SQLITE_OMIT_FLOATING_POINT 64075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# undef double 64085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 64095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 64105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef __cplusplus 64115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} /* End of the 'extern "C"' block */ 64125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 64135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 6414