Fork github.com/mattn/go-sqlite3 with adjustment for go1.16.2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12937 lines
603 KiB

  1. #ifndef USE_LIBSQLITE3
  2. /*
  3. ** 2001-09-15
  4. **
  5. ** The author disclaims copyright to this source code. In place of
  6. ** a legal notice, here is a blessing:
  7. **
  8. ** May you do good and not evil.
  9. ** May you find forgiveness for yourself and forgive others.
  10. ** May you share freely, never taking more than you give.
  11. **
  12. *************************************************************************
  13. ** This header file defines the interface that the SQLite library
  14. ** presents to client programs. If a C-function, structure, datatype,
  15. ** or constant definition does not appear in this file, then it is
  16. ** not a published API of SQLite, is subject to change without
  17. ** notice, and should not be referenced by programs that use SQLite.
  18. **
  19. ** Some of the definitions that are in this file are marked as
  20. ** "experimental". Experimental interfaces are normally new
  21. ** features recently added to SQLite. We do not anticipate changes
  22. ** to experimental interfaces but reserve the right to make minor changes
  23. ** if experience from use "in the wild" suggest such changes are prudent.
  24. **
  25. ** The official C-language API documentation for SQLite is derived
  26. ** from comments in this file. This file is the authoritative source
  27. ** on how SQLite interfaces are supposed to operate.
  28. **
  29. ** The name of this file under configuration management is "sqlite.h.in".
  30. ** The makefile makes some minor changes to this file (such as inserting
  31. ** the version number) and changes its name to "sqlite3.h" as
  32. ** part of the build process.
  33. */
  34. #ifndef SQLITE3_H
  35. #define SQLITE3_H
  36. #include <stdarg.h> /* Needed for the definition of va_list */
  37. /*
  38. ** Make sure we can call this stuff from C++.
  39. */
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /*
  44. ** Facilitate override of interface linkage and calling conventions.
  45. ** Be aware that these macros may not be used within this particular
  46. ** translation of the amalgamation and its associated header file.
  47. **
  48. ** The SQLITE_EXTERN and SQLITE_API macros are used to instruct the
  49. ** compiler that the target identifier should have external linkage.
  50. **
  51. ** The SQLITE_CDECL macro is used to set the calling convention for
  52. ** public functions that accept a variable number of arguments.
  53. **
  54. ** The SQLITE_APICALL macro is used to set the calling convention for
  55. ** public functions that accept a fixed number of arguments.
  56. **
  57. ** The SQLITE_STDCALL macro is no longer used and is now deprecated.
  58. **
  59. ** The SQLITE_CALLBACK macro is used to set the calling convention for
  60. ** function pointers.
  61. **
  62. ** The SQLITE_SYSAPI macro is used to set the calling convention for
  63. ** functions provided by the operating system.
  64. **
  65. ** Currently, the SQLITE_CDECL, SQLITE_APICALL, SQLITE_CALLBACK, and
  66. ** SQLITE_SYSAPI macros are used only when building for environments
  67. ** that require non-default calling conventions.
  68. */
  69. #ifndef SQLITE_EXTERN
  70. # define SQLITE_EXTERN extern
  71. #endif
  72. #ifndef SQLITE_API
  73. # define SQLITE_API
  74. #endif
  75. #ifndef SQLITE_CDECL
  76. # define SQLITE_CDECL
  77. #endif
  78. #ifndef SQLITE_APICALL
  79. # define SQLITE_APICALL
  80. #endif
  81. #ifndef SQLITE_STDCALL
  82. # define SQLITE_STDCALL SQLITE_APICALL
  83. #endif
  84. #ifndef SQLITE_CALLBACK
  85. # define SQLITE_CALLBACK
  86. #endif
  87. #ifndef SQLITE_SYSAPI
  88. # define SQLITE_SYSAPI
  89. #endif
  90. /*
  91. ** These no-op macros are used in front of interfaces to mark those
  92. ** interfaces as either deprecated or experimental. New applications
  93. ** should not use deprecated interfaces - they are supported for backwards
  94. ** compatibility only. Application writers should be aware that
  95. ** experimental interfaces are subject to change in point releases.
  96. **
  97. ** These macros used to resolve to various kinds of compiler magic that
  98. ** would generate warning messages when they were used. But that
  99. ** compiler magic ended up generating such a flurry of bug reports
  100. ** that we have taken it all out and gone back to using simple
  101. ** noop macros.
  102. */
  103. #define SQLITE_DEPRECATED
  104. #define SQLITE_EXPERIMENTAL
  105. /*
  106. ** Ensure these symbols were not defined by some previous header file.
  107. */
  108. #ifdef SQLITE_VERSION
  109. # undef SQLITE_VERSION
  110. #endif
  111. #ifdef SQLITE_VERSION_NUMBER
  112. # undef SQLITE_VERSION_NUMBER
  113. #endif
  114. /*
  115. ** CAPI3REF: Compile-Time Library Version Numbers
  116. **
  117. ** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header
  118. ** evaluates to a string literal that is the SQLite version in the
  119. ** format "X.Y.Z" where X is the major version number (always 3 for
  120. ** SQLite3) and Y is the minor version number and Z is the release number.)^
  121. ** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer
  122. ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
  123. ** numbers used in [SQLITE_VERSION].)^
  124. ** The SQLITE_VERSION_NUMBER for any given release of SQLite will also
  125. ** be larger than the release from which it is derived. Either Y will
  126. ** be held constant and Z will be incremented or else Y will be incremented
  127. ** and Z will be reset to zero.
  128. **
  129. ** Since [version 3.6.18] ([dateof:3.6.18]),
  130. ** SQLite source code has been stored in the
  131. ** <a href="http://www.fossil-scm.org/">Fossil configuration management
  132. ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to
  133. ** a string which identifies a particular check-in of SQLite
  134. ** within its configuration management system. ^The SQLITE_SOURCE_ID
  135. ** string contains the date and time of the check-in (UTC) and a SHA1
  136. ** or SHA3-256 hash of the entire source tree. If the source code has
  137. ** been edited in any way since it was last checked in, then the last
  138. ** four hexadecimal digits of the hash may be modified.
  139. **
  140. ** See also: [sqlite3_libversion()],
  141. ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
  142. ** [sqlite_version()] and [sqlite_source_id()].
  143. */
  144. #define SQLITE_VERSION "3.39.4"
  145. #define SQLITE_VERSION_NUMBER 3039004
  146. #define SQLITE_SOURCE_ID "2022-09-29 15:55:41 a29f9949895322123f7c38fbe94c649a9d6e6c9cd0c3b41c96d694552f26b309"
  147. /*
  148. ** CAPI3REF: Run-Time Library Version Numbers
  149. ** KEYWORDS: sqlite3_version sqlite3_sourceid
  150. **
  151. ** These interfaces provide the same information as the [SQLITE_VERSION],
  152. ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
  153. ** but are associated with the library instead of the header file. ^(Cautious
  154. ** programmers might include assert() statements in their application to
  155. ** verify that values returned by these interfaces match the macros in
  156. ** the header, and thus ensure that the application is
  157. ** compiled with matching library and header files.
  158. **
  159. ** <blockquote><pre>
  160. ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
  161. ** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );
  162. ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
  163. ** </pre></blockquote>)^
  164. **
  165. ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
  166. ** macro. ^The sqlite3_libversion() function returns a pointer to the
  167. ** to the sqlite3_version[] string constant. The sqlite3_libversion()
  168. ** function is provided for use in DLLs since DLL users usually do not have
  169. ** direct access to string constants within the DLL. ^The
  170. ** sqlite3_libversion_number() function returns an integer equal to
  171. ** [SQLITE_VERSION_NUMBER]. ^(The sqlite3_sourceid() function returns
  172. ** a pointer to a string constant whose value is the same as the
  173. ** [SQLITE_SOURCE_ID] C preprocessor macro. Except if SQLite is built
  174. ** using an edited copy of [the amalgamation], then the last four characters
  175. ** of the hash might be different from [SQLITE_SOURCE_ID].)^
  176. **
  177. ** See also: [sqlite_version()] and [sqlite_source_id()].
  178. */
  179. SQLITE_API SQLITE_EXTERN const char sqlite3_version[];
  180. SQLITE_API const char *sqlite3_libversion(void);
  181. SQLITE_API const char *sqlite3_sourceid(void);
  182. SQLITE_API int sqlite3_libversion_number(void);
  183. /*
  184. ** CAPI3REF: Run-Time Library Compilation Options Diagnostics
  185. **
  186. ** ^The sqlite3_compileoption_used() function returns 0 or 1
  187. ** indicating whether the specified option was defined at
  188. ** compile time. ^The SQLITE_ prefix may be omitted from the
  189. ** option name passed to sqlite3_compileoption_used().
  190. **
  191. ** ^The sqlite3_compileoption_get() function allows iterating
  192. ** over the list of options that were defined at compile time by
  193. ** returning the N-th compile time option string. ^If N is out of range,
  194. ** sqlite3_compileoption_get() returns a NULL pointer. ^The SQLITE_
  195. ** prefix is omitted from any strings returned by
  196. ** sqlite3_compileoption_get().
  197. **
  198. ** ^Support for the diagnostic functions sqlite3_compileoption_used()
  199. ** and sqlite3_compileoption_get() may be omitted by specifying the
  200. ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
  201. **
  202. ** See also: SQL functions [sqlite_compileoption_used()] and
  203. ** [sqlite_compileoption_get()] and the [compile_options pragma].
  204. */
  205. #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
  206. SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
  207. SQLITE_API const char *sqlite3_compileoption_get(int N);
  208. #else
  209. # define sqlite3_compileoption_used(X) 0
  210. # define sqlite3_compileoption_get(X) ((void*)0)
  211. #endif
  212. /*
  213. ** CAPI3REF: Test To See If The Library Is Threadsafe
  214. **
  215. ** ^The sqlite3_threadsafe() function returns zero if and only if
  216. ** SQLite was compiled with mutexing code omitted due to the
  217. ** [SQLITE_THREADSAFE] compile-time option being set to 0.
  218. **
  219. ** SQLite can be compiled with or without mutexes. When
  220. ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes
  221. ** are enabled and SQLite is threadsafe. When the
  222. ** [SQLITE_THREADSAFE] macro is 0,
  223. ** the mutexes are omitted. Without the mutexes, it is not safe
  224. ** to use SQLite concurrently from more than one thread.
  225. **
  226. ** Enabling mutexes incurs a measurable performance penalty.
  227. ** So if speed is of utmost importance, it makes sense to disable
  228. ** the mutexes. But for maximum safety, mutexes should be enabled.
  229. ** ^The default behavior is for mutexes to be enabled.
  230. **
  231. ** This interface can be used by an application to make sure that the
  232. ** version of SQLite that it is linking against was compiled with
  233. ** the desired setting of the [SQLITE_THREADSAFE] macro.
  234. **
  235. ** This interface only reports on the compile-time mutex setting
  236. ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
  237. ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
  238. ** can be fully or partially disabled using a call to [sqlite3_config()]
  239. ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
  240. ** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the
  241. ** sqlite3_threadsafe() function shows only the compile-time setting of
  242. ** thread safety, not any run-time changes to that setting made by
  243. ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
  244. ** is unchanged by calls to sqlite3_config().)^
  245. **
  246. ** See the [threading mode] documentation for additional information.
  247. */
  248. SQLITE_API int sqlite3_threadsafe(void);
  249. /*
  250. ** CAPI3REF: Database Connection Handle
  251. ** KEYWORDS: {database connection} {database connections}
  252. **
  253. ** Each open SQLite database is represented by a pointer to an instance of
  254. ** the opaque structure named "sqlite3". It is useful to think of an sqlite3
  255. ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and
  256. ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
  257. ** and [sqlite3_close_v2()] are its destructors. There are many other
  258. ** interfaces (such as
  259. ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
  260. ** [sqlite3_busy_timeout()] to name but three) that are methods on an
  261. ** sqlite3 object.
  262. */
  263. typedef struct sqlite3 sqlite3;
  264. /*
  265. ** CAPI3REF: 64-Bit Integer Types
  266. ** KEYWORDS: sqlite_int64 sqlite_uint64
  267. **
  268. ** Because there is no cross-platform way to specify 64-bit integer types
  269. ** SQLite includes typedefs for 64-bit signed and unsigned integers.
  270. **
  271. ** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
  272. ** The sqlite_int64 and sqlite_uint64 types are supported for backwards
  273. ** compatibility only.
  274. **
  275. ** ^The sqlite3_int64 and sqlite_int64 types can store integer values
  276. ** between -9223372036854775808 and +9223372036854775807 inclusive. ^The
  277. ** sqlite3_uint64 and sqlite_uint64 types can store integer values
  278. ** between 0 and +18446744073709551615 inclusive.
  279. */
  280. #ifdef SQLITE_INT64_TYPE
  281. typedef SQLITE_INT64_TYPE sqlite_int64;
  282. # ifdef SQLITE_UINT64_TYPE
  283. typedef SQLITE_UINT64_TYPE sqlite_uint64;
  284. # else
  285. typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
  286. # endif
  287. #elif defined(_MSC_VER) || defined(__BORLANDC__)
  288. typedef __int64 sqlite_int64;
  289. typedef unsigned __int64 sqlite_uint64;
  290. #else
  291. typedef long long int sqlite_int64;
  292. typedef unsigned long long int sqlite_uint64;
  293. #endif
  294. typedef sqlite_int64 sqlite3_int64;
  295. typedef sqlite_uint64 sqlite3_uint64;
  296. /*
  297. ** If compiling for a processor that lacks floating point support,
  298. ** substitute integer for floating-point.
  299. */
  300. #ifdef SQLITE_OMIT_FLOATING_POINT
  301. # define double sqlite3_int64
  302. #endif
  303. /*
  304. ** CAPI3REF: Closing A Database Connection
  305. ** DESTRUCTOR: sqlite3
  306. **
  307. ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
  308. ** for the [sqlite3] object.
  309. ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
  310. ** the [sqlite3] object is successfully destroyed and all associated
  311. ** resources are deallocated.
  312. **
  313. ** Ideally, applications should [sqlite3_finalize | finalize] all
  314. ** [prepared statements], [sqlite3_blob_close | close] all [BLOB handles], and
  315. ** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated
  316. ** with the [sqlite3] object prior to attempting to close the object.
  317. ** ^If the database connection is associated with unfinalized prepared
  318. ** statements, BLOB handlers, and/or unfinished sqlite3_backup objects then
  319. ** sqlite3_close() will leave the database connection open and return
  320. ** [SQLITE_BUSY]. ^If sqlite3_close_v2() is called with unfinalized prepared
  321. ** statements, unclosed BLOB handlers, and/or unfinished sqlite3_backups,
  322. ** it returns [SQLITE_OK] regardless, but instead of deallocating the database
  323. ** connection immediately, it marks the database connection as an unusable
  324. ** "zombie" and makes arrangements to automatically deallocate the database
  325. ** connection after all prepared statements are finalized, all BLOB handles
  326. ** are closed, and all backups have finished. The sqlite3_close_v2() interface
  327. ** is intended for use with host languages that are garbage collected, and
  328. ** where the order in which destructors are called is arbitrary.
  329. **
  330. ** ^If an [sqlite3] object is destroyed while a transaction is open,
  331. ** the transaction is automatically rolled back.
  332. **
  333. ** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)]
  334. ** must be either a NULL
  335. ** pointer or an [sqlite3] object pointer obtained
  336. ** from [sqlite3_open()], [sqlite3_open16()], or
  337. ** [sqlite3_open_v2()], and not previously closed.
  338. ** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer
  339. ** argument is a harmless no-op.
  340. */
  341. SQLITE_API int sqlite3_close(sqlite3*);
  342. SQLITE_API int sqlite3_close_v2(sqlite3*);
  343. /*
  344. ** The type for a callback function.
  345. ** This is legacy and deprecated. It is included for historical
  346. ** compatibility and is not documented.
  347. */
  348. typedef int (*sqlite3_callback)(void*,int,char**, char**);
  349. /*
  350. ** CAPI3REF: One-Step Query Execution Interface
  351. ** METHOD: sqlite3
  352. **
  353. ** The sqlite3_exec() interface is a convenience wrapper around
  354. ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
  355. ** that allows an application to run multiple statements of SQL
  356. ** without having to use a lot of C code.
  357. **
  358. ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
  359. ** semicolon-separate SQL statements passed into its 2nd argument,
  360. ** in the context of the [database connection] passed in as its 1st
  361. ** argument. ^If the callback function of the 3rd argument to
  362. ** sqlite3_exec() is not NULL, then it is invoked for each result row
  363. ** coming out of the evaluated SQL statements. ^The 4th argument to
  364. ** sqlite3_exec() is relayed through to the 1st argument of each
  365. ** callback invocation. ^If the callback pointer to sqlite3_exec()
  366. ** is NULL, then no callback is ever invoked and result rows are
  367. ** ignored.
  368. **
  369. ** ^If an error occurs while evaluating the SQL statements passed into
  370. ** sqlite3_exec(), then execution of the current statement stops and
  371. ** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec()
  372. ** is not NULL then any error message is written into memory obtained
  373. ** from [sqlite3_malloc()] and passed back through the 5th parameter.
  374. ** To avoid memory leaks, the application should invoke [sqlite3_free()]
  375. ** on error message strings returned through the 5th parameter of
  376. ** sqlite3_exec() after the error message string is no longer needed.
  377. ** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors
  378. ** occur, then sqlite3_exec() sets the pointer in its 5th parameter to
  379. ** NULL before returning.
  380. **
  381. ** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec()
  382. ** routine returns SQLITE_ABORT without invoking the callback again and
  383. ** without running any subsequent SQL statements.
  384. **
  385. ** ^The 2nd argument to the sqlite3_exec() callback function is the
  386. ** number of columns in the result. ^The 3rd argument to the sqlite3_exec()
  387. ** callback is an array of pointers to strings obtained as if from
  388. ** [sqlite3_column_text()], one for each column. ^If an element of a
  389. ** result row is NULL then the corresponding string pointer for the
  390. ** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the
  391. ** sqlite3_exec() callback is an array of pointers to strings where each
  392. ** entry represents the name of corresponding result column as obtained
  393. ** from [sqlite3_column_name()].
  394. **
  395. ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
  396. ** to an empty string, or a pointer that contains only whitespace and/or
  397. ** SQL comments, then no SQL statements are evaluated and the database
  398. ** is not changed.
  399. **
  400. ** Restrictions:
  401. **
  402. ** <ul>
  403. ** <li> The application must ensure that the 1st parameter to sqlite3_exec()
  404. ** is a valid and open [database connection].
  405. ** <li> The application must not close the [database connection] specified by
  406. ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
  407. ** <li> The application must not modify the SQL statement text passed into
  408. ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
  409. ** </ul>
  410. */
  411. SQLITE_API int sqlite3_exec(
  412. sqlite3*, /* An open database */
  413. const char *sql, /* SQL to be evaluated */
  414. int (*callback)(void*,int,char**,char**), /* Callback function */
  415. void *, /* 1st argument to callback */
  416. char **errmsg /* Error msg written here */
  417. );
  418. /*
  419. ** CAPI3REF: Result Codes
  420. ** KEYWORDS: {result code definitions}
  421. **
  422. ** Many SQLite functions return an integer result code from the set shown
  423. ** here in order to indicate success or failure.
  424. **
  425. ** New error codes may be added in future versions of SQLite.
  426. **
  427. ** See also: [extended result code definitions]
  428. */
  429. #define SQLITE_OK 0 /* Successful result */
  430. /* beginning-of-error-codes */
  431. #define SQLITE_ERROR 1 /* Generic error */
  432. #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
  433. #define SQLITE_PERM 3 /* Access permission denied */
  434. #define SQLITE_ABORT 4 /* Callback routine requested an abort */
  435. #define SQLITE_BUSY 5 /* The database file is locked */
  436. #define SQLITE_LOCKED 6 /* A table in the database is locked */
  437. #define SQLITE_NOMEM 7 /* A malloc() failed */
  438. #define SQLITE_READONLY 8 /* Attempt to write a readonly database */
  439. #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
  440. #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
  441. #define SQLITE_CORRUPT 11 /* The database disk image is malformed */
  442. #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
  443. #define SQLITE_FULL 13 /* Insertion failed because database is full */
  444. #define SQLITE_CANTOPEN 14 /* Unable to open the database file */
  445. #define SQLITE_PROTOCOL 15 /* Database lock protocol error */
  446. #define SQLITE_EMPTY 16 /* Internal use only */
  447. #define SQLITE_SCHEMA 17 /* The database schema changed */
  448. #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
  449. #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
  450. #define SQLITE_MISMATCH 20 /* Data type mismatch */
  451. #define SQLITE_MISUSE 21 /* Library used incorrectly */
  452. #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
  453. #define SQLITE_AUTH 23 /* Authorization denied */
  454. #define SQLITE_FORMAT 24 /* Not used */
  455. #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
  456. #define SQLITE_NOTADB 26 /* File opened that is not a database file */
  457. #define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */
  458. #define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */
  459. #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
  460. #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
  461. /* end-of-error-codes */
  462. /*
  463. ** CAPI3REF: Extended Result Codes
  464. ** KEYWORDS: {extended result code definitions}
  465. **
  466. ** In its default configuration, SQLite API routines return one of 30 integer
  467. ** [result codes]. However, experience has shown that many of
  468. ** these result codes are too coarse-grained. They do not provide as
  469. ** much information about problems as programmers might like. In an effort to
  470. ** address this, newer versions of SQLite (version 3.3.8 [dateof:3.3.8]
  471. ** and later) include
  472. ** support for additional result codes that provide more detailed information
  473. ** about errors. These [extended result codes] are enabled or disabled
  474. ** on a per database connection basis using the
  475. ** [sqlite3_extended_result_codes()] API. Or, the extended code for
  476. ** the most recent error can be obtained using
  477. ** [sqlite3_extended_errcode()].
  478. */
  479. #define SQLITE_ERROR_MISSING_COLLSEQ (SQLITE_ERROR | (1<<8))
  480. #define SQLITE_ERROR_RETRY (SQLITE_ERROR | (2<<8))
  481. #define SQLITE_ERROR_SNAPSHOT (SQLITE_ERROR | (3<<8))
  482. #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))
  483. #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))
  484. #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8))
  485. #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8))
  486. #define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8))
  487. #define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8))
  488. #define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8))
  489. #define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8))
  490. #define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8))
  491. #define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8))
  492. #define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8))
  493. #define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8))
  494. #define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8))
  495. #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
  496. #define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8))
  497. #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8))
  498. #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8))
  499. #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8))
  500. #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8))
  501. #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8))
  502. #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8))
  503. #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
  504. #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))
  505. #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
  506. #define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
  507. #define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
  508. #define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8))
  509. #define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8))
  510. #define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8))
  511. #define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8))
  512. #define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8))
  513. #define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8))
  514. #define SQLITE_IOERR_CORRUPTFS (SQLITE_IOERR | (33<<8))
  515. #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
  516. #define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8))
  517. #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
  518. #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
  519. #define SQLITE_BUSY_TIMEOUT (SQLITE_BUSY | (3<<8))
  520. #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
  521. #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
  522. #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
  523. #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
  524. #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */
  525. #define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8))
  526. #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
  527. #define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8))
  528. #define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8))
  529. #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
  530. #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
  531. #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
  532. #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
  533. #define SQLITE_READONLY_CANTINIT (SQLITE_READONLY | (5<<8))
  534. #define SQLITE_READONLY_DIRECTORY (SQLITE_READONLY | (6<<8))
  535. #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
  536. #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
  537. #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
  538. #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
  539. #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
  540. #define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8))
  541. #define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))
  542. #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
  543. #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
  544. #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
  545. #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
  546. #define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT |(11<<8))
  547. #define SQLITE_CONSTRAINT_DATATYPE (SQLITE_CONSTRAINT |(12<<8))
  548. #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
  549. #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
  550. #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
  551. #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
  552. #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
  553. #define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */
  554. /*
  555. ** CAPI3REF: Flags For File Open Operations
  556. **
  557. ** These bit values are intended for use in the
  558. ** 3rd parameter to the [sqlite3_open_v2()] interface and
  559. ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
  560. **
  561. ** Only those flags marked as "Ok for sqlite3_open_v2()" may be
  562. ** used as the third argument to the [sqlite3_open_v2()] interface.
  563. ** The other flags have historically been ignored by sqlite3_open_v2(),
  564. ** though future versions of SQLite might change so that an error is
  565. ** raised if any of the disallowed bits are passed into sqlite3_open_v2().
  566. ** Applications should not depend on the historical behavior.
  567. **
  568. ** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into
  569. ** [sqlite3_open_v2()] does *not* cause the underlying database file
  570. ** to be opened using O_EXCL. Passing SQLITE_OPEN_EXCLUSIVE into
  571. ** [sqlite3_open_v2()] has historically be a no-op and might become an
  572. ** error in future versions of SQLite.
  573. */
  574. #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
  575. #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
  576. #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
  577. #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
  578. #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
  579. #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
  580. #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */
  581. #define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */
  582. #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
  583. #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
  584. #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
  585. #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
  586. #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
  587. #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */
  588. #define SQLITE_OPEN_SUPER_JOURNAL 0x00004000 /* VFS only */
  589. #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
  590. #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
  591. #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
  592. #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
  593. #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
  594. #define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */
  595. #define SQLITE_OPEN_EXRESCODE 0x02000000 /* Extended result codes */
  596. /* Reserved: 0x00F00000 */
  597. /* Legacy compatibility: */
  598. #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */
  599. /*
  600. ** CAPI3REF: Device Characteristics
  601. **
  602. ** The xDeviceCharacteristics method of the [sqlite3_io_methods]
  603. ** object returns an integer which is a vector of these
  604. ** bit values expressing I/O characteristics of the mass storage
  605. ** device that holds the file that the [sqlite3_io_methods]
  606. ** refers to.
  607. **
  608. ** The SQLITE_IOCAP_ATOMIC property means that all writes of
  609. ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
  610. ** mean that writes of blocks that are nnn bytes in size and
  611. ** are aligned to an address which is an integer multiple of
  612. ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
  613. ** that when data is appended to a file, the data is appended
  614. ** first then the size of the file is extended, never the other
  615. ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
  616. ** information is written to disk in the same order as calls
  617. ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
  618. ** after reboot following a crash or power loss, the only bytes in a
  619. ** file that were written at the application level might have changed
  620. ** and that adjacent bytes, even bytes within the same sector are
  621. ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
  622. ** flag indicates that a file cannot be deleted when open. The
  623. ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
  624. ** read-only media and cannot be changed even by processes with
  625. ** elevated privileges.
  626. **
  627. ** The SQLITE_IOCAP_BATCH_ATOMIC property means that the underlying
  628. ** filesystem supports doing multiple write operations atomically when those
  629. ** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and
  630. ** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].
  631. */
  632. #define SQLITE_IOCAP_ATOMIC 0x00000001
  633. #define SQLITE_IOCAP_ATOMIC512 0x00000002
  634. #define SQLITE_IOCAP_ATOMIC1K 0x00000004
  635. #define SQLITE_IOCAP_ATOMIC2K 0x00000008
  636. #define SQLITE_IOCAP_ATOMIC4K 0x00000010
  637. #define SQLITE_IOCAP_ATOMIC8K 0x00000020
  638. #define SQLITE_IOCAP_ATOMIC16K 0x00000040
  639. #define SQLITE_IOCAP_ATOMIC32K 0x00000080
  640. #define SQLITE_IOCAP_ATOMIC64K 0x00000100
  641. #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
  642. #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
  643. #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800
  644. #define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000
  645. #define SQLITE_IOCAP_IMMUTABLE 0x00002000
  646. #define SQLITE_IOCAP_BATCH_ATOMIC 0x00004000
  647. /*
  648. ** CAPI3REF: File Locking Levels
  649. **
  650. ** SQLite uses one of these integer values as the second
  651. ** argument to calls it makes to the xLock() and xUnlock() methods
  652. ** of an [sqlite3_io_methods] object.
  653. */
  654. #define SQLITE_LOCK_NONE 0
  655. #define SQLITE_LOCK_SHARED 1
  656. #define SQLITE_LOCK_RESERVED 2
  657. #define SQLITE_LOCK_PENDING 3
  658. #define SQLITE_LOCK_EXCLUSIVE 4
  659. /*
  660. ** CAPI3REF: Synchronization Type Flags
  661. **
  662. ** When SQLite invokes the xSync() method of an
  663. ** [sqlite3_io_methods] object it uses a combination of
  664. ** these integer values as the second argument.
  665. **
  666. ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
  667. ** sync operation only needs to flush data to mass storage. Inode
  668. ** information need not be flushed. If the lower four bits of the flag
  669. ** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics.
  670. ** If the lower four bits equal SQLITE_SYNC_FULL, that means
  671. ** to use Mac OS X style fullsync instead of fsync().
  672. **
  673. ** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags
  674. ** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL
  675. ** settings. The [synchronous pragma] determines when calls to the
  676. ** xSync VFS method occur and applies uniformly across all platforms.
  677. ** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how
  678. ** energetic or rigorous or forceful the sync operations are and
  679. ** only make a difference on Mac OSX for the default SQLite code.
  680. ** (Third-party VFS implementations might also make the distinction
  681. ** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the
  682. ** operating systems natively supported by SQLite, only Mac OSX
  683. ** cares about the difference.)
  684. */
  685. #define SQLITE_SYNC_NORMAL 0x00002
  686. #define SQLITE_SYNC_FULL 0x00003
  687. #define SQLITE_SYNC_DATAONLY 0x00010
  688. /*
  689. ** CAPI3REF: OS Interface Open File Handle
  690. **
  691. ** An [sqlite3_file] object represents an open file in the
  692. ** [sqlite3_vfs | OS interface layer]. Individual OS interface
  693. ** implementations will
  694. ** want to subclass this object by appending additional fields
  695. ** for their own use. The pMethods entry is a pointer to an
  696. ** [sqlite3_io_methods] object that defines methods for performing
  697. ** I/O operations on the open file.
  698. */
  699. typedef struct sqlite3_file sqlite3_file;
  700. struct sqlite3_file {
  701. const struct sqlite3_io_methods *pMethods; /* Methods for an open file */
  702. };
  703. /*
  704. ** CAPI3REF: OS Interface File Virtual Methods Object
  705. **
  706. ** Every file opened by the [sqlite3_vfs.xOpen] method populates an
  707. ** [sqlite3_file] object (or, more commonly, a subclass of the
  708. ** [sqlite3_file] object) with a pointer to an instance of this object.
  709. ** This object defines the methods used to perform various operations
  710. ** against the open file represented by the [sqlite3_file] object.
  711. **
  712. ** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element
  713. ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
  714. ** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The
  715. ** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]
  716. ** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element
  717. ** to NULL.
  718. **
  719. ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
  720. ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
  721. ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]
  722. ** flag may be ORed in to indicate that only the data of the file
  723. ** and not its inode needs to be synced.
  724. **
  725. ** The integer values to xLock() and xUnlock() are one of
  726. ** <ul>
  727. ** <li> [SQLITE_LOCK_NONE],
  728. ** <li> [SQLITE_LOCK_SHARED],
  729. ** <li> [SQLITE_LOCK_RESERVED],
  730. ** <li> [SQLITE_LOCK_PENDING], or
  731. ** <li> [SQLITE_LOCK_EXCLUSIVE].
  732. ** </ul>
  733. ** xLock() increases the lock. xUnlock() decreases the lock.
  734. ** The xCheckReservedLock() method checks whether any database connection,
  735. ** either in this process or in some other process, is holding a RESERVED,
  736. ** PENDING, or EXCLUSIVE lock on the file. It returns true
  737. ** if such a lock exists and false otherwise.
  738. **
  739. ** The xFileControl() method is a generic interface that allows custom
  740. ** VFS implementations to directly control an open file using the
  741. ** [sqlite3_file_control()] interface. The second "op" argument is an
  742. ** integer opcode. The third argument is a generic pointer intended to
  743. ** point to a structure that may contain arguments or space in which to
  744. ** write return values. Potential uses for xFileControl() might be
  745. ** functions to enable blocking locks with timeouts, to change the
  746. ** locking strategy (for example to use dot-file locks), to inquire
  747. ** about the status of a lock, or to break stale locks. The SQLite
  748. ** core reserves all opcodes less than 100 for its own use.
  749. ** A [file control opcodes | list of opcodes] less than 100 is available.
  750. ** Applications that define a custom xFileControl method should use opcodes
  751. ** greater than 100 to avoid conflicts. VFS implementations should
  752. ** return [SQLITE_NOTFOUND] for file control opcodes that they do not
  753. ** recognize.
  754. **
  755. ** The xSectorSize() method returns the sector size of the
  756. ** device that underlies the file. The sector size is the
  757. ** minimum write that can be performed without disturbing
  758. ** other bytes in the file. The xDeviceCharacteristics()
  759. ** method returns a bit vector describing behaviors of the
  760. ** underlying device:
  761. **
  762. ** <ul>
  763. ** <li> [SQLITE_IOCAP_ATOMIC]
  764. ** <li> [SQLITE_IOCAP_ATOMIC512]
  765. ** <li> [SQLITE_IOCAP_ATOMIC1K]
  766. ** <li> [SQLITE_IOCAP_ATOMIC2K]
  767. ** <li> [SQLITE_IOCAP_ATOMIC4K]
  768. ** <li> [SQLITE_IOCAP_ATOMIC8K]
  769. ** <li> [SQLITE_IOCAP_ATOMIC16K]
  770. ** <li> [SQLITE_IOCAP_ATOMIC32K]
  771. ** <li> [SQLITE_IOCAP_ATOMIC64K]
  772. ** <li> [SQLITE_IOCAP_SAFE_APPEND]
  773. ** <li> [SQLITE_IOCAP_SEQUENTIAL]
  774. ** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
  775. ** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
  776. ** <li> [SQLITE_IOCAP_IMMUTABLE]
  777. ** <li> [SQLITE_IOCAP_BATCH_ATOMIC]
  778. ** </ul>
  779. **
  780. ** The SQLITE_IOCAP_ATOMIC property means that all writes of
  781. ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
  782. ** mean that writes of blocks that are nnn bytes in size and
  783. ** are aligned to an address which is an integer multiple of
  784. ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
  785. ** that when data is appended to a file, the data is appended
  786. ** first then the size of the file is extended, never the other
  787. ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
  788. ** information is written to disk in the same order as calls
  789. ** to xWrite().
  790. **
  791. ** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
  792. ** in the unread portions of the buffer with zeros. A VFS that
  793. ** fails to zero-fill short reads might seem to work. However,
  794. ** failure to zero-fill short reads will eventually lead to
  795. ** database corruption.
  796. */
  797. typedef struct sqlite3_io_methods sqlite3_io_methods;
  798. struct sqlite3_io_methods {
  799. int iVersion;
  800. int (*xClose)(sqlite3_file*);
  801. int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
  802. int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
  803. int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
  804. int (*xSync)(sqlite3_file*, int flags);
  805. int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
  806. int (*xLock)(sqlite3_file*, int);
  807. int (*xUnlock)(sqlite3_file*, int);
  808. int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);
  809. int (*xFileControl)(sqlite3_file*, int op, void *pArg);
  810. int (*xSectorSize)(sqlite3_file*);
  811. int (*xDeviceCharacteristics)(sqlite3_file*);
  812. /* Methods above are valid for version 1 */
  813. int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
  814. int (*xShmLock)(sqlite3_file*, int offset, int n, int flags);
  815. void (*xShmBarrier)(sqlite3_file*);
  816. int (*xShmUnmap)(sqlite3_file*, int deleteFlag);
  817. /* Methods above are valid for version 2 */
  818. int (*xFetch)(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
  819. int (*xUnfetch)(sqlite3_file*, sqlite3_int64 iOfst, void *p);
  820. /* Methods above are valid for version 3 */
  821. /* Additional methods may be added in future releases */
  822. };
  823. /*
  824. ** CAPI3REF: Standard File Control Opcodes
  825. ** KEYWORDS: {file control opcodes} {file control opcode}
  826. **
  827. ** These integer constants are opcodes for the xFileControl method
  828. ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
  829. ** interface.
  830. **
  831. ** <ul>
  832. ** <li>[[SQLITE_FCNTL_LOCKSTATE]]
  833. ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This
  834. ** opcode causes the xFileControl method to write the current state of
  835. ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
  836. ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
  837. ** into an integer that the pArg argument points to. This capability
  838. ** is used during testing and is only available when the SQLITE_TEST
  839. ** compile-time option is used.
  840. **
  841. ** <li>[[SQLITE_FCNTL_SIZE_HINT]]
  842. ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
  843. ** layer a hint of how large the database file will grow to be during the
  844. ** current transaction. This hint is not guaranteed to be accurate but it
  845. ** is often close. The underlying VFS might choose to preallocate database
  846. ** file space based on this hint in order to help writes to the database
  847. ** file run faster.
  848. **
  849. ** <li>[[SQLITE_FCNTL_SIZE_LIMIT]]
  850. ** The [SQLITE_FCNTL_SIZE_LIMIT] opcode is used by in-memory VFS that
  851. ** implements [sqlite3_deserialize()] to set an upper bound on the size
  852. ** of the in-memory database. The argument is a pointer to a [sqlite3_int64].
  853. ** If the integer pointed to is negative, then it is filled in with the
  854. ** current limit. Otherwise the limit is set to the larger of the value
  855. ** of the integer pointed to and the current database size. The integer
  856. ** pointed to is set to the new limit.
  857. **
  858. ** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
  859. ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
  860. ** extends and truncates the database file in chunks of a size specified
  861. ** by the user. The fourth argument to [sqlite3_file_control()] should
  862. ** point to an integer (type int) containing the new chunk-size to use
  863. ** for the nominated database. Allocating database file space in large
  864. ** chunks (say 1MB at a time), may reduce file-system fragmentation and
  865. ** improve performance on some systems.
  866. **
  867. ** <li>[[SQLITE_FCNTL_FILE_POINTER]]
  868. ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
  869. ** to the [sqlite3_file] object associated with a particular database
  870. ** connection. See also [SQLITE_FCNTL_JOURNAL_POINTER].
  871. **
  872. ** <li>[[SQLITE_FCNTL_JOURNAL_POINTER]]
  873. ** The [SQLITE_FCNTL_JOURNAL_POINTER] opcode is used to obtain a pointer
  874. ** to the [sqlite3_file] object associated with the journal file (either
  875. ** the [rollback journal] or the [write-ahead log]) for a particular database
  876. ** connection. See also [SQLITE_FCNTL_FILE_POINTER].
  877. **
  878. ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
  879. ** No longer in use.
  880. **
  881. ** <li>[[SQLITE_FCNTL_SYNC]]
  882. ** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
  883. ** sent to the VFS immediately before the xSync method is invoked on a
  884. ** database file descriptor. Or, if the xSync method is not invoked
  885. ** because the user has configured SQLite with
  886. ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
  887. ** of the xSync method. In most cases, the pointer argument passed with
  888. ** this file-control is NULL. However, if the database file is being synced
  889. ** as part of a multi-database commit, the argument points to a nul-terminated
  890. ** string containing the transactions super-journal file name. VFSes that
  891. ** do not need this signal should silently ignore this opcode. Applications
  892. ** should not call [sqlite3_file_control()] with this opcode as doing so may
  893. ** disrupt the operation of the specialized VFSes that do require it.
  894. **
  895. ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
  896. ** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite
  897. ** and sent to the VFS after a transaction has been committed immediately
  898. ** but before the database is unlocked. VFSes that do not need this signal
  899. ** should silently ignore this opcode. Applications should not call
  900. ** [sqlite3_file_control()] with this opcode as doing so may disrupt the
  901. ** operation of the specialized VFSes that do require it.
  902. **
  903. ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
  904. ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
  905. ** retry counts and intervals for certain disk I/O operations for the
  906. ** windows [VFS] in order to provide robustness in the presence of
  907. ** anti-virus programs. By default, the windows VFS will retry file read,
  908. ** file write, and file delete operations up to 10 times, with a delay
  909. ** of 25 milliseconds before the first retry and with the delay increasing
  910. ** by an additional 25 milliseconds with each subsequent retry. This
  911. ** opcode allows these two values (10 retries and 25 milliseconds of delay)
  912. ** to be adjusted. The values are changed for all database connections
  913. ** within the same process. The argument is a pointer to an array of two
  914. ** integers where the first integer is the new retry count and the second
  915. ** integer is the delay. If either integer is negative, then the setting
  916. ** is not changed but instead the prior value of that setting is written
  917. ** into the array entry, allowing the current retry settings to be
  918. ** interrogated. The zDbName parameter is ignored.
  919. **
  920. ** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
  921. ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
  922. ** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary
  923. ** write ahead log ([WAL file]) and shared memory
  924. ** files used for transaction control
  925. ** are automatically deleted when the latest connection to the database
  926. ** closes. Setting persistent WAL mode causes those files to persist after
  927. ** close. Persisting the files is useful when other processes that do not
  928. ** have write permission on the directory containing the database file want
  929. ** to read the database file, as the WAL and shared memory files must exist
  930. ** in order for the database to be readable. The fourth parameter to
  931. ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
  932. ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
  933. ** WAL mode. If the integer is -1, then it is overwritten with the current
  934. ** WAL persistence setting.
  935. **
  936. ** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]]
  937. ** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the
  938. ** persistent "powersafe-overwrite" or "PSOW" setting. The PSOW setting
  939. ** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the
  940. ** xDeviceCharacteristics methods. The fourth parameter to
  941. ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
  942. ** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage
  943. ** mode. If the integer is -1, then it is overwritten with the current
  944. ** zero-damage mode setting.
  945. **
  946. ** <li>[[SQLITE_FCNTL_OVERWRITE]]
  947. ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
  948. ** a write transaction to indicate that, unless it is rolled back for some
  949. ** reason, the entire database file will be overwritten by the current
  950. ** transaction. This is used by VACUUM operations.
  951. **
  952. ** <li>[[SQLITE_FCNTL_VFSNAME]]
  953. ** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
  954. ** all [VFSes] in the VFS stack. The names are of all VFS shims and the
  955. ** final bottom-level VFS are written into memory obtained from
  956. ** [sqlite3_malloc()] and the result is stored in the char* variable
  957. ** that the fourth parameter of [sqlite3_file_control()] points to.
  958. ** The caller is responsible for freeing the memory when done. As with
  959. ** all file-control actions, there is no guarantee that this will actually
  960. ** do anything. Callers should initialize the char* variable to a NULL
  961. ** pointer in case this file-control is not implemented. This file-control
  962. ** is intended for diagnostic use only.
  963. **
  964. ** <li>[[SQLITE_FCNTL_VFS_POINTER]]
  965. ** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level
  966. ** [VFSes] currently in use. ^(The argument X in
  967. ** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be
  968. ** of type "[sqlite3_vfs] **". This opcodes will set *X
  969. ** to a pointer to the top-level VFS.)^
  970. ** ^When there are multiple VFS shims in the stack, this opcode finds the
  971. ** upper-most shim only.
  972. **
  973. ** <li>[[SQLITE_FCNTL_PRAGMA]]
  974. ** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA]
  975. ** file control is sent to the open [sqlite3_file] object corresponding
  976. ** to the database file to which the pragma statement refers. ^The argument
  977. ** to the [SQLITE_FCNTL_PRAGMA] file control is an array of
  978. ** pointers to strings (char**) in which the second element of the array
  979. ** is the name of the pragma and the third element is the argument to the
  980. ** pragma or NULL if the pragma has no argument. ^The handler for an
  981. ** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element
  982. ** of the char** argument point to a string obtained from [sqlite3_mprintf()]
  983. ** or the equivalent and that string will become the result of the pragma or
  984. ** the error message if the pragma fails. ^If the
  985. ** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal
  986. ** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA]
  987. ** file control returns [SQLITE_OK], then the parser assumes that the
  988. ** VFS has handled the PRAGMA itself and the parser generates a no-op
  989. ** prepared statement if result string is NULL, or that returns a copy
  990. ** of the result string if the string is non-NULL.
  991. ** ^If the [SQLITE_FCNTL_PRAGMA] file control returns
  992. ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
  993. ** that the VFS encountered an error while handling the [PRAGMA] and the
  994. ** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA]
  995. ** file control occurs at the beginning of pragma statement analysis and so
  996. ** it is able to override built-in [PRAGMA] statements.
  997. **
  998. ** <li>[[SQLITE_FCNTL_BUSYHANDLER]]
  999. ** ^The [SQLITE_FCNTL_BUSYHANDLER]
  1000. ** file-control may be invoked by SQLite on the database file handle
  1001. ** shortly after it is opened in order to provide a custom VFS with access
  1002. ** to the connection's busy-handler callback. The argument is of type (void**)
  1003. ** - an array of two (void *) values. The first (void *) actually points
  1004. ** to a function of type (int (*)(void *)). In order to invoke the connection's
  1005. ** busy-handler, this function should be invoked with the second (void *) in
  1006. ** the array as the only argument. If it returns non-zero, then the operation
  1007. ** should be retried. If it returns zero, the custom VFS should abandon the
  1008. ** current operation.
  1009. **
  1010. ** <li>[[SQLITE_FCNTL_TEMPFILENAME]]
  1011. ** ^Applications can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
  1012. ** to have SQLite generate a
  1013. ** temporary filename using the same algorithm that is followed to generate
  1014. ** temporary filenames for TEMP tables and other internal uses. The
  1015. ** argument should be a char** which will be filled with the filename
  1016. ** written into memory obtained from [sqlite3_malloc()]. The caller should
  1017. ** invoke [sqlite3_free()] on the result to avoid a memory leak.
  1018. **
  1019. ** <li>[[SQLITE_FCNTL_MMAP_SIZE]]
  1020. ** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the
  1021. ** maximum number of bytes that will be used for memory-mapped I/O.
  1022. ** The argument is a pointer to a value of type sqlite3_int64 that
  1023. ** is an advisory maximum number of bytes in the file to memory map. The
  1024. ** pointer is overwritten with the old value. The limit is not changed if
  1025. ** the value originally pointed to is negative, and so the current limit
  1026. ** can be queried by passing in a pointer to a negative number. This
  1027. ** file-control is used internally to implement [PRAGMA mmap_size].
  1028. **
  1029. ** <li>[[SQLITE_FCNTL_TRACE]]
  1030. ** The [SQLITE_FCNTL_TRACE] file control provides advisory information
  1031. ** to the VFS about what the higher layers of the SQLite stack are doing.
  1032. ** This file control is used by some VFS activity tracing [shims].
  1033. ** The argument is a zero-terminated string. Higher layers in the
  1034. ** SQLite stack may generate instances of this file control if
  1035. ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
  1036. **
  1037. ** <li>[[SQLITE_FCNTL_HAS_MOVED]]
  1038. ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
  1039. ** pointer to an integer and it writes a boolean into that integer depending
  1040. ** on whether or not the file has been renamed, moved, or deleted since it
  1041. ** was first opened.
  1042. **
  1043. ** <li>[[SQLITE_FCNTL_WIN32_GET_HANDLE]]
  1044. ** The [SQLITE_FCNTL_WIN32_GET_HANDLE] opcode can be used to obtain the
  1045. ** underlying native file handle associated with a file handle. This file
  1046. ** control interprets its argument as a pointer to a native file handle and
  1047. ** writes the resulting value there.
  1048. **
  1049. ** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]
  1050. ** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This
  1051. ** opcode causes the xFileControl method to swap the file handle with the one
  1052. ** pointed to by the pArg argument. This capability is used during testing
  1053. ** and only needs to be supported when SQLITE_TEST is defined.
  1054. **
  1055. ** <li>[[SQLITE_FCNTL_WAL_BLOCK]]
  1056. ** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might
  1057. ** be advantageous to block on the next WAL lock if the lock is not immediately
  1058. ** available. The WAL subsystem issues this signal during rare
  1059. ** circumstances in order to fix a problem with priority inversion.
  1060. ** Applications should <em>not</em> use this file-control.
  1061. **
  1062. ** <li>[[SQLITE_FCNTL_ZIPVFS]]
  1063. ** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other
  1064. ** VFS should return SQLITE_NOTFOUND for this opcode.
  1065. **
  1066. ** <li>[[SQLITE_FCNTL_RBU]]
  1067. ** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
  1068. ** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for
  1069. ** this opcode.
  1070. **
  1071. ** <li>[[SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]]
  1072. ** If the [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] opcode returns SQLITE_OK, then
  1073. ** the file descriptor is placed in "batch write mode", which
  1074. ** means all subsequent write operations will be deferred and done
  1075. ** atomically at the next [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]. Systems
  1076. ** that do not support batch atomic writes will return SQLITE_NOTFOUND.
  1077. ** ^Following a successful SQLITE_FCNTL_BEGIN_ATOMIC_WRITE and prior to
  1078. ** the closing [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] or
  1079. ** [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE], SQLite will make
  1080. ** no VFS interface calls on the same [sqlite3_file] file descriptor
  1081. ** except for calls to the xWrite method and the xFileControl method
  1082. ** with [SQLITE_FCNTL_SIZE_HINT].
  1083. **
  1084. ** <li>[[SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]]
  1085. ** The [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] opcode causes all write
  1086. ** operations since the previous successful call to
  1087. ** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be performed atomically.
  1088. ** This file control returns [SQLITE_OK] if and only if the writes were
  1089. ** all performed successfully and have been committed to persistent storage.
  1090. ** ^Regardless of whether or not it is successful, this file control takes
  1091. ** the file descriptor out of batch write mode so that all subsequent
  1092. ** write operations are independent.
  1093. ** ^SQLite will never invoke SQLITE_FCNTL_COMMIT_ATOMIC_WRITE without
  1094. ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
  1095. **
  1096. ** <li>[[SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE]]
  1097. ** The [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE] opcode causes all write
  1098. ** operations since the previous successful call to
  1099. ** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be rolled back.
  1100. ** ^This file control takes the file descriptor out of batch write mode
  1101. ** so that all subsequent write operations are independent.
  1102. ** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without
  1103. ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
  1104. **
  1105. ** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]]
  1106. ** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode is used to configure a VFS
  1107. ** to block for up to M milliseconds before failing when attempting to
  1108. ** obtain a file lock using the xLock or xShmLock methods of the VFS.
  1109. ** The parameter is a pointer to a 32-bit signed integer that contains
  1110. ** the value that M is to be set to. Before returning, the 32-bit signed
  1111. ** integer is overwritten with the previous value of M.
  1112. **
  1113. ** <li>[[SQLITE_FCNTL_DATA_VERSION]]
  1114. ** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to
  1115. ** a database file. The argument is a pointer to a 32-bit unsigned integer.
  1116. ** The "data version" for the pager is written into the pointer. The
  1117. ** "data version" changes whenever any change occurs to the corresponding
  1118. ** database file, either through SQL statements on the same database
  1119. ** connection or through transactions committed by separate database
  1120. ** connections possibly in other processes. The [sqlite3_total_changes()]
  1121. ** interface can be used to find if any database on the connection has changed,
  1122. ** but that interface responds to changes on TEMP as well as MAIN and does
  1123. ** not provide a mechanism to detect changes to MAIN only. Also, the
  1124. ** [sqlite3_total_changes()] interface responds to internal changes only and
  1125. ** omits changes made by other database connections. The
  1126. ** [PRAGMA data_version] command provides a mechanism to detect changes to
  1127. ** a single attached database that occur due to other database connections,
  1128. ** but omits changes implemented by the database connection on which it is
  1129. ** called. This file control is the only mechanism to detect changes that
  1130. ** happen either internally or externally and that are associated with
  1131. ** a particular attached database.
  1132. **
  1133. ** <li>[[SQLITE_FCNTL_CKPT_START]]
  1134. ** The [SQLITE_FCNTL_CKPT_START] opcode is invoked from within a checkpoint
  1135. ** in wal mode before the client starts to copy pages from the wal
  1136. ** file to the database file.
  1137. **
  1138. ** <li>[[SQLITE_FCNTL_CKPT_DONE]]
  1139. ** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint
  1140. ** in wal mode after the client has finished copying pages from the wal
  1141. ** file to the database file, but before the *-shm file is updated to
  1142. ** record the fact that the pages have been checkpointed.
  1143. ** </ul>
  1144. **
  1145. ** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]
  1146. ** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect
  1147. ** whether or not there is a database client in another process with a wal-mode
  1148. ** transaction open on the database or not. It is only available on unix.The
  1149. ** (void*) argument passed with this file-control should be a pointer to a
  1150. ** value of type (int). The integer value is set to 1 if the database is a wal
  1151. ** mode database and there exists at least one client in another process that
  1152. ** currently has an SQL transaction open on the database. It is set to 0 if
  1153. ** the database is not a wal-mode db, or if there is no such connection in any
  1154. ** other process. This opcode cannot be used to detect transactions opened
  1155. ** by clients within the current process, only within other processes.
  1156. ** </ul>
  1157. **
  1158. ** <li>[[SQLITE_FCNTL_CKSM_FILE]]
  1159. ** Used by the cksmvfs VFS module only.
  1160. ** </ul>
  1161. */
  1162. #define SQLITE_FCNTL_LOCKSTATE 1
  1163. #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
  1164. #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
  1165. #define SQLITE_FCNTL_LAST_ERRNO 4
  1166. #define SQLITE_FCNTL_SIZE_HINT 5
  1167. #define SQLITE_FCNTL_CHUNK_SIZE 6
  1168. #define SQLITE_FCNTL_FILE_POINTER 7
  1169. #define SQLITE_FCNTL_SYNC_OMITTED 8
  1170. #define SQLITE_FCNTL_WIN32_AV_RETRY 9
  1171. #define SQLITE_FCNTL_PERSIST_WAL 10
  1172. #define SQLITE_FCNTL_OVERWRITE 11
  1173. #define SQLITE_FCNTL_VFSNAME 12
  1174. #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13
  1175. #define SQLITE_FCNTL_PRAGMA 14
  1176. #define SQLITE_FCNTL_BUSYHANDLER 15
  1177. #define SQLITE_FCNTL_TEMPFILENAME 16
  1178. #define SQLITE_FCNTL_MMAP_SIZE 18
  1179. #define SQLITE_FCNTL_TRACE 19
  1180. #define SQLITE_FCNTL_HAS_MOVED 20
  1181. #define SQLITE_FCNTL_SYNC 21
  1182. #define SQLITE_FCNTL_COMMIT_PHASETWO 22
  1183. #define SQLITE_FCNTL_WIN32_SET_HANDLE 23
  1184. #define SQLITE_FCNTL_WAL_BLOCK 24
  1185. #define SQLITE_FCNTL_ZIPVFS 25
  1186. #define SQLITE_FCNTL_RBU 26
  1187. #define SQLITE_FCNTL_VFS_POINTER 27
  1188. #define SQLITE_FCNTL_JOURNAL_POINTER 28
  1189. #define SQLITE_FCNTL_WIN32_GET_HANDLE 29
  1190. #define SQLITE_FCNTL_PDB 30
  1191. #define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31
  1192. #define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32
  1193. #define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33
  1194. #define SQLITE_FCNTL_LOCK_TIMEOUT 34
  1195. #define SQLITE_FCNTL_DATA_VERSION 35
  1196. #define SQLITE_FCNTL_SIZE_LIMIT 36
  1197. #define SQLITE_FCNTL_CKPT_DONE 37
  1198. #define SQLITE_FCNTL_RESERVE_BYTES 38
  1199. #define SQLITE_FCNTL_CKPT_START 39
  1200. #define SQLITE_FCNTL_EXTERNAL_READER 40
  1201. #define SQLITE_FCNTL_CKSM_FILE 41
  1202. /* deprecated names */
  1203. #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
  1204. #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
  1205. #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
  1206. /*
  1207. ** CAPI3REF: Mutex Handle
  1208. **
  1209. ** The mutex module within SQLite defines [sqlite3_mutex] to be an
  1210. ** abstract type for a mutex object. The SQLite core never looks
  1211. ** at the internal representation of an [sqlite3_mutex]. It only
  1212. ** deals with pointers to the [sqlite3_mutex] object.
  1213. **
  1214. ** Mutexes are created using [sqlite3_mutex_alloc()].
  1215. */
  1216. typedef struct sqlite3_mutex sqlite3_mutex;
  1217. /*
  1218. ** CAPI3REF: Loadable Extension Thunk
  1219. **
  1220. ** A pointer to the opaque sqlite3_api_routines structure is passed as
  1221. ** the third parameter to entry points of [loadable extensions]. This
  1222. ** structure must be typedefed in order to work around compiler warnings
  1223. ** on some platforms.
  1224. */
  1225. typedef struct sqlite3_api_routines sqlite3_api_routines;
  1226. /*
  1227. ** CAPI3REF: OS Interface Object
  1228. **
  1229. ** An instance of the sqlite3_vfs object defines the interface between
  1230. ** the SQLite core and the underlying operating system. The "vfs"
  1231. ** in the name of the object stands for "virtual file system". See
  1232. ** the [VFS | VFS documentation] for further information.
  1233. **
  1234. ** The VFS interface is sometimes extended by adding new methods onto
  1235. ** the end. Each time such an extension occurs, the iVersion field
  1236. ** is incremented. The iVersion value started out as 1 in
  1237. ** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2
  1238. ** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased
  1239. ** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6]. Additional fields
  1240. ** may be appended to the sqlite3_vfs object and the iVersion value
  1241. ** may increase again in future versions of SQLite.
  1242. ** Note that due to an oversight, the structure
  1243. ** of the sqlite3_vfs object changed in the transition from
  1244. ** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]
  1245. ** and yet the iVersion field was not increased.
  1246. **
  1247. ** The szOsFile field is the size of the subclassed [sqlite3_file]
  1248. ** structure used by this VFS. mxPathname is the maximum length of
  1249. ** a pathname in this VFS.
  1250. **
  1251. ** Registered sqlite3_vfs objects are kept on a linked list formed by
  1252. ** the pNext pointer. The [sqlite3_vfs_register()]
  1253. ** and [sqlite3_vfs_unregister()] interfaces manage this list
  1254. ** in a thread-safe way. The [sqlite3_vfs_find()] interface
  1255. ** searches the list. Neither the application code nor the VFS
  1256. ** implementation should use the pNext pointer.
  1257. **
  1258. ** The pNext field is the only field in the sqlite3_vfs
  1259. ** structure that SQLite will ever modify. SQLite will only access
  1260. ** or modify this field while holding a particular static mutex.
  1261. ** The application should never modify anything within the sqlite3_vfs
  1262. ** object once the object has been registered.
  1263. **
  1264. ** The zName field holds the name of the VFS module. The name must
  1265. ** be unique across all VFS modules.
  1266. **
  1267. ** [[sqlite3_vfs.xOpen]]
  1268. ** ^SQLite guarantees that the zFilename parameter to xOpen
  1269. ** is either a NULL pointer or string obtained
  1270. ** from xFullPathname() with an optional suffix added.
  1271. ** ^If a suffix is added to the zFilename parameter, it will
  1272. ** consist of a single "-" character followed by no more than
  1273. ** 11 alphanumeric and/or "-" characters.
  1274. ** ^SQLite further guarantees that
  1275. ** the string will be valid and unchanged until xClose() is
  1276. ** called. Because of the previous sentence,
  1277. ** the [sqlite3_file] can safely store a pointer to the
  1278. ** filename if it needs to remember the filename for some reason.
  1279. ** If the zFilename parameter to xOpen is a NULL pointer then xOpen
  1280. ** must invent its own temporary name for the file. ^Whenever the
  1281. ** xFilename parameter is NULL it will also be the case that the
  1282. ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
  1283. **
  1284. ** The flags argument to xOpen() includes all bits set in
  1285. ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]
  1286. ** or [sqlite3_open16()] is used, then flags includes at least
  1287. ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
  1288. ** If xOpen() opens a file read-only then it sets *pOutFlags to
  1289. ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.
  1290. **
  1291. ** ^(SQLite will also add one of the following flags to the xOpen()
  1292. ** call, depending on the object being opened:
  1293. **
  1294. ** <ul>
  1295. ** <li> [SQLITE_OPEN_MAIN_DB]
  1296. ** <li> [SQLITE_OPEN_MAIN_JOURNAL]
  1297. ** <li> [SQLITE_OPEN_TEMP_DB]
  1298. ** <li> [SQLITE_OPEN_TEMP_JOURNAL]
  1299. ** <li> [SQLITE_OPEN_TRANSIENT_DB]
  1300. ** <li> [SQLITE_OPEN_SUBJOURNAL]
  1301. ** <li> [SQLITE_OPEN_SUPER_JOURNAL]
  1302. ** <li> [SQLITE_OPEN_WAL]
  1303. ** </ul>)^
  1304. **
  1305. ** The file I/O implementation can use the object type flags to
  1306. ** change the way it deals with files. For example, an application
  1307. ** that does not care about crash recovery or rollback might make
  1308. ** the open of a journal file a no-op. Writes to this journal would
  1309. ** also be no-ops, and any attempt to read the journal would return
  1310. ** SQLITE_IOERR. Or the implementation might recognize that a database
  1311. ** file will be doing page-aligned sector reads and writes in a random
  1312. ** order and set up its I/O subsystem accordingly.
  1313. **
  1314. ** SQLite might also add one of the following flags to the xOpen method:
  1315. **
  1316. ** <ul>
  1317. ** <li> [SQLITE_OPEN_DELETEONCLOSE]
  1318. ** <li> [SQLITE_OPEN_EXCLUSIVE]
  1319. ** </ul>
  1320. **
  1321. ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
  1322. ** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE]
  1323. ** will be set for TEMP databases and their journals, transient
  1324. ** databases, and subjournals.
  1325. **
  1326. ** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
  1327. ** with the [SQLITE_OPEN_CREATE] flag, which are both directly
  1328. ** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
  1329. ** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the
  1330. ** SQLITE_OPEN_CREATE, is used to indicate that file should always
  1331. ** be created, and that it is an error if it already exists.
  1332. ** It is <i>not</i> used to indicate the file should be opened
  1333. ** for exclusive access.
  1334. **
  1335. ** ^At least szOsFile bytes of memory are allocated by SQLite
  1336. ** to hold the [sqlite3_file] structure passed as the third
  1337. ** argument to xOpen. The xOpen method does not have to
  1338. ** allocate the structure; it should just fill it in. Note that
  1339. ** the xOpen method must set the sqlite3_file.pMethods to either
  1340. ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
  1341. ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
  1342. ** element will be valid after xOpen returns regardless of the success
  1343. ** or failure of the xOpen call.
  1344. **
  1345. ** [[sqlite3_vfs.xAccess]]
  1346. ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
  1347. ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
  1348. ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
  1349. ** to test whether a file is at least readable. The SQLITE_ACCESS_READ
  1350. ** flag is never actually used and is not implemented in the built-in
  1351. ** VFSes of SQLite. The file is named by the second argument and can be a
  1352. ** directory. The xAccess method returns [SQLITE_OK] on success or some
  1353. ** non-zero error code if there is an I/O error or if the name of
  1354. ** the file given in the second argument is illegal. If SQLITE_OK
  1355. ** is returned, then non-zero or zero is written into *pResOut to indicate
  1356. ** whether or not the file is accessible.
  1357. **
  1358. ** ^SQLite will always allocate at least mxPathname+1 bytes for the
  1359. ** output buffer xFullPathname. The exact size of the output buffer
  1360. ** is also passed as a parameter to both methods. If the output buffer
  1361. ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
  1362. ** handled as a fatal error by SQLite, vfs implementations should endeavor
  1363. ** to prevent this by setting mxPathname to a sufficiently large value.
  1364. **
  1365. ** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
  1366. ** interfaces are not strictly a part of the filesystem, but they are
  1367. ** included in the VFS structure for completeness.
  1368. ** The xRandomness() function attempts to return nBytes bytes
  1369. ** of good-quality randomness into zOut. The return value is
  1370. ** the actual number of bytes of randomness obtained.
  1371. ** The xSleep() method causes the calling thread to sleep for at
  1372. ** least the number of microseconds given. ^The xCurrentTime()
  1373. ** method returns a Julian Day Number for the current date and time as
  1374. ** a floating point value.
  1375. ** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
  1376. ** Day Number multiplied by 86400000 (the number of milliseconds in
  1377. ** a 24-hour day).
  1378. ** ^SQLite will use the xCurrentTimeInt64() method to get the current
  1379. ** date and time if that method is available (if iVersion is 2 or
  1380. ** greater and the function pointer is not NULL) and will fall back
  1381. ** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
  1382. **
  1383. ** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
  1384. ** are not used by the SQLite core. These optional interfaces are provided
  1385. ** by some VFSes to facilitate testing of the VFS code. By overriding
  1386. ** system calls with functions under its control, a test program can
  1387. ** simulate faults and error conditions that would otherwise be difficult
  1388. ** or impossible to induce. The set of system calls that can be overridden
  1389. ** varies from one VFS to another, and from one version of the same VFS to the
  1390. ** next. Applications that use these interfaces must be prepared for any
  1391. ** or all of these interfaces to be NULL or for their behavior to change
  1392. ** from one release to the next. Applications must not attempt to access
  1393. ** any of these methods if the iVersion of the VFS is less than 3.
  1394. */
  1395. typedef struct sqlite3_vfs sqlite3_vfs;
  1396. typedef void (*sqlite3_syscall_ptr)(void);
  1397. struct sqlite3_vfs {
  1398. int iVersion; /* Structure version number (currently 3) */
  1399. int szOsFile; /* Size of subclassed sqlite3_file */
  1400. int mxPathname; /* Maximum file pathname length */
  1401. sqlite3_vfs *pNext; /* Next registered VFS */
  1402. const char *zName; /* Name of this virtual file system */
  1403. void *pAppData; /* Pointer to application-specific data */
  1404. int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*,
  1405. int flags, int *pOutFlags);
  1406. int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
  1407. int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
  1408. int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
  1409. void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
  1410. void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
  1411. void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
  1412. void (*xDlClose)(sqlite3_vfs*, void*);
  1413. int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
  1414. int (*xSleep)(sqlite3_vfs*, int microseconds);
  1415. int (*xCurrentTime)(sqlite3_vfs*, double*);
  1416. int (*xGetLastError)(sqlite3_vfs*, int, char *);
  1417. /*
  1418. ** The methods above are in version 1 of the sqlite_vfs object
  1419. ** definition. Those that follow are added in version 2 or later
  1420. */
  1421. int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
  1422. /*
  1423. ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
  1424. ** Those below are for version 3 and greater.
  1425. */
  1426. int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);
  1427. sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);
  1428. const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
  1429. /*
  1430. ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
  1431. ** New fields may be appended in future versions. The iVersion
  1432. ** value will increment whenever this happens.
  1433. */
  1434. };
  1435. /*
  1436. ** CAPI3REF: Flags for the xAccess VFS method
  1437. **
  1438. ** These integer constants can be used as the third parameter to
  1439. ** the xAccess method of an [sqlite3_vfs] object. They determine
  1440. ** what kind of permissions the xAccess method is looking for.
  1441. ** With SQLITE_ACCESS_EXISTS, the xAccess method
  1442. ** simply checks whether the file exists.
  1443. ** With SQLITE_ACCESS_READWRITE, the xAccess method
  1444. ** checks whether the named directory is both readable and writable
  1445. ** (in other words, if files can be added, removed, and renamed within
  1446. ** the directory).
  1447. ** The SQLITE_ACCESS_READWRITE constant is currently used only by the
  1448. ** [temp_store_directory pragma], though this could change in a future
  1449. ** release of SQLite.
  1450. ** With SQLITE_ACCESS_READ, the xAccess method
  1451. ** checks whether the file is readable. The SQLITE_ACCESS_READ constant is
  1452. ** currently unused, though it might be used in a future release of
  1453. ** SQLite.
  1454. */
  1455. #define SQLITE_ACCESS_EXISTS 0
  1456. #define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */
  1457. #define SQLITE_ACCESS_READ 2 /* Unused */
  1458. /*
  1459. ** CAPI3REF: Flags for the xShmLock VFS method
  1460. **
  1461. ** These integer constants define the various locking operations
  1462. ** allowed by the xShmLock method of [sqlite3_io_methods]. The
  1463. ** following are the only legal combinations of flags to the
  1464. ** xShmLock method:
  1465. **
  1466. ** <ul>
  1467. ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_SHARED
  1468. ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE
  1469. ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
  1470. ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
  1471. ** </ul>
  1472. **
  1473. ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as
  1474. ** was given on the corresponding lock.
  1475. **
  1476. ** The xShmLock method can transition between unlocked and SHARED or
  1477. ** between unlocked and EXCLUSIVE. It cannot transition between SHARED
  1478. ** and EXCLUSIVE.
  1479. */
  1480. #define SQLITE_SHM_UNLOCK 1
  1481. #define SQLITE_SHM_LOCK 2
  1482. #define SQLITE_SHM_SHARED 4
  1483. #define SQLITE_SHM_EXCLUSIVE 8
  1484. /*
  1485. ** CAPI3REF: Maximum xShmLock index
  1486. **
  1487. ** The xShmLock method on [sqlite3_io_methods] may use values
  1488. ** between 0 and this upper bound as its "offset" argument.
  1489. ** The SQLite core will never attempt to acquire or release a
  1490. ** lock outside of this range
  1491. */
  1492. #define SQLITE_SHM_NLOCK 8
  1493. /*
  1494. ** CAPI3REF: Initialize The SQLite Library
  1495. **
  1496. ** ^The sqlite3_initialize() routine initializes the
  1497. ** SQLite library. ^The sqlite3_shutdown() routine
  1498. ** deallocates any resources that were allocated by sqlite3_initialize().
  1499. ** These routines are designed to aid in process initialization and
  1500. ** shutdown on embedded systems. Workstation applications using
  1501. ** SQLite normally do not need to invoke either of these routines.
  1502. **
  1503. ** A call to sqlite3_initialize() is an "effective" call if it is
  1504. ** the first time sqlite3_initialize() is invoked during the lifetime of
  1505. ** the process, or if it is the first time sqlite3_initialize() is invoked
  1506. ** following a call to sqlite3_shutdown(). ^(Only an effective call
  1507. ** of sqlite3_initialize() does any initialization. All other calls
  1508. ** are harmless no-ops.)^
  1509. **
  1510. ** A call to sqlite3_shutdown() is an "effective" call if it is the first
  1511. ** call to sqlite3_shutdown() since the last sqlite3_initialize(). ^(Only
  1512. ** an effective call to sqlite3_shutdown() does any deinitialization.
  1513. ** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^
  1514. **
  1515. ** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown()
  1516. ** is not. The sqlite3_shutdown() interface must only be called from a
  1517. ** single thread. All open [database connections] must be closed and all
  1518. ** other SQLite resources must be deallocated prior to invoking
  1519. ** sqlite3_shutdown().
  1520. **
  1521. ** Among other things, ^sqlite3_initialize() will invoke
  1522. ** sqlite3_os_init(). Similarly, ^sqlite3_shutdown()
  1523. ** will invoke sqlite3_os_end().
  1524. **
  1525. ** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success.
  1526. ** ^If for some reason, sqlite3_initialize() is unable to initialize
  1527. ** the library (perhaps it is unable to allocate a needed resource such
  1528. ** as a mutex) it returns an [error code] other than [SQLITE_OK].
  1529. **
  1530. ** ^The sqlite3_initialize() routine is called internally by many other
  1531. ** SQLite interfaces so that an application usually does not need to
  1532. ** invoke sqlite3_initialize() directly. For example, [sqlite3_open()]
  1533. ** calls sqlite3_initialize() so the SQLite library will be automatically
  1534. ** initialized when [sqlite3_open()] is called if it has not be initialized
  1535. ** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
  1536. ** compile-time option, then the automatic calls to sqlite3_initialize()
  1537. ** are omitted and the application must call sqlite3_initialize() directly
  1538. ** prior to using any other SQLite interface. For maximum portability,
  1539. ** it is recommended that applications always invoke sqlite3_initialize()
  1540. ** directly prior to using any other SQLite interface. Future releases
  1541. ** of SQLite may require this. In other words, the behavior exhibited
  1542. ** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the
  1543. ** default behavior in some future release of SQLite.
  1544. **
  1545. ** The sqlite3_os_init() routine does operating-system specific
  1546. ** initialization of the SQLite library. The sqlite3_os_end()
  1547. ** routine undoes the effect of sqlite3_os_init(). Typical tasks
  1548. ** performed by these routines include allocation or deallocation
  1549. ** of static resources, initialization of global variables,
  1550. ** setting up a default [sqlite3_vfs] module, or setting up
  1551. ** a default configuration using [sqlite3_config()].
  1552. **
  1553. ** The application should never invoke either sqlite3_os_init()
  1554. ** or sqlite3_os_end() directly. The application should only invoke
  1555. ** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init()
  1556. ** interface is called automatically by sqlite3_initialize() and
  1557. ** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate
  1558. ** implementations for sqlite3_os_init() and sqlite3_os_end()
  1559. ** are built into SQLite when it is compiled for Unix, Windows, or OS/2.
  1560. ** When [custom builds | built for other platforms]
  1561. ** (using the [SQLITE_OS_OTHER=1] compile-time
  1562. ** option) the application must supply a suitable implementation for
  1563. ** sqlite3_os_init() and sqlite3_os_end(). An application-supplied
  1564. ** implementation of sqlite3_os_init() or sqlite3_os_end()
  1565. ** must return [SQLITE_OK] on success and some other [error code] upon
  1566. ** failure.
  1567. */
  1568. SQLITE_API int sqlite3_initialize(void);
  1569. SQLITE_API int sqlite3_shutdown(void);
  1570. SQLITE_API int sqlite3_os_init(void);
  1571. SQLITE_API int sqlite3_os_end(void);
  1572. /*
  1573. ** CAPI3REF: Configuring The SQLite Library
  1574. **
  1575. ** The sqlite3_config() interface is used to make global configuration
  1576. ** changes to SQLite in order to tune SQLite to the specific needs of
  1577. ** the application. The default configuration is recommended for most
  1578. ** applications and so this routine is usually not necessary. It is
  1579. ** provided to support rare applications with unusual needs.
  1580. **
  1581. ** <b>The sqlite3_config() interface is not threadsafe. The application
  1582. ** must ensure that no other SQLite interfaces are invoked by other
  1583. ** threads while sqlite3_config() is running.</b>
  1584. **
  1585. ** The sqlite3_config() interface
  1586. ** may only be invoked prior to library initialization using
  1587. ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
  1588. ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before
  1589. ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
  1590. ** Note, however, that ^sqlite3_config() can be called as part of the
  1591. ** implementation of an application-defined [sqlite3_os_init()].
  1592. **
  1593. ** The first argument to sqlite3_config() is an integer
  1594. ** [configuration option] that determines
  1595. ** what property of SQLite is to be configured. Subsequent arguments
  1596. ** vary depending on the [configuration option]
  1597. ** in the first argument.
  1598. **
  1599. ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
  1600. ** ^If the option is unknown or SQLite is unable to set the option
  1601. ** then this routine returns a non-zero [error code].
  1602. */
  1603. SQLITE_API int sqlite3_config(int, ...);
  1604. /*
  1605. ** CAPI3REF: Configure database connections
  1606. ** METHOD: sqlite3
  1607. **
  1608. ** The sqlite3_db_config() interface is used to make configuration
  1609. ** changes to a [database connection]. The interface is similar to
  1610. ** [sqlite3_config()] except that the changes apply to a single
  1611. ** [database connection] (specified in the first argument).
  1612. **
  1613. ** The second argument to sqlite3_db_config(D,V,...) is the
  1614. ** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code
  1615. ** that indicates what aspect of the [database connection] is being configured.
  1616. ** Subsequent arguments vary depending on the configuration verb.
  1617. **
  1618. ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
  1619. ** the call is considered successful.
  1620. */
  1621. SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
  1622. /*
  1623. ** CAPI3REF: Memory Allocation Routines
  1624. **
  1625. ** An instance of this object defines the interface between SQLite
  1626. ** and low-level memory allocation routines.
  1627. **
  1628. ** This object is used in only one place in the SQLite interface.
  1629. ** A pointer to an instance of this object is the argument to
  1630. ** [sqlite3_config()] when the configuration option is
  1631. ** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC].
  1632. ** By creating an instance of this object
  1633. ** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC])
  1634. ** during configuration, an application can specify an alternative
  1635. ** memory allocation subsystem for SQLite to use for all of its
  1636. ** dynamic memory needs.
  1637. **
  1638. ** Note that SQLite comes with several [built-in memory allocators]
  1639. ** that are perfectly adequate for the overwhelming majority of applications
  1640. ** and that this object is only useful to a tiny minority of applications
  1641. ** with specialized memory allocation requirements. This object is
  1642. ** also used during testing of SQLite in order to specify an alternative
  1643. ** memory allocator that simulates memory out-of-memory conditions in
  1644. ** order to verify that SQLite recovers gracefully from such
  1645. ** conditions.
  1646. **
  1647. ** The xMalloc, xRealloc, and xFree methods must work like the
  1648. ** malloc(), realloc() and free() functions from the standard C library.
  1649. ** ^SQLite guarantees that the second argument to
  1650. ** xRealloc is always a value returned by a prior call to xRoundup.
  1651. **
  1652. ** xSize should return the allocated size of a memory allocation
  1653. ** previously obtained from xMalloc or xRealloc. The allocated size
  1654. ** is always at least as big as the requested size but may be larger.
  1655. **
  1656. ** The xRoundup method returns what would be the allocated size of
  1657. ** a memory allocation given a particular requested size. Most memory
  1658. ** allocators round up memory allocations at least to the next multiple
  1659. ** of 8. Some allocators round up to a larger multiple or to a power of 2.
  1660. ** Every memory allocation request coming in through [sqlite3_malloc()]
  1661. ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
  1662. ** that causes the corresponding memory allocation to fail.
  1663. **
  1664. ** The xInit method initializes the memory allocator. For example,
  1665. ** it might allocate any required mutexes or initialize internal data
  1666. ** structures. The xShutdown method is invoked (indirectly) by
  1667. ** [sqlite3_shutdown()] and should deallocate any resources acquired
  1668. ** by xInit. The pAppData pointer is used as the only parameter to
  1669. ** xInit and xShutdown.
  1670. **
  1671. ** SQLite holds the [SQLITE_MUTEX_STATIC_MAIN] mutex when it invokes
  1672. ** the xInit method, so the xInit method need not be threadsafe. The
  1673. ** xShutdown method is only called from [sqlite3_shutdown()] so it does
  1674. ** not need to be threadsafe either. For all other methods, SQLite
  1675. ** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
  1676. ** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
  1677. ** it is by default) and so the methods are automatically serialized.
  1678. ** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other
  1679. ** methods must be threadsafe or else make their own arrangements for
  1680. ** serialization.
  1681. **
  1682. ** SQLite will never invoke xInit() more than once without an intervening
  1683. ** call to xShutdown().
  1684. */
  1685. typedef struct sqlite3_mem_methods sqlite3_mem_methods;
  1686. struct sqlite3_mem_methods {
  1687. void *(*xMalloc)(int); /* Memory allocation function */
  1688. void (*xFree)(void*); /* Free a prior allocation */
  1689. void *(*xRealloc)(void*,int); /* Resize an allocation */
  1690. int (*xSize)(void*); /* Return the size of an allocation */
  1691. int (*xRoundup)(int); /* Round up request size to allocation size */
  1692. int (*xInit)(void*); /* Initialize the memory allocator */
  1693. void (*xShutdown)(void*); /* Deinitialize the memory allocator */
  1694. void *pAppData; /* Argument to xInit() and xShutdown() */
  1695. };
  1696. /*
  1697. ** CAPI3REF: Configuration Options
  1698. ** KEYWORDS: {configuration option}
  1699. **
  1700. ** These constants are the available integer configuration options that
  1701. ** can be passed as the first argument to the [sqlite3_config()] interface.
  1702. **
  1703. ** New configuration options may be added in future releases of SQLite.
  1704. ** Existing configuration options might be discontinued. Applications
  1705. ** should check the return code from [sqlite3_config()] to make sure that
  1706. ** the call worked. The [sqlite3_config()] interface will return a
  1707. ** non-zero [error code] if a discontinued or unsupported configuration option
  1708. ** is invoked.
  1709. **
  1710. ** <dl>
  1711. ** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
  1712. ** <dd>There are no arguments to this option. ^This option sets the
  1713. ** [threading mode] to Single-thread. In other words, it disables
  1714. ** all mutexing and puts SQLite into a mode where it can only be used
  1715. ** by a single thread. ^If SQLite is compiled with
  1716. ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1717. ** it is not possible to change the [threading mode] from its default
  1718. ** value of Single-thread and so [sqlite3_config()] will return
  1719. ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
  1720. ** configuration option.</dd>
  1721. **
  1722. ** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>
  1723. ** <dd>There are no arguments to this option. ^This option sets the
  1724. ** [threading mode] to Multi-thread. In other words, it disables
  1725. ** mutexing on [database connection] and [prepared statement] objects.
  1726. ** The application is responsible for serializing access to
  1727. ** [database connections] and [prepared statements]. But other mutexes
  1728. ** are enabled so that SQLite will be safe to use in a multi-threaded
  1729. ** environment as long as no two threads attempt to use the same
  1730. ** [database connection] at the same time. ^If SQLite is compiled with
  1731. ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1732. ** it is not possible to set the Multi-thread [threading mode] and
  1733. ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
  1734. ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
  1735. **
  1736. ** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>
  1737. ** <dd>There are no arguments to this option. ^This option sets the
  1738. ** [threading mode] to Serialized. In other words, this option enables
  1739. ** all mutexes including the recursive
  1740. ** mutexes on [database connection] and [prepared statement] objects.
  1741. ** In this mode (which is the default when SQLite is compiled with
  1742. ** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access
  1743. ** to [database connections] and [prepared statements] so that the
  1744. ** application is free to use the same [database connection] or the
  1745. ** same [prepared statement] in different threads at the same time.
  1746. ** ^If SQLite is compiled with
  1747. ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1748. ** it is not possible to set the Serialized [threading mode] and
  1749. ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
  1750. ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
  1751. **
  1752. ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
  1753. ** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is
  1754. ** a pointer to an instance of the [sqlite3_mem_methods] structure.
  1755. ** The argument specifies
  1756. ** alternative low-level memory allocation routines to be used in place of
  1757. ** the memory allocation routines built into SQLite.)^ ^SQLite makes
  1758. ** its own private copy of the content of the [sqlite3_mem_methods] structure
  1759. ** before the [sqlite3_config()] call returns.</dd>
  1760. **
  1761. ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
  1762. ** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
  1763. ** is a pointer to an instance of the [sqlite3_mem_methods] structure.
  1764. ** The [sqlite3_mem_methods]
  1765. ** structure is filled with the currently defined memory allocation routines.)^
  1766. ** This option can be used to overload the default memory allocation
  1767. ** routines with a wrapper that simulations memory allocation failure or
  1768. ** tracks memory usage, for example. </dd>
  1769. **
  1770. ** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt>
  1771. ** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes single argument of
  1772. ** type int, interpreted as a boolean, which if true provides a hint to
  1773. ** SQLite that it should avoid large memory allocations if possible.
  1774. ** SQLite will run faster if it is free to make large memory allocations,
  1775. ** but some application might prefer to run slower in exchange for
  1776. ** guarantees about memory fragmentation that are possible if large
  1777. ** allocations are avoided. This hint is normally off.
  1778. ** </dd>
  1779. **
  1780. ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
  1781. ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
  1782. ** interpreted as a boolean, which enables or disables the collection of
  1783. ** memory allocation statistics. ^(When memory allocation statistics are
  1784. ** disabled, the following SQLite interfaces become non-operational:
  1785. ** <ul>
  1786. ** <li> [sqlite3_hard_heap_limit64()]
  1787. ** <li> [sqlite3_memory_used()]
  1788. ** <li> [sqlite3_memory_highwater()]
  1789. ** <li> [sqlite3_soft_heap_limit64()]
  1790. ** <li> [sqlite3_status64()]
  1791. ** </ul>)^
  1792. ** ^Memory allocation statistics are enabled by default unless SQLite is
  1793. ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
  1794. ** allocation statistics are disabled by default.
  1795. ** </dd>
  1796. **
  1797. ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
  1798. ** <dd> The SQLITE_CONFIG_SCRATCH option is no longer used.
  1799. ** </dd>
  1800. **
  1801. ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
  1802. ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
  1803. ** that SQLite can use for the database page cache with the default page
  1804. ** cache implementation.
  1805. ** This configuration option is a no-op if an application-defined page
  1806. ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2].
  1807. ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
  1808. ** 8-byte aligned memory (pMem), the size of each page cache line (sz),
  1809. ** and the number of cache lines (N).
  1810. ** The sz argument should be the size of the largest database page
  1811. ** (a power of two between 512 and 65536) plus some extra bytes for each
  1812. ** page header. ^The number of extra bytes needed by the page header
  1813. ** can be determined using [SQLITE_CONFIG_PCACHE_HDRSZ].
  1814. ** ^It is harmless, apart from the wasted memory,
  1815. ** for the sz parameter to be larger than necessary. The pMem
  1816. ** argument must be either a NULL pointer or a pointer to an 8-byte
  1817. ** aligned block of memory of at least sz*N bytes, otherwise
  1818. ** subsequent behavior is undefined.
  1819. ** ^When pMem is not NULL, SQLite will strive to use the memory provided
  1820. ** to satisfy page cache needs, falling back to [sqlite3_malloc()] if
  1821. ** a page cache line is larger than sz bytes or if all of the pMem buffer
  1822. ** is exhausted.
  1823. ** ^If pMem is NULL and N is non-zero, then each database connection
  1824. ** does an initial bulk allocation for page cache memory
  1825. ** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or
  1826. ** of -1024*N bytes if N is negative, . ^If additional
  1827. ** page cache memory is needed beyond what is provided by the initial
  1828. ** allocation, then SQLite goes to [sqlite3_malloc()] separately for each
  1829. ** additional cache line. </dd>
  1830. **
  1831. ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
  1832. ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
  1833. ** that SQLite will use for all of its dynamic memory allocation needs
  1834. ** beyond those provided for by [SQLITE_CONFIG_PAGECACHE].
  1835. ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
  1836. ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
  1837. ** [SQLITE_ERROR] if invoked otherwise.
  1838. ** ^There are three arguments to SQLITE_CONFIG_HEAP:
  1839. ** An 8-byte aligned pointer to the memory,
  1840. ** the number of bytes in the memory buffer, and the minimum allocation size.
  1841. ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
  1842. ** to using its default memory allocator (the system malloc() implementation),
  1843. ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
  1844. ** memory pointer is not NULL then the alternative memory
  1845. ** allocator is engaged to handle all of SQLites memory allocation needs.
  1846. ** The first pointer (the memory pointer) must be aligned to an 8-byte
  1847. ** boundary or subsequent behavior of SQLite will be undefined.
  1848. ** The minimum allocation size is capped at 2**12. Reasonable values
  1849. ** for the minimum allocation size are 2**5 through 2**8.</dd>
  1850. **
  1851. ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
  1852. ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
  1853. ** pointer to an instance of the [sqlite3_mutex_methods] structure.
  1854. ** The argument specifies alternative low-level mutex routines to be used
  1855. ** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of
  1856. ** the content of the [sqlite3_mutex_methods] structure before the call to
  1857. ** [sqlite3_config()] returns. ^If SQLite is compiled with
  1858. ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1859. ** the entire mutexing subsystem is omitted from the build and hence calls to
  1860. ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
  1861. ** return [SQLITE_ERROR].</dd>
  1862. **
  1863. ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
  1864. ** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which
  1865. ** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The
  1866. ** [sqlite3_mutex_methods]
  1867. ** structure is filled with the currently defined mutex routines.)^
  1868. ** This option can be used to overload the default mutex allocation
  1869. ** routines with a wrapper used to track mutex usage for performance
  1870. ** profiling or testing, for example. ^If SQLite is compiled with
  1871. ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1872. ** the entire mutexing subsystem is omitted from the build and hence calls to
  1873. ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
  1874. ** return [SQLITE_ERROR].</dd>
  1875. **
  1876. ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
  1877. ** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
  1878. ** the default size of lookaside memory on each [database connection].
  1879. ** The first argument is the
  1880. ** size of each lookaside buffer slot and the second is the number of
  1881. ** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE
  1882. ** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
  1883. ** option to [sqlite3_db_config()] can be used to change the lookaside
  1884. ** configuration on individual connections.)^ </dd>
  1885. **
  1886. ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
  1887. ** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
  1888. ** a pointer to an [sqlite3_pcache_methods2] object. This object specifies
  1889. ** the interface to a custom page cache implementation.)^
  1890. ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
  1891. **
  1892. ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
  1893. ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
  1894. ** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of
  1895. ** the current page cache implementation into that object.)^ </dd>
  1896. **
  1897. ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
  1898. ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
  1899. ** global [error log].
  1900. ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
  1901. ** function with a call signature of void(*)(void*,int,const char*),
  1902. ** and a pointer to void. ^If the function pointer is not NULL, it is
  1903. ** invoked by [sqlite3_log()] to process each logging event. ^If the
  1904. ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
  1905. ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
  1906. ** passed through as the first parameter to the application-defined logger
  1907. ** function whenever that function is invoked. ^The second parameter to
  1908. ** the logger function is a copy of the first parameter to the corresponding
  1909. ** [sqlite3_log()] call and is intended to be a [result code] or an
  1910. ** [extended result code]. ^The third parameter passed to the logger is
  1911. ** log message after formatting via [sqlite3_snprintf()].
  1912. ** The SQLite logging interface is not reentrant; the logger function
  1913. ** supplied by the application must not invoke any SQLite interface.
  1914. ** In a multi-threaded application, the application-defined logger
  1915. ** function must be threadsafe. </dd>
  1916. **
  1917. ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
  1918. ** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.
  1919. ** If non-zero, then URI handling is globally enabled. If the parameter is zero,
  1920. ** then URI handling is globally disabled.)^ ^If URI handling is globally
  1921. ** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()],
  1922. ** [sqlite3_open16()] or
  1923. ** specified as part of [ATTACH] commands are interpreted as URIs, regardless
  1924. ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
  1925. ** connection is opened. ^If it is globally disabled, filenames are
  1926. ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
  1927. ** database connection is opened. ^(By default, URI handling is globally
  1928. ** disabled. The default value may be changed by compiling with the
  1929. ** [SQLITE_USE_URI] symbol defined.)^
  1930. **
  1931. ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
  1932. ** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer
  1933. ** argument which is interpreted as a boolean in order to enable or disable
  1934. ** the use of covering indices for full table scans in the query optimizer.
  1935. ** ^The default setting is determined
  1936. ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
  1937. ** if that compile-time option is omitted.
  1938. ** The ability to disable the use of covering indices for full table scans
  1939. ** is because some incorrectly coded legacy applications might malfunction
  1940. ** when the optimization is enabled. Providing the ability to
  1941. ** disable the optimization allows the older, buggy application code to work
  1942. ** without change even with newer versions of SQLite.
  1943. **
  1944. ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
  1945. ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE
  1946. ** <dd> These options are obsolete and should not be used by new code.
  1947. ** They are retained for backwards compatibility but are now no-ops.
  1948. ** </dd>
  1949. **
  1950. ** [[SQLITE_CONFIG_SQLLOG]]
  1951. ** <dt>SQLITE_CONFIG_SQLLOG
  1952. ** <dd>This option is only available if sqlite is compiled with the
  1953. ** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should
  1954. ** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int).
  1955. ** The second should be of type (void*). The callback is invoked by the library
  1956. ** in three separate circumstances, identified by the value passed as the
  1957. ** fourth parameter. If the fourth parameter is 0, then the database connection
  1958. ** passed as the second argument has just been opened. The third argument
  1959. ** points to a buffer containing the name of the main database file. If the
  1960. ** fourth parameter is 1, then the SQL statement that the third parameter
  1961. ** points to has just been executed. Or, if the fourth parameter is 2, then
  1962. ** the connection being passed as the second parameter is being closed. The
  1963. ** third parameter is passed NULL In this case. An example of using this
  1964. ** configuration option can be seen in the "test_sqllog.c" source file in
  1965. ** the canonical SQLite source tree.</dd>
  1966. **
  1967. ** [[SQLITE_CONFIG_MMAP_SIZE]]
  1968. ** <dt>SQLITE_CONFIG_MMAP_SIZE
  1969. ** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values
  1970. ** that are the default mmap size limit (the default setting for
  1971. ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
  1972. ** ^The default setting can be overridden by each database connection using
  1973. ** either the [PRAGMA mmap_size] command, or by using the
  1974. ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size
  1975. ** will be silently truncated if necessary so that it does not exceed the
  1976. ** compile-time maximum mmap size set by the
  1977. ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
  1978. ** ^If either argument to this option is negative, then that argument is
  1979. ** changed to its compile-time default.
  1980. **
  1981. ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
  1982. ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
  1983. ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
  1984. ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro
  1985. ** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
  1986. ** that specifies the maximum size of the created heap.
  1987. **
  1988. ** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
  1989. ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
  1990. ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
  1991. ** is a pointer to an integer and writes into that integer the number of extra
  1992. ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
  1993. ** The amount of extra space required can change depending on the compiler,
  1994. ** target platform, and SQLite version.
  1995. **
  1996. ** [[SQLITE_CONFIG_PMASZ]]
  1997. ** <dt>SQLITE_CONFIG_PMASZ
  1998. ** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which
  1999. ** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded
  2000. ** sorter to that integer. The default minimum PMA Size is set by the
  2001. ** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched
  2002. ** to help with sort operations when multithreaded sorting
  2003. ** is enabled (using the [PRAGMA threads] command) and the amount of content
  2004. ** to be sorted exceeds the page size times the minimum of the
  2005. ** [PRAGMA cache_size] setting and this value.
  2006. **
  2007. ** [[SQLITE_CONFIG_STMTJRNL_SPILL]]
  2008. ** <dt>SQLITE_CONFIG_STMTJRNL_SPILL
  2009. ** <dd>^The SQLITE_CONFIG_STMTJRNL_SPILL option takes a single parameter which
  2010. ** becomes the [statement journal] spill-to-disk threshold.
  2011. ** [Statement journals] are held in memory until their size (in bytes)
  2012. ** exceeds this threshold, at which point they are written to disk.
  2013. ** Or if the threshold is -1, statement journals are always held
  2014. ** exclusively in memory.
  2015. ** Since many statement journals never become large, setting the spill
  2016. ** threshold to a value such as 64KiB can greatly reduce the amount of
  2017. ** I/O required to support statement rollback.
  2018. ** The default value for this setting is controlled by the
  2019. ** [SQLITE_STMTJRNL_SPILL] compile-time option.
  2020. **
  2021. ** [[SQLITE_CONFIG_SORTERREF_SIZE]]
  2022. ** <dt>SQLITE_CONFIG_SORTERREF_SIZE
  2023. ** <dd>The SQLITE_CONFIG_SORTERREF_SIZE option accepts a single parameter
  2024. ** of type (int) - the new value of the sorter-reference size threshold.
  2025. ** Usually, when SQLite uses an external sort to order records according
  2026. ** to an ORDER BY clause, all fields required by the caller are present in the
  2027. ** sorted records. However, if SQLite determines based on the declared type
  2028. ** of a table column that its values are likely to be very large - larger
  2029. ** than the configured sorter-reference size threshold - then a reference
  2030. ** is stored in each sorted record and the required column values loaded
  2031. ** from the database as records are returned in sorted order. The default
  2032. ** value for this option is to never use this optimization. Specifying a
  2033. ** negative value for this option restores the default behaviour.
  2034. ** This option is only available if SQLite is compiled with the
  2035. ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.
  2036. **
  2037. ** [[SQLITE_CONFIG_MEMDB_MAXSIZE]]
  2038. ** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE
  2039. ** <dd>The SQLITE_CONFIG_MEMDB_MAXSIZE option accepts a single parameter
  2040. ** [sqlite3_int64] parameter which is the default maximum size for an in-memory
  2041. ** database created using [sqlite3_deserialize()]. This default maximum
  2042. ** size can be adjusted up or down for individual databases using the
  2043. ** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this
  2044. ** configuration setting is never used, then the default maximum is determined
  2045. ** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that
  2046. ** compile-time option is not set, then the default maximum is 1073741824.
  2047. ** </dl>
  2048. */
  2049. #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
  2050. #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
  2051. #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
  2052. #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
  2053. #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */
  2054. #define SQLITE_CONFIG_SCRATCH 6 /* No longer used */
  2055. #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */
  2056. #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */
  2057. #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */
  2058. #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */
  2059. #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */
  2060. /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
  2061. #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */
  2062. #define SQLITE_CONFIG_PCACHE 14 /* no-op */
  2063. #define SQLITE_CONFIG_GETPCACHE 15 /* no-op */
  2064. #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
  2065. #define SQLITE_CONFIG_URI 17 /* int */
  2066. #define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */
  2067. #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
  2068. #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
  2069. #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
  2070. #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
  2071. #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
  2072. #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
  2073. #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
  2074. #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
  2075. #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */
  2076. #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */
  2077. #define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */
  2078. /*
  2079. ** CAPI3REF: Database Connection Configuration Options
  2080. **
  2081. ** These constants are the available integer configuration options that
  2082. ** can be passed as the second argument to the [sqlite3_db_config()] interface.
  2083. **
  2084. ** New configuration options may be added in future releases of SQLite.
  2085. ** Existing configuration options might be discontinued. Applications
  2086. ** should check the return code from [sqlite3_db_config()] to make sure that
  2087. ** the call worked. ^The [sqlite3_db_config()] interface will return a
  2088. ** non-zero [error code] if a discontinued or unsupported configuration option
  2089. ** is invoked.
  2090. **
  2091. ** <dl>
  2092. ** [[SQLITE_DBCONFIG_LOOKASIDE]]
  2093. ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
  2094. ** <dd> ^This option takes three additional arguments that determine the
  2095. ** [lookaside memory allocator] configuration for the [database connection].
  2096. ** ^The first argument (the third parameter to [sqlite3_db_config()] is a
  2097. ** pointer to a memory buffer to use for lookaside memory.
  2098. ** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
  2099. ** may be NULL in which case SQLite will allocate the
  2100. ** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the
  2101. ** size of each lookaside buffer slot. ^The third argument is the number of
  2102. ** slots. The size of the buffer in the first argument must be greater than
  2103. ** or equal to the product of the second and third arguments. The buffer
  2104. ** must be aligned to an 8-byte boundary. ^If the second argument to
  2105. ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
  2106. ** rounded down to the next smaller multiple of 8. ^(The lookaside memory
  2107. ** configuration for a database connection can only be changed when that
  2108. ** connection is not currently using lookaside memory, or in other words
  2109. ** when the "current value" returned by
  2110. ** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
  2111. ** Any attempt to change the lookaside memory configuration when lookaside
  2112. ** memory is in use leaves the configuration unchanged and returns
  2113. ** [SQLITE_BUSY].)^</dd>
  2114. **
  2115. ** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
  2116. ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
  2117. ** <dd> ^This option is used to enable or disable the enforcement of
  2118. ** [foreign key constraints]. There should be two additional arguments.
  2119. ** The first argument is an integer which is 0 to disable FK enforcement,
  2120. ** positive to enable FK enforcement or negative to leave FK enforcement
  2121. ** unchanged. The second parameter is a pointer to an integer into which
  2122. ** is written 0 or 1 to indicate whether FK enforcement is off or on
  2123. ** following this call. The second parameter may be a NULL pointer, in
  2124. ** which case the FK enforcement setting is not reported back. </dd>
  2125. **
  2126. ** [[SQLITE_DBCONFIG_ENABLE_TRIGGER]]
  2127. ** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
  2128. ** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
  2129. ** There should be two additional arguments.
  2130. ** The first argument is an integer which is 0 to disable triggers,
  2131. ** positive to enable triggers or negative to leave the setting unchanged.
  2132. ** The second parameter is a pointer to an integer into which
  2133. ** is written 0 or 1 to indicate whether triggers are disabled or enabled
  2134. ** following this call. The second parameter may be a NULL pointer, in
  2135. ** which case the trigger setting is not reported back.
  2136. **
  2137. ** <p>Originally this option disabled all triggers. ^(However, since
  2138. ** SQLite version 3.35.0, TEMP triggers are still allowed even if
  2139. ** this option is off. So, in other words, this option now only disables
  2140. ** triggers in the main database schema or in the schemas of ATTACH-ed
  2141. ** databases.)^ </dd>
  2142. **
  2143. ** [[SQLITE_DBCONFIG_ENABLE_VIEW]]
  2144. ** <dt>SQLITE_DBCONFIG_ENABLE_VIEW</dt>
  2145. ** <dd> ^This option is used to enable or disable [CREATE VIEW | views].
  2146. ** There should be two additional arguments.
  2147. ** The first argument is an integer which is 0 to disable views,
  2148. ** positive to enable views or negative to leave the setting unchanged.
  2149. ** The second parameter is a pointer to an integer into which
  2150. ** is written 0 or 1 to indicate whether views are disabled or enabled
  2151. ** following this call. The second parameter may be a NULL pointer, in
  2152. ** which case the view setting is not reported back.
  2153. **
  2154. ** <p>Originally this option disabled all views. ^(However, since
  2155. ** SQLite version 3.35.0, TEMP views are still allowed even if
  2156. ** this option is off. So, in other words, this option now only disables
  2157. ** views in the main database schema or in the schemas of ATTACH-ed
  2158. ** databases.)^ </dd>
  2159. **
  2160. ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
  2161. ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
  2162. ** <dd> ^This option is used to enable or disable the
  2163. ** [fts3_tokenizer()] function which is part of the
  2164. ** [FTS3] full-text search engine extension.
  2165. ** There should be two additional arguments.
  2166. ** The first argument is an integer which is 0 to disable fts3_tokenizer() or
  2167. ** positive to enable fts3_tokenizer() or negative to leave the setting
  2168. ** unchanged.
  2169. ** The second parameter is a pointer to an integer into which
  2170. ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
  2171. ** following this call. The second parameter may be a NULL pointer, in
  2172. ** which case the new setting is not reported back. </dd>
  2173. **
  2174. ** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]]
  2175. ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
  2176. ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
  2177. ** interface independently of the [load_extension()] SQL function.
  2178. ** The [sqlite3_enable_load_extension()] API enables or disables both the
  2179. ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
  2180. ** There should be two additional arguments.
  2181. ** When the first argument to this interface is 1, then only the C-API is
  2182. ** enabled and the SQL function remains disabled. If the first argument to
  2183. ** this interface is 0, then both the C-API and the SQL function are disabled.
  2184. ** If the first argument is -1, then no changes are made to state of either the
  2185. ** C-API or the SQL function.
  2186. ** The second parameter is a pointer to an integer into which
  2187. ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
  2188. ** is disabled or enabled following this call. The second parameter may
  2189. ** be a NULL pointer, in which case the new setting is not reported back.
  2190. ** </dd>
  2191. **
  2192. ** [[SQLITE_DBCONFIG_MAINDBNAME]] <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
  2193. ** <dd> ^This option is used to change the name of the "main" database
  2194. ** schema. ^The sole argument is a pointer to a constant UTF8 string
  2195. ** which will become the new schema name in place of "main". ^SQLite
  2196. ** does not make a copy of the new main schema name string, so the application
  2197. ** must ensure that the argument passed into this DBCONFIG option is unchanged
  2198. ** until after the database connection closes.
  2199. ** </dd>
  2200. **
  2201. ** [[SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE]]
  2202. ** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
  2203. ** <dd> Usually, when a database in wal mode is closed or detached from a
  2204. ** database handle, SQLite checks if this will mean that there are now no
  2205. ** connections at all to the database. If so, it performs a checkpoint
  2206. ** operation before closing the connection. This option may be used to
  2207. ** override this behaviour. The first parameter passed to this operation
  2208. ** is an integer - positive to disable checkpoints-on-close, or zero (the
  2209. ** default) to enable them, and negative to leave the setting unchanged.
  2210. ** The second parameter is a pointer to an integer
  2211. ** into which is written 0 or 1 to indicate whether checkpoints-on-close
  2212. ** have been disabled - 0 if they are not disabled, 1 if they are.
  2213. ** </dd>
  2214. **
  2215. ** [[SQLITE_DBCONFIG_ENABLE_QPSG]] <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
  2216. ** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
  2217. ** the [query planner stability guarantee] (QPSG). When the QPSG is active,
  2218. ** a single SQL query statement will always use the same algorithm regardless
  2219. ** of values of [bound parameters].)^ The QPSG disables some query optimizations
  2220. ** that look at the values of bound parameters, which can make some queries
  2221. ** slower. But the QPSG has the advantage of more predictable behavior. With
  2222. ** the QPSG active, SQLite will always use the same query plan in the field as
  2223. ** was used during testing in the lab.
  2224. ** The first argument to this setting is an integer which is 0 to disable
  2225. ** the QPSG, positive to enable QPSG, or negative to leave the setting
  2226. ** unchanged. The second parameter is a pointer to an integer into which
  2227. ** is written 0 or 1 to indicate whether the QPSG is disabled or enabled
  2228. ** following this call.
  2229. ** </dd>
  2230. **
  2231. ** [[SQLITE_DBCONFIG_TRIGGER_EQP]] <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>
  2232. ** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not
  2233. ** include output for any operations performed by trigger programs. This
  2234. ** option is used to set or clear (the default) a flag that governs this
  2235. ** behavior. The first parameter passed to this operation is an integer -
  2236. ** positive to enable output for trigger programs, or zero to disable it,
  2237. ** or negative to leave the setting unchanged.
  2238. ** The second parameter is a pointer to an integer into which is written
  2239. ** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if
  2240. ** it is not disabled, 1 if it is.
  2241. ** </dd>
  2242. **
  2243. ** [[SQLITE_DBCONFIG_RESET_DATABASE]] <dt>SQLITE_DBCONFIG_RESET_DATABASE</dt>
  2244. ** <dd> Set the SQLITE_DBCONFIG_RESET_DATABASE flag and then run
  2245. ** [VACUUM] in order to reset a database back to an empty database
  2246. ** with no schema and no content. The following process works even for
  2247. ** a badly corrupted database file:
  2248. ** <ol>
  2249. ** <li> If the database connection is newly opened, make sure it has read the
  2250. ** database schema by preparing then discarding some query against the
  2251. ** database, or calling sqlite3_table_column_metadata(), ignoring any
  2252. ** errors. This step is only necessary if the application desires to keep
  2253. ** the database in WAL mode after the reset if it was in WAL mode before
  2254. ** the reset.
  2255. ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);
  2256. ** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0);
  2257. ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
  2258. ** </ol>
  2259. ** Because resetting a database is destructive and irreversible, the
  2260. ** process requires the use of this obscure API and multiple steps to help
  2261. ** ensure that it does not happen by accident.
  2262. **
  2263. ** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt>
  2264. ** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the
  2265. ** "defensive" flag for a database connection. When the defensive
  2266. ** flag is enabled, language features that allow ordinary SQL to
  2267. ** deliberately corrupt the database file are disabled. The disabled
  2268. ** features include but are not limited to the following:
  2269. ** <ul>
  2270. ** <li> The [PRAGMA writable_schema=ON] statement.
  2271. ** <li> The [PRAGMA journal_mode=OFF] statement.
  2272. ** <li> Writes to the [sqlite_dbpage] virtual table.
  2273. ** <li> Direct writes to [shadow tables].
  2274. ** </ul>
  2275. ** </dd>
  2276. **
  2277. ** [[SQLITE_DBCONFIG_WRITABLE_SCHEMA]] <dt>SQLITE_DBCONFIG_WRITABLE_SCHEMA</dt>
  2278. ** <dd>The SQLITE_DBCONFIG_WRITABLE_SCHEMA option activates or deactivates the
  2279. ** "writable_schema" flag. This has the same effect and is logically equivalent
  2280. ** to setting [PRAGMA writable_schema=ON] or [PRAGMA writable_schema=OFF].
  2281. ** The first argument to this setting is an integer which is 0 to disable
  2282. ** the writable_schema, positive to enable writable_schema, or negative to
  2283. ** leave the setting unchanged. The second parameter is a pointer to an
  2284. ** integer into which is written 0 or 1 to indicate whether the writable_schema
  2285. ** is enabled or disabled following this call.
  2286. ** </dd>
  2287. **
  2288. ** [[SQLITE_DBCONFIG_LEGACY_ALTER_TABLE]]
  2289. ** <dt>SQLITE_DBCONFIG_LEGACY_ALTER_TABLE</dt>
  2290. ** <dd>The SQLITE_DBCONFIG_LEGACY_ALTER_TABLE option activates or deactivates
  2291. ** the legacy behavior of the [ALTER TABLE RENAME] command such it
  2292. ** behaves as it did prior to [version 3.24.0] (2018-06-04). See the
  2293. ** "Compatibility Notice" on the [ALTER TABLE RENAME documentation] for
  2294. ** additional information. This feature can also be turned on and off
  2295. ** using the [PRAGMA legacy_alter_table] statement.
  2296. ** </dd>
  2297. **
  2298. ** [[SQLITE_DBCONFIG_DQS_DML]]
  2299. ** <dt>SQLITE_DBCONFIG_DQS_DML</td>
  2300. ** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates
  2301. ** the legacy [double-quoted string literal] misfeature for DML statements
  2302. ** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The
  2303. ** default value of this setting is determined by the [-DSQLITE_DQS]
  2304. ** compile-time option.
  2305. ** </dd>
  2306. **
  2307. ** [[SQLITE_DBCONFIG_DQS_DDL]]
  2308. ** <dt>SQLITE_DBCONFIG_DQS_DDL</td>
  2309. ** <dd>The SQLITE_DBCONFIG_DQS option activates or deactivates
  2310. ** the legacy [double-quoted string literal] misfeature for DDL statements,
  2311. ** such as CREATE TABLE and CREATE INDEX. The
  2312. ** default value of this setting is determined by the [-DSQLITE_DQS]
  2313. ** compile-time option.
  2314. ** </dd>
  2315. **
  2316. ** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
  2317. ** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td>
  2318. ** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to
  2319. ** assume that database schemas are untainted by malicious content.
  2320. ** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
  2321. ** takes additional defensive steps to protect the application from harm
  2322. ** including:
  2323. ** <ul>
  2324. ** <li> Prohibit the use of SQL functions inside triggers, views,
  2325. ** CHECK constraints, DEFAULT clauses, expression indexes,
  2326. ** partial indexes, or generated columns
  2327. ** unless those functions are tagged with [SQLITE_INNOCUOUS].
  2328. ** <li> Prohibit the use of virtual tables inside of triggers or views
  2329. ** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS].
  2330. ** </ul>
  2331. ** This setting defaults to "on" for legacy compatibility, however
  2332. ** all applications are advised to turn it off if possible. This setting
  2333. ** can also be controlled using the [PRAGMA trusted_schema] statement.
  2334. ** </dd>
  2335. **
  2336. ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
  2337. ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</td>
  2338. ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
  2339. ** the legacy file format flag. When activated, this flag causes all newly
  2340. ** created database file to have a schema format version number (the 4-byte
  2341. ** integer found at offset 44 into the database header) of 1. This in turn
  2342. ** means that the resulting database file will be readable and writable by
  2343. ** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting,
  2344. ** newly created databases are generally not understandable by SQLite versions
  2345. ** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there
  2346. ** is now scarcely any need to generated database files that are compatible
  2347. ** all the way back to version 3.0.0, and so this setting is of little
  2348. ** practical use, but is provided so that SQLite can continue to claim the
  2349. ** ability to generate new database files that are compatible with version
  2350. ** 3.0.0.
  2351. ** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on,
  2352. ** the [VACUUM] command will fail with an obscure error when attempting to
  2353. ** process a table with generated columns and a descending index. This is
  2354. ** not considered a bug since SQLite versions 3.3.0 and earlier do not support
  2355. ** either generated columns or decending indexes.
  2356. ** </dd>
  2357. ** </dl>
  2358. */
  2359. #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
  2360. #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
  2361. #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
  2362. #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
  2363. #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
  2364. #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
  2365. #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */
  2366. #define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */
  2367. #define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */
  2368. #define SQLITE_DBCONFIG_RESET_DATABASE 1009 /* int int* */
  2369. #define SQLITE_DBCONFIG_DEFENSIVE 1010 /* int int* */
  2370. #define SQLITE_DBCONFIG_WRITABLE_SCHEMA 1011 /* int int* */
  2371. #define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE 1012 /* int int* */
  2372. #define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */
  2373. #define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */
  2374. #define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */
  2375. #define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */
  2376. #define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */
  2377. #define SQLITE_DBCONFIG_MAX 1017 /* Largest DBCONFIG */
  2378. /*
  2379. ** CAPI3REF: Enable Or Disable Extended Result Codes
  2380. ** METHOD: sqlite3
  2381. **
  2382. ** ^The sqlite3_extended_result_codes() routine enables or disables the
  2383. ** [extended result codes] feature of SQLite. ^The extended result
  2384. ** codes are disabled by default for historical compatibility.
  2385. */
  2386. SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
  2387. /*
  2388. ** CAPI3REF: Last Insert Rowid
  2389. ** METHOD: sqlite3
  2390. **
  2391. ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
  2392. ** has a unique 64-bit signed
  2393. ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
  2394. ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
  2395. ** names are not also used by explicitly declared columns. ^If
  2396. ** the table has a column of type [INTEGER PRIMARY KEY] then that column
  2397. ** is another alias for the rowid.
  2398. **
  2399. ** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of
  2400. ** the most recent successful [INSERT] into a rowid table or [virtual table]
  2401. ** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not
  2402. ** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred
  2403. ** on the database connection D, then sqlite3_last_insert_rowid(D) returns
  2404. ** zero.
  2405. **
  2406. ** As well as being set automatically as rows are inserted into database
  2407. ** tables, the value returned by this function may be set explicitly by
  2408. ** [sqlite3_set_last_insert_rowid()]
  2409. **
  2410. ** Some virtual table implementations may INSERT rows into rowid tables as
  2411. ** part of committing a transaction (e.g. to flush data accumulated in memory
  2412. ** to disk). In this case subsequent calls to this function return the rowid
  2413. ** associated with these internal INSERT operations, which leads to
  2414. ** unintuitive results. Virtual table implementations that do write to rowid
  2415. ** tables in this way can avoid this problem by restoring the original
  2416. ** rowid value using [sqlite3_set_last_insert_rowid()] before returning
  2417. ** control to the user.
  2418. **
  2419. ** ^(If an [INSERT] occurs within a trigger then this routine will
  2420. ** return the [rowid] of the inserted row as long as the trigger is
  2421. ** running. Once the trigger program ends, the value returned
  2422. ** by this routine reverts to what it was before the trigger was fired.)^
  2423. **
  2424. ** ^An [INSERT] that fails due to a constraint violation is not a
  2425. ** successful [INSERT] and does not change the value returned by this
  2426. ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
  2427. ** and INSERT OR ABORT make no changes to the return value of this
  2428. ** routine when their insertion fails. ^(When INSERT OR REPLACE
  2429. ** encounters a constraint violation, it does not fail. The
  2430. ** INSERT continues to completion after deleting rows that caused
  2431. ** the constraint problem so INSERT OR REPLACE will always change
  2432. ** the return value of this interface.)^
  2433. **
  2434. ** ^For the purposes of this routine, an [INSERT] is considered to
  2435. ** be successful even if it is subsequently rolled back.
  2436. **
  2437. ** This function is accessible to SQL statements via the
  2438. ** [last_insert_rowid() SQL function].
  2439. **
  2440. ** If a separate thread performs a new [INSERT] on the same
  2441. ** database connection while the [sqlite3_last_insert_rowid()]
  2442. ** function is running and thus changes the last insert [rowid],
  2443. ** then the value returned by [sqlite3_last_insert_rowid()] is
  2444. ** unpredictable and might not equal either the old or the new
  2445. ** last insert [rowid].
  2446. */
  2447. SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
  2448. /*
  2449. ** CAPI3REF: Set the Last Insert Rowid value.
  2450. ** METHOD: sqlite3
  2451. **
  2452. ** The sqlite3_set_last_insert_rowid(D, R) method allows the application to
  2453. ** set the value returned by calling sqlite3_last_insert_rowid(D) to R
  2454. ** without inserting a row into the database.
  2455. */
  2456. SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64);
  2457. /*
  2458. ** CAPI3REF: Count The Number Of Rows Modified
  2459. ** METHOD: sqlite3
  2460. **
  2461. ** ^These functions return the number of rows modified, inserted or
  2462. ** deleted by the most recently completed INSERT, UPDATE or DELETE
  2463. ** statement on the database connection specified by the only parameter.
  2464. ** The two functions are identical except for the type of the return value
  2465. ** and that if the number of rows modified by the most recent INSERT, UPDATE
  2466. ** or DELETE is greater than the maximum value supported by type "int", then
  2467. ** the return value of sqlite3_changes() is undefined. ^Executing any other
  2468. ** type of SQL statement does not modify the value returned by these functions.
  2469. **
  2470. ** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
  2471. ** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
  2472. ** [foreign key actions] or [REPLACE] constraint resolution are not counted.
  2473. **
  2474. ** Changes to a view that are intercepted by
  2475. ** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value
  2476. ** returned by sqlite3_changes() immediately after an INSERT, UPDATE or
  2477. ** DELETE statement run on a view is always zero. Only changes made to real
  2478. ** tables are counted.
  2479. **
  2480. ** Things are more complicated if the sqlite3_changes() function is
  2481. ** executed while a trigger program is running. This may happen if the
  2482. ** program uses the [changes() SQL function], or if some other callback
  2483. ** function invokes sqlite3_changes() directly. Essentially:
  2484. **
  2485. ** <ul>
  2486. ** <li> ^(Before entering a trigger program the value returned by
  2487. ** sqlite3_changes() function is saved. After the trigger program
  2488. ** has finished, the original value is restored.)^
  2489. **
  2490. ** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE
  2491. ** statement sets the value returned by sqlite3_changes()
  2492. ** upon completion as normal. Of course, this value will not include
  2493. ** any changes performed by sub-triggers, as the sqlite3_changes()
  2494. ** value will be saved and restored after each sub-trigger has run.)^
  2495. ** </ul>
  2496. **
  2497. ** ^This means that if the changes() SQL function (or similar) is used
  2498. ** by the first INSERT, UPDATE or DELETE statement within a trigger, it
  2499. ** returns the value as set when the calling statement began executing.
  2500. ** ^If it is used by the second or subsequent such statement within a trigger
  2501. ** program, the value returned reflects the number of rows modified by the
  2502. ** previous INSERT, UPDATE or DELETE statement within the same trigger.
  2503. **
  2504. ** If a separate thread makes changes on the same database connection
  2505. ** while [sqlite3_changes()] is running then the value returned
  2506. ** is unpredictable and not meaningful.
  2507. **
  2508. ** See also:
  2509. ** <ul>
  2510. ** <li> the [sqlite3_total_changes()] interface
  2511. ** <li> the [count_changes pragma]
  2512. ** <li> the [changes() SQL function]
  2513. ** <li> the [data_version pragma]
  2514. ** </ul>
  2515. */
  2516. SQLITE_API int sqlite3_changes(sqlite3*);
  2517. SQLITE_API sqlite3_int64 sqlite3_changes64(sqlite3*);
  2518. /*
  2519. ** CAPI3REF: Total Number Of Rows Modified
  2520. ** METHOD: sqlite3
  2521. **
  2522. ** ^These functions return the total number of rows inserted, modified or
  2523. ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
  2524. ** since the database connection was opened, including those executed as
  2525. ** part of trigger programs. The two functions are identical except for the
  2526. ** type of the return value and that if the number of rows modified by the
  2527. ** connection exceeds the maximum value supported by type "int", then
  2528. ** the return value of sqlite3_total_changes() is undefined. ^Executing
  2529. ** any other type of SQL statement does not affect the value returned by
  2530. ** sqlite3_total_changes().
  2531. **
  2532. ** ^Changes made as part of [foreign key actions] are included in the
  2533. ** count, but those made as part of REPLACE constraint resolution are
  2534. ** not. ^Changes to a view that are intercepted by INSTEAD OF triggers
  2535. ** are not counted.
  2536. **
  2537. ** The [sqlite3_total_changes(D)] interface only reports the number
  2538. ** of rows that changed due to SQL statement run against database
  2539. ** connection D. Any changes by other database connections are ignored.
  2540. ** To detect changes against a database file from other database
  2541. ** connections use the [PRAGMA data_version] command or the
  2542. ** [SQLITE_FCNTL_DATA_VERSION] [file control].
  2543. **
  2544. ** If a separate thread makes changes on the same database connection
  2545. ** while [sqlite3_total_changes()] is running then the value
  2546. ** returned is unpredictable and not meaningful.
  2547. **
  2548. ** See also:
  2549. ** <ul>
  2550. ** <li> the [sqlite3_changes()] interface
  2551. ** <li> the [count_changes pragma]
  2552. ** <li> the [changes() SQL function]
  2553. ** <li> the [data_version pragma]
  2554. ** <li> the [SQLITE_FCNTL_DATA_VERSION] [file control]
  2555. ** </ul>
  2556. */
  2557. SQLITE_API int sqlite3_total_changes(sqlite3*);
  2558. SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3*);
  2559. /*
  2560. ** CAPI3REF: Interrupt A Long-Running Query
  2561. ** METHOD: sqlite3
  2562. **
  2563. ** ^This function causes any pending database operation to abort and
  2564. ** return at its earliest opportunity. This routine is typically
  2565. ** called in response to a user action such as pressing "Cancel"
  2566. ** or Ctrl-C where the user wants a long query operation to halt
  2567. ** immediately.
  2568. **
  2569. ** ^It is safe to call this routine from a thread different from the
  2570. ** thread that is currently running the database operation. But it
  2571. ** is not safe to call this routine with a [database connection] that
  2572. ** is closed or might close before sqlite3_interrupt() returns.
  2573. **
  2574. ** ^If an SQL operation is very nearly finished at the time when
  2575. ** sqlite3_interrupt() is called, then it might not have an opportunity
  2576. ** to be interrupted and might continue to completion.
  2577. **
  2578. ** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT].
  2579. ** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
  2580. ** that is inside an explicit transaction, then the entire transaction
  2581. ** will be rolled back automatically.
  2582. **
  2583. ** ^The sqlite3_interrupt(D) call is in effect until all currently running
  2584. ** SQL statements on [database connection] D complete. ^Any new SQL statements
  2585. ** that are started after the sqlite3_interrupt() call and before the
  2586. ** running statement count reaches zero are interrupted as if they had been
  2587. ** running prior to the sqlite3_interrupt() call. ^New SQL statements
  2588. ** that are started after the running statement count reaches zero are
  2589. ** not effected by the sqlite3_interrupt().
  2590. ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
  2591. ** SQL statements is a no-op and has no effect on SQL statements
  2592. ** that are started after the sqlite3_interrupt() call returns.
  2593. */
  2594. SQLITE_API void sqlite3_interrupt(sqlite3*);
  2595. /*
  2596. ** CAPI3REF: Determine If An SQL Statement Is Complete
  2597. **
  2598. ** These routines are useful during command-line input to determine if the
  2599. ** currently entered text seems to form a complete SQL statement or
  2600. ** if additional input is needed before sending the text into
  2601. ** SQLite for parsing. ^These routines return 1 if the input string
  2602. ** appears to be a complete SQL statement. ^A statement is judged to be
  2603. ** complete if it ends with a semicolon token and is not a prefix of a
  2604. ** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within
  2605. ** string literals or quoted identifier names or comments are not
  2606. ** independent tokens (they are part of the token in which they are
  2607. ** embedded) and thus do not count as a statement terminator. ^Whitespace
  2608. ** and comments that follow the final semicolon are ignored.
  2609. **
  2610. ** ^These routines return 0 if the statement is incomplete. ^If a
  2611. ** memory allocation fails, then SQLITE_NOMEM is returned.
  2612. **
  2613. ** ^These routines do not parse the SQL statements thus
  2614. ** will not detect syntactically incorrect SQL.
  2615. **
  2616. ** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior
  2617. ** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
  2618. ** automatically by sqlite3_complete16(). If that initialization fails,
  2619. ** then the return value from sqlite3_complete16() will be non-zero
  2620. ** regardless of whether or not the input SQL is complete.)^
  2621. **
  2622. ** The input to [sqlite3_complete()] must be a zero-terminated
  2623. ** UTF-8 string.
  2624. **
  2625. ** The input to [sqlite3_complete16()] must be a zero-terminated
  2626. ** UTF-16 string in native byte order.
  2627. */
  2628. SQLITE_API int sqlite3_complete(const char *sql);
  2629. SQLITE_API int sqlite3_complete16(const void *sql);
  2630. /*
  2631. ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
  2632. ** KEYWORDS: {busy-handler callback} {busy handler}
  2633. ** METHOD: sqlite3
  2634. **
  2635. ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
  2636. ** that might be invoked with argument P whenever
  2637. ** an attempt is made to access a database table associated with
  2638. ** [database connection] D when another thread
  2639. ** or process has the table locked.
  2640. ** The sqlite3_busy_handler() interface is used to implement
  2641. ** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].
  2642. **
  2643. ** ^If the busy callback is NULL, then [SQLITE_BUSY]
  2644. ** is returned immediately upon encountering the lock. ^If the busy callback
  2645. ** is not NULL, then the callback might be invoked with two arguments.
  2646. **
  2647. ** ^The first argument to the busy handler is a copy of the void* pointer which
  2648. ** is the third argument to sqlite3_busy_handler(). ^The second argument to
  2649. ** the busy handler callback is the number of times that the busy handler has
  2650. ** been invoked previously for the same locking event. ^If the
  2651. ** busy callback returns 0, then no additional attempts are made to
  2652. ** access the database and [SQLITE_BUSY] is returned
  2653. ** to the application.
  2654. ** ^If the callback returns non-zero, then another attempt
  2655. ** is made to access the database and the cycle repeats.
  2656. **
  2657. ** The presence of a busy handler does not guarantee that it will be invoked
  2658. ** when there is lock contention. ^If SQLite determines that invoking the busy
  2659. ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
  2660. ** to the application instead of invoking the
  2661. ** busy handler.
  2662. ** Consider a scenario where one process is holding a read lock that
  2663. ** it is trying to promote to a reserved lock and
  2664. ** a second process is holding a reserved lock that it is trying
  2665. ** to promote to an exclusive lock. The first process cannot proceed
  2666. ** because it is blocked by the second and the second process cannot
  2667. ** proceed because it is blocked by the first. If both processes
  2668. ** invoke the busy handlers, neither will make any progress. Therefore,
  2669. ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
  2670. ** will induce the first process to release its read lock and allow
  2671. ** the second process to proceed.
  2672. **
  2673. ** ^The default busy callback is NULL.
  2674. **
  2675. ** ^(There can only be a single busy handler defined for each
  2676. ** [database connection]. Setting a new busy handler clears any
  2677. ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()]
  2678. ** or evaluating [PRAGMA busy_timeout=N] will change the
  2679. ** busy handler and thus clear any previously set busy handler.
  2680. **
  2681. ** The busy callback should not take any actions which modify the
  2682. ** database connection that invoked the busy handler. In other words,
  2683. ** the busy handler is not reentrant. Any such actions
  2684. ** result in undefined behavior.
  2685. **
  2686. ** A busy handler must not close the database connection
  2687. ** or [prepared statement] that invoked the busy handler.
  2688. */
  2689. SQLITE_API int sqlite3_busy_handler(sqlite3*,int(*)(void*,int),void*);
  2690. /*
  2691. ** CAPI3REF: Set A Busy Timeout
  2692. ** METHOD: sqlite3
  2693. **
  2694. ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
  2695. ** for a specified amount of time when a table is locked. ^The handler
  2696. ** will sleep multiple times until at least "ms" milliseconds of sleeping
  2697. ** have accumulated. ^After at least "ms" milliseconds of sleeping,
  2698. ** the handler returns 0 which causes [sqlite3_step()] to return
  2699. ** [SQLITE_BUSY].
  2700. **
  2701. ** ^Calling this routine with an argument less than or equal to zero
  2702. ** turns off all busy handlers.
  2703. **
  2704. ** ^(There can only be a single busy handler for a particular
  2705. ** [database connection] at any given moment. If another busy handler
  2706. ** was defined (using [sqlite3_busy_handler()]) prior to calling
  2707. ** this routine, that other busy handler is cleared.)^
  2708. **
  2709. ** See also: [PRAGMA busy_timeout]
  2710. */
  2711. SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
  2712. /*
  2713. ** CAPI3REF: Convenience Routines For Running Queries
  2714. ** METHOD: sqlite3
  2715. **
  2716. ** This is a legacy interface that is preserved for backwards compatibility.
  2717. ** Use of this interface is not recommended.
  2718. **
  2719. ** Definition: A <b>result table</b> is memory data structure created by the
  2720. ** [sqlite3_get_table()] interface. A result table records the
  2721. ** complete query results from one or more queries.
  2722. **
  2723. ** The table conceptually has a number of rows and columns. But
  2724. ** these numbers are not part of the result table itself. These
  2725. ** numbers are obtained separately. Let N be the number of rows
  2726. ** and M be the number of columns.
  2727. **
  2728. ** A result table is an array of pointers to zero-terminated UTF-8 strings.
  2729. ** There are (N+1)*M elements in the array. The first M pointers point
  2730. ** to zero-terminated strings that contain the names of the columns.
  2731. ** The remaining entries all point to query results. NULL values result
  2732. ** in NULL pointers. All other values are in their UTF-8 zero-terminated
  2733. ** string representation as returned by [sqlite3_column_text()].
  2734. **
  2735. ** A result table might consist of one or more memory allocations.
  2736. ** It is not safe to pass a result table directly to [sqlite3_free()].
  2737. ** A result table should be deallocated using [sqlite3_free_table()].
  2738. **
  2739. ** ^(As an example of the result table format, suppose a query result
  2740. ** is as follows:
  2741. **
  2742. ** <blockquote><pre>
  2743. ** Name | Age
  2744. ** -----------------------
  2745. ** Alice | 43
  2746. ** Bob | 28
  2747. ** Cindy | 21
  2748. ** </pre></blockquote>
  2749. **
  2750. ** There are two columns (M==2) and three rows (N==3). Thus the
  2751. ** result table has 8 entries. Suppose the result table is stored
  2752. ** in an array named azResult. Then azResult holds this content:
  2753. **
  2754. ** <blockquote><pre>
  2755. ** azResult&#91;0] = "Name";
  2756. ** azResult&#91;1] = "Age";
  2757. ** azResult&#91;2] = "Alice";
  2758. ** azResult&#91;3] = "43";
  2759. ** azResult&#91;4] = "Bob";
  2760. ** azResult&#91;5] = "28";
  2761. ** azResult&#91;6] = "Cindy";
  2762. ** azResult&#91;7] = "21";
  2763. ** </pre></blockquote>)^
  2764. **
  2765. ** ^The sqlite3_get_table() function evaluates one or more
  2766. ** semicolon-separated SQL statements in the zero-terminated UTF-8
  2767. ** string of its 2nd parameter and returns a result table to the
  2768. ** pointer given in its 3rd parameter.
  2769. **
  2770. ** After the application has finished with the result from sqlite3_get_table(),
  2771. ** it must pass the result table pointer to sqlite3_free_table() in order to
  2772. ** release the memory that was malloced. Because of the way the
  2773. ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
  2774. ** function must not try to call [sqlite3_free()] directly. Only
  2775. ** [sqlite3_free_table()] is able to release the memory properly and safely.
  2776. **
  2777. ** The sqlite3_get_table() interface is implemented as a wrapper around
  2778. ** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access
  2779. ** to any internal data structures of SQLite. It uses only the public
  2780. ** interface defined here. As a consequence, errors that occur in the
  2781. ** wrapper layer outside of the internal [sqlite3_exec()] call are not
  2782. ** reflected in subsequent calls to [sqlite3_errcode()] or
  2783. ** [sqlite3_errmsg()].
  2784. */
  2785. SQLITE_API int sqlite3_get_table(
  2786. sqlite3 *db, /* An open database */
  2787. const char *zSql, /* SQL to be evaluated */
  2788. char ***pazResult, /* Results of the query */
  2789. int *pnRow, /* Number of result rows written here */
  2790. int *pnColumn, /* Number of result columns written here */
  2791. char **pzErrmsg /* Error msg written here */
  2792. );
  2793. SQLITE_API void sqlite3_free_table(char **result);
  2794. /*
  2795. ** CAPI3REF: Formatted String Printing Functions
  2796. **
  2797. ** These routines are work-alikes of the "printf()" family of functions
  2798. ** from the standard C library.
  2799. ** These routines understand most of the common formatting options from
  2800. ** the standard library printf()
  2801. ** plus some additional non-standard formats ([%q], [%Q], [%w], and [%z]).
  2802. ** See the [built-in printf()] documentation for details.
  2803. **
  2804. ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
  2805. ** results into memory obtained from [sqlite3_malloc64()].
  2806. ** The strings returned by these two routines should be
  2807. ** released by [sqlite3_free()]. ^Both routines return a
  2808. ** NULL pointer if [sqlite3_malloc64()] is unable to allocate enough
  2809. ** memory to hold the resulting string.
  2810. **
  2811. ** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from
  2812. ** the standard C library. The result is written into the
  2813. ** buffer supplied as the second parameter whose size is given by
  2814. ** the first parameter. Note that the order of the
  2815. ** first two parameters is reversed from snprintf().)^ This is an
  2816. ** historical accident that cannot be fixed without breaking
  2817. ** backwards compatibility. ^(Note also that sqlite3_snprintf()
  2818. ** returns a pointer to its buffer instead of the number of
  2819. ** characters actually written into the buffer.)^ We admit that
  2820. ** the number of characters written would be a more useful return
  2821. ** value but we cannot change the implementation of sqlite3_snprintf()
  2822. ** now without breaking compatibility.
  2823. **
  2824. ** ^As long as the buffer size is greater than zero, sqlite3_snprintf()
  2825. ** guarantees that the buffer is always zero-terminated. ^The first
  2826. ** parameter "n" is the total size of the buffer, including space for
  2827. ** the zero terminator. So the longest string that can be completely
  2828. ** written will be n-1 characters.
  2829. **
  2830. ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
  2831. **
  2832. ** See also: [built-in printf()], [printf() SQL function]
  2833. */
  2834. SQLITE_API char *sqlite3_mprintf(const char*,...);
  2835. SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
  2836. SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
  2837. SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
  2838. /*
  2839. ** CAPI3REF: Memory Allocation Subsystem
  2840. **
  2841. ** The SQLite core uses these three routines for all of its own
  2842. ** internal memory allocation needs. "Core" in the previous sentence
  2843. ** does not include operating-system specific [VFS] implementation. The
  2844. ** Windows VFS uses native malloc() and free() for some operations.
  2845. **
  2846. ** ^The sqlite3_malloc() routine returns a pointer to a block
  2847. ** of memory at least N bytes in length, where N is the parameter.
  2848. ** ^If sqlite3_malloc() is unable to obtain sufficient free
  2849. ** memory, it returns a NULL pointer. ^If the parameter N to
  2850. ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
  2851. ** a NULL pointer.
  2852. **
  2853. ** ^The sqlite3_malloc64(N) routine works just like
  2854. ** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead
  2855. ** of a signed 32-bit integer.
  2856. **
  2857. ** ^Calling sqlite3_free() with a pointer previously returned
  2858. ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
  2859. ** that it might be reused. ^The sqlite3_free() routine is
  2860. ** a no-op if is called with a NULL pointer. Passing a NULL pointer
  2861. ** to sqlite3_free() is harmless. After being freed, memory
  2862. ** should neither be read nor written. Even reading previously freed
  2863. ** memory might result in a segmentation fault or other severe error.
  2864. ** Memory corruption, a segmentation fault, or other severe error
  2865. ** might result if sqlite3_free() is called with a non-NULL pointer that
  2866. ** was not obtained from sqlite3_malloc() or sqlite3_realloc().
  2867. **
  2868. ** ^The sqlite3_realloc(X,N) interface attempts to resize a
  2869. ** prior memory allocation X to be at least N bytes.
  2870. ** ^If the X parameter to sqlite3_realloc(X,N)
  2871. ** is a NULL pointer then its behavior is identical to calling
  2872. ** sqlite3_malloc(N).
  2873. ** ^If the N parameter to sqlite3_realloc(X,N) is zero or
  2874. ** negative then the behavior is exactly the same as calling
  2875. ** sqlite3_free(X).
  2876. ** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
  2877. ** of at least N bytes in size or NULL if insufficient memory is available.
  2878. ** ^If M is the size of the prior allocation, then min(N,M) bytes
  2879. ** of the prior allocation are copied into the beginning of buffer returned
  2880. ** by sqlite3_realloc(X,N) and the prior allocation is freed.
  2881. ** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
  2882. ** prior allocation is not freed.
  2883. **
  2884. ** ^The sqlite3_realloc64(X,N) interfaces works the same as
  2885. ** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
  2886. ** of a 32-bit signed integer.
  2887. **
  2888. ** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
  2889. ** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
  2890. ** sqlite3_msize(X) returns the size of that memory allocation in bytes.
  2891. ** ^The value returned by sqlite3_msize(X) might be larger than the number
  2892. ** of bytes requested when X was allocated. ^If X is a NULL pointer then
  2893. ** sqlite3_msize(X) returns zero. If X points to something that is not
  2894. ** the beginning of memory allocation, or if it points to a formerly
  2895. ** valid memory allocation that has now been freed, then the behavior
  2896. ** of sqlite3_msize(X) is undefined and possibly harmful.
  2897. **
  2898. ** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(),
  2899. ** sqlite3_malloc64(), and sqlite3_realloc64()
  2900. ** is always aligned to at least an 8 byte boundary, or to a
  2901. ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
  2902. ** option is used.
  2903. **
  2904. ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
  2905. ** must be either NULL or else pointers obtained from a prior
  2906. ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
  2907. ** not yet been released.
  2908. **
  2909. ** The application must not read or write any part of
  2910. ** a block of memory after it has been released using
  2911. ** [sqlite3_free()] or [sqlite3_realloc()].
  2912. */
  2913. SQLITE_API void *sqlite3_malloc(int);
  2914. SQLITE_API void *sqlite3_malloc64(sqlite3_uint64);
  2915. SQLITE_API void *sqlite3_realloc(void*, int);
  2916. SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64);
  2917. SQLITE_API void sqlite3_free(void*);
  2918. SQLITE_API sqlite3_uint64 sqlite3_msize(void*);
  2919. /*
  2920. ** CAPI3REF: Memory Allocator Statistics
  2921. **
  2922. ** SQLite provides these two interfaces for reporting on the status
  2923. ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
  2924. ** routines, which form the built-in memory allocation subsystem.
  2925. **
  2926. ** ^The [sqlite3_memory_used()] routine returns the number of bytes
  2927. ** of memory currently outstanding (malloced but not freed).
  2928. ** ^The [sqlite3_memory_highwater()] routine returns the maximum
  2929. ** value of [sqlite3_memory_used()] since the high-water mark
  2930. ** was last reset. ^The values returned by [sqlite3_memory_used()] and
  2931. ** [sqlite3_memory_highwater()] include any overhead
  2932. ** added by SQLite in its implementation of [sqlite3_malloc()],
  2933. ** but not overhead added by the any underlying system library
  2934. ** routines that [sqlite3_malloc()] may call.
  2935. **
  2936. ** ^The memory high-water mark is reset to the current value of
  2937. ** [sqlite3_memory_used()] if and only if the parameter to
  2938. ** [sqlite3_memory_highwater()] is true. ^The value returned
  2939. ** by [sqlite3_memory_highwater(1)] is the high-water mark
  2940. ** prior to the reset.
  2941. */
  2942. SQLITE_API sqlite3_int64 sqlite3_memory_used(void);
  2943. SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
  2944. /*
  2945. ** CAPI3REF: Pseudo-Random Number Generator
  2946. **
  2947. ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
  2948. ** select random [ROWID | ROWIDs] when inserting new records into a table that
  2949. ** already uses the largest possible [ROWID]. The PRNG is also used for
  2950. ** the built-in random() and randomblob() SQL functions. This interface allows
  2951. ** applications to access the same PRNG for other purposes.
  2952. **
  2953. ** ^A call to this routine stores N bytes of randomness into buffer P.
  2954. ** ^The P parameter can be a NULL pointer.
  2955. **
  2956. ** ^If this routine has not been previously called or if the previous
  2957. ** call had N less than one or a NULL pointer for P, then the PRNG is
  2958. ** seeded using randomness obtained from the xRandomness method of
  2959. ** the default [sqlite3_vfs] object.
  2960. ** ^If the previous call to this routine had an N of 1 or more and a
  2961. ** non-NULL P then the pseudo-randomness is generated
  2962. ** internally and without recourse to the [sqlite3_vfs] xRandomness
  2963. ** method.
  2964. */
  2965. SQLITE_API void sqlite3_randomness(int N, void *P);
  2966. /*
  2967. ** CAPI3REF: Compile-Time Authorization Callbacks
  2968. ** METHOD: sqlite3
  2969. ** KEYWORDS: {authorizer callback}
  2970. **
  2971. ** ^This routine registers an authorizer callback with a particular
  2972. ** [database connection], supplied in the first argument.
  2973. ** ^The authorizer callback is invoked as SQL statements are being compiled
  2974. ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
  2975. ** [sqlite3_prepare_v3()], [sqlite3_prepare16()], [sqlite3_prepare16_v2()],
  2976. ** and [sqlite3_prepare16_v3()]. ^At various
  2977. ** points during the compilation process, as logic is being created
  2978. ** to perform various actions, the authorizer callback is invoked to
  2979. ** see if those actions are allowed. ^The authorizer callback should
  2980. ** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the
  2981. ** specific action but allow the SQL statement to continue to be
  2982. ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
  2983. ** rejected with an error. ^If the authorizer callback returns
  2984. ** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]
  2985. ** then the [sqlite3_prepare_v2()] or equivalent call that triggered
  2986. ** the authorizer will fail with an error message.
  2987. **
  2988. ** When the callback returns [SQLITE_OK], that means the operation
  2989. ** requested is ok. ^When the callback returns [SQLITE_DENY], the
  2990. ** [sqlite3_prepare_v2()] or equivalent call that triggered the
  2991. ** authorizer will fail with an error message explaining that
  2992. ** access is denied.
  2993. **
  2994. ** ^The first parameter to the authorizer callback is a copy of the third
  2995. ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
  2996. ** to the callback is an integer [SQLITE_COPY | action code] that specifies
  2997. ** the particular action to be authorized. ^The third through sixth parameters
  2998. ** to the callback are either NULL pointers or zero-terminated strings
  2999. ** that contain additional details about the action to be authorized.
  3000. ** Applications must always be prepared to encounter a NULL pointer in any
  3001. ** of the third through the sixth parameters of the authorization callback.
  3002. **
  3003. ** ^If the action code is [SQLITE_READ]
  3004. ** and the callback returns [SQLITE_IGNORE] then the
  3005. ** [prepared statement] statement is constructed to substitute
  3006. ** a NULL value in place of the table column that would have
  3007. ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE]
  3008. ** return can be used to deny an untrusted user access to individual
  3009. ** columns of a table.
  3010. ** ^When a table is referenced by a [SELECT] but no column values are
  3011. ** extracted from that table (for example in a query like
  3012. ** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback
  3013. ** is invoked once for that table with a column name that is an empty string.
  3014. ** ^If the action code is [SQLITE_DELETE] and the callback returns
  3015. ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
  3016. ** [truncate optimization] is disabled and all rows are deleted individually.
  3017. **
  3018. ** An authorizer is used when [sqlite3_prepare | preparing]
  3019. ** SQL statements from an untrusted source, to ensure that the SQL statements
  3020. ** do not try to access data they are not allowed to see, or that they do not
  3021. ** try to execute malicious statements that damage the database. For
  3022. ** example, an application may allow a user to enter arbitrary
  3023. ** SQL queries for evaluation by a database. But the application does
  3024. ** not want the user to be able to make arbitrary changes to the
  3025. ** database. An authorizer could then be put in place while the
  3026. ** user-entered SQL is being [sqlite3_prepare | prepared] that
  3027. ** disallows everything except [SELECT] statements.
  3028. **
  3029. ** Applications that need to process SQL from untrusted sources
  3030. ** might also consider lowering resource limits using [sqlite3_limit()]
  3031. ** and limiting database size using the [max_page_count] [PRAGMA]
  3032. ** in addition to using an authorizer.
  3033. **
  3034. ** ^(Only a single authorizer can be in place on a database connection
  3035. ** at a time. Each call to sqlite3_set_authorizer overrides the
  3036. ** previous call.)^ ^Disable the authorizer by installing a NULL callback.
  3037. ** The authorizer is disabled by default.
  3038. **
  3039. ** The authorizer callback must not do anything that will modify
  3040. ** the database connection that invoked the authorizer callback.
  3041. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  3042. ** database connections for the meaning of "modify" in this paragraph.
  3043. **
  3044. ** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the
  3045. ** statement might be re-prepared during [sqlite3_step()] due to a
  3046. ** schema change. Hence, the application should ensure that the
  3047. ** correct authorizer callback remains in place during the [sqlite3_step()].
  3048. **
  3049. ** ^Note that the authorizer callback is invoked only during
  3050. ** [sqlite3_prepare()] or its variants. Authorization is not
  3051. ** performed during statement evaluation in [sqlite3_step()], unless
  3052. ** as stated in the previous paragraph, sqlite3_step() invokes
  3053. ** sqlite3_prepare_v2() to reprepare a statement after a schema change.
  3054. */
  3055. SQLITE_API int sqlite3_set_authorizer(
  3056. sqlite3*,
  3057. int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
  3058. void *pUserData
  3059. );
  3060. /*
  3061. ** CAPI3REF: Authorizer Return Codes
  3062. **
  3063. ** The [sqlite3_set_authorizer | authorizer callback function] must
  3064. ** return either [SQLITE_OK] or one of these two constants in order
  3065. ** to signal SQLite whether or not the action is permitted. See the
  3066. ** [sqlite3_set_authorizer | authorizer documentation] for additional
  3067. ** information.
  3068. **
  3069. ** Note that SQLITE_IGNORE is also used as a [conflict resolution mode]
  3070. ** returned from the [sqlite3_vtab_on_conflict()] interface.
  3071. */
  3072. #define SQLITE_DENY 1 /* Abort the SQL statement with an error */
  3073. #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
  3074. /*
  3075. ** CAPI3REF: Authorizer Action Codes
  3076. **
  3077. ** The [sqlite3_set_authorizer()] interface registers a callback function
  3078. ** that is invoked to authorize certain SQL statement actions. The
  3079. ** second parameter to the callback is an integer code that specifies
  3080. ** what action is being authorized. These are the integer action codes that
  3081. ** the authorizer callback may be passed.
  3082. **
  3083. ** These action code values signify what kind of operation is to be
  3084. ** authorized. The 3rd and 4th parameters to the authorization
  3085. ** callback function will be parameters or NULL depending on which of these
  3086. ** codes is used as the second parameter. ^(The 5th parameter to the
  3087. ** authorizer callback is the name of the database ("main", "temp",
  3088. ** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback
  3089. ** is the name of the inner-most trigger or view that is responsible for
  3090. ** the access attempt or NULL if this access attempt is directly from
  3091. ** top-level SQL code.
  3092. */
  3093. /******************************************* 3rd ************ 4th ***********/
  3094. #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
  3095. #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
  3096. #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
  3097. #define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */
  3098. #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */
  3099. #define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */
  3100. #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */
  3101. #define SQLITE_CREATE_VIEW 8 /* View Name NULL */
  3102. #define SQLITE_DELETE 9 /* Table Name NULL */
  3103. #define SQLITE_DROP_INDEX 10 /* Index Name Table Name */
  3104. #define SQLITE_DROP_TABLE 11 /* Table Name NULL */
  3105. #define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */
  3106. #define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */
  3107. #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */
  3108. #define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */
  3109. #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */
  3110. #define SQLITE_DROP_VIEW 17 /* View Name NULL */
  3111. #define SQLITE_INSERT 18 /* Table Name NULL */
  3112. #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */
  3113. #define SQLITE_READ 20 /* Table Name Column Name */
  3114. #define SQLITE_SELECT 21 /* NULL NULL */
  3115. #define SQLITE_TRANSACTION 22 /* Operation NULL */
  3116. #define SQLITE_UPDATE 23 /* Table Name Column Name */
  3117. #define SQLITE_ATTACH 24 /* Filename NULL */
  3118. #define SQLITE_DETACH 25 /* Database Name NULL */
  3119. #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
  3120. #define SQLITE_REINDEX 27 /* Index Name NULL */
  3121. #define SQLITE_ANALYZE 28 /* Table Name NULL */
  3122. #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
  3123. #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
  3124. #define SQLITE_FUNCTION 31 /* NULL Function Name */
  3125. #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
  3126. #define SQLITE_COPY 0 /* No longer used */
  3127. #define SQLITE_RECURSIVE 33 /* NULL NULL */
  3128. /*
  3129. ** CAPI3REF: Tracing And Profiling Functions
  3130. ** METHOD: sqlite3
  3131. **
  3132. ** These routines are deprecated. Use the [sqlite3_trace_v2()] interface
  3133. ** instead of the routines described here.
  3134. **
  3135. ** These routines register callback functions that can be used for
  3136. ** tracing and profiling the execution of SQL statements.
  3137. **
  3138. ** ^The callback function registered by sqlite3_trace() is invoked at
  3139. ** various times when an SQL statement is being run by [sqlite3_step()].
  3140. ** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the
  3141. ** SQL statement text as the statement first begins executing.
  3142. ** ^(Additional sqlite3_trace() callbacks might occur
  3143. ** as each triggered subprogram is entered. The callbacks for triggers
  3144. ** contain a UTF-8 SQL comment that identifies the trigger.)^
  3145. **
  3146. ** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit
  3147. ** the length of [bound parameter] expansion in the output of sqlite3_trace().
  3148. **
  3149. ** ^The callback function registered by sqlite3_profile() is invoked
  3150. ** as each SQL statement finishes. ^The profile callback contains
  3151. ** the original statement text and an estimate of wall-clock time
  3152. ** of how long that statement took to run. ^The profile callback
  3153. ** time is in units of nanoseconds, however the current implementation
  3154. ** is only capable of millisecond resolution so the six least significant
  3155. ** digits in the time are meaningless. Future versions of SQLite
  3156. ** might provide greater resolution on the profiler callback. Invoking
  3157. ** either [sqlite3_trace()] or [sqlite3_trace_v2()] will cancel the
  3158. ** profile callback.
  3159. */
  3160. SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(sqlite3*,
  3161. void(*xTrace)(void*,const char*), void*);
  3162. SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*,
  3163. void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
  3164. /*
  3165. ** CAPI3REF: SQL Trace Event Codes
  3166. ** KEYWORDS: SQLITE_TRACE
  3167. **
  3168. ** These constants identify classes of events that can be monitored
  3169. ** using the [sqlite3_trace_v2()] tracing logic. The M argument
  3170. ** to [sqlite3_trace_v2(D,M,X,P)] is an OR-ed combination of one or more of
  3171. ** the following constants. ^The first argument to the trace callback
  3172. ** is one of the following constants.
  3173. **
  3174. ** New tracing constants may be added in future releases.
  3175. **
  3176. ** ^A trace callback has four arguments: xCallback(T,C,P,X).
  3177. ** ^The T argument is one of the integer type codes above.
  3178. ** ^The C argument is a copy of the context pointer passed in as the
  3179. ** fourth argument to [sqlite3_trace_v2()].
  3180. ** The P and X arguments are pointers whose meanings depend on T.
  3181. **
  3182. ** <dl>
  3183. ** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt>
  3184. ** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement
  3185. ** first begins running and possibly at other times during the
  3186. ** execution of the prepared statement, such as at the start of each
  3187. ** trigger subprogram. ^The P argument is a pointer to the
  3188. ** [prepared statement]. ^The X argument is a pointer to a string which
  3189. ** is the unexpanded SQL text of the prepared statement or an SQL comment
  3190. ** that indicates the invocation of a trigger. ^The callback can compute
  3191. ** the same text that would have been returned by the legacy [sqlite3_trace()]
  3192. ** interface by using the X argument when X begins with "--" and invoking
  3193. ** [sqlite3_expanded_sql(P)] otherwise.
  3194. **
  3195. ** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>
  3196. ** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
  3197. ** information as is provided by the [sqlite3_profile()] callback.
  3198. ** ^The P argument is a pointer to the [prepared statement] and the
  3199. ** X argument points to a 64-bit integer which is the estimated of
  3200. ** the number of nanosecond that the prepared statement took to run.
  3201. ** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
  3202. **
  3203. ** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
  3204. ** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared
  3205. ** statement generates a single row of result.
  3206. ** ^The P argument is a pointer to the [prepared statement] and the
  3207. ** X argument is unused.
  3208. **
  3209. ** [[SQLITE_TRACE_CLOSE]] <dt>SQLITE_TRACE_CLOSE</dt>
  3210. ** <dd>^An SQLITE_TRACE_CLOSE callback is invoked when a database
  3211. ** connection closes.
  3212. ** ^The P argument is a pointer to the [database connection] object
  3213. ** and the X argument is unused.
  3214. ** </dl>
  3215. */
  3216. #define SQLITE_TRACE_STMT 0x01
  3217. #define SQLITE_TRACE_PROFILE 0x02
  3218. #define SQLITE_TRACE_ROW 0x04
  3219. #define SQLITE_TRACE_CLOSE 0x08
  3220. /*
  3221. ** CAPI3REF: SQL Trace Hook
  3222. ** METHOD: sqlite3
  3223. **
  3224. ** ^The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback
  3225. ** function X against [database connection] D, using property mask M
  3226. ** and context pointer P. ^If the X callback is
  3227. ** NULL or if the M mask is zero, then tracing is disabled. The
  3228. ** M argument should be the bitwise OR-ed combination of
  3229. ** zero or more [SQLITE_TRACE] constants.
  3230. **
  3231. ** ^Each call to either sqlite3_trace() or sqlite3_trace_v2() overrides
  3232. ** (cancels) any prior calls to sqlite3_trace() or sqlite3_trace_v2().
  3233. **
  3234. ** ^The X callback is invoked whenever any of the events identified by
  3235. ** mask M occur. ^The integer return value from the callback is currently
  3236. ** ignored, though this may change in future releases. Callback
  3237. ** implementations should return zero to ensure future compatibility.
  3238. **
  3239. ** ^A trace callback is invoked with four arguments: callback(T,C,P,X).
  3240. ** ^The T argument is one of the [SQLITE_TRACE]
  3241. ** constants to indicate why the callback was invoked.
  3242. ** ^The C argument is a copy of the context pointer.
  3243. ** The P and X arguments are pointers whose meanings depend on T.
  3244. **
  3245. ** The sqlite3_trace_v2() interface is intended to replace the legacy
  3246. ** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which
  3247. ** are deprecated.
  3248. */
  3249. SQLITE_API int sqlite3_trace_v2(
  3250. sqlite3*,
  3251. unsigned uMask,
  3252. int(*xCallback)(unsigned,void*,void*,void*),
  3253. void *pCtx
  3254. );
  3255. /*
  3256. ** CAPI3REF: Query Progress Callbacks
  3257. ** METHOD: sqlite3
  3258. **
  3259. ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
  3260. ** function X to be invoked periodically during long running calls to
  3261. ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
  3262. ** database connection D. An example use for this
  3263. ** interface is to keep a GUI updated during a large query.
  3264. **
  3265. ** ^The parameter P is passed through as the only parameter to the
  3266. ** callback function X. ^The parameter N is the approximate number of
  3267. ** [virtual machine instructions] that are evaluated between successive
  3268. ** invocations of the callback X. ^If N is less than one then the progress
  3269. ** handler is disabled.
  3270. **
  3271. ** ^Only a single progress handler may be defined at one time per
  3272. ** [database connection]; setting a new progress handler cancels the
  3273. ** old one. ^Setting parameter X to NULL disables the progress handler.
  3274. ** ^The progress handler is also disabled by setting N to a value less
  3275. ** than 1.
  3276. **
  3277. ** ^If the progress callback returns non-zero, the operation is
  3278. ** interrupted. This feature can be used to implement a
  3279. ** "Cancel" button on a GUI progress dialog box.
  3280. **
  3281. ** The progress handler callback must not do anything that will modify
  3282. ** the database connection that invoked the progress handler.
  3283. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  3284. ** database connections for the meaning of "modify" in this paragraph.
  3285. **
  3286. */
  3287. SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
  3288. /*
  3289. ** CAPI3REF: Opening A New Database Connection
  3290. ** CONSTRUCTOR: sqlite3
  3291. **
  3292. ** ^These routines open an SQLite database file as specified by the
  3293. ** filename argument. ^The filename argument is interpreted as UTF-8 for
  3294. ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
  3295. ** order for sqlite3_open16(). ^(A [database connection] handle is usually
  3296. ** returned in *ppDb, even if an error occurs. The only exception is that
  3297. ** if SQLite is unable to allocate memory to hold the [sqlite3] object,
  3298. ** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]
  3299. ** object.)^ ^(If the database is opened (and/or created) successfully, then
  3300. ** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The
  3301. ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
  3302. ** an English language description of the error following a failure of any
  3303. ** of the sqlite3_open() routines.
  3304. **
  3305. ** ^The default encoding will be UTF-8 for databases created using
  3306. ** sqlite3_open() or sqlite3_open_v2(). ^The default encoding for databases
  3307. ** created using sqlite3_open16() will be UTF-16 in the native byte order.
  3308. **
  3309. ** Whether or not an error occurs when it is opened, resources
  3310. ** associated with the [database connection] handle should be released by
  3311. ** passing it to [sqlite3_close()] when it is no longer required.
  3312. **
  3313. ** The sqlite3_open_v2() interface works like sqlite3_open()
  3314. ** except that it accepts two additional parameters for additional control
  3315. ** over the new database connection. ^(The flags parameter to
  3316. ** sqlite3_open_v2() must include, at a minimum, one of the following
  3317. ** three flag combinations:)^
  3318. **
  3319. ** <dl>
  3320. ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
  3321. ** <dd>The database is opened in read-only mode. If the database does not
  3322. ** already exist, an error is returned.</dd>)^
  3323. **
  3324. ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
  3325. ** <dd>The database is opened for reading and writing if possible, or reading
  3326. ** only if the file is write protected by the operating system. In either
  3327. ** case the database must already exist, otherwise an error is returned.</dd>)^
  3328. **
  3329. ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
  3330. ** <dd>The database is opened for reading and writing, and is created if
  3331. ** it does not already exist. This is the behavior that is always used for
  3332. ** sqlite3_open() and sqlite3_open16().</dd>)^
  3333. ** </dl>
  3334. **
  3335. ** In addition to the required flags, the following optional flags are
  3336. ** also supported:
  3337. **
  3338. ** <dl>
  3339. ** ^(<dt>[SQLITE_OPEN_URI]</dt>
  3340. ** <dd>The filename can be interpreted as a URI if this flag is set.</dd>)^
  3341. **
  3342. ** ^(<dt>[SQLITE_OPEN_MEMORY]</dt>
  3343. ** <dd>The database will be opened as an in-memory database. The database
  3344. ** is named by the "filename" argument for the purposes of cache-sharing,
  3345. ** if shared cache mode is enabled, but the "filename" is otherwise ignored.
  3346. ** </dd>)^
  3347. **
  3348. ** ^(<dt>[SQLITE_OPEN_NOMUTEX]</dt>
  3349. ** <dd>The new database connection will use the "multi-thread"
  3350. ** [threading mode].)^ This means that separate threads are allowed
  3351. ** to use SQLite at the same time, as long as each thread is using
  3352. ** a different [database connection].
  3353. **
  3354. ** ^(<dt>[SQLITE_OPEN_FULLMUTEX]</dt>
  3355. ** <dd>The new database connection will use the "serialized"
  3356. ** [threading mode].)^ This means the multiple threads can safely
  3357. ** attempt to use the same database connection at the same time.
  3358. ** (Mutexes will block any actual concurrency, but in this mode
  3359. ** there is no harm in trying.)
  3360. **
  3361. ** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>
  3362. ** <dd>The database is opened [shared cache] enabled, overriding
  3363. ** the default shared cache setting provided by
  3364. ** [sqlite3_enable_shared_cache()].)^
  3365. **
  3366. ** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
  3367. ** <dd>The database is opened [shared cache] disabled, overriding
  3368. ** the default shared cache setting provided by
  3369. ** [sqlite3_enable_shared_cache()].)^
  3370. **
  3371. ** [[OPEN_EXRESCODE]] ^(<dt>[SQLITE_OPEN_EXRESCODE]</dt>
  3372. ** <dd>The database connection comes up in "extended result code mode".
  3373. ** In other words, the database behaves has if
  3374. ** [sqlite3_extended_result_codes(db,1)] where called on the database
  3375. ** connection as soon as the connection is created. In addition to setting
  3376. ** the extended result code mode, this flag also causes [sqlite3_open_v2()]
  3377. ** to return an extended result code.</dd>
  3378. **
  3379. ** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
  3380. ** <dd>The database filename is not allowed to be a symbolic link</dd>
  3381. ** </dl>)^
  3382. **
  3383. ** If the 3rd parameter to sqlite3_open_v2() is not one of the
  3384. ** required combinations shown above optionally combined with other
  3385. ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
  3386. ** then the behavior is undefined. Historic versions of SQLite
  3387. ** have silently ignored surplus bits in the flags parameter to
  3388. ** sqlite3_open_v2(), however that behavior might not be carried through
  3389. ** into future versions of SQLite and so applications should not rely
  3390. ** upon it. Note in particular that the SQLITE_OPEN_EXCLUSIVE flag is a no-op
  3391. ** for sqlite3_open_v2(). The SQLITE_OPEN_EXCLUSIVE does *not* cause
  3392. ** the open to fail if the database already exists. The SQLITE_OPEN_EXCLUSIVE
  3393. ** flag is intended for use by the [sqlite3_vfs|VFS interface] only, and not
  3394. ** by sqlite3_open_v2().
  3395. **
  3396. ** ^The fourth parameter to sqlite3_open_v2() is the name of the
  3397. ** [sqlite3_vfs] object that defines the operating system interface that
  3398. ** the new database connection should use. ^If the fourth parameter is
  3399. ** a NULL pointer then the default [sqlite3_vfs] object is used.
  3400. **
  3401. ** ^If the filename is ":memory:", then a private, temporary in-memory database
  3402. ** is created for the connection. ^This in-memory database will vanish when
  3403. ** the database connection is closed. Future versions of SQLite might
  3404. ** make use of additional special filenames that begin with the ":" character.
  3405. ** It is recommended that when a database filename actually does begin with
  3406. ** a ":" character you should prefix the filename with a pathname such as
  3407. ** "./" to avoid ambiguity.
  3408. **
  3409. ** ^If the filename is an empty string, then a private, temporary
  3410. ** on-disk database will be created. ^This private database will be
  3411. ** automatically deleted as soon as the database connection is closed.
  3412. **
  3413. ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
  3414. **
  3415. ** ^If [URI filename] interpretation is enabled, and the filename argument
  3416. ** begins with "file:", then the filename is interpreted as a URI. ^URI
  3417. ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
  3418. ** set in the third argument to sqlite3_open_v2(), or if it has
  3419. ** been enabled globally using the [SQLITE_CONFIG_URI] option with the
  3420. ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
  3421. ** URI filename interpretation is turned off
  3422. ** by default, but future releases of SQLite might enable URI filename
  3423. ** interpretation by default. See "[URI filenames]" for additional
  3424. ** information.
  3425. **
  3426. ** URI filenames are parsed according to RFC 3986. ^If the URI contains an
  3427. ** authority, then it must be either an empty string or the string
  3428. ** "localhost". ^If the authority is not an empty string or "localhost", an
  3429. ** error is returned to the caller. ^The fragment component of a URI, if
  3430. ** present, is ignored.
  3431. **
  3432. ** ^SQLite uses the path component of the URI as the name of the disk file
  3433. ** which contains the database. ^If the path begins with a '/' character,
  3434. ** then it is interpreted as an absolute path. ^If the path does not begin
  3435. ** with a '/' (meaning that the authority section is omitted from the URI)
  3436. ** then the path is interpreted as a relative path.
  3437. ** ^(On windows, the first component of an absolute path
  3438. ** is a drive specification (e.g. "C:").)^
  3439. **
  3440. ** [[core URI query parameters]]
  3441. ** The query component of a URI may contain parameters that are interpreted
  3442. ** either by SQLite itself, or by a [VFS | custom VFS implementation].
  3443. ** SQLite and its built-in [VFSes] interpret the
  3444. ** following query parameters:
  3445. **
  3446. ** <ul>
  3447. ** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
  3448. ** a VFS object that provides the operating system interface that should
  3449. ** be used to access the database file on disk. ^If this option is set to
  3450. ** an empty string the default VFS object is used. ^Specifying an unknown
  3451. ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
  3452. ** present, then the VFS specified by the option takes precedence over
  3453. ** the value passed as the fourth parameter to sqlite3_open_v2().
  3454. **
  3455. ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
  3456. ** "rwc", or "memory". Attempting to set it to any other value is
  3457. ** an error)^.
  3458. ** ^If "ro" is specified, then the database is opened for read-only
  3459. ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
  3460. ** third argument to sqlite3_open_v2(). ^If the mode option is set to
  3461. ** "rw", then the database is opened for read-write (but not create)
  3462. ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
  3463. ** been set. ^Value "rwc" is equivalent to setting both
  3464. ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is
  3465. ** set to "memory" then a pure [in-memory database] that never reads
  3466. ** or writes from disk is used. ^It is an error to specify a value for
  3467. ** the mode parameter that is less restrictive than that specified by
  3468. ** the flags passed in the third parameter to sqlite3_open_v2().
  3469. **
  3470. ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
  3471. ** "private". ^Setting it to "shared" is equivalent to setting the
  3472. ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
  3473. ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
  3474. ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
  3475. ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
  3476. ** a URI filename, its value overrides any behavior requested by setting
  3477. ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
  3478. **
  3479. ** <li> <b>psow</b>: ^The psow parameter indicates whether or not the
  3480. ** [powersafe overwrite] property does or does not apply to the
  3481. ** storage media on which the database file resides.
  3482. **
  3483. ** <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter
  3484. ** which if set disables file locking in rollback journal modes. This
  3485. ** is useful for accessing a database on a filesystem that does not
  3486. ** support locking. Caution: Database corruption might result if two
  3487. ** or more processes write to the same database and any one of those
  3488. ** processes uses nolock=1.
  3489. **
  3490. ** <li> <b>immutable</b>: ^The immutable parameter is a boolean query
  3491. ** parameter that indicates that the database file is stored on
  3492. ** read-only media. ^When immutable is set, SQLite assumes that the
  3493. ** database file cannot be changed, even by a process with higher
  3494. ** privilege, and so the database is opened read-only and all locking
  3495. ** and change detection is disabled. Caution: Setting the immutable
  3496. ** property on a database file that does in fact change can result
  3497. ** in incorrect query results and/or [SQLITE_CORRUPT] errors.
  3498. ** See also: [SQLITE_IOCAP_IMMUTABLE].
  3499. **
  3500. ** </ul>
  3501. **
  3502. ** ^Specifying an unknown parameter in the query component of a URI is not an
  3503. ** error. Future versions of SQLite might understand additional query
  3504. ** parameters. See "[query parameters with special meaning to SQLite]" for
  3505. ** additional information.
  3506. **
  3507. ** [[URI filename examples]] <h3>URI filename examples</h3>
  3508. **
  3509. ** <table border="1" align=center cellpadding=5>
  3510. ** <tr><th> URI filenames <th> Results
  3511. ** <tr><td> file:data.db <td>
  3512. ** Open the file "data.db" in the current directory.
  3513. ** <tr><td> file:/home/fred/data.db<br>
  3514. ** file:///home/fred/data.db <br>
  3515. ** file://localhost/home/fred/data.db <br> <td>
  3516. ** Open the database file "/home/fred/data.db".
  3517. ** <tr><td> file://darkstar/home/fred/data.db <td>
  3518. ** An error. "darkstar" is not a recognized authority.
  3519. ** <tr><td style="white-space:nowrap">
  3520. ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
  3521. ** <td> Windows only: Open the file "data.db" on fred's desktop on drive
  3522. ** C:. Note that the %20 escaping in this example is not strictly
  3523. ** necessary - space characters can be used literally
  3524. ** in URI filenames.
  3525. ** <tr><td> file:data.db?mode=ro&cache=private <td>
  3526. ** Open file "data.db" in the current directory for read-only access.
  3527. ** Regardless of whether or not shared-cache mode is enabled by
  3528. ** default, use a private cache.
  3529. ** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td>
  3530. ** Open file "/home/fred/data.db". Use the special VFS "unix-dotfile"
  3531. ** that uses dot-files in place of posix advisory locking.
  3532. ** <tr><td> file:data.db?mode=readonly <td>
  3533. ** An error. "readonly" is not a valid option for the "mode" parameter.
  3534. ** Use "ro" instead: "file:data.db?mode=ro".
  3535. ** </table>
  3536. **
  3537. ** ^URI hexadecimal escape sequences (%HH) are supported within the path and
  3538. ** query components of a URI. A hexadecimal escape sequence consists of a
  3539. ** percent sign - "%" - followed by exactly two hexadecimal digits
  3540. ** specifying an octet value. ^Before the path or query components of a
  3541. ** URI filename are interpreted, they are encoded using UTF-8 and all
  3542. ** hexadecimal escape sequences replaced by a single byte containing the
  3543. ** corresponding octet. If this process generates an invalid UTF-8 encoding,
  3544. ** the results are undefined.
  3545. **
  3546. ** <b>Note to Windows users:</b> The encoding used for the filename argument
  3547. ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
  3548. ** codepage is currently defined. Filenames containing international
  3549. ** characters must be converted to UTF-8 prior to passing them into
  3550. ** sqlite3_open() or sqlite3_open_v2().
  3551. **
  3552. ** <b>Note to Windows Runtime users:</b> The temporary directory must be set
  3553. ** prior to calling sqlite3_open() or sqlite3_open_v2(). Otherwise, various
  3554. ** features that require the use of temporary files may fail.
  3555. **
  3556. ** See also: [sqlite3_temp_directory]
  3557. */
  3558. SQLITE_API int sqlite3_open(
  3559. const char *filename, /* Database filename (UTF-8) */
  3560. sqlite3 **ppDb /* OUT: SQLite db handle */
  3561. );
  3562. SQLITE_API int sqlite3_open16(
  3563. const void *filename, /* Database filename (UTF-16) */
  3564. sqlite3 **ppDb /* OUT: SQLite db handle */
  3565. );
  3566. SQLITE_API int sqlite3_open_v2(
  3567. const char *filename, /* Database filename (UTF-8) */
  3568. sqlite3 **ppDb, /* OUT: SQLite db handle */
  3569. int flags, /* Flags */
  3570. const char *zVfs /* Name of VFS module to use */
  3571. );
  3572. /*
  3573. ** CAPI3REF: Obtain Values For URI Parameters
  3574. **
  3575. ** These are utility routines, useful to [VFS|custom VFS implementations],
  3576. ** that check if a database file was a URI that contained a specific query
  3577. ** parameter, and if so obtains the value of that query parameter.
  3578. **
  3579. ** The first parameter to these interfaces (hereafter referred to
  3580. ** as F) must be one of:
  3581. ** <ul>
  3582. ** <li> A database filename pointer created by the SQLite core and
  3583. ** passed into the xOpen() method of a VFS implemention, or
  3584. ** <li> A filename obtained from [sqlite3_db_filename()], or
  3585. ** <li> A new filename constructed using [sqlite3_create_filename()].
  3586. ** </ul>
  3587. ** If the F parameter is not one of the above, then the behavior is
  3588. ** undefined and probably undesirable. Older versions of SQLite were
  3589. ** more tolerant of invalid F parameters than newer versions.
  3590. **
  3591. ** If F is a suitable filename (as described in the previous paragraph)
  3592. ** and if P is the name of the query parameter, then
  3593. ** sqlite3_uri_parameter(F,P) returns the value of the P
  3594. ** parameter if it exists or a NULL pointer if P does not appear as a
  3595. ** query parameter on F. If P is a query parameter of F and it
  3596. ** has no explicit value, then sqlite3_uri_parameter(F,P) returns
  3597. ** a pointer to an empty string.
  3598. **
  3599. ** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
  3600. ** parameter and returns true (1) or false (0) according to the value
  3601. ** of P. The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the
  3602. ** value of query parameter P is one of "yes", "true", or "on" in any
  3603. ** case or if the value begins with a non-zero number. The
  3604. ** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
  3605. ** query parameter P is one of "no", "false", or "off" in any case or
  3606. ** if the value begins with a numeric zero. If P is not a query
  3607. ** parameter on F or if the value of P does not match any of the
  3608. ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
  3609. **
  3610. ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
  3611. ** 64-bit signed integer and returns that integer, or D if P does not
  3612. ** exist. If the value of P is something other than an integer, then
  3613. ** zero is returned.
  3614. **
  3615. ** The sqlite3_uri_key(F,N) returns a pointer to the name (not
  3616. ** the value) of the N-th query parameter for filename F, or a NULL
  3617. ** pointer if N is less than zero or greater than the number of query
  3618. ** parameters minus 1. The N value is zero-based so N should be 0 to obtain
  3619. ** the name of the first query parameter, 1 for the second parameter, and
  3620. ** so forth.
  3621. **
  3622. ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
  3623. ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and
  3624. ** is not a database file pathname pointer that the SQLite core passed
  3625. ** into the xOpen VFS method, then the behavior of this routine is undefined
  3626. ** and probably undesirable.
  3627. **
  3628. ** Beginning with SQLite [version 3.31.0] ([dateof:3.31.0]) the input F
  3629. ** parameter can also be the name of a rollback journal file or WAL file
  3630. ** in addition to the main database file. Prior to version 3.31.0, these
  3631. ** routines would only work if F was the name of the main database file.
  3632. ** When the F parameter is the name of the rollback journal or WAL file,
  3633. ** it has access to all the same query parameters as were found on the
  3634. ** main database file.
  3635. **
  3636. ** See the [URI filename] documentation for additional information.
  3637. */
  3638. SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
  3639. SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
  3640. SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
  3641. SQLITE_API const char *sqlite3_uri_key(const char *zFilename, int N);
  3642. /*
  3643. ** CAPI3REF: Translate filenames
  3644. **
  3645. ** These routines are available to [VFS|custom VFS implementations] for
  3646. ** translating filenames between the main database file, the journal file,
  3647. ** and the WAL file.
  3648. **
  3649. ** If F is the name of an sqlite database file, journal file, or WAL file
  3650. ** passed by the SQLite core into the VFS, then sqlite3_filename_database(F)
  3651. ** returns the name of the corresponding database file.
  3652. **
  3653. ** If F is the name of an sqlite database file, journal file, or WAL file
  3654. ** passed by the SQLite core into the VFS, or if F is a database filename
  3655. ** obtained from [sqlite3_db_filename()], then sqlite3_filename_journal(F)
  3656. ** returns the name of the corresponding rollback journal file.
  3657. **
  3658. ** If F is the name of an sqlite database file, journal file, or WAL file
  3659. ** that was passed by the SQLite core into the VFS, or if F is a database
  3660. ** filename obtained from [sqlite3_db_filename()], then
  3661. ** sqlite3_filename_wal(F) returns the name of the corresponding
  3662. ** WAL file.
  3663. **
  3664. ** In all of the above, if F is not the name of a database, journal or WAL
  3665. ** filename passed into the VFS from the SQLite core and F is not the
  3666. ** return value from [sqlite3_db_filename()], then the result is
  3667. ** undefined and is likely a memory access violation.
  3668. */
  3669. SQLITE_API const char *sqlite3_filename_database(const char*);
  3670. SQLITE_API const char *sqlite3_filename_journal(const char*);
  3671. SQLITE_API const char *sqlite3_filename_wal(const char*);
  3672. /*
  3673. ** CAPI3REF: Database File Corresponding To A Journal
  3674. **
  3675. ** ^If X is the name of a rollback or WAL-mode journal file that is
  3676. ** passed into the xOpen method of [sqlite3_vfs], then
  3677. ** sqlite3_database_file_object(X) returns a pointer to the [sqlite3_file]
  3678. ** object that represents the main database file.
  3679. **
  3680. ** This routine is intended for use in custom [VFS] implementations
  3681. ** only. It is not a general-purpose interface.
  3682. ** The argument sqlite3_file_object(X) must be a filename pointer that
  3683. ** has been passed into [sqlite3_vfs].xOpen method where the
  3684. ** flags parameter to xOpen contains one of the bits
  3685. ** [SQLITE_OPEN_MAIN_JOURNAL] or [SQLITE_OPEN_WAL]. Any other use
  3686. ** of this routine results in undefined and probably undesirable
  3687. ** behavior.
  3688. */
  3689. SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*);
  3690. /*
  3691. ** CAPI3REF: Create and Destroy VFS Filenames
  3692. **
  3693. ** These interfces are provided for use by [VFS shim] implementations and
  3694. ** are not useful outside of that context.
  3695. **
  3696. ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
  3697. ** database filename D with corresponding journal file J and WAL file W and
  3698. ** with N URI parameters key/values pairs in the array P. The result from
  3699. ** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that
  3700. ** is safe to pass to routines like:
  3701. ** <ul>
  3702. ** <li> [sqlite3_uri_parameter()],
  3703. ** <li> [sqlite3_uri_boolean()],
  3704. ** <li> [sqlite3_uri_int64()],
  3705. ** <li> [sqlite3_uri_key()],
  3706. ** <li> [sqlite3_filename_database()],
  3707. ** <li> [sqlite3_filename_journal()], or
  3708. ** <li> [sqlite3_filename_wal()].
  3709. ** </ul>
  3710. ** If a memory allocation error occurs, sqlite3_create_filename() might
  3711. ** return a NULL pointer. The memory obtained from sqlite3_create_filename(X)
  3712. ** must be released by a corresponding call to sqlite3_free_filename(Y).
  3713. **
  3714. ** The P parameter in sqlite3_create_filename(D,J,W,N,P) should be an array
  3715. ** of 2*N pointers to strings. Each pair of pointers in this array corresponds
  3716. ** to a key and value for a query parameter. The P parameter may be a NULL
  3717. ** pointer if N is zero. None of the 2*N pointers in the P array may be
  3718. ** NULL pointers and key pointers should not be empty strings.
  3719. ** None of the D, J, or W parameters to sqlite3_create_filename(D,J,W,N,P) may
  3720. ** be NULL pointers, though they can be empty strings.
  3721. **
  3722. ** The sqlite3_free_filename(Y) routine releases a memory allocation
  3723. ** previously obtained from sqlite3_create_filename(). Invoking
  3724. ** sqlite3_free_filename(Y) where Y is a NULL pointer is a harmless no-op.
  3725. **
  3726. ** If the Y parameter to sqlite3_free_filename(Y) is anything other
  3727. ** than a NULL pointer or a pointer previously acquired from
  3728. ** sqlite3_create_filename(), then bad things such as heap
  3729. ** corruption or segfaults may occur. The value Y should not be
  3730. ** used again after sqlite3_free_filename(Y) has been called. This means
  3731. ** that if the [sqlite3_vfs.xOpen()] method of a VFS has been called using Y,
  3732. ** then the corresponding [sqlite3_module.xClose() method should also be
  3733. ** invoked prior to calling sqlite3_free_filename(Y).
  3734. */
  3735. SQLITE_API char *sqlite3_create_filename(
  3736. const char *zDatabase,
  3737. const char *zJournal,
  3738. const char *zWal,
  3739. int nParam,
  3740. const char **azParam
  3741. );
  3742. SQLITE_API void sqlite3_free_filename(char*);
  3743. /*
  3744. ** CAPI3REF: Error Codes And Messages
  3745. ** METHOD: sqlite3
  3746. **
  3747. ** ^If the most recent sqlite3_* API call associated with
  3748. ** [database connection] D failed, then the sqlite3_errcode(D) interface
  3749. ** returns the numeric [result code] or [extended result code] for that
  3750. ** API call.
  3751. ** ^The sqlite3_extended_errcode()
  3752. ** interface is the same except that it always returns the
  3753. ** [extended result code] even when extended result codes are
  3754. ** disabled.
  3755. **
  3756. ** The values returned by sqlite3_errcode() and/or
  3757. ** sqlite3_extended_errcode() might change with each API call.
  3758. ** Except, there are some interfaces that are guaranteed to never
  3759. ** change the value of the error code. The error-code preserving
  3760. ** interfaces include the following:
  3761. **
  3762. ** <ul>
  3763. ** <li> sqlite3_errcode()
  3764. ** <li> sqlite3_extended_errcode()
  3765. ** <li> sqlite3_errmsg()
  3766. ** <li> sqlite3_errmsg16()
  3767. ** <li> sqlite3_error_offset()
  3768. ** </ul>
  3769. **
  3770. ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
  3771. ** text that describes the error, as either UTF-8 or UTF-16 respectively.
  3772. ** ^(Memory to hold the error message string is managed internally.
  3773. ** The application does not need to worry about freeing the result.
  3774. ** However, the error string might be overwritten or deallocated by
  3775. ** subsequent calls to other SQLite interface functions.)^
  3776. **
  3777. ** ^The sqlite3_errstr() interface returns the English-language text
  3778. ** that describes the [result code], as UTF-8.
  3779. ** ^(Memory to hold the error message string is managed internally
  3780. ** and must not be freed by the application)^.
  3781. **
  3782. ** ^If the most recent error references a specific token in the input
  3783. ** SQL, the sqlite3_error_offset() interface returns the byte offset
  3784. ** of the start of that token. ^The byte offset returned by
  3785. ** sqlite3_error_offset() assumes that the input SQL is UTF8.
  3786. ** ^If the most recent error does not reference a specific token in the input
  3787. ** SQL, then the sqlite3_error_offset() function returns -1.
  3788. **
  3789. ** When the serialized [threading mode] is in use, it might be the
  3790. ** case that a second error occurs on a separate thread in between
  3791. ** the time of the first error and the call to these interfaces.
  3792. ** When that happens, the second error will be reported since these
  3793. ** interfaces always report the most recent result. To avoid
  3794. ** this, each thread can obtain exclusive use of the [database connection] D
  3795. ** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning
  3796. ** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after
  3797. ** all calls to the interfaces listed here are completed.
  3798. **
  3799. ** If an interface fails with SQLITE_MISUSE, that means the interface
  3800. ** was invoked incorrectly by the application. In that case, the
  3801. ** error code and message may or may not be set.
  3802. */
  3803. SQLITE_API int sqlite3_errcode(sqlite3 *db);
  3804. SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
  3805. SQLITE_API const char *sqlite3_errmsg(sqlite3*);
  3806. SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
  3807. SQLITE_API const char *sqlite3_errstr(int);
  3808. SQLITE_API int sqlite3_error_offset(sqlite3 *db);
  3809. /*
  3810. ** CAPI3REF: Prepared Statement Object
  3811. ** KEYWORDS: {prepared statement} {prepared statements}
  3812. **
  3813. ** An instance of this object represents a single SQL statement that
  3814. ** has been compiled into binary form and is ready to be evaluated.
  3815. **
  3816. ** Think of each SQL statement as a separate computer program. The
  3817. ** original SQL text is source code. A prepared statement object
  3818. ** is the compiled object code. All SQL must be converted into a
  3819. ** prepared statement before it can be run.
  3820. **
  3821. ** The life-cycle of a prepared statement object usually goes like this:
  3822. **
  3823. ** <ol>
  3824. ** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
  3825. ** <li> Bind values to [parameters] using the sqlite3_bind_*()
  3826. ** interfaces.
  3827. ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
  3828. ** <li> Reset the prepared statement using [sqlite3_reset()] then go back
  3829. ** to step 2. Do this zero or more times.
  3830. ** <li> Destroy the object using [sqlite3_finalize()].
  3831. ** </ol>
  3832. */
  3833. typedef struct sqlite3_stmt sqlite3_stmt;
  3834. /*
  3835. ** CAPI3REF: Run-time Limits
  3836. ** METHOD: sqlite3
  3837. **
  3838. ** ^(This interface allows the size of various constructs to be limited
  3839. ** on a connection by connection basis. The first parameter is the
  3840. ** [database connection] whose limit is to be set or queried. The
  3841. ** second parameter is one of the [limit categories] that define a
  3842. ** class of constructs to be size limited. The third parameter is the
  3843. ** new limit for that construct.)^
  3844. **
  3845. ** ^If the new limit is a negative number, the limit is unchanged.
  3846. ** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a
  3847. ** [limits | hard upper bound]
  3848. ** set at compile-time by a C preprocessor macro called
  3849. ** [limits | SQLITE_MAX_<i>NAME</i>].
  3850. ** (The "_LIMIT_" in the name is changed to "_MAX_".))^
  3851. ** ^Attempts to increase a limit above its hard upper bound are
  3852. ** silently truncated to the hard upper bound.
  3853. **
  3854. ** ^Regardless of whether or not the limit was changed, the
  3855. ** [sqlite3_limit()] interface returns the prior value of the limit.
  3856. ** ^Hence, to find the current value of a limit without changing it,
  3857. ** simply invoke this interface with the third parameter set to -1.
  3858. **
  3859. ** Run-time limits are intended for use in applications that manage
  3860. ** both their own internal database and also databases that are controlled
  3861. ** by untrusted external sources. An example application might be a
  3862. ** web browser that has its own databases for storing history and
  3863. ** separate databases controlled by JavaScript applications downloaded
  3864. ** off the Internet. The internal databases can be given the
  3865. ** large, default limits. Databases managed by external sources can
  3866. ** be given much smaller limits designed to prevent a denial of service
  3867. ** attack. Developers might also want to use the [sqlite3_set_authorizer()]
  3868. ** interface to further control untrusted SQL. The size of the database
  3869. ** created by an untrusted script can be contained using the
  3870. ** [max_page_count] [PRAGMA].
  3871. **
  3872. ** New run-time limit categories may be added in future releases.
  3873. */
  3874. SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
  3875. /*
  3876. ** CAPI3REF: Run-Time Limit Categories
  3877. ** KEYWORDS: {limit category} {*limit categories}
  3878. **
  3879. ** These constants define various performance limits
  3880. ** that can be lowered at run-time using [sqlite3_limit()].
  3881. ** The synopsis of the meanings of the various limits is shown below.
  3882. ** Additional information is available at [limits | Limits in SQLite].
  3883. **
  3884. ** <dl>
  3885. ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
  3886. ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
  3887. **
  3888. ** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
  3889. ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
  3890. **
  3891. ** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>
  3892. ** <dd>The maximum number of columns in a table definition or in the
  3893. ** result set of a [SELECT] or the maximum number of columns in an index
  3894. ** or in an ORDER BY or GROUP BY clause.</dd>)^
  3895. **
  3896. ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
  3897. ** <dd>The maximum depth of the parse tree on any expression.</dd>)^
  3898. **
  3899. ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
  3900. ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
  3901. **
  3902. ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
  3903. ** <dd>The maximum number of instructions in a virtual machine program
  3904. ** used to implement an SQL statement. If [sqlite3_prepare_v2()] or
  3905. ** the equivalent tries to allocate space for more than this many opcodes
  3906. ** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^
  3907. **
  3908. ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
  3909. ** <dd>The maximum number of arguments on a function.</dd>)^
  3910. **
  3911. ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
  3912. ** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
  3913. **
  3914. ** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]
  3915. ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
  3916. ** <dd>The maximum length of the pattern argument to the [LIKE] or
  3917. ** [GLOB] operators.</dd>)^
  3918. **
  3919. ** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
  3920. ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
  3921. ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
  3922. **
  3923. ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
  3924. ** <dd>The maximum depth of recursion for triggers.</dd>)^
  3925. **
  3926. ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
  3927. ** <dd>The maximum number of auxiliary worker threads that a single
  3928. ** [prepared statement] may start.</dd>)^
  3929. ** </dl>
  3930. */
  3931. #define SQLITE_LIMIT_LENGTH 0
  3932. #define SQLITE_LIMIT_SQL_LENGTH 1
  3933. #define SQLITE_LIMIT_COLUMN 2
  3934. #define SQLITE_LIMIT_EXPR_DEPTH 3
  3935. #define SQLITE_LIMIT_COMPOUND_SELECT 4
  3936. #define SQLITE_LIMIT_VDBE_OP 5
  3937. #define SQLITE_LIMIT_FUNCTION_ARG 6
  3938. #define SQLITE_LIMIT_ATTACHED 7
  3939. #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
  3940. #define SQLITE_LIMIT_VARIABLE_NUMBER 9
  3941. #define SQLITE_LIMIT_TRIGGER_DEPTH 10
  3942. #define SQLITE_LIMIT_WORKER_THREADS 11
  3943. /*
  3944. ** CAPI3REF: Prepare Flags
  3945. **
  3946. ** These constants define various flags that can be passed into
  3947. ** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
  3948. ** [sqlite3_prepare16_v3()] interfaces.
  3949. **
  3950. ** New flags may be added in future releases of SQLite.
  3951. **
  3952. ** <dl>
  3953. ** [[SQLITE_PREPARE_PERSISTENT]] ^(<dt>SQLITE_PREPARE_PERSISTENT</dt>
  3954. ** <dd>The SQLITE_PREPARE_PERSISTENT flag is a hint to the query planner
  3955. ** that the prepared statement will be retained for a long time and
  3956. ** probably reused many times.)^ ^Without this flag, [sqlite3_prepare_v3()]
  3957. ** and [sqlite3_prepare16_v3()] assume that the prepared statement will
  3958. ** be used just once or at most a few times and then destroyed using
  3959. ** [sqlite3_finalize()] relatively soon. The current implementation acts
  3960. ** on this hint by avoiding the use of [lookaside memory] so as not to
  3961. ** deplete the limited store of lookaside memory. Future versions of
  3962. ** SQLite may act on this hint differently.
  3963. **
  3964. ** [[SQLITE_PREPARE_NORMALIZE]] <dt>SQLITE_PREPARE_NORMALIZE</dt>
  3965. ** <dd>The SQLITE_PREPARE_NORMALIZE flag is a no-op. This flag used
  3966. ** to be required for any prepared statement that wanted to use the
  3967. ** [sqlite3_normalized_sql()] interface. However, the
  3968. ** [sqlite3_normalized_sql()] interface is now available to all
  3969. ** prepared statements, regardless of whether or not they use this
  3970. ** flag.
  3971. **
  3972. ** [[SQLITE_PREPARE_NO_VTAB]] <dt>SQLITE_PREPARE_NO_VTAB</dt>
  3973. ** <dd>The SQLITE_PREPARE_NO_VTAB flag causes the SQL compiler
  3974. ** to return an error (error code SQLITE_ERROR) if the statement uses
  3975. ** any virtual tables.
  3976. ** </dl>
  3977. */
  3978. #define SQLITE_PREPARE_PERSISTENT 0x01
  3979. #define SQLITE_PREPARE_NORMALIZE 0x02
  3980. #define SQLITE_PREPARE_NO_VTAB 0x04
  3981. /*
  3982. ** CAPI3REF: Compiling An SQL Statement
  3983. ** KEYWORDS: {SQL statement compiler}
  3984. ** METHOD: sqlite3
  3985. ** CONSTRUCTOR: sqlite3_stmt
  3986. **
  3987. ** To execute an SQL statement, it must first be compiled into a byte-code
  3988. ** program using one of these routines. Or, in other words, these routines
  3989. ** are constructors for the [prepared statement] object.
  3990. **
  3991. ** The preferred routine to use is [sqlite3_prepare_v2()]. The
  3992. ** [sqlite3_prepare()] interface is legacy and should be avoided.
  3993. ** [sqlite3_prepare_v3()] has an extra "prepFlags" option that is used
  3994. ** for special purposes.
  3995. **
  3996. ** The use of the UTF-8 interfaces is preferred, as SQLite currently
  3997. ** does all parsing using UTF-8. The UTF-16 interfaces are provided
  3998. ** as a convenience. The UTF-16 interfaces work by converting the
  3999. ** input text into UTF-8, then invoking the corresponding UTF-8 interface.
  4000. **
  4001. ** The first argument, "db", is a [database connection] obtained from a
  4002. ** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or
  4003. ** [sqlite3_open16()]. The database connection must not have been closed.
  4004. **
  4005. ** The second argument, "zSql", is the statement to be compiled, encoded
  4006. ** as either UTF-8 or UTF-16. The sqlite3_prepare(), sqlite3_prepare_v2(),
  4007. ** and sqlite3_prepare_v3()
  4008. ** interfaces use UTF-8, and sqlite3_prepare16(), sqlite3_prepare16_v2(),
  4009. ** and sqlite3_prepare16_v3() use UTF-16.
  4010. **
  4011. ** ^If the nByte argument is negative, then zSql is read up to the
  4012. ** first zero terminator. ^If nByte is positive, then it is the
  4013. ** number of bytes read from zSql. ^If nByte is zero, then no prepared
  4014. ** statement is generated.
  4015. ** If the caller knows that the supplied string is nul-terminated, then
  4016. ** there is a small performance advantage to passing an nByte parameter that
  4017. ** is the number of bytes in the input string <i>including</i>
  4018. ** the nul-terminator.
  4019. **
  4020. ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
  4021. ** past the end of the first SQL statement in zSql. These routines only
  4022. ** compile the first statement in zSql, so *pzTail is left pointing to
  4023. ** what remains uncompiled.
  4024. **
  4025. ** ^*ppStmt is left pointing to a compiled [prepared statement] that can be
  4026. ** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set
  4027. ** to NULL. ^If the input text contains no SQL (if the input is an empty
  4028. ** string or a comment) then *ppStmt is set to NULL.
  4029. ** The calling procedure is responsible for deleting the compiled
  4030. ** SQL statement using [sqlite3_finalize()] after it has finished with it.
  4031. ** ppStmt may not be NULL.
  4032. **
  4033. ** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK];
  4034. ** otherwise an [error code] is returned.
  4035. **
  4036. ** The sqlite3_prepare_v2(), sqlite3_prepare_v3(), sqlite3_prepare16_v2(),
  4037. ** and sqlite3_prepare16_v3() interfaces are recommended for all new programs.
  4038. ** The older interfaces (sqlite3_prepare() and sqlite3_prepare16())
  4039. ** are retained for backwards compatibility, but their use is discouraged.
  4040. ** ^In the "vX" interfaces, the prepared statement
  4041. ** that is returned (the [sqlite3_stmt] object) contains a copy of the
  4042. ** original SQL text. This causes the [sqlite3_step()] interface to
  4043. ** behave differently in three ways:
  4044. **
  4045. ** <ol>
  4046. ** <li>
  4047. ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
  4048. ** always used to do, [sqlite3_step()] will automatically recompile the SQL
  4049. ** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY]
  4050. ** retries will occur before sqlite3_step() gives up and returns an error.
  4051. ** </li>
  4052. **
  4053. ** <li>
  4054. ** ^When an error occurs, [sqlite3_step()] will return one of the detailed
  4055. ** [error codes] or [extended error codes]. ^The legacy behavior was that
  4056. ** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code
  4057. ** and the application would have to make a second call to [sqlite3_reset()]
  4058. ** in order to find the underlying cause of the problem. With the "v2" prepare
  4059. ** interfaces, the underlying reason for the error is returned immediately.
  4060. ** </li>
  4061. **
  4062. ** <li>
  4063. ** ^If the specific value bound to a [parameter | host parameter] in the
  4064. ** WHERE clause might influence the choice of query plan for a statement,
  4065. ** then the statement will be automatically recompiled, as if there had been
  4066. ** a schema change, on the first [sqlite3_step()] call following any change
  4067. ** to the [sqlite3_bind_text | bindings] of that [parameter].
  4068. ** ^The specific value of a WHERE-clause [parameter] might influence the
  4069. ** choice of query plan if the parameter is the left-hand side of a [LIKE]
  4070. ** or [GLOB] operator or if the parameter is compared to an indexed column
  4071. ** and the [SQLITE_ENABLE_STAT4] compile-time option is enabled.
  4072. ** </li>
  4073. ** </ol>
  4074. **
  4075. ** <p>^sqlite3_prepare_v3() differs from sqlite3_prepare_v2() only in having
  4076. ** the extra prepFlags parameter, which is a bit array consisting of zero or
  4077. ** more of the [SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_*] flags. ^The
  4078. ** sqlite3_prepare_v2() interface works exactly the same as
  4079. ** sqlite3_prepare_v3() with a zero prepFlags parameter.
  4080. */
  4081. SQLITE_API int sqlite3_prepare(
  4082. sqlite3 *db, /* Database handle */
  4083. const char *zSql, /* SQL statement, UTF-8 encoded */
  4084. int nByte, /* Maximum length of zSql in bytes. */
  4085. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  4086. const char **pzTail /* OUT: Pointer to unused portion of zSql */
  4087. );
  4088. SQLITE_API int sqlite3_prepare_v2(
  4089. sqlite3 *db, /* Database handle */
  4090. const char *zSql, /* SQL statement, UTF-8 encoded */
  4091. int nByte, /* Maximum length of zSql in bytes. */
  4092. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  4093. const char **pzTail /* OUT: Pointer to unused portion of zSql */
  4094. );
  4095. SQLITE_API int sqlite3_prepare_v3(
  4096. sqlite3 *db, /* Database handle */
  4097. const char *zSql, /* SQL statement, UTF-8 encoded */
  4098. int nByte, /* Maximum length of zSql in bytes. */
  4099. unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
  4100. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  4101. const char **pzTail /* OUT: Pointer to unused portion of zSql */
  4102. );
  4103. SQLITE_API int sqlite3_prepare16(
  4104. sqlite3 *db, /* Database handle */
  4105. const void *zSql, /* SQL statement, UTF-16 encoded */
  4106. int nByte, /* Maximum length of zSql in bytes. */
  4107. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  4108. const void **pzTail /* OUT: Pointer to unused portion of zSql */
  4109. );
  4110. SQLITE_API int sqlite3_prepare16_v2(
  4111. sqlite3 *db, /* Database handle */
  4112. const void *zSql, /* SQL statement, UTF-16 encoded */
  4113. int nByte, /* Maximum length of zSql in bytes. */
  4114. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  4115. const void **pzTail /* OUT: Pointer to unused portion of zSql */
  4116. );
  4117. SQLITE_API int sqlite3_prepare16_v3(
  4118. sqlite3 *db, /* Database handle */
  4119. const void *zSql, /* SQL statement, UTF-16 encoded */
  4120. int nByte, /* Maximum length of zSql in bytes. */
  4121. unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
  4122. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  4123. const void **pzTail /* OUT: Pointer to unused portion of zSql */
  4124. );
  4125. /*
  4126. ** CAPI3REF: Retrieving Statement SQL
  4127. ** METHOD: sqlite3_stmt
  4128. **
  4129. ** ^The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-8
  4130. ** SQL text used to create [prepared statement] P if P was
  4131. ** created by [sqlite3_prepare_v2()], [sqlite3_prepare_v3()],
  4132. ** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].
  4133. ** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-8
  4134. ** string containing the SQL text of prepared statement P with
  4135. ** [bound parameters] expanded.
  4136. ** ^The sqlite3_normalized_sql(P) interface returns a pointer to a UTF-8
  4137. ** string containing the normalized SQL text of prepared statement P. The
  4138. ** semantics used to normalize a SQL statement are unspecified and subject
  4139. ** to change. At a minimum, literal values will be replaced with suitable
  4140. ** placeholders.
  4141. **
  4142. ** ^(For example, if a prepared statement is created using the SQL
  4143. ** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 2345
  4144. ** and parameter :xyz is unbound, then sqlite3_sql() will return
  4145. ** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
  4146. ** will return "SELECT 2345,NULL".)^
  4147. **
  4148. ** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
  4149. ** is available to hold the result, or if the result would exceed the
  4150. ** the maximum string length determined by the [SQLITE_LIMIT_LENGTH].
  4151. **
  4152. ** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
  4153. ** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time
  4154. ** option causes sqlite3_expanded_sql() to always return NULL.
  4155. **
  4156. ** ^The strings returned by sqlite3_sql(P) and sqlite3_normalized_sql(P)
  4157. ** are managed by SQLite and are automatically freed when the prepared
  4158. ** statement is finalized.
  4159. ** ^The string returned by sqlite3_expanded_sql(P), on the other hand,
  4160. ** is obtained from [sqlite3_malloc()] and must be freed by the application
  4161. ** by passing it to [sqlite3_free()].
  4162. **
  4163. ** ^The sqlite3_normalized_sql() interface is only available if
  4164. ** the [SQLITE_ENABLE_NORMALIZE] compile-time option is defined.
  4165. */
  4166. SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
  4167. SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt);
  4168. #ifdef SQLITE_ENABLE_NORMALIZE
  4169. SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt);
  4170. #endif
  4171. /*
  4172. ** CAPI3REF: Determine If An SQL Statement Writes The Database
  4173. ** METHOD: sqlite3_stmt
  4174. **
  4175. ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
  4176. ** and only if the [prepared statement] X makes no direct changes to
  4177. ** the content of the database file.
  4178. **
  4179. ** Note that [application-defined SQL functions] or
  4180. ** [virtual tables] might change the database indirectly as a side effect.
  4181. ** ^(For example, if an application defines a function "eval()" that
  4182. ** calls [sqlite3_exec()], then the following SQL statement would
  4183. ** change the database file through side-effects:
  4184. **
  4185. ** <blockquote><pre>
  4186. ** SELECT eval('DELETE FROM t1') FROM t2;
  4187. ** </pre></blockquote>
  4188. **
  4189. ** But because the [SELECT] statement does not change the database file
  4190. ** directly, sqlite3_stmt_readonly() would still return true.)^
  4191. **
  4192. ** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
  4193. ** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
  4194. ** since the statements themselves do not actually modify the database but
  4195. ** rather they control the timing of when other statements modify the
  4196. ** database. ^The [ATTACH] and [DETACH] statements also cause
  4197. ** sqlite3_stmt_readonly() to return true since, while those statements
  4198. ** change the configuration of a database connection, they do not make
  4199. ** changes to the content of the database files on disk.
  4200. ** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
  4201. ** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
  4202. ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
  4203. ** sqlite3_stmt_readonly() returns false for those commands.
  4204. **
  4205. ** ^This routine returns false if there is any possibility that the
  4206. ** statement might change the database file. ^A false return does
  4207. ** not guarantee that the statement will change the database file.
  4208. ** ^For example, an UPDATE statement might have a WHERE clause that
  4209. ** makes it a no-op, but the sqlite3_stmt_readonly() result would still
  4210. ** be false. ^Similarly, a CREATE TABLE IF NOT EXISTS statement is a
  4211. ** read-only no-op if the table already exists, but
  4212. ** sqlite3_stmt_readonly() still returns false for such a statement.
  4213. **
  4214. ** ^If prepared statement X is an [EXPLAIN] or [EXPLAIN QUERY PLAN]
  4215. ** statement, then sqlite3_stmt_readonly(X) returns the same value as
  4216. ** if the EXPLAIN or EXPLAIN QUERY PLAN prefix were omitted.
  4217. */
  4218. SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
  4219. /*
  4220. ** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
  4221. ** METHOD: sqlite3_stmt
  4222. **
  4223. ** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the
  4224. ** prepared statement S is an EXPLAIN statement, or 2 if the
  4225. ** statement S is an EXPLAIN QUERY PLAN.
  4226. ** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is
  4227. ** an ordinary statement or a NULL pointer.
  4228. */
  4229. SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt);
  4230. /*
  4231. ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
  4232. ** METHOD: sqlite3_stmt
  4233. **
  4234. ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
  4235. ** [prepared statement] S has been stepped at least once using
  4236. ** [sqlite3_step(S)] but has neither run to completion (returned
  4237. ** [SQLITE_DONE] from [sqlite3_step(S)]) nor
  4238. ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
  4239. ** interface returns false if S is a NULL pointer. If S is not a
  4240. ** NULL pointer and is not a pointer to a valid [prepared statement]
  4241. ** object, then the behavior is undefined and probably undesirable.
  4242. **
  4243. ** This interface can be used in combination [sqlite3_next_stmt()]
  4244. ** to locate all prepared statements associated with a database
  4245. ** connection that are in need of being reset. This can be used,
  4246. ** for example, in diagnostic routines to search for prepared
  4247. ** statements that are holding a transaction open.
  4248. */
  4249. SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*);
  4250. /*
  4251. ** CAPI3REF: Dynamically Typed Value Object
  4252. ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
  4253. **
  4254. ** SQLite uses the sqlite3_value object to represent all values
  4255. ** that can be stored in a database table. SQLite uses dynamic typing
  4256. ** for the values it stores. ^Values stored in sqlite3_value objects
  4257. ** can be integers, floating point values, strings, BLOBs, or NULL.
  4258. **
  4259. ** An sqlite3_value object may be either "protected" or "unprotected".
  4260. ** Some interfaces require a protected sqlite3_value. Other interfaces
  4261. ** will accept either a protected or an unprotected sqlite3_value.
  4262. ** Every interface that accepts sqlite3_value arguments specifies
  4263. ** whether or not it requires a protected sqlite3_value. The
  4264. ** [sqlite3_value_dup()] interface can be used to construct a new
  4265. ** protected sqlite3_value from an unprotected sqlite3_value.
  4266. **
  4267. ** The terms "protected" and "unprotected" refer to whether or not
  4268. ** a mutex is held. An internal mutex is held for a protected
  4269. ** sqlite3_value object but no mutex is held for an unprotected
  4270. ** sqlite3_value object. If SQLite is compiled to be single-threaded
  4271. ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
  4272. ** or if SQLite is run in one of reduced mutex modes
  4273. ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
  4274. ** then there is no distinction between protected and unprotected
  4275. ** sqlite3_value objects and they can be used interchangeably. However,
  4276. ** for maximum code portability it is recommended that applications
  4277. ** still make the distinction between protected and unprotected
  4278. ** sqlite3_value objects even when not strictly required.
  4279. **
  4280. ** ^The sqlite3_value objects that are passed as parameters into the
  4281. ** implementation of [application-defined SQL functions] are protected.
  4282. ** ^The sqlite3_value objects returned by [sqlite3_vtab_rhs_value()]
  4283. ** are protected.
  4284. ** ^The sqlite3_value object returned by
  4285. ** [sqlite3_column_value()] is unprotected.
  4286. ** Unprotected sqlite3_value objects may only be used as arguments
  4287. ** to [sqlite3_result_value()], [sqlite3_bind_value()], and
  4288. ** [sqlite3_value_dup()].
  4289. ** The [sqlite3_value_blob | sqlite3_value_type()] family of
  4290. ** interfaces require protected sqlite3_value objects.
  4291. */
  4292. typedef struct sqlite3_value sqlite3_value;
  4293. /*
  4294. ** CAPI3REF: SQL Function Context Object
  4295. **
  4296. ** The context in which an SQL function executes is stored in an
  4297. ** sqlite3_context object. ^A pointer to an sqlite3_context object
  4298. ** is always first parameter to [application-defined SQL functions].
  4299. ** The application-defined SQL function implementation will pass this
  4300. ** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
  4301. ** [sqlite3_aggregate_context()], [sqlite3_user_data()],
  4302. ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
  4303. ** and/or [sqlite3_set_auxdata()].
  4304. */
  4305. typedef struct sqlite3_context sqlite3_context;
  4306. /*
  4307. ** CAPI3REF: Binding Values To Prepared Statements
  4308. ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
  4309. ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
  4310. ** METHOD: sqlite3_stmt
  4311. **
  4312. ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
  4313. ** literals may be replaced by a [parameter] that matches one of following
  4314. ** templates:
  4315. **
  4316. ** <ul>
  4317. ** <li> ?
  4318. ** <li> ?NNN
  4319. ** <li> :VVV
  4320. ** <li> @VVV
  4321. ** <li> $VVV
  4322. ** </ul>
  4323. **
  4324. ** In the templates above, NNN represents an integer literal,
  4325. ** and VVV represents an alphanumeric identifier.)^ ^The values of these
  4326. ** parameters (also called "host parameter names" or "SQL parameters")
  4327. ** can be set using the sqlite3_bind_*() routines defined here.
  4328. **
  4329. ** ^The first argument to the sqlite3_bind_*() routines is always
  4330. ** a pointer to the [sqlite3_stmt] object returned from
  4331. ** [sqlite3_prepare_v2()] or its variants.
  4332. **
  4333. ** ^The second argument is the index of the SQL parameter to be set.
  4334. ** ^The leftmost SQL parameter has an index of 1. ^When the same named
  4335. ** SQL parameter is used more than once, second and subsequent
  4336. ** occurrences have the same index as the first occurrence.
  4337. ** ^The index for named parameters can be looked up using the
  4338. ** [sqlite3_bind_parameter_index()] API if desired. ^The index
  4339. ** for "?NNN" parameters is the value of NNN.
  4340. ** ^The NNN value must be between 1 and the [sqlite3_limit()]
  4341. ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 32766).
  4342. **
  4343. ** ^The third argument is the value to bind to the parameter.
  4344. ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
  4345. ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
  4346. ** is ignored and the end result is the same as sqlite3_bind_null().
  4347. ** ^If the third parameter to sqlite3_bind_text() is not NULL, then
  4348. ** it should be a pointer to well-formed UTF8 text.
  4349. ** ^If the third parameter to sqlite3_bind_text16() is not NULL, then
  4350. ** it should be a pointer to well-formed UTF16 text.
  4351. ** ^If the third parameter to sqlite3_bind_text64() is not NULL, then
  4352. ** it should be a pointer to a well-formed unicode string that is
  4353. ** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16
  4354. ** otherwise.
  4355. **
  4356. ** [[byte-order determination rules]] ^The byte-order of
  4357. ** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)
  4358. ** found in first character, which is removed, or in the absence of a BOM
  4359. ** the byte order is the native byte order of the host
  4360. ** machine for sqlite3_bind_text16() or the byte order specified in
  4361. ** the 6th parameter for sqlite3_bind_text64().)^
  4362. ** ^If UTF16 input text contains invalid unicode
  4363. ** characters, then SQLite might change those invalid characters
  4364. ** into the unicode replacement character: U+FFFD.
  4365. **
  4366. ** ^(In those routines that have a fourth argument, its value is the
  4367. ** number of bytes in the parameter. To be clear: the value is the
  4368. ** number of <u>bytes</u> in the value, not the number of characters.)^
  4369. ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
  4370. ** is negative, then the length of the string is
  4371. ** the number of bytes up to the first zero terminator.
  4372. ** If the fourth parameter to sqlite3_bind_blob() is negative, then
  4373. ** the behavior is undefined.
  4374. ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
  4375. ** or sqlite3_bind_text16() or sqlite3_bind_text64() then
  4376. ** that parameter must be the byte offset
  4377. ** where the NUL terminator would occur assuming the string were NUL
  4378. ** terminated. If any NUL characters occurs at byte offsets less than
  4379. ** the value of the fourth parameter then the resulting string value will
  4380. ** contain embedded NULs. The result of expressions involving strings
  4381. ** with embedded NULs is undefined.
  4382. **
  4383. ** ^The fifth argument to the BLOB and string binding interfaces controls
  4384. ** or indicates the lifetime of the object referenced by the third parameter.
  4385. ** These three options exist:
  4386. ** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished
  4387. ** with it may be passed. ^It is called to dispose of the BLOB or string even
  4388. ** if the call to the bind API fails, except the destructor is not called if
  4389. ** the third parameter is a NULL pointer or the fourth parameter is negative.
  4390. ** ^ (2) The special constant, [SQLITE_STATIC], may be passsed to indicate that
  4391. ** the application remains responsible for disposing of the object. ^In this
  4392. ** case, the object and the provided pointer to it must remain valid until
  4393. ** either the prepared statement is finalized or the same SQL parameter is
  4394. ** bound to something else, whichever occurs sooner.
  4395. ** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the
  4396. ** object is to be copied prior to the return from sqlite3_bind_*(). ^The
  4397. ** object and pointer to it must remain valid until then. ^SQLite will then
  4398. ** manage the lifetime of its private copy.
  4399. **
  4400. ** ^The sixth argument to sqlite3_bind_text64() must be one of
  4401. ** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
  4402. ** to specify the encoding of the text in the third parameter. If
  4403. ** the sixth argument to sqlite3_bind_text64() is not one of the
  4404. ** allowed values shown above, or if the text encoding is different
  4405. ** from the encoding specified by the sixth parameter, then the behavior
  4406. ** is undefined.
  4407. **
  4408. ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
  4409. ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory
  4410. ** (just an integer to hold its size) while it is being processed.
  4411. ** Zeroblobs are intended to serve as placeholders for BLOBs whose
  4412. ** content is later written using
  4413. ** [sqlite3_blob_open | incremental BLOB I/O] routines.
  4414. ** ^A negative value for the zeroblob results in a zero-length BLOB.
  4415. **
  4416. ** ^The sqlite3_bind_pointer(S,I,P,T,D) routine causes the I-th parameter in
  4417. ** [prepared statement] S to have an SQL value of NULL, but to also be
  4418. ** associated with the pointer P of type T. ^D is either a NULL pointer or
  4419. ** a pointer to a destructor function for P. ^SQLite will invoke the
  4420. ** destructor D with a single argument of P when it is finished using
  4421. ** P. The T parameter should be a static string, preferably a string
  4422. ** literal. The sqlite3_bind_pointer() routine is part of the
  4423. ** [pointer passing interface] added for SQLite 3.20.0.
  4424. **
  4425. ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
  4426. ** for the [prepared statement] or with a prepared statement for which
  4427. ** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
  4428. ** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_()
  4429. ** routine is passed a [prepared statement] that has been finalized, the
  4430. ** result is undefined and probably harmful.
  4431. **
  4432. ** ^Bindings are not cleared by the [sqlite3_reset()] routine.
  4433. ** ^Unbound parameters are interpreted as NULL.
  4434. **
  4435. ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
  4436. ** [error code] if anything goes wrong.
  4437. ** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB
  4438. ** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or
  4439. ** [SQLITE_MAX_LENGTH].
  4440. ** ^[SQLITE_RANGE] is returned if the parameter
  4441. ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails.
  4442. **
  4443. ** See also: [sqlite3_bind_parameter_count()],
  4444. ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
  4445. */
  4446. SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
  4447. SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,
  4448. void(*)(void*));
  4449. SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
  4450. SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
  4451. SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
  4452. SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
  4453. SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
  4454. SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
  4455. SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
  4456. void(*)(void*), unsigned char encoding);
  4457. SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
  4458. SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*, const char*,void(*)(void*));
  4459. SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
  4460. SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
  4461. /*
  4462. ** CAPI3REF: Number Of SQL Parameters
  4463. ** METHOD: sqlite3_stmt
  4464. **
  4465. ** ^This routine can be used to find the number of [SQL parameters]
  4466. ** in a [prepared statement]. SQL parameters are tokens of the
  4467. ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
  4468. ** placeholders for values that are [sqlite3_bind_blob | bound]
  4469. ** to the parameters at a later time.
  4470. **
  4471. ** ^(This routine actually returns the index of the largest (rightmost)
  4472. ** parameter. For all forms except ?NNN, this will correspond to the
  4473. ** number of unique parameters. If parameters of the ?NNN form are used,
  4474. ** there may be gaps in the list.)^
  4475. **
  4476. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  4477. ** [sqlite3_bind_parameter_name()], and
  4478. ** [sqlite3_bind_parameter_index()].
  4479. */
  4480. SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*);
  4481. /*
  4482. ** CAPI3REF: Name Of A Host Parameter
  4483. ** METHOD: sqlite3_stmt
  4484. **
  4485. ** ^The sqlite3_bind_parameter_name(P,N) interface returns
  4486. ** the name of the N-th [SQL parameter] in the [prepared statement] P.
  4487. ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
  4488. ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
  4489. ** respectively.
  4490. ** In other words, the initial ":" or "$" or "@" or "?"
  4491. ** is included as part of the name.)^
  4492. ** ^Parameters of the form "?" without a following integer have no name
  4493. ** and are referred to as "nameless" or "anonymous parameters".
  4494. **
  4495. ** ^The first host parameter has an index of 1, not 0.
  4496. **
  4497. ** ^If the value N is out of range or if the N-th parameter is
  4498. ** nameless, then NULL is returned. ^The returned string is
  4499. ** always in UTF-8 encoding even if the named parameter was
  4500. ** originally specified as UTF-16 in [sqlite3_prepare16()],
  4501. ** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].
  4502. **
  4503. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  4504. ** [sqlite3_bind_parameter_count()], and
  4505. ** [sqlite3_bind_parameter_index()].
  4506. */
  4507. SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
  4508. /*
  4509. ** CAPI3REF: Index Of A Parameter With A Given Name
  4510. ** METHOD: sqlite3_stmt
  4511. **
  4512. ** ^Return the index of an SQL parameter given its name. ^The
  4513. ** index value returned is suitable for use as the second
  4514. ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
  4515. ** is returned if no matching parameter is found. ^The parameter
  4516. ** name must be given in UTF-8 even if the original statement
  4517. ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()] or
  4518. ** [sqlite3_prepare16_v3()].
  4519. **
  4520. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  4521. ** [sqlite3_bind_parameter_count()], and
  4522. ** [sqlite3_bind_parameter_name()].
  4523. */
  4524. SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
  4525. /*
  4526. ** CAPI3REF: Reset All Bindings On A Prepared Statement
  4527. ** METHOD: sqlite3_stmt
  4528. **
  4529. ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
  4530. ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
  4531. ** ^Use this routine to reset all host parameters to NULL.
  4532. */
  4533. SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*);
  4534. /*
  4535. ** CAPI3REF: Number Of Columns In A Result Set
  4536. ** METHOD: sqlite3_stmt
  4537. **
  4538. ** ^Return the number of columns in the result set returned by the
  4539. ** [prepared statement]. ^If this routine returns 0, that means the
  4540. ** [prepared statement] returns no data (for example an [UPDATE]).
  4541. ** ^However, just because this routine returns a positive number does not
  4542. ** mean that one or more rows of data will be returned. ^A SELECT statement
  4543. ** will always have a positive sqlite3_column_count() but depending on the
  4544. ** WHERE clause constraints and the table content, it might return no rows.
  4545. **
  4546. ** See also: [sqlite3_data_count()]
  4547. */
  4548. SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
  4549. /*
  4550. ** CAPI3REF: Column Names In A Result Set
  4551. ** METHOD: sqlite3_stmt
  4552. **
  4553. ** ^These routines return the name assigned to a particular column
  4554. ** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
  4555. ** interface returns a pointer to a zero-terminated UTF-8 string
  4556. ** and sqlite3_column_name16() returns a pointer to a zero-terminated
  4557. ** UTF-16 string. ^The first parameter is the [prepared statement]
  4558. ** that implements the [SELECT] statement. ^The second parameter is the
  4559. ** column number. ^The leftmost column is number 0.
  4560. **
  4561. ** ^The returned string pointer is valid until either the [prepared statement]
  4562. ** is destroyed by [sqlite3_finalize()] or until the statement is automatically
  4563. ** reprepared by the first call to [sqlite3_step()] for a particular run
  4564. ** or until the next call to
  4565. ** sqlite3_column_name() or sqlite3_column_name16() on the same column.
  4566. **
  4567. ** ^If sqlite3_malloc() fails during the processing of either routine
  4568. ** (for example during a conversion from UTF-8 to UTF-16) then a
  4569. ** NULL pointer is returned.
  4570. **
  4571. ** ^The name of a result column is the value of the "AS" clause for
  4572. ** that column, if there is an AS clause. If there is no AS clause
  4573. ** then the name of the column is unspecified and may change from
  4574. ** one release of SQLite to the next.
  4575. */
  4576. SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N);
  4577. SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N);
  4578. /*
  4579. ** CAPI3REF: Source Of Data In A Query Result
  4580. ** METHOD: sqlite3_stmt
  4581. **
  4582. ** ^These routines provide a means to determine the database, table, and
  4583. ** table column that is the origin of a particular result column in
  4584. ** [SELECT] statement.
  4585. ** ^The name of the database or table or column can be returned as
  4586. ** either a UTF-8 or UTF-16 string. ^The _database_ routines return
  4587. ** the database name, the _table_ routines return the table name, and
  4588. ** the origin_ routines return the column name.
  4589. ** ^The returned string is valid until the [prepared statement] is destroyed
  4590. ** using [sqlite3_finalize()] or until the statement is automatically
  4591. ** reprepared by the first call to [sqlite3_step()] for a particular run
  4592. ** or until the same information is requested
  4593. ** again in a different encoding.
  4594. **
  4595. ** ^The names returned are the original un-aliased names of the
  4596. ** database, table, and column.
  4597. **
  4598. ** ^The first argument to these interfaces is a [prepared statement].
  4599. ** ^These functions return information about the Nth result column returned by
  4600. ** the statement, where N is the second function argument.
  4601. ** ^The left-most column is column 0 for these routines.
  4602. **
  4603. ** ^If the Nth column returned by the statement is an expression or
  4604. ** subquery and is not a column value, then all of these functions return
  4605. ** NULL. ^These routines might also return NULL if a memory allocation error
  4606. ** occurs. ^Otherwise, they return the name of the attached database, table,
  4607. ** or column that query result column was extracted from.
  4608. **
  4609. ** ^As with all other SQLite APIs, those whose names end with "16" return
  4610. ** UTF-16 encoded strings and the other functions return UTF-8.
  4611. **
  4612. ** ^These APIs are only available if the library was compiled with the
  4613. ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
  4614. **
  4615. ** If two or more threads call one or more
  4616. ** [sqlite3_column_database_name | column metadata interfaces]
  4617. ** for the same [prepared statement] and result column
  4618. ** at the same time then the results are undefined.
  4619. */
  4620. SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int);
  4621. SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
  4622. SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int);
  4623. SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
  4624. SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
  4625. SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
  4626. /*
  4627. ** CAPI3REF: Declared Datatype Of A Query Result
  4628. ** METHOD: sqlite3_stmt
  4629. **
  4630. ** ^(The first parameter is a [prepared statement].
  4631. ** If this statement is a [SELECT] statement and the Nth column of the
  4632. ** returned result set of that [SELECT] is a table column (not an
  4633. ** expression or subquery) then the declared type of the table
  4634. ** column is returned.)^ ^If the Nth column of the result set is an
  4635. ** expression or subquery, then a NULL pointer is returned.
  4636. ** ^The returned string is always UTF-8 encoded.
  4637. **
  4638. ** ^(For example, given the database schema:
  4639. **
  4640. ** CREATE TABLE t1(c1 VARIANT);
  4641. **
  4642. ** and the following statement to be compiled:
  4643. **
  4644. ** SELECT c1 + 1, c1 FROM t1;
  4645. **
  4646. ** this routine would return the string "VARIANT" for the second result
  4647. ** column (i==1), and a NULL pointer for the first result column (i==0).)^
  4648. **
  4649. ** ^SQLite uses dynamic run-time typing. ^So just because a column
  4650. ** is declared to contain a particular type does not mean that the
  4651. ** data stored in that column is of the declared type. SQLite is
  4652. ** strongly typed, but the typing is dynamic not static. ^Type
  4653. ** is associated with individual values, not with the containers
  4654. ** used to hold those values.
  4655. */
  4656. SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int);
  4657. SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
  4658. /*
  4659. ** CAPI3REF: Evaluate An SQL Statement
  4660. ** METHOD: sqlite3_stmt
  4661. **
  4662. ** After a [prepared statement] has been prepared using any of
  4663. ** [sqlite3_prepare_v2()], [sqlite3_prepare_v3()], [sqlite3_prepare16_v2()],
  4664. ** or [sqlite3_prepare16_v3()] or one of the legacy
  4665. ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
  4666. ** must be called one or more times to evaluate the statement.
  4667. **
  4668. ** The details of the behavior of the sqlite3_step() interface depend
  4669. ** on whether the statement was prepared using the newer "vX" interfaces
  4670. ** [sqlite3_prepare_v3()], [sqlite3_prepare_v2()], [sqlite3_prepare16_v3()],
  4671. ** [sqlite3_prepare16_v2()] or the older legacy
  4672. ** interfaces [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the
  4673. ** new "vX" interface is recommended for new applications but the legacy
  4674. ** interface will continue to be supported.
  4675. **
  4676. ** ^In the legacy interface, the return value will be either [SQLITE_BUSY],
  4677. ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
  4678. ** ^With the "v2" interface, any of the other [result codes] or
  4679. ** [extended result codes] might be returned as well.
  4680. **
  4681. ** ^[SQLITE_BUSY] means that the database engine was unable to acquire the
  4682. ** database locks it needs to do its job. ^If the statement is a [COMMIT]
  4683. ** or occurs outside of an explicit transaction, then you can retry the
  4684. ** statement. If the statement is not a [COMMIT] and occurs within an
  4685. ** explicit transaction then you should rollback the transaction before
  4686. ** continuing.
  4687. **
  4688. ** ^[SQLITE_DONE] means that the statement has finished executing
  4689. ** successfully. sqlite3_step() should not be called again on this virtual
  4690. ** machine without first calling [sqlite3_reset()] to reset the virtual
  4691. ** machine back to its initial state.
  4692. **
  4693. ** ^If the SQL statement being executed returns any data, then [SQLITE_ROW]
  4694. ** is returned each time a new row of data is ready for processing by the
  4695. ** caller. The values may be accessed using the [column access functions].
  4696. ** sqlite3_step() is called again to retrieve the next row of data.
  4697. **
  4698. ** ^[SQLITE_ERROR] means that a run-time error (such as a constraint
  4699. ** violation) has occurred. sqlite3_step() should not be called again on
  4700. ** the VM. More information may be found by calling [sqlite3_errmsg()].
  4701. ** ^With the legacy interface, a more specific error code (for example,
  4702. ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
  4703. ** can be obtained by calling [sqlite3_reset()] on the
  4704. ** [prepared statement]. ^In the "v2" interface,
  4705. ** the more specific error code is returned directly by sqlite3_step().
  4706. **
  4707. ** [SQLITE_MISUSE] means that the this routine was called inappropriately.
  4708. ** Perhaps it was called on a [prepared statement] that has
  4709. ** already been [sqlite3_finalize | finalized] or on one that had
  4710. ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could
  4711. ** be the case that the same database connection is being used by two or
  4712. ** more threads at the same moment in time.
  4713. **
  4714. ** For all versions of SQLite up to and including 3.6.23.1, a call to
  4715. ** [sqlite3_reset()] was required after sqlite3_step() returned anything
  4716. ** other than [SQLITE_ROW] before any subsequent invocation of
  4717. ** sqlite3_step(). Failure to reset the prepared statement using
  4718. ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
  4719. ** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1],
  4720. ** sqlite3_step() began
  4721. ** calling [sqlite3_reset()] automatically in this circumstance rather
  4722. ** than returning [SQLITE_MISUSE]. This is not considered a compatibility
  4723. ** break because any application that ever receives an SQLITE_MISUSE error
  4724. ** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option
  4725. ** can be used to restore the legacy behavior.
  4726. **
  4727. ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
  4728. ** API always returns a generic error code, [SQLITE_ERROR], following any
  4729. ** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call
  4730. ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the
  4731. ** specific [error codes] that better describes the error.
  4732. ** We admit that this is a goofy design. The problem has been fixed
  4733. ** with the "v2" interface. If you prepare all of your SQL statements
  4734. ** using [sqlite3_prepare_v3()] or [sqlite3_prepare_v2()]
  4735. ** or [sqlite3_prepare16_v2()] or [sqlite3_prepare16_v3()] instead
  4736. ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,
  4737. ** then the more specific [error codes] are returned directly
  4738. ** by sqlite3_step(). The use of the "vX" interfaces is recommended.
  4739. */
  4740. SQLITE_API int sqlite3_step(sqlite3_stmt*);
  4741. /*
  4742. ** CAPI3REF: Number of columns in a result set
  4743. ** METHOD: sqlite3_stmt
  4744. **
  4745. ** ^The sqlite3_data_count(P) interface returns the number of columns in the
  4746. ** current row of the result set of [prepared statement] P.
  4747. ** ^If prepared statement P does not have results ready to return
  4748. ** (via calls to the [sqlite3_column_int | sqlite3_column()] family of
  4749. ** interfaces) then sqlite3_data_count(P) returns 0.
  4750. ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
  4751. ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
  4752. ** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)
  4753. ** will return non-zero if previous call to [sqlite3_step](P) returned
  4754. ** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]
  4755. ** where it always returns zero since each step of that multi-step
  4756. ** pragma returns 0 columns of data.
  4757. **
  4758. ** See also: [sqlite3_column_count()]
  4759. */
  4760. SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
  4761. /*
  4762. ** CAPI3REF: Fundamental Datatypes
  4763. ** KEYWORDS: SQLITE_TEXT
  4764. **
  4765. ** ^(Every value in SQLite has one of five fundamental datatypes:
  4766. **
  4767. ** <ul>
  4768. ** <li> 64-bit signed integer
  4769. ** <li> 64-bit IEEE floating point number
  4770. ** <li> string
  4771. ** <li> BLOB
  4772. ** <li> NULL
  4773. ** </ul>)^
  4774. **
  4775. ** These constants are codes for each of those types.
  4776. **
  4777. ** Note that the SQLITE_TEXT constant was also used in SQLite version 2
  4778. ** for a completely different meaning. Software that links against both
  4779. ** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not
  4780. ** SQLITE_TEXT.
  4781. */
  4782. #define SQLITE_INTEGER 1
  4783. #define SQLITE_FLOAT 2
  4784. #define SQLITE_BLOB 4
  4785. #define SQLITE_NULL 5
  4786. #ifdef SQLITE_TEXT
  4787. # undef SQLITE_TEXT
  4788. #else
  4789. # define SQLITE_TEXT 3
  4790. #endif
  4791. #define SQLITE3_TEXT 3
  4792. /*
  4793. ** CAPI3REF: Result Values From A Query
  4794. ** KEYWORDS: {column access functions}
  4795. ** METHOD: sqlite3_stmt
  4796. **
  4797. ** <b>Summary:</b>
  4798. ** <blockquote><table border=0 cellpadding=0 cellspacing=0>
  4799. ** <tr><td><b>sqlite3_column_blob</b><td>&rarr;<td>BLOB result
  4800. ** <tr><td><b>sqlite3_column_double</b><td>&rarr;<td>REAL result
  4801. ** <tr><td><b>sqlite3_column_int</b><td>&rarr;<td>32-bit INTEGER result
  4802. ** <tr><td><b>sqlite3_column_int64</b><td>&rarr;<td>64-bit INTEGER result
  4803. ** <tr><td><b>sqlite3_column_text</b><td>&rarr;<td>UTF-8 TEXT result
  4804. ** <tr><td><b>sqlite3_column_text16</b><td>&rarr;<td>UTF-16 TEXT result
  4805. ** <tr><td><b>sqlite3_column_value</b><td>&rarr;<td>The result as an
  4806. ** [sqlite3_value|unprotected sqlite3_value] object.
  4807. ** <tr><td>&nbsp;<td>&nbsp;<td>&nbsp;
  4808. ** <tr><td><b>sqlite3_column_bytes</b><td>&rarr;<td>Size of a BLOB
  4809. ** or a UTF-8 TEXT result in bytes
  4810. ** <tr><td><b>sqlite3_column_bytes16&nbsp;&nbsp;</b>
  4811. ** <td>&rarr;&nbsp;&nbsp;<td>Size of UTF-16
  4812. ** TEXT in bytes
  4813. ** <tr><td><b>sqlite3_column_type</b><td>&rarr;<td>Default
  4814. ** datatype of the result
  4815. ** </table></blockquote>
  4816. **
  4817. ** <b>Details:</b>
  4818. **
  4819. ** ^These routines return information about a single column of the current
  4820. ** result row of a query. ^In every case the first argument is a pointer
  4821. ** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]
  4822. ** that was returned from [sqlite3_prepare_v2()] or one of its variants)
  4823. ** and the second argument is the index of the column for which information
  4824. ** should be returned. ^The leftmost column of the result set has the index 0.
  4825. ** ^The number of columns in the result can be determined using
  4826. ** [sqlite3_column_count()].
  4827. **
  4828. ** If the SQL statement does not currently point to a valid row, or if the
  4829. ** column index is out of range, the result is undefined.
  4830. ** These routines may only be called when the most recent call to
  4831. ** [sqlite3_step()] has returned [SQLITE_ROW] and neither
  4832. ** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently.
  4833. ** If any of these routines are called after [sqlite3_reset()] or
  4834. ** [sqlite3_finalize()] or after [sqlite3_step()] has returned
  4835. ** something other than [SQLITE_ROW], the results are undefined.
  4836. ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()]
  4837. ** are called from a different thread while any of these routines
  4838. ** are pending, then the results are undefined.
  4839. **
  4840. ** The first six interfaces (_blob, _double, _int, _int64, _text, and _text16)
  4841. ** each return the value of a result column in a specific data format. If
  4842. ** the result column is not initially in the requested format (for example,
  4843. ** if the query returns an integer but the sqlite3_column_text() interface
  4844. ** is used to extract the value) then an automatic type conversion is performed.
  4845. **
  4846. ** ^The sqlite3_column_type() routine returns the
  4847. ** [SQLITE_INTEGER | datatype code] for the initial data type
  4848. ** of the result column. ^The returned value is one of [SQLITE_INTEGER],
  4849. ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].
  4850. ** The return value of sqlite3_column_type() can be used to decide which
  4851. ** of the first six interface should be used to extract the column value.
  4852. ** The value returned by sqlite3_column_type() is only meaningful if no
  4853. ** automatic type conversions have occurred for the value in question.
  4854. ** After a type conversion, the result of calling sqlite3_column_type()
  4855. ** is undefined, though harmless. Future
  4856. ** versions of SQLite may change the behavior of sqlite3_column_type()
  4857. ** following a type conversion.
  4858. **
  4859. ** If the result is a BLOB or a TEXT string, then the sqlite3_column_bytes()
  4860. ** or sqlite3_column_bytes16() interfaces can be used to determine the size
  4861. ** of that BLOB or string.
  4862. **
  4863. ** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
  4864. ** routine returns the number of bytes in that BLOB or string.
  4865. ** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts
  4866. ** the string to UTF-8 and then returns the number of bytes.
  4867. ** ^If the result is a numeric value then sqlite3_column_bytes() uses
  4868. ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
  4869. ** the number of bytes in that string.
  4870. ** ^If the result is NULL, then sqlite3_column_bytes() returns zero.
  4871. **
  4872. ** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16()
  4873. ** routine returns the number of bytes in that BLOB or string.
  4874. ** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts
  4875. ** the string to UTF-16 and then returns the number of bytes.
  4876. ** ^If the result is a numeric value then sqlite3_column_bytes16() uses
  4877. ** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns
  4878. ** the number of bytes in that string.
  4879. ** ^If the result is NULL, then sqlite3_column_bytes16() returns zero.
  4880. **
  4881. ** ^The values returned by [sqlite3_column_bytes()] and
  4882. ** [sqlite3_column_bytes16()] do not include the zero terminators at the end
  4883. ** of the string. ^For clarity: the values returned by
  4884. ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of
  4885. ** bytes in the string, not the number of characters.
  4886. **
  4887. ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
  4888. ** even empty strings, are always zero-terminated. ^The return
  4889. ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
  4890. **
  4891. ** ^Strings returned by sqlite3_column_text16() always have the endianness
  4892. ** which is native to the platform, regardless of the text encoding set
  4893. ** for the database.
  4894. **
  4895. ** <b>Warning:</b> ^The object returned by [sqlite3_column_value()] is an
  4896. ** [unprotected sqlite3_value] object. In a multithreaded environment,
  4897. ** an unprotected sqlite3_value object may only be used safely with
  4898. ** [sqlite3_bind_value()] and [sqlite3_result_value()].
  4899. ** If the [unprotected sqlite3_value] object returned by
  4900. ** [sqlite3_column_value()] is used in any other way, including calls
  4901. ** to routines like [sqlite3_value_int()], [sqlite3_value_text()],
  4902. ** or [sqlite3_value_bytes()], the behavior is not threadsafe.
  4903. ** Hence, the sqlite3_column_value() interface
  4904. ** is normally only useful within the implementation of
  4905. ** [application-defined SQL functions] or [virtual tables], not within
  4906. ** top-level application code.
  4907. **
  4908. ** These routines may attempt to convert the datatype of the result.
  4909. ** ^For example, if the internal representation is FLOAT and a text result
  4910. ** is requested, [sqlite3_snprintf()] is used internally to perform the
  4911. ** conversion automatically. ^(The following table details the conversions
  4912. ** that are applied:
  4913. **
  4914. ** <blockquote>
  4915. ** <table border="1">
  4916. ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion
  4917. **
  4918. ** <tr><td> NULL <td> INTEGER <td> Result is 0
  4919. ** <tr><td> NULL <td> FLOAT <td> Result is 0.0
  4920. ** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer
  4921. ** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer
  4922. ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
  4923. ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
  4924. ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT
  4925. ** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER
  4926. ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
  4927. ** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB
  4928. ** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER
  4929. ** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL
  4930. ** <tr><td> TEXT <td> BLOB <td> No change
  4931. ** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER
  4932. ** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL
  4933. ** <tr><td> BLOB <td> TEXT <td> [CAST] to TEXT, ensure zero terminator
  4934. ** </table>
  4935. ** </blockquote>)^
  4936. **
  4937. ** Note that when type conversions occur, pointers returned by prior
  4938. ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
  4939. ** sqlite3_column_text16() may be invalidated.
  4940. ** Type conversions and pointer invalidations might occur
  4941. ** in the following cases:
  4942. **
  4943. ** <ul>
  4944. ** <li> The initial content is a BLOB and sqlite3_column_text() or
  4945. ** sqlite3_column_text16() is called. A zero-terminator might
  4946. ** need to be added to the string.</li>
  4947. ** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or
  4948. ** sqlite3_column_text16() is called. The content must be converted
  4949. ** to UTF-16.</li>
  4950. ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
  4951. ** sqlite3_column_text() is called. The content must be converted
  4952. ** to UTF-8.</li>
  4953. ** </ul>
  4954. **
  4955. ** ^Conversions between UTF-16be and UTF-16le are always done in place and do
  4956. ** not invalidate a prior pointer, though of course the content of the buffer
  4957. ** that the prior pointer references will have been modified. Other kinds
  4958. ** of conversion are done in place when it is possible, but sometimes they
  4959. ** are not possible and in those cases prior pointers are invalidated.
  4960. **
  4961. ** The safest policy is to invoke these routines
  4962. ** in one of the following ways:
  4963. **
  4964. ** <ul>
  4965. ** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
  4966. ** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
  4967. ** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
  4968. ** </ul>
  4969. **
  4970. ** In other words, you should call sqlite3_column_text(),
  4971. ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
  4972. ** into the desired format, then invoke sqlite3_column_bytes() or
  4973. ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls
  4974. ** to sqlite3_column_text() or sqlite3_column_blob() with calls to
  4975. ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()
  4976. ** with calls to sqlite3_column_bytes().
  4977. **
  4978. ** ^The pointers returned are valid until a type conversion occurs as
  4979. ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
  4980. ** [sqlite3_finalize()] is called. ^The memory space used to hold strings
  4981. ** and BLOBs is freed automatically. Do not pass the pointers returned
  4982. ** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
  4983. ** [sqlite3_free()].
  4984. **
  4985. ** As long as the input parameters are correct, these routines will only
  4986. ** fail if an out-of-memory error occurs during a format conversion.
  4987. ** Only the following subset of interfaces are subject to out-of-memory
  4988. ** errors:
  4989. **
  4990. ** <ul>
  4991. ** <li> sqlite3_column_blob()
  4992. ** <li> sqlite3_column_text()
  4993. ** <li> sqlite3_column_text16()
  4994. ** <li> sqlite3_column_bytes()
  4995. ** <li> sqlite3_column_bytes16()
  4996. ** </ul>
  4997. **
  4998. ** If an out-of-memory error occurs, then the return value from these
  4999. ** routines is the same as if the column had contained an SQL NULL value.
  5000. ** Valid SQL NULL returns can be distinguished from out-of-memory errors
  5001. ** by invoking the [sqlite3_errcode()] immediately after the suspect
  5002. ** return value is obtained and before any
  5003. ** other SQLite interface is called on the same [database connection].
  5004. */
  5005. SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
  5006. SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol);
  5007. SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol);
  5008. SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
  5009. SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
  5010. SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
  5011. SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
  5012. SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
  5013. SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
  5014. SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol);
  5015. /*
  5016. ** CAPI3REF: Destroy A Prepared Statement Object
  5017. ** DESTRUCTOR: sqlite3_stmt
  5018. **
  5019. ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
  5020. ** ^If the most recent evaluation of the statement encountered no errors
  5021. ** or if the statement is never been evaluated, then sqlite3_finalize() returns
  5022. ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
  5023. ** sqlite3_finalize(S) returns the appropriate [error code] or
  5024. ** [extended error code].
  5025. **
  5026. ** ^The sqlite3_finalize(S) routine can be called at any point during
  5027. ** the life cycle of [prepared statement] S:
  5028. ** before statement S is ever evaluated, after
  5029. ** one or more calls to [sqlite3_reset()], or after any call
  5030. ** to [sqlite3_step()] regardless of whether or not the statement has
  5031. ** completed execution.
  5032. **
  5033. ** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op.
  5034. **
  5035. ** The application must finalize every [prepared statement] in order to avoid
  5036. ** resource leaks. It is a grievous error for the application to try to use
  5037. ** a prepared statement after it has been finalized. Any use of a prepared
  5038. ** statement after it has been finalized can result in undefined and
  5039. ** undesirable behavior such as segfaults and heap corruption.
  5040. */
  5041. SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
  5042. /*
  5043. ** CAPI3REF: Reset A Prepared Statement Object
  5044. ** METHOD: sqlite3_stmt
  5045. **
  5046. ** The sqlite3_reset() function is called to reset a [prepared statement]
  5047. ** object back to its initial state, ready to be re-executed.
  5048. ** ^Any SQL statement variables that had values bound to them using
  5049. ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
  5050. ** Use [sqlite3_clear_bindings()] to reset the bindings.
  5051. **
  5052. ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S
  5053. ** back to the beginning of its program.
  5054. **
  5055. ** ^If the most recent call to [sqlite3_step(S)] for the
  5056. ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE],
  5057. ** or if [sqlite3_step(S)] has never before been called on S,
  5058. ** then [sqlite3_reset(S)] returns [SQLITE_OK].
  5059. **
  5060. ** ^If the most recent call to [sqlite3_step(S)] for the
  5061. ** [prepared statement] S indicated an error, then
  5062. ** [sqlite3_reset(S)] returns an appropriate [error code].
  5063. **
  5064. ** ^The [sqlite3_reset(S)] interface does not change the values
  5065. ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
  5066. */
  5067. SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
  5068. /*
  5069. ** CAPI3REF: Create Or Redefine SQL Functions
  5070. ** KEYWORDS: {function creation routines}
  5071. ** METHOD: sqlite3
  5072. **
  5073. ** ^These functions (collectively known as "function creation routines")
  5074. ** are used to add SQL functions or aggregates or to redefine the behavior
  5075. ** of existing SQL functions or aggregates. The only differences between
  5076. ** the three "sqlite3_create_function*" routines are the text encoding
  5077. ** expected for the second parameter (the name of the function being
  5078. ** created) and the presence or absence of a destructor callback for
  5079. ** the application data pointer. Function sqlite3_create_window_function()
  5080. ** is similar, but allows the user to supply the extra callback functions
  5081. ** needed by [aggregate window functions].
  5082. **
  5083. ** ^The first parameter is the [database connection] to which the SQL
  5084. ** function is to be added. ^If an application uses more than one database
  5085. ** connection then application-defined SQL functions must be added
  5086. ** to each database connection separately.
  5087. **
  5088. ** ^The second parameter is the name of the SQL function to be created or
  5089. ** redefined. ^The length of the name is limited to 255 bytes in a UTF-8
  5090. ** representation, exclusive of the zero-terminator. ^Note that the name
  5091. ** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.
  5092. ** ^Any attempt to create a function with a longer name
  5093. ** will result in [SQLITE_MISUSE] being returned.
  5094. **
  5095. ** ^The third parameter (nArg)
  5096. ** is the number of arguments that the SQL function or
  5097. ** aggregate takes. ^If this parameter is -1, then the SQL function or
  5098. ** aggregate may take any number of arguments between 0 and the limit
  5099. ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third
  5100. ** parameter is less than -1 or greater than 127 then the behavior is
  5101. ** undefined.
  5102. **
  5103. ** ^The fourth parameter, eTextRep, specifies what
  5104. ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
  5105. ** its parameters. The application should set this parameter to
  5106. ** [SQLITE_UTF16LE] if the function implementation invokes
  5107. ** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the
  5108. ** implementation invokes [sqlite3_value_text16be()] on an input, or
  5109. ** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8]
  5110. ** otherwise. ^The same SQL function may be registered multiple times using
  5111. ** different preferred text encodings, with different implementations for
  5112. ** each encoding.
  5113. ** ^When multiple implementations of the same function are available, SQLite
  5114. ** will pick the one that involves the least amount of data conversion.
  5115. **
  5116. ** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC]
  5117. ** to signal that the function will always return the same result given
  5118. ** the same inputs within a single SQL statement. Most SQL functions are
  5119. ** deterministic. The built-in [random()] SQL function is an example of a
  5120. ** function that is not deterministic. The SQLite query planner is able to
  5121. ** perform additional optimizations on deterministic functions, so use
  5122. ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
  5123. **
  5124. ** ^The fourth parameter may also optionally include the [SQLITE_DIRECTONLY]
  5125. ** flag, which if present prevents the function from being invoked from
  5126. ** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,
  5127. ** index expressions, or the WHERE clause of partial indexes.
  5128. **
  5129. ** For best security, the [SQLITE_DIRECTONLY] flag is recommended for
  5130. ** all application-defined SQL functions that do not need to be
  5131. ** used inside of triggers, view, CHECK constraints, or other elements of
  5132. ** the database schema. This flags is especially recommended for SQL
  5133. ** functions that have side effects or reveal internal application state.
  5134. ** Without this flag, an attacker might be able to modify the schema of
  5135. ** a database file to include invocations of the function with parameters
  5136. ** chosen by the attacker, which the application will then execute when
  5137. ** the database file is opened and read.
  5138. **
  5139. ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
  5140. ** function can gain access to this pointer using [sqlite3_user_data()].)^
  5141. **
  5142. ** ^The sixth, seventh and eighth parameters passed to the three
  5143. ** "sqlite3_create_function*" functions, xFunc, xStep and xFinal, are
  5144. ** pointers to C-language functions that implement the SQL function or
  5145. ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
  5146. ** callback only; NULL pointers must be passed as the xStep and xFinal
  5147. ** parameters. ^An aggregate SQL function requires an implementation of xStep
  5148. ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
  5149. ** SQL function or aggregate, pass NULL pointers for all three function
  5150. ** callbacks.
  5151. **
  5152. ** ^The sixth, seventh, eighth and ninth parameters (xStep, xFinal, xValue
  5153. ** and xInverse) passed to sqlite3_create_window_function are pointers to
  5154. ** C-language callbacks that implement the new function. xStep and xFinal
  5155. ** must both be non-NULL. xValue and xInverse may either both be NULL, in
  5156. ** which case a regular aggregate function is created, or must both be
  5157. ** non-NULL, in which case the new function may be used as either an aggregate
  5158. ** or aggregate window function. More details regarding the implementation
  5159. ** of aggregate window functions are
  5160. ** [user-defined window functions|available here].
  5161. **
  5162. ** ^(If the final parameter to sqlite3_create_function_v2() or
  5163. ** sqlite3_create_window_function() is not NULL, then it is destructor for
  5164. ** the application data pointer. The destructor is invoked when the function
  5165. ** is deleted, either by being overloaded or when the database connection
  5166. ** closes.)^ ^The destructor is also invoked if the call to
  5167. ** sqlite3_create_function_v2() fails. ^When the destructor callback is
  5168. ** invoked, it is passed a single argument which is a copy of the application
  5169. ** data pointer which was the fifth parameter to sqlite3_create_function_v2().
  5170. **
  5171. ** ^It is permitted to register multiple implementations of the same
  5172. ** functions with the same name but with either differing numbers of
  5173. ** arguments or differing preferred text encodings. ^SQLite will use
  5174. ** the implementation that most closely matches the way in which the
  5175. ** SQL function is used. ^A function implementation with a non-negative
  5176. ** nArg parameter is a better match than a function implementation with
  5177. ** a negative nArg. ^A function where the preferred text encoding
  5178. ** matches the database encoding is a better
  5179. ** match than a function where the encoding is different.
  5180. ** ^A function where the encoding difference is between UTF16le and UTF16be
  5181. ** is a closer match than a function where the encoding difference is
  5182. ** between UTF8 and UTF16.
  5183. **
  5184. ** ^Built-in functions may be overloaded by new application-defined functions.
  5185. **
  5186. ** ^An application-defined function is permitted to call other
  5187. ** SQLite interfaces. However, such calls must not
  5188. ** close the database connection nor finalize or reset the prepared
  5189. ** statement in which the function is running.
  5190. */
  5191. SQLITE_API int sqlite3_create_function(
  5192. sqlite3 *db,
  5193. const char *zFunctionName,
  5194. int nArg,
  5195. int eTextRep,
  5196. void *pApp,
  5197. void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  5198. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  5199. void (*xFinal)(sqlite3_context*)
  5200. );
  5201. SQLITE_API int sqlite3_create_function16(
  5202. sqlite3 *db,
  5203. const void *zFunctionName,
  5204. int nArg,
  5205. int eTextRep,
  5206. void *pApp,
  5207. void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  5208. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  5209. void (*xFinal)(sqlite3_context*)
  5210. );
  5211. SQLITE_API int sqlite3_create_function_v2(
  5212. sqlite3 *db,
  5213. const char *zFunctionName,
  5214. int nArg,
  5215. int eTextRep,
  5216. void *pApp,
  5217. void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  5218. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  5219. void (*xFinal)(sqlite3_context*),
  5220. void(*xDestroy)(void*)
  5221. );
  5222. SQLITE_API int sqlite3_create_window_function(
  5223. sqlite3 *db,
  5224. const char *zFunctionName,
  5225. int nArg,
  5226. int eTextRep,
  5227. void *pApp,
  5228. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  5229. void (*xFinal)(sqlite3_context*),
  5230. void (*xValue)(sqlite3_context*),
  5231. void (*xInverse)(sqlite3_context*,int,sqlite3_value**),
  5232. void(*xDestroy)(void*)
  5233. );
  5234. /*
  5235. ** CAPI3REF: Text Encodings
  5236. **
  5237. ** These constant define integer codes that represent the various
  5238. ** text encodings supported by SQLite.
  5239. */
  5240. #define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
  5241. #define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
  5242. #define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
  5243. #define SQLITE_UTF16 4 /* Use native byte order */
  5244. #define SQLITE_ANY 5 /* Deprecated */
  5245. #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
  5246. /*
  5247. ** CAPI3REF: Function Flags
  5248. **
  5249. ** These constants may be ORed together with the
  5250. ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
  5251. ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
  5252. ** [sqlite3_create_function_v2()].
  5253. **
  5254. ** <dl>
  5255. ** [[SQLITE_DETERMINISTIC]] <dt>SQLITE_DETERMINISTIC</dt><dd>
  5256. ** The SQLITE_DETERMINISTIC flag means that the new function always gives
  5257. ** the same output when the input parameters are the same.
  5258. ** The [abs|abs() function] is deterministic, for example, but
  5259. ** [randomblob|randomblob()] is not. Functions must
  5260. ** be deterministic in order to be used in certain contexts such as
  5261. ** with the WHERE clause of [partial indexes] or in [generated columns].
  5262. ** SQLite might also optimize deterministic functions by factoring them
  5263. ** out of inner loops.
  5264. ** </dd>
  5265. **
  5266. ** [[SQLITE_DIRECTONLY]] <dt>SQLITE_DIRECTONLY</dt><dd>
  5267. ** The SQLITE_DIRECTONLY flag means that the function may only be invoked
  5268. ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in
  5269. ** schema structures such as [CHECK constraints], [DEFAULT clauses],
  5270. ** [expression indexes], [partial indexes], or [generated columns].
  5271. ** The SQLITE_DIRECTONLY flags is a security feature which is recommended
  5272. ** for all [application-defined SQL functions], and especially for functions
  5273. ** that have side-effects or that could potentially leak sensitive
  5274. ** information.
  5275. ** </dd>
  5276. **
  5277. ** [[SQLITE_INNOCUOUS]] <dt>SQLITE_INNOCUOUS</dt><dd>
  5278. ** The SQLITE_INNOCUOUS flag means that the function is unlikely
  5279. ** to cause problems even if misused. An innocuous function should have
  5280. ** no side effects and should not depend on any values other than its
  5281. ** input parameters. The [abs|abs() function] is an example of an
  5282. ** innocuous function.
  5283. ** The [load_extension() SQL function] is not innocuous because of its
  5284. ** side effects.
  5285. ** <p> SQLITE_INNOCUOUS is similar to SQLITE_DETERMINISTIC, but is not
  5286. ** exactly the same. The [random|random() function] is an example of a
  5287. ** function that is innocuous but not deterministic.
  5288. ** <p>Some heightened security settings
  5289. ** ([SQLITE_DBCONFIG_TRUSTED_SCHEMA] and [PRAGMA trusted_schema=OFF])
  5290. ** disable the use of SQL functions inside views and triggers and in
  5291. ** schema structures such as [CHECK constraints], [DEFAULT clauses],
  5292. ** [expression indexes], [partial indexes], and [generated columns] unless
  5293. ** the function is tagged with SQLITE_INNOCUOUS. Most built-in functions
  5294. ** are innocuous. Developers are advised to avoid using the
  5295. ** SQLITE_INNOCUOUS flag for application-defined functions unless the
  5296. ** function has been carefully audited and found to be free of potentially
  5297. ** security-adverse side-effects and information-leaks.
  5298. ** </dd>
  5299. **
  5300. ** [[SQLITE_SUBTYPE]] <dt>SQLITE_SUBTYPE</dt><dd>
  5301. ** The SQLITE_SUBTYPE flag indicates to SQLite that a function may call
  5302. ** [sqlite3_value_subtype()] to inspect the sub-types of its arguments.
  5303. ** Specifying this flag makes no difference for scalar or aggregate user
  5304. ** functions. However, if it is not specified for a user-defined window
  5305. ** function, then any sub-types belonging to arguments passed to the window
  5306. ** function may be discarded before the window function is called (i.e.
  5307. ** sqlite3_value_subtype() will always return 0).
  5308. ** </dd>
  5309. ** </dl>
  5310. */
  5311. #define SQLITE_DETERMINISTIC 0x000000800
  5312. #define SQLITE_DIRECTONLY 0x000080000
  5313. #define SQLITE_SUBTYPE 0x000100000
  5314. #define SQLITE_INNOCUOUS 0x000200000
  5315. /*
  5316. ** CAPI3REF: Deprecated Functions
  5317. ** DEPRECATED
  5318. **
  5319. ** These functions are [deprecated]. In order to maintain
  5320. ** backwards compatibility with older code, these functions continue
  5321. ** to be supported. However, new applications should avoid
  5322. ** the use of these functions. To encourage programmers to avoid
  5323. ** these functions, we will not explain what they do.
  5324. */
  5325. #ifndef SQLITE_OMIT_DEPRECATED
  5326. SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
  5327. SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
  5328. SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
  5329. SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);
  5330. SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
  5331. SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),
  5332. void*,sqlite3_int64);
  5333. #endif
  5334. /*
  5335. ** CAPI3REF: Obtaining SQL Values
  5336. ** METHOD: sqlite3_value
  5337. **
  5338. ** <b>Summary:</b>
  5339. ** <blockquote><table border=0 cellpadding=0 cellspacing=0>
  5340. ** <tr><td><b>sqlite3_value_blob</b><td>&rarr;<td>BLOB value
  5341. ** <tr><td><b>sqlite3_value_double</b><td>&rarr;<td>REAL value
  5342. ** <tr><td><b>sqlite3_value_int</b><td>&rarr;<td>32-bit INTEGER value
  5343. ** <tr><td><b>sqlite3_value_int64</b><td>&rarr;<td>64-bit INTEGER value
  5344. ** <tr><td><b>sqlite3_value_pointer</b><td>&rarr;<td>Pointer value
  5345. ** <tr><td><b>sqlite3_value_text</b><td>&rarr;<td>UTF-8 TEXT value
  5346. ** <tr><td><b>sqlite3_value_text16</b><td>&rarr;<td>UTF-16 TEXT value in
  5347. ** the native byteorder
  5348. ** <tr><td><b>sqlite3_value_text16be</b><td>&rarr;<td>UTF-16be TEXT value
  5349. ** <tr><td><b>sqlite3_value_text16le</b><td>&rarr;<td>UTF-16le TEXT value
  5350. ** <tr><td>&nbsp;<td>&nbsp;<td>&nbsp;
  5351. ** <tr><td><b>sqlite3_value_bytes</b><td>&rarr;<td>Size of a BLOB
  5352. ** or a UTF-8 TEXT in bytes
  5353. ** <tr><td><b>sqlite3_value_bytes16&nbsp;&nbsp;</b>
  5354. ** <td>&rarr;&nbsp;&nbsp;<td>Size of UTF-16
  5355. ** TEXT in bytes
  5356. ** <tr><td><b>sqlite3_value_type</b><td>&rarr;<td>Default
  5357. ** datatype of the value
  5358. ** <tr><td><b>sqlite3_value_numeric_type&nbsp;&nbsp;</b>
  5359. ** <td>&rarr;&nbsp;&nbsp;<td>Best numeric datatype of the value
  5360. ** <tr><td><b>sqlite3_value_nochange&nbsp;&nbsp;</b>
  5361. ** <td>&rarr;&nbsp;&nbsp;<td>True if the column is unchanged in an UPDATE
  5362. ** against a virtual table.
  5363. ** <tr><td><b>sqlite3_value_frombind&nbsp;&nbsp;</b>
  5364. ** <td>&rarr;&nbsp;&nbsp;<td>True if value originated from a [bound parameter]
  5365. ** </table></blockquote>
  5366. **
  5367. ** <b>Details:</b>
  5368. **
  5369. ** These routines extract type, size, and content information from
  5370. ** [protected sqlite3_value] objects. Protected sqlite3_value objects
  5371. ** are used to pass parameter information into the functions that
  5372. ** implement [application-defined SQL functions] and [virtual tables].
  5373. **
  5374. ** These routines work only with [protected sqlite3_value] objects.
  5375. ** Any attempt to use these routines on an [unprotected sqlite3_value]
  5376. ** is not threadsafe.
  5377. **
  5378. ** ^These routines work just like the corresponding [column access functions]
  5379. ** except that these routines take a single [protected sqlite3_value] object
  5380. ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
  5381. **
  5382. ** ^The sqlite3_value_text16() interface extracts a UTF-16 string
  5383. ** in the native byte-order of the host machine. ^The
  5384. ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
  5385. ** extract UTF-16 strings as big-endian and little-endian respectively.
  5386. **
  5387. ** ^If [sqlite3_value] object V was initialized
  5388. ** using [sqlite3_bind_pointer(S,I,P,X,D)] or [sqlite3_result_pointer(C,P,X,D)]
  5389. ** and if X and Y are strings that compare equal according to strcmp(X,Y),
  5390. ** then sqlite3_value_pointer(V,Y) will return the pointer P. ^Otherwise,
  5391. ** sqlite3_value_pointer(V,Y) returns a NULL. The sqlite3_bind_pointer()
  5392. ** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
  5393. **
  5394. ** ^(The sqlite3_value_type(V) interface returns the
  5395. ** [SQLITE_INTEGER | datatype code] for the initial datatype of the
  5396. ** [sqlite3_value] object V. The returned value is one of [SQLITE_INTEGER],
  5397. ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].)^
  5398. ** Other interfaces might change the datatype for an sqlite3_value object.
  5399. ** For example, if the datatype is initially SQLITE_INTEGER and
  5400. ** sqlite3_value_text(V) is called to extract a text value for that
  5401. ** integer, then subsequent calls to sqlite3_value_type(V) might return
  5402. ** SQLITE_TEXT. Whether or not a persistent internal datatype conversion
  5403. ** occurs is undefined and may change from one release of SQLite to the next.
  5404. **
  5405. ** ^(The sqlite3_value_numeric_type() interface attempts to apply
  5406. ** numeric affinity to the value. This means that an attempt is
  5407. ** made to convert the value to an integer or floating point. If
  5408. ** such a conversion is possible without loss of information (in other
  5409. ** words, if the value is a string that looks like a number)
  5410. ** then the conversion is performed. Otherwise no conversion occurs.
  5411. ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
  5412. **
  5413. ** ^Within the [xUpdate] method of a [virtual table], the
  5414. ** sqlite3_value_nochange(X) interface returns true if and only if
  5415. ** the column corresponding to X is unchanged by the UPDATE operation
  5416. ** that the xUpdate method call was invoked to implement and if
  5417. ** and the prior [xColumn] method call that was invoked to extracted
  5418. ** the value for that column returned without setting a result (probably
  5419. ** because it queried [sqlite3_vtab_nochange()] and found that the column
  5420. ** was unchanging). ^Within an [xUpdate] method, any value for which
  5421. ** sqlite3_value_nochange(X) is true will in all other respects appear
  5422. ** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
  5423. ** than within an [xUpdate] method call for an UPDATE statement, then
  5424. ** the return value is arbitrary and meaningless.
  5425. **
  5426. ** ^The sqlite3_value_frombind(X) interface returns non-zero if the
  5427. ** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()]
  5428. ** interfaces. ^If X comes from an SQL literal value, or a table column,
  5429. ** or an expression, then sqlite3_value_frombind(X) returns zero.
  5430. **
  5431. ** Please pay particular attention to the fact that the pointer returned
  5432. ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
  5433. ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
  5434. ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
  5435. ** or [sqlite3_value_text16()].
  5436. **
  5437. ** These routines must be called from the same thread as
  5438. ** the SQL function that supplied the [sqlite3_value*] parameters.
  5439. **
  5440. ** As long as the input parameter is correct, these routines can only
  5441. ** fail if an out-of-memory error occurs during a format conversion.
  5442. ** Only the following subset of interfaces are subject to out-of-memory
  5443. ** errors:
  5444. **
  5445. ** <ul>
  5446. ** <li> sqlite3_value_blob()
  5447. ** <li> sqlite3_value_text()
  5448. ** <li> sqlite3_value_text16()
  5449. ** <li> sqlite3_value_text16le()
  5450. ** <li> sqlite3_value_text16be()
  5451. ** <li> sqlite3_value_bytes()
  5452. ** <li> sqlite3_value_bytes16()
  5453. ** </ul>
  5454. **
  5455. ** If an out-of-memory error occurs, then the return value from these
  5456. ** routines is the same as if the column had contained an SQL NULL value.
  5457. ** Valid SQL NULL returns can be distinguished from out-of-memory errors
  5458. ** by invoking the [sqlite3_errcode()] immediately after the suspect
  5459. ** return value is obtained and before any
  5460. ** other SQLite interface is called on the same [database connection].
  5461. */
  5462. SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);
  5463. SQLITE_API double sqlite3_value_double(sqlite3_value*);
  5464. SQLITE_API int sqlite3_value_int(sqlite3_value*);
  5465. SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
  5466. SQLITE_API void *sqlite3_value_pointer(sqlite3_value*, const char*);
  5467. SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);
  5468. SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);
  5469. SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);
  5470. SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
  5471. SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
  5472. SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
  5473. SQLITE_API int sqlite3_value_type(sqlite3_value*);
  5474. SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
  5475. SQLITE_API int sqlite3_value_nochange(sqlite3_value*);
  5476. SQLITE_API int sqlite3_value_frombind(sqlite3_value*);
  5477. /*
  5478. ** CAPI3REF: Finding The Subtype Of SQL Values
  5479. ** METHOD: sqlite3_value
  5480. **
  5481. ** The sqlite3_value_subtype(V) function returns the subtype for
  5482. ** an [application-defined SQL function] argument V. The subtype
  5483. ** information can be used to pass a limited amount of context from
  5484. ** one SQL function to another. Use the [sqlite3_result_subtype()]
  5485. ** routine to set the subtype for the return value of an SQL function.
  5486. */
  5487. SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value*);
  5488. /*
  5489. ** CAPI3REF: Copy And Free SQL Values
  5490. ** METHOD: sqlite3_value
  5491. **
  5492. ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
  5493. ** object D and returns a pointer to that copy. ^The [sqlite3_value] returned
  5494. ** is a [protected sqlite3_value] object even if the input is not.
  5495. ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
  5496. ** memory allocation fails. ^If V is a [pointer value], then the result
  5497. ** of sqlite3_value_dup(V) is a NULL value.
  5498. **
  5499. ** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object
  5500. ** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer
  5501. ** then sqlite3_value_free(V) is a harmless no-op.
  5502. */
  5503. SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value*);
  5504. SQLITE_API void sqlite3_value_free(sqlite3_value*);
  5505. /*
  5506. ** CAPI3REF: Obtain Aggregate Function Context
  5507. ** METHOD: sqlite3_context
  5508. **
  5509. ** Implementations of aggregate SQL functions use this
  5510. ** routine to allocate memory for storing their state.
  5511. **
  5512. ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
  5513. ** for a particular aggregate function, SQLite allocates
  5514. ** N bytes of memory, zeroes out that memory, and returns a pointer
  5515. ** to the new memory. ^On second and subsequent calls to
  5516. ** sqlite3_aggregate_context() for the same aggregate function instance,
  5517. ** the same buffer is returned. Sqlite3_aggregate_context() is normally
  5518. ** called once for each invocation of the xStep callback and then one
  5519. ** last time when the xFinal callback is invoked. ^(When no rows match
  5520. ** an aggregate query, the xStep() callback of the aggregate function
  5521. ** implementation is never called and xFinal() is called exactly once.
  5522. ** In those cases, sqlite3_aggregate_context() might be called for the
  5523. ** first time from within xFinal().)^
  5524. **
  5525. ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
  5526. ** when first called if N is less than or equal to zero or if a memory
  5527. ** allocate error occurs.
  5528. **
  5529. ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
  5530. ** determined by the N parameter on first successful call. Changing the
  5531. ** value of N in any subsequent call to sqlite3_aggregate_context() within
  5532. ** the same aggregate function instance will not resize the memory
  5533. ** allocation.)^ Within the xFinal callback, it is customary to set
  5534. ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
  5535. ** pointless memory allocations occur.
  5536. **
  5537. ** ^SQLite automatically frees the memory allocated by
  5538. ** sqlite3_aggregate_context() when the aggregate query concludes.
  5539. **
  5540. ** The first parameter must be a copy of the
  5541. ** [sqlite3_context | SQL function context] that is the first parameter
  5542. ** to the xStep or xFinal callback routine that implements the aggregate
  5543. ** function.
  5544. **
  5545. ** This routine must be called from the same thread in which
  5546. ** the aggregate SQL function is running.
  5547. */
  5548. SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
  5549. /*
  5550. ** CAPI3REF: User Data For Functions
  5551. ** METHOD: sqlite3_context
  5552. **
  5553. ** ^The sqlite3_user_data() interface returns a copy of
  5554. ** the pointer that was the pUserData parameter (the 5th parameter)
  5555. ** of the [sqlite3_create_function()]
  5556. ** and [sqlite3_create_function16()] routines that originally
  5557. ** registered the application defined function.
  5558. **
  5559. ** This routine must be called from the same thread in which
  5560. ** the application-defined function is running.
  5561. */
  5562. SQLITE_API void *sqlite3_user_data(sqlite3_context*);
  5563. /*
  5564. ** CAPI3REF: Database Connection For Functions
  5565. ** METHOD: sqlite3_context
  5566. **
  5567. ** ^The sqlite3_context_db_handle() interface returns a copy of
  5568. ** the pointer to the [database connection] (the 1st parameter)
  5569. ** of the [sqlite3_create_function()]
  5570. ** and [sqlite3_create_function16()] routines that originally
  5571. ** registered the application defined function.
  5572. */
  5573. SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
  5574. /*
  5575. ** CAPI3REF: Function Auxiliary Data
  5576. ** METHOD: sqlite3_context
  5577. **
  5578. ** These functions may be used by (non-aggregate) SQL functions to
  5579. ** associate metadata with argument values. If the same value is passed to
  5580. ** multiple invocations of the same SQL function during query execution, under
  5581. ** some circumstances the associated metadata may be preserved. An example
  5582. ** of where this might be useful is in a regular-expression matching
  5583. ** function. The compiled version of the regular expression can be stored as
  5584. ** metadata associated with the pattern string.
  5585. ** Then as long as the pattern string remains the same,
  5586. ** the compiled regular expression can be reused on multiple
  5587. ** invocations of the same function.
  5588. **
  5589. ** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the metadata
  5590. ** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument
  5591. ** value to the application-defined function. ^N is zero for the left-most
  5592. ** function argument. ^If there is no metadata
  5593. ** associated with the function argument, the sqlite3_get_auxdata(C,N) interface
  5594. ** returns a NULL pointer.
  5595. **
  5596. ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
  5597. ** argument of the application-defined function. ^Subsequent
  5598. ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
  5599. ** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or
  5600. ** NULL if the metadata has been discarded.
  5601. ** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL,
  5602. ** SQLite will invoke the destructor function X with parameter P exactly
  5603. ** once, when the metadata is discarded.
  5604. ** SQLite is free to discard the metadata at any time, including: <ul>
  5605. ** <li> ^(when the corresponding function parameter changes)^, or
  5606. ** <li> ^(when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
  5607. ** SQL statement)^, or
  5608. ** <li> ^(when sqlite3_set_auxdata() is invoked again on the same
  5609. ** parameter)^, or
  5610. ** <li> ^(during the original sqlite3_set_auxdata() call when a memory
  5611. ** allocation error occurs.)^ </ul>
  5612. **
  5613. ** Note the last bullet in particular. The destructor X in
  5614. ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the
  5615. ** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata()
  5616. ** should be called near the end of the function implementation and the
  5617. ** function implementation should not make any use of P after
  5618. ** sqlite3_set_auxdata() has been called.
  5619. **
  5620. ** ^(In practice, metadata is preserved between function calls for
  5621. ** function parameters that are compile-time constants, including literal
  5622. ** values and [parameters] and expressions composed from the same.)^
  5623. **
  5624. ** The value of the N parameter to these interfaces should be non-negative.
  5625. ** Future enhancements may make use of negative N values to define new
  5626. ** kinds of function caching behavior.
  5627. **
  5628. ** These routines must be called from the same thread in which
  5629. ** the SQL function is running.
  5630. */
  5631. SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
  5632. SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
  5633. /*
  5634. ** CAPI3REF: Constants Defining Special Destructor Behavior
  5635. **
  5636. ** These are special values for the destructor that is passed in as the
  5637. ** final argument to routines like [sqlite3_result_blob()]. ^If the destructor
  5638. ** argument is SQLITE_STATIC, it means that the content pointer is constant
  5639. ** and will never change. It does not need to be destroyed. ^The
  5640. ** SQLITE_TRANSIENT value means that the content will likely change in
  5641. ** the near future and that SQLite should make its own private copy of
  5642. ** the content before returning.
  5643. **
  5644. ** The typedef is necessary to work around problems in certain
  5645. ** C++ compilers.
  5646. */
  5647. typedef void (*sqlite3_destructor_type)(void*);
  5648. #define SQLITE_STATIC ((sqlite3_destructor_type)0)
  5649. #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
  5650. /*
  5651. ** CAPI3REF: Setting The Result Of An SQL Function
  5652. ** METHOD: sqlite3_context
  5653. **
  5654. ** These routines are used by the xFunc or xFinal callbacks that
  5655. ** implement SQL functions and aggregates. See
  5656. ** [sqlite3_create_function()] and [sqlite3_create_function16()]
  5657. ** for additional information.
  5658. **
  5659. ** These functions work very much like the [parameter binding] family of
  5660. ** functions used to bind values to host parameters in prepared statements.
  5661. ** Refer to the [SQL parameter] documentation for additional information.
  5662. **
  5663. ** ^The sqlite3_result_blob() interface sets the result from
  5664. ** an application-defined function to be the BLOB whose content is pointed
  5665. ** to by the second parameter and which is N bytes long where N is the
  5666. ** third parameter.
  5667. **
  5668. ** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N)
  5669. ** interfaces set the result of the application-defined function to be
  5670. ** a BLOB containing all zero bytes and N bytes in size.
  5671. **
  5672. ** ^The sqlite3_result_double() interface sets the result from
  5673. ** an application-defined function to be a floating point value specified
  5674. ** by its 2nd argument.
  5675. **
  5676. ** ^The sqlite3_result_error() and sqlite3_result_error16() functions
  5677. ** cause the implemented SQL function to throw an exception.
  5678. ** ^SQLite uses the string pointed to by the
  5679. ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
  5680. ** as the text of an error message. ^SQLite interprets the error
  5681. ** message string from sqlite3_result_error() as UTF-8. ^SQLite
  5682. ** interprets the string from sqlite3_result_error16() as UTF-16 using
  5683. ** the same [byte-order determination rules] as [sqlite3_bind_text16()].
  5684. ** ^If the third parameter to sqlite3_result_error()
  5685. ** or sqlite3_result_error16() is negative then SQLite takes as the error
  5686. ** message all text up through the first zero character.
  5687. ** ^If the third parameter to sqlite3_result_error() or
  5688. ** sqlite3_result_error16() is non-negative then SQLite takes that many
  5689. ** bytes (not characters) from the 2nd parameter as the error message.
  5690. ** ^The sqlite3_result_error() and sqlite3_result_error16()
  5691. ** routines make a private copy of the error message text before
  5692. ** they return. Hence, the calling function can deallocate or
  5693. ** modify the text after they return without harm.
  5694. ** ^The sqlite3_result_error_code() function changes the error code
  5695. ** returned by SQLite as a result of an error in a function. ^By default,
  5696. ** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error()
  5697. ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
  5698. **
  5699. ** ^The sqlite3_result_error_toobig() interface causes SQLite to throw an
  5700. ** error indicating that a string or BLOB is too long to represent.
  5701. **
  5702. ** ^The sqlite3_result_error_nomem() interface causes SQLite to throw an
  5703. ** error indicating that a memory allocation failed.
  5704. **
  5705. ** ^The sqlite3_result_int() interface sets the return value
  5706. ** of the application-defined function to be the 32-bit signed integer
  5707. ** value given in the 2nd argument.
  5708. ** ^The sqlite3_result_int64() interface sets the return value
  5709. ** of the application-defined function to be the 64-bit signed integer
  5710. ** value given in the 2nd argument.
  5711. **
  5712. ** ^The sqlite3_result_null() interface sets the return value
  5713. ** of the application-defined function to be NULL.
  5714. **
  5715. ** ^The sqlite3_result_text(), sqlite3_result_text16(),
  5716. ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
  5717. ** set the return value of the application-defined function to be
  5718. ** a text string which is represented as UTF-8, UTF-16 native byte order,
  5719. ** UTF-16 little endian, or UTF-16 big endian, respectively.
  5720. ** ^The sqlite3_result_text64() interface sets the return value of an
  5721. ** application-defined function to be a text string in an encoding
  5722. ** specified by the fifth (and last) parameter, which must be one
  5723. ** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE].
  5724. ** ^SQLite takes the text result from the application from
  5725. ** the 2nd parameter of the sqlite3_result_text* interfaces.
  5726. ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
  5727. ** is negative, then SQLite takes result text from the 2nd parameter
  5728. ** through the first zero character.
  5729. ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
  5730. ** is non-negative, then as many bytes (not characters) of the text
  5731. ** pointed to by the 2nd parameter are taken as the application-defined
  5732. ** function result. If the 3rd parameter is non-negative, then it
  5733. ** must be the byte offset into the string where the NUL terminator would
  5734. ** appear if the string where NUL terminated. If any NUL characters occur
  5735. ** in the string at a byte offset that is less than the value of the 3rd
  5736. ** parameter, then the resulting string will contain embedded NULs and the
  5737. ** result of expressions operating on strings with embedded NULs is undefined.
  5738. ** ^If the 4th parameter to the sqlite3_result_text* interfaces
  5739. ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
  5740. ** function as the destructor on the text or BLOB result when it has
  5741. ** finished using that result.
  5742. ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to
  5743. ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite
  5744. ** assumes that the text or BLOB result is in constant space and does not
  5745. ** copy the content of the parameter nor call a destructor on the content
  5746. ** when it has finished using that result.
  5747. ** ^If the 4th parameter to the sqlite3_result_text* interfaces
  5748. ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
  5749. ** then SQLite makes a copy of the result into space obtained
  5750. ** from [sqlite3_malloc()] before it returns.
  5751. **
  5752. ** ^For the sqlite3_result_text16(), sqlite3_result_text16le(), and
  5753. ** sqlite3_result_text16be() routines, and for sqlite3_result_text64()
  5754. ** when the encoding is not UTF8, if the input UTF16 begins with a
  5755. ** byte-order mark (BOM, U+FEFF) then the BOM is removed from the
  5756. ** string and the rest of the string is interpreted according to the
  5757. ** byte-order specified by the BOM. ^The byte-order specified by
  5758. ** the BOM at the beginning of the text overrides the byte-order
  5759. ** specified by the interface procedure. ^So, for example, if
  5760. ** sqlite3_result_text16le() is invoked with text that begins
  5761. ** with bytes 0xfe, 0xff (a big-endian byte-order mark) then the
  5762. ** first two bytes of input are skipped and the remaining input
  5763. ** is interpreted as UTF16BE text.
  5764. **
  5765. ** ^For UTF16 input text to the sqlite3_result_text16(),
  5766. ** sqlite3_result_text16be(), sqlite3_result_text16le(), and
  5767. ** sqlite3_result_text64() routines, if the text contains invalid
  5768. ** UTF16 characters, the invalid characters might be converted
  5769. ** into the unicode replacement character, U+FFFD.
  5770. **
  5771. ** ^The sqlite3_result_value() interface sets the result of
  5772. ** the application-defined function to be a copy of the
  5773. ** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The
  5774. ** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
  5775. ** so that the [sqlite3_value] specified in the parameter may change or
  5776. ** be deallocated after sqlite3_result_value() returns without harm.
  5777. ** ^A [protected sqlite3_value] object may always be used where an
  5778. ** [unprotected sqlite3_value] object is required, so either
  5779. ** kind of [sqlite3_value] object can be used with this interface.
  5780. **
  5781. ** ^The sqlite3_result_pointer(C,P,T,D) interface sets the result to an
  5782. ** SQL NULL value, just like [sqlite3_result_null(C)], except that it
  5783. ** also associates the host-language pointer P or type T with that
  5784. ** NULL value such that the pointer can be retrieved within an
  5785. ** [application-defined SQL function] using [sqlite3_value_pointer()].
  5786. ** ^If the D parameter is not NULL, then it is a pointer to a destructor
  5787. ** for the P parameter. ^SQLite invokes D with P as its only argument
  5788. ** when SQLite is finished with P. The T parameter should be a static
  5789. ** string and preferably a string literal. The sqlite3_result_pointer()
  5790. ** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
  5791. **
  5792. ** If these routines are called from within the different thread
  5793. ** than the one containing the application-defined function that received
  5794. ** the [sqlite3_context] pointer, the results are undefined.
  5795. */
  5796. SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
  5797. SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,
  5798. sqlite3_uint64,void(*)(void*));
  5799. SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
  5800. SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
  5801. SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
  5802. SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
  5803. SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
  5804. SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int);
  5805. SQLITE_API void sqlite3_result_int(sqlite3_context*, int);
  5806. SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
  5807. SQLITE_API void sqlite3_result_null(sqlite3_context*);
  5808. SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
  5809. SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64,
  5810. void(*)(void*), unsigned char encoding);
  5811. SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
  5812. SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
  5813. SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
  5814. SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
  5815. SQLITE_API void sqlite3_result_pointer(sqlite3_context*, void*,const char*,void(*)(void*));
  5816. SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
  5817. SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
  5818. /*
  5819. ** CAPI3REF: Setting The Subtype Of An SQL Function
  5820. ** METHOD: sqlite3_context
  5821. **
  5822. ** The sqlite3_result_subtype(C,T) function causes the subtype of
  5823. ** the result from the [application-defined SQL function] with
  5824. ** [sqlite3_context] C to be the value T. Only the lower 8 bits
  5825. ** of the subtype T are preserved in current versions of SQLite;
  5826. ** higher order bits are discarded.
  5827. ** The number of subtype bytes preserved by SQLite might increase
  5828. ** in future releases of SQLite.
  5829. */
  5830. SQLITE_API void sqlite3_result_subtype(sqlite3_context*,unsigned int);
  5831. /*
  5832. ** CAPI3REF: Define New Collating Sequences
  5833. ** METHOD: sqlite3
  5834. **
  5835. ** ^These functions add, remove, or modify a [collation] associated
  5836. ** with the [database connection] specified as the first argument.
  5837. **
  5838. ** ^The name of the collation is a UTF-8 string
  5839. ** for sqlite3_create_collation() and sqlite3_create_collation_v2()
  5840. ** and a UTF-16 string in native byte order for sqlite3_create_collation16().
  5841. ** ^Collation names that compare equal according to [sqlite3_strnicmp()] are
  5842. ** considered to be the same name.
  5843. **
  5844. ** ^(The third argument (eTextRep) must be one of the constants:
  5845. ** <ul>
  5846. ** <li> [SQLITE_UTF8],
  5847. ** <li> [SQLITE_UTF16LE],
  5848. ** <li> [SQLITE_UTF16BE],
  5849. ** <li> [SQLITE_UTF16], or
  5850. ** <li> [SQLITE_UTF16_ALIGNED].
  5851. ** </ul>)^
  5852. ** ^The eTextRep argument determines the encoding of strings passed
  5853. ** to the collating function callback, xCompare.
  5854. ** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
  5855. ** force strings to be UTF16 with native byte order.
  5856. ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
  5857. ** on an even byte address.
  5858. **
  5859. ** ^The fourth argument, pArg, is an application data pointer that is passed
  5860. ** through as the first argument to the collating function callback.
  5861. **
  5862. ** ^The fifth argument, xCompare, is a pointer to the collating function.
  5863. ** ^Multiple collating functions can be registered using the same name but
  5864. ** with different eTextRep parameters and SQLite will use whichever
  5865. ** function requires the least amount of data transformation.
  5866. ** ^If the xCompare argument is NULL then the collating function is
  5867. ** deleted. ^When all collating functions having the same name are deleted,
  5868. ** that collation is no longer usable.
  5869. **
  5870. ** ^The collating function callback is invoked with a copy of the pArg
  5871. ** application data pointer and with two strings in the encoding specified
  5872. ** by the eTextRep argument. The two integer parameters to the collating
  5873. ** function callback are the length of the two strings, in bytes. The collating
  5874. ** function must return an integer that is negative, zero, or positive
  5875. ** if the first string is less than, equal to, or greater than the second,
  5876. ** respectively. A collating function must always return the same answer
  5877. ** given the same inputs. If two or more collating functions are registered
  5878. ** to the same collation name (using different eTextRep values) then all
  5879. ** must give an equivalent answer when invoked with equivalent strings.
  5880. ** The collating function must obey the following properties for all
  5881. ** strings A, B, and C:
  5882. **
  5883. ** <ol>
  5884. ** <li> If A==B then B==A.
  5885. ** <li> If A==B and B==C then A==C.
  5886. ** <li> If A&lt;B THEN B&gt;A.
  5887. ** <li> If A&lt;B and B&lt;C then A&lt;C.
  5888. ** </ol>
  5889. **
  5890. ** If a collating function fails any of the above constraints and that
  5891. ** collating function is registered and used, then the behavior of SQLite
  5892. ** is undefined.
  5893. **
  5894. ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
  5895. ** with the addition that the xDestroy callback is invoked on pArg when
  5896. ** the collating function is deleted.
  5897. ** ^Collating functions are deleted when they are overridden by later
  5898. ** calls to the collation creation functions or when the
  5899. ** [database connection] is closed using [sqlite3_close()].
  5900. **
  5901. ** ^The xDestroy callback is <u>not</u> called if the
  5902. ** sqlite3_create_collation_v2() function fails. Applications that invoke
  5903. ** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should
  5904. ** check the return code and dispose of the application data pointer
  5905. ** themselves rather than expecting SQLite to deal with it for them.
  5906. ** This is different from every other SQLite interface. The inconsistency
  5907. ** is unfortunate but cannot be changed without breaking backwards
  5908. ** compatibility.
  5909. **
  5910. ** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
  5911. */
  5912. SQLITE_API int sqlite3_create_collation(
  5913. sqlite3*,
  5914. const char *zName,
  5915. int eTextRep,
  5916. void *pArg,
  5917. int(*xCompare)(void*,int,const void*,int,const void*)
  5918. );
  5919. SQLITE_API int sqlite3_create_collation_v2(
  5920. sqlite3*,
  5921. const char *zName,
  5922. int eTextRep,
  5923. void *pArg,
  5924. int(*xCompare)(void*,int,const void*,int,const void*),
  5925. void(*xDestroy)(void*)
  5926. );
  5927. SQLITE_API int sqlite3_create_collation16(
  5928. sqlite3*,
  5929. const void *zName,
  5930. int eTextRep,
  5931. void *pArg,
  5932. int(*xCompare)(void*,int,const void*,int,const void*)
  5933. );
  5934. /*
  5935. ** CAPI3REF: Collation Needed Callbacks
  5936. ** METHOD: sqlite3
  5937. **
  5938. ** ^To avoid having to register all collation sequences before a database
  5939. ** can be used, a single callback function may be registered with the
  5940. ** [database connection] to be invoked whenever an undefined collation
  5941. ** sequence is required.
  5942. **
  5943. ** ^If the function is registered using the sqlite3_collation_needed() API,
  5944. ** then it is passed the names of undefined collation sequences as strings
  5945. ** encoded in UTF-8. ^If sqlite3_collation_needed16() is used,
  5946. ** the names are passed as UTF-16 in machine native byte order.
  5947. ** ^A call to either function replaces the existing collation-needed callback.
  5948. **
  5949. ** ^(When the callback is invoked, the first argument passed is a copy
  5950. ** of the second argument to sqlite3_collation_needed() or
  5951. ** sqlite3_collation_needed16(). The second argument is the database
  5952. ** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE],
  5953. ** or [SQLITE_UTF16LE], indicating the most desirable form of the collation
  5954. ** sequence function required. The fourth parameter is the name of the
  5955. ** required collation sequence.)^
  5956. **
  5957. ** The callback function should register the desired collation using
  5958. ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
  5959. ** [sqlite3_create_collation_v2()].
  5960. */
  5961. SQLITE_API int sqlite3_collation_needed(
  5962. sqlite3*,
  5963. void*,
  5964. void(*)(void*,sqlite3*,int eTextRep,const char*)
  5965. );
  5966. SQLITE_API int sqlite3_collation_needed16(
  5967. sqlite3*,
  5968. void*,
  5969. void(*)(void*,sqlite3*,int eTextRep,const void*)
  5970. );
  5971. #ifdef SQLITE_ENABLE_CEROD
  5972. /*
  5973. ** Specify the activation key for a CEROD database. Unless
  5974. ** activated, none of the CEROD routines will work.
  5975. */
  5976. SQLITE_API void sqlite3_activate_cerod(
  5977. const char *zPassPhrase /* Activation phrase */
  5978. );
  5979. #endif
  5980. /*
  5981. ** CAPI3REF: Suspend Execution For A Short Time
  5982. **
  5983. ** The sqlite3_sleep() function causes the current thread to suspend execution
  5984. ** for at least a number of milliseconds specified in its parameter.
  5985. **
  5986. ** If the operating system does not support sleep requests with
  5987. ** millisecond time resolution, then the time will be rounded up to
  5988. ** the nearest second. The number of milliseconds of sleep actually
  5989. ** requested from the operating system is returned.
  5990. **
  5991. ** ^SQLite implements this interface by calling the xSleep()
  5992. ** method of the default [sqlite3_vfs] object. If the xSleep() method
  5993. ** of the default VFS is not implemented correctly, or not implemented at
  5994. ** all, then the behavior of sqlite3_sleep() may deviate from the description
  5995. ** in the previous paragraphs.
  5996. */
  5997. SQLITE_API int sqlite3_sleep(int);
  5998. /*
  5999. ** CAPI3REF: Name Of The Folder Holding Temporary Files
  6000. **
  6001. ** ^(If this global variable is made to point to a string which is
  6002. ** the name of a folder (a.k.a. directory), then all temporary files
  6003. ** created by SQLite when using a built-in [sqlite3_vfs | VFS]
  6004. ** will be placed in that directory.)^ ^If this variable
  6005. ** is a NULL pointer, then SQLite performs a search for an appropriate
  6006. ** temporary file directory.
  6007. **
  6008. ** Applications are strongly discouraged from using this global variable.
  6009. ** It is required to set a temporary folder on Windows Runtime (WinRT).
  6010. ** But for all other platforms, it is highly recommended that applications
  6011. ** neither read nor write this variable. This global variable is a relic
  6012. ** that exists for backwards compatibility of legacy applications and should
  6013. ** be avoided in new projects.
  6014. **
  6015. ** It is not safe to read or modify this variable in more than one
  6016. ** thread at a time. It is not safe to read or modify this variable
  6017. ** if a [database connection] is being used at the same time in a separate
  6018. ** thread.
  6019. ** It is intended that this variable be set once
  6020. ** as part of process initialization and before any SQLite interface
  6021. ** routines have been called and that this variable remain unchanged
  6022. ** thereafter.
  6023. **
  6024. ** ^The [temp_store_directory pragma] may modify this variable and cause
  6025. ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore,
  6026. ** the [temp_store_directory pragma] always assumes that any string
  6027. ** that this variable points to is held in memory obtained from
  6028. ** [sqlite3_malloc] and the pragma may attempt to free that memory
  6029. ** using [sqlite3_free].
  6030. ** Hence, if this variable is modified directly, either it should be
  6031. ** made NULL or made to point to memory obtained from [sqlite3_malloc]
  6032. ** or else the use of the [temp_store_directory pragma] should be avoided.
  6033. ** Except when requested by the [temp_store_directory pragma], SQLite
  6034. ** does not free the memory that sqlite3_temp_directory points to. If
  6035. ** the application wants that memory to be freed, it must do
  6036. ** so itself, taking care to only do so after all [database connection]
  6037. ** objects have been destroyed.
  6038. **
  6039. ** <b>Note to Windows Runtime users:</b> The temporary directory must be set
  6040. ** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various
  6041. ** features that require the use of temporary files may fail. Here is an
  6042. ** example of how to do this using C++ with the Windows Runtime:
  6043. **
  6044. ** <blockquote><pre>
  6045. ** LPCWSTR zPath = Windows::Storage::ApplicationData::Current->
  6046. ** &nbsp; TemporaryFolder->Path->Data();
  6047. ** char zPathBuf&#91;MAX_PATH + 1&#93;;
  6048. ** memset(zPathBuf, 0, sizeof(zPathBuf));
  6049. ** WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf, sizeof(zPathBuf),
  6050. ** &nbsp; NULL, NULL);
  6051. ** sqlite3_temp_directory = sqlite3_mprintf("%s", zPathBuf);
  6052. ** </pre></blockquote>
  6053. */
  6054. SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory;
  6055. /*
  6056. ** CAPI3REF: Name Of The Folder Holding Database Files
  6057. **
  6058. ** ^(If this global variable is made to point to a string which is
  6059. ** the name of a folder (a.k.a. directory), then all database files
  6060. ** specified with a relative pathname and created or accessed by
  6061. ** SQLite when using a built-in windows [sqlite3_vfs | VFS] will be assumed
  6062. ** to be relative to that directory.)^ ^If this variable is a NULL
  6063. ** pointer, then SQLite assumes that all database files specified
  6064. ** with a relative pathname are relative to the current directory
  6065. ** for the process. Only the windows VFS makes use of this global
  6066. ** variable; it is ignored by the unix VFS.
  6067. **
  6068. ** Changing the value of this variable while a database connection is
  6069. ** open can result in a corrupt database.
  6070. **
  6071. ** It is not safe to read or modify this variable in more than one
  6072. ** thread at a time. It is not safe to read or modify this variable
  6073. ** if a [database connection] is being used at the same time in a separate
  6074. ** thread.
  6075. ** It is intended that this variable be set once
  6076. ** as part of process initialization and before any SQLite interface
  6077. ** routines have been called and that this variable remain unchanged
  6078. ** thereafter.
  6079. **
  6080. ** ^The [data_store_directory pragma] may modify this variable and cause
  6081. ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore,
  6082. ** the [data_store_directory pragma] always assumes that any string
  6083. ** that this variable points to is held in memory obtained from
  6084. ** [sqlite3_malloc] and the pragma may attempt to free that memory
  6085. ** using [sqlite3_free].
  6086. ** Hence, if this variable is modified directly, either it should be
  6087. ** made NULL or made to point to memory obtained from [sqlite3_malloc]
  6088. ** or else the use of the [data_store_directory pragma] should be avoided.
  6089. */
  6090. SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory;
  6091. /*
  6092. ** CAPI3REF: Win32 Specific Interface
  6093. **
  6094. ** These interfaces are available only on Windows. The
  6095. ** [sqlite3_win32_set_directory] interface is used to set the value associated
  6096. ** with the [sqlite3_temp_directory] or [sqlite3_data_directory] variable, to
  6097. ** zValue, depending on the value of the type parameter. The zValue parameter
  6098. ** should be NULL to cause the previous value to be freed via [sqlite3_free];
  6099. ** a non-NULL value will be copied into memory obtained from [sqlite3_malloc]
  6100. ** prior to being used. The [sqlite3_win32_set_directory] interface returns
  6101. ** [SQLITE_OK] to indicate success, [SQLITE_ERROR] if the type is unsupported,
  6102. ** or [SQLITE_NOMEM] if memory could not be allocated. The value of the
  6103. ** [sqlite3_data_directory] variable is intended to act as a replacement for
  6104. ** the current directory on the sub-platforms of Win32 where that concept is
  6105. ** not present, e.g. WinRT and UWP. The [sqlite3_win32_set_directory8] and
  6106. ** [sqlite3_win32_set_directory16] interfaces behave exactly the same as the
  6107. ** sqlite3_win32_set_directory interface except the string parameter must be
  6108. ** UTF-8 or UTF-16, respectively.
  6109. */
  6110. SQLITE_API int sqlite3_win32_set_directory(
  6111. unsigned long type, /* Identifier for directory being set or reset */
  6112. void *zValue /* New value for directory being set or reset */
  6113. );
  6114. SQLITE_API int sqlite3_win32_set_directory8(unsigned long type, const char *zValue);
  6115. SQLITE_API int sqlite3_win32_set_directory16(unsigned long type, const void *zValue);
  6116. /*
  6117. ** CAPI3REF: Win32 Directory Types
  6118. **
  6119. ** These macros are only available on Windows. They define the allowed values
  6120. ** for the type argument to the [sqlite3_win32_set_directory] interface.
  6121. */
  6122. #define SQLITE_WIN32_DATA_DIRECTORY_TYPE 1
  6123. #define SQLITE_WIN32_TEMP_DIRECTORY_TYPE 2
  6124. /*
  6125. ** CAPI3REF: Test For Auto-Commit Mode
  6126. ** KEYWORDS: {autocommit mode}
  6127. ** METHOD: sqlite3
  6128. **
  6129. ** ^The sqlite3_get_autocommit() interface returns non-zero or
  6130. ** zero if the given database connection is or is not in autocommit mode,
  6131. ** respectively. ^Autocommit mode is on by default.
  6132. ** ^Autocommit mode is disabled by a [BEGIN] statement.
  6133. ** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].
  6134. **
  6135. ** If certain kinds of errors occur on a statement within a multi-statement
  6136. ** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR],
  6137. ** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the
  6138. ** transaction might be rolled back automatically. The only way to
  6139. ** find out whether SQLite automatically rolled back the transaction after
  6140. ** an error is to use this function.
  6141. **
  6142. ** If another thread changes the autocommit status of the database
  6143. ** connection while this routine is running, then the return value
  6144. ** is undefined.
  6145. */
  6146. SQLITE_API int sqlite3_get_autocommit(sqlite3*);
  6147. /*
  6148. ** CAPI3REF: Find The Database Handle Of A Prepared Statement
  6149. ** METHOD: sqlite3_stmt
  6150. **
  6151. ** ^The sqlite3_db_handle interface returns the [database connection] handle
  6152. ** to which a [prepared statement] belongs. ^The [database connection]
  6153. ** returned by sqlite3_db_handle is the same [database connection]
  6154. ** that was the first argument
  6155. ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
  6156. ** create the statement in the first place.
  6157. */
  6158. SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
  6159. /*
  6160. ** CAPI3REF: Return The Schema Name For A Database Connection
  6161. ** METHOD: sqlite3
  6162. **
  6163. ** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name
  6164. ** for the N-th database on database connection D, or a NULL pointer of N is
  6165. ** out of range. An N value of 0 means the main database file. An N of 1 is
  6166. ** the "temp" schema. Larger values of N correspond to various ATTACH-ed
  6167. ** databases.
  6168. **
  6169. ** Space to hold the string that is returned by sqlite3_db_name() is managed
  6170. ** by SQLite itself. The string might be deallocated by any operation that
  6171. ** changes the schema, including [ATTACH] or [DETACH] or calls to
  6172. ** [sqlite3_serialize()] or [sqlite3_deserialize()], even operations that
  6173. ** occur on a different thread. Applications that need to
  6174. ** remember the string long-term should make their own copy. Applications that
  6175. ** are accessing the same database connection simultaneously on multiple
  6176. ** threads should mutex-protect calls to this API and should make their own
  6177. ** private copy of the result prior to releasing the mutex.
  6178. */
  6179. SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N);
  6180. /*
  6181. ** CAPI3REF: Return The Filename For A Database Connection
  6182. ** METHOD: sqlite3
  6183. **
  6184. ** ^The sqlite3_db_filename(D,N) interface returns a pointer to the filename
  6185. ** associated with database N of connection D.
  6186. ** ^If there is no attached database N on the database
  6187. ** connection D, or if database N is a temporary or in-memory database, then
  6188. ** this function will return either a NULL pointer or an empty string.
  6189. **
  6190. ** ^The string value returned by this routine is owned and managed by
  6191. ** the database connection. ^The value will be valid until the database N
  6192. ** is [DETACH]-ed or until the database connection closes.
  6193. **
  6194. ** ^The filename returned by this function is the output of the
  6195. ** xFullPathname method of the [VFS]. ^In other words, the filename
  6196. ** will be an absolute pathname, even if the filename used
  6197. ** to open the database originally was a URI or relative pathname.
  6198. **
  6199. ** If the filename pointer returned by this routine is not NULL, then it
  6200. ** can be used as the filename input parameter to these routines:
  6201. ** <ul>
  6202. ** <li> [sqlite3_uri_parameter()]
  6203. ** <li> [sqlite3_uri_boolean()]
  6204. ** <li> [sqlite3_uri_int64()]
  6205. ** <li> [sqlite3_filename_database()]
  6206. ** <li> [sqlite3_filename_journal()]
  6207. ** <li> [sqlite3_filename_wal()]
  6208. ** </ul>
  6209. */
  6210. SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
  6211. /*
  6212. ** CAPI3REF: Determine if a database is read-only
  6213. ** METHOD: sqlite3
  6214. **
  6215. ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
  6216. ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
  6217. ** the name of a database on connection D.
  6218. */
  6219. SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
  6220. /*
  6221. ** CAPI3REF: Determine the transaction state of a database
  6222. ** METHOD: sqlite3
  6223. **
  6224. ** ^The sqlite3_txn_state(D,S) interface returns the current
  6225. ** [transaction state] of schema S in database connection D. ^If S is NULL,
  6226. ** then the highest transaction state of any schema on database connection D
  6227. ** is returned. Transaction states are (in order of lowest to highest):
  6228. ** <ol>
  6229. ** <li value="0"> SQLITE_TXN_NONE
  6230. ** <li value="1"> SQLITE_TXN_READ
  6231. ** <li value="2"> SQLITE_TXN_WRITE
  6232. ** </ol>
  6233. ** ^If the S argument to sqlite3_txn_state(D,S) is not the name of
  6234. ** a valid schema, then -1 is returned.
  6235. */
  6236. SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema);
  6237. /*
  6238. ** CAPI3REF: Allowed return values from [sqlite3_txn_state()]
  6239. ** KEYWORDS: {transaction state}
  6240. **
  6241. ** These constants define the current transaction state of a database file.
  6242. ** ^The [sqlite3_txn_state(D,S)] interface returns one of these
  6243. ** constants in order to describe the transaction state of schema S
  6244. ** in [database connection] D.
  6245. **
  6246. ** <dl>
  6247. ** [[SQLITE_TXN_NONE]] <dt>SQLITE_TXN_NONE</dt>
  6248. ** <dd>The SQLITE_TXN_NONE state means that no transaction is currently
  6249. ** pending.</dd>
  6250. **
  6251. ** [[SQLITE_TXN_READ]] <dt>SQLITE_TXN_READ</dt>
  6252. ** <dd>The SQLITE_TXN_READ state means that the database is currently
  6253. ** in a read transaction. Content has been read from the database file
  6254. ** but nothing in the database file has changed. The transaction state
  6255. ** will advanced to SQLITE_TXN_WRITE if any changes occur and there are
  6256. ** no other conflicting concurrent write transactions. The transaction
  6257. ** state will revert to SQLITE_TXN_NONE following a [ROLLBACK] or
  6258. ** [COMMIT].</dd>
  6259. **
  6260. ** [[SQLITE_TXN_WRITE]] <dt>SQLITE_TXN_WRITE</dt>
  6261. ** <dd>The SQLITE_TXN_WRITE state means that the database is currently
  6262. ** in a write transaction. Content has been written to the database file
  6263. ** but has not yet committed. The transaction state will change to
  6264. ** to SQLITE_TXN_NONE at the next [ROLLBACK] or [COMMIT].</dd>
  6265. */
  6266. #define SQLITE_TXN_NONE 0
  6267. #define SQLITE_TXN_READ 1
  6268. #define SQLITE_TXN_WRITE 2
  6269. /*
  6270. ** CAPI3REF: Find the next prepared statement
  6271. ** METHOD: sqlite3
  6272. **
  6273. ** ^This interface returns a pointer to the next [prepared statement] after
  6274. ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
  6275. ** then this interface returns a pointer to the first prepared statement
  6276. ** associated with the database connection pDb. ^If no prepared statement
  6277. ** satisfies the conditions of this routine, it returns NULL.
  6278. **
  6279. ** The [database connection] pointer D in a call to
  6280. ** [sqlite3_next_stmt(D,S)] must refer to an open database
  6281. ** connection and in particular must not be a NULL pointer.
  6282. */
  6283. SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
  6284. /*
  6285. ** CAPI3REF: Commit And Rollback Notification Callbacks
  6286. ** METHOD: sqlite3
  6287. **
  6288. ** ^The sqlite3_commit_hook() interface registers a callback
  6289. ** function to be invoked whenever a transaction is [COMMIT | committed].
  6290. ** ^Any callback set by a previous call to sqlite3_commit_hook()
  6291. ** for the same database connection is overridden.
  6292. ** ^The sqlite3_rollback_hook() interface registers a callback
  6293. ** function to be invoked whenever a transaction is [ROLLBACK | rolled back].
  6294. ** ^Any callback set by a previous call to sqlite3_rollback_hook()
  6295. ** for the same database connection is overridden.
  6296. ** ^The pArg argument is passed through to the callback.
  6297. ** ^If the callback on a commit hook function returns non-zero,
  6298. ** then the commit is converted into a rollback.
  6299. **
  6300. ** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions
  6301. ** return the P argument from the previous call of the same function
  6302. ** on the same [database connection] D, or NULL for
  6303. ** the first call for each function on D.
  6304. **
  6305. ** The commit and rollback hook callbacks are not reentrant.
  6306. ** The callback implementation must not do anything that will modify
  6307. ** the database connection that invoked the callback. Any actions
  6308. ** to modify the database connection must be deferred until after the
  6309. ** completion of the [sqlite3_step()] call that triggered the commit
  6310. ** or rollback hook in the first place.
  6311. ** Note that running any other SQL statements, including SELECT statements,
  6312. ** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify
  6313. ** the database connections for the meaning of "modify" in this paragraph.
  6314. **
  6315. ** ^Registering a NULL function disables the callback.
  6316. **
  6317. ** ^When the commit hook callback routine returns zero, the [COMMIT]
  6318. ** operation is allowed to continue normally. ^If the commit hook
  6319. ** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK].
  6320. ** ^The rollback hook is invoked on a rollback that results from a commit
  6321. ** hook returning non-zero, just as it would be with any other rollback.
  6322. **
  6323. ** ^For the purposes of this API, a transaction is said to have been
  6324. ** rolled back if an explicit "ROLLBACK" statement is executed, or
  6325. ** an error or constraint causes an implicit rollback to occur.
  6326. ** ^The rollback callback is not invoked if a transaction is
  6327. ** automatically rolled back because the database connection is closed.
  6328. **
  6329. ** See also the [sqlite3_update_hook()] interface.
  6330. */
  6331. SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
  6332. SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
  6333. /*
  6334. ** CAPI3REF: Autovacuum Compaction Amount Callback
  6335. ** METHOD: sqlite3
  6336. **
  6337. ** ^The sqlite3_autovacuum_pages(D,C,P,X) interface registers a callback
  6338. ** function C that is invoked prior to each autovacuum of the database
  6339. ** file. ^The callback is passed a copy of the generic data pointer (P),
  6340. ** the schema-name of the attached database that is being autovacuumed,
  6341. ** the the size of the database file in pages, the number of free pages,
  6342. ** and the number of bytes per page, respectively. The callback should
  6343. ** return the number of free pages that should be removed by the
  6344. ** autovacuum. ^If the callback returns zero, then no autovacuum happens.
  6345. ** ^If the value returned is greater than or equal to the number of
  6346. ** free pages, then a complete autovacuum happens.
  6347. **
  6348. ** <p>^If there are multiple ATTACH-ed database files that are being
  6349. ** modified as part of a transaction commit, then the autovacuum pages
  6350. ** callback is invoked separately for each file.
  6351. **
  6352. ** <p><b>The callback is not reentrant.</b> The callback function should
  6353. ** not attempt to invoke any other SQLite interface. If it does, bad
  6354. ** things may happen, including segmentation faults and corrupt database
  6355. ** files. The callback function should be a simple function that
  6356. ** does some arithmetic on its input parameters and returns a result.
  6357. **
  6358. ** ^The X parameter to sqlite3_autovacuum_pages(D,C,P,X) is an optional
  6359. ** destructor for the P parameter. ^If X is not NULL, then X(P) is
  6360. ** invoked whenever the database connection closes or when the callback
  6361. ** is overwritten by another invocation of sqlite3_autovacuum_pages().
  6362. **
  6363. ** <p>^There is only one autovacuum pages callback per database connection.
  6364. ** ^Each call to the sqlite3_autovacuum_pages() interface overrides all
  6365. ** previous invocations for that database connection. ^If the callback
  6366. ** argument (C) to sqlite3_autovacuum_pages(D,C,P,X) is a NULL pointer,
  6367. ** then the autovacuum steps callback is cancelled. The return value
  6368. ** from sqlite3_autovacuum_pages() is normally SQLITE_OK, but might
  6369. ** be some other error code if something goes wrong. The current
  6370. ** implementation will only return SQLITE_OK or SQLITE_MISUSE, but other
  6371. ** return codes might be added in future releases.
  6372. **
  6373. ** <p>If no autovacuum pages callback is specified (the usual case) or
  6374. ** a NULL pointer is provided for the callback,
  6375. ** then the default behavior is to vacuum all free pages. So, in other
  6376. ** words, the default behavior is the same as if the callback function
  6377. ** were something like this:
  6378. **
  6379. ** <blockquote><pre>
  6380. ** &nbsp; unsigned int demonstration_autovac_pages_callback(
  6381. ** &nbsp; void *pClientData,
  6382. ** &nbsp; const char *zSchema,
  6383. ** &nbsp; unsigned int nDbPage,
  6384. ** &nbsp; unsigned int nFreePage,
  6385. ** &nbsp; unsigned int nBytePerPage
  6386. ** &nbsp; ){
  6387. ** &nbsp; return nFreePage;
  6388. ** &nbsp; }
  6389. ** </pre></blockquote>
  6390. */
  6391. SQLITE_API int sqlite3_autovacuum_pages(
  6392. sqlite3 *db,
  6393. unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),
  6394. void*,
  6395. void(*)(void*)
  6396. );
  6397. /*
  6398. ** CAPI3REF: Data Change Notification Callbacks
  6399. ** METHOD: sqlite3
  6400. **
  6401. ** ^The sqlite3_update_hook() interface registers a callback function
  6402. ** with the [database connection] identified by the first argument
  6403. ** to be invoked whenever a row is updated, inserted or deleted in
  6404. ** a [rowid table].
  6405. ** ^Any callback set by a previous call to this function
  6406. ** for the same database connection is overridden.
  6407. **
  6408. ** ^The second argument is a pointer to the function to invoke when a
  6409. ** row is updated, inserted or deleted in a rowid table.
  6410. ** ^The first argument to the callback is a copy of the third argument
  6411. ** to sqlite3_update_hook().
  6412. ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
  6413. ** or [SQLITE_UPDATE], depending on the operation that caused the callback
  6414. ** to be invoked.
  6415. ** ^The third and fourth arguments to the callback contain pointers to the
  6416. ** database and table name containing the affected row.
  6417. ** ^The final callback parameter is the [rowid] of the row.
  6418. ** ^In the case of an update, this is the [rowid] after the update takes place.
  6419. **
  6420. ** ^(The update hook is not invoked when internal system tables are
  6421. ** modified (i.e. sqlite_sequence).)^
  6422. ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
  6423. **
  6424. ** ^In the current implementation, the update hook
  6425. ** is not invoked when conflicting rows are deleted because of an
  6426. ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
  6427. ** invoked when rows are deleted using the [truncate optimization].
  6428. ** The exceptions defined in this paragraph might change in a future
  6429. ** release of SQLite.
  6430. **
  6431. ** The update hook implementation must not do anything that will modify
  6432. ** the database connection that invoked the update hook. Any actions
  6433. ** to modify the database connection must be deferred until after the
  6434. ** completion of the [sqlite3_step()] call that triggered the update hook.
  6435. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  6436. ** database connections for the meaning of "modify" in this paragraph.
  6437. **
  6438. ** ^The sqlite3_update_hook(D,C,P) function
  6439. ** returns the P argument from the previous call
  6440. ** on the same [database connection] D, or NULL for
  6441. ** the first call on D.
  6442. **
  6443. ** See also the [sqlite3_commit_hook()], [sqlite3_rollback_hook()],
  6444. ** and [sqlite3_preupdate_hook()] interfaces.
  6445. */
  6446. SQLITE_API void *sqlite3_update_hook(
  6447. sqlite3*,
  6448. void(*)(void *,int ,char const *,char const *,sqlite3_int64),
  6449. void*
  6450. );
  6451. /*
  6452. ** CAPI3REF: Enable Or Disable Shared Pager Cache
  6453. **
  6454. ** ^(This routine enables or disables the sharing of the database cache
  6455. ** and schema data structures between [database connection | connections]
  6456. ** to the same database. Sharing is enabled if the argument is true
  6457. ** and disabled if the argument is false.)^
  6458. **
  6459. ** ^Cache sharing is enabled and disabled for an entire process.
  6460. ** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]).
  6461. ** In prior versions of SQLite,
  6462. ** sharing was enabled or disabled for each thread separately.
  6463. **
  6464. ** ^(The cache sharing mode set by this interface effects all subsequent
  6465. ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
  6466. ** Existing database connections continue to use the sharing mode
  6467. ** that was in effect at the time they were opened.)^
  6468. **
  6469. ** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled
  6470. ** successfully. An [error code] is returned otherwise.)^
  6471. **
  6472. ** ^Shared cache is disabled by default. It is recommended that it stay
  6473. ** that way. In other words, do not use this routine. This interface
  6474. ** continues to be provided for historical compatibility, but its use is
  6475. ** discouraged. Any use of shared cache is discouraged. If shared cache
  6476. ** must be used, it is recommended that shared cache only be enabled for
  6477. ** individual database connections using the [sqlite3_open_v2()] interface
  6478. ** with the [SQLITE_OPEN_SHAREDCACHE] flag.
  6479. **
  6480. ** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0
  6481. ** and will always return SQLITE_MISUSE. On those systems,
  6482. ** shared cache mode should be enabled per-database connection via
  6483. ** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].
  6484. **
  6485. ** This interface is threadsafe on processors where writing a
  6486. ** 32-bit integer is atomic.
  6487. **
  6488. ** See Also: [SQLite Shared-Cache Mode]
  6489. */
  6490. SQLITE_API int sqlite3_enable_shared_cache(int);
  6491. /*
  6492. ** CAPI3REF: Attempt To Free Heap Memory
  6493. **
  6494. ** ^The sqlite3_release_memory() interface attempts to free N bytes
  6495. ** of heap memory by deallocating non-essential memory allocations
  6496. ** held by the database library. Memory used to cache database
  6497. ** pages to improve performance is an example of non-essential memory.
  6498. ** ^sqlite3_release_memory() returns the number of bytes actually freed,
  6499. ** which might be more or less than the amount requested.
  6500. ** ^The sqlite3_release_memory() routine is a no-op returning zero
  6501. ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT].
  6502. **
  6503. ** See also: [sqlite3_db_release_memory()]
  6504. */
  6505. SQLITE_API int sqlite3_release_memory(int);
  6506. /*
  6507. ** CAPI3REF: Free Memory Used By A Database Connection
  6508. ** METHOD: sqlite3
  6509. **
  6510. ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
  6511. ** memory as possible from database connection D. Unlike the
  6512. ** [sqlite3_release_memory()] interface, this interface is in effect even
  6513. ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
  6514. ** omitted.
  6515. **
  6516. ** See also: [sqlite3_release_memory()]
  6517. */
  6518. SQLITE_API int sqlite3_db_release_memory(sqlite3*);
  6519. /*
  6520. ** CAPI3REF: Impose A Limit On Heap Size
  6521. **
  6522. ** These interfaces impose limits on the amount of heap memory that will be
  6523. ** by all database connections within a single process.
  6524. **
  6525. ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
  6526. ** soft limit on the amount of heap memory that may be allocated by SQLite.
  6527. ** ^SQLite strives to keep heap memory utilization below the soft heap
  6528. ** limit by reducing the number of pages held in the page cache
  6529. ** as heap memory usages approaches the limit.
  6530. ** ^The soft heap limit is "soft" because even though SQLite strives to stay
  6531. ** below the limit, it will exceed the limit rather than generate
  6532. ** an [SQLITE_NOMEM] error. In other words, the soft heap limit
  6533. ** is advisory only.
  6534. **
  6535. ** ^The sqlite3_hard_heap_limit64(N) interface sets a hard upper bound of
  6536. ** N bytes on the amount of memory that will be allocated. ^The
  6537. ** sqlite3_hard_heap_limit64(N) interface is similar to
  6538. ** sqlite3_soft_heap_limit64(N) except that memory allocations will fail
  6539. ** when the hard heap limit is reached.
  6540. **
  6541. ** ^The return value from both sqlite3_soft_heap_limit64() and
  6542. ** sqlite3_hard_heap_limit64() is the size of
  6543. ** the heap limit prior to the call, or negative in the case of an
  6544. ** error. ^If the argument N is negative
  6545. ** then no change is made to the heap limit. Hence, the current
  6546. ** size of heap limits can be determined by invoking
  6547. ** sqlite3_soft_heap_limit64(-1) or sqlite3_hard_heap_limit(-1).
  6548. **
  6549. ** ^Setting the heap limits to zero disables the heap limiter mechanism.
  6550. **
  6551. ** ^The soft heap limit may not be greater than the hard heap limit.
  6552. ** ^If the hard heap limit is enabled and if sqlite3_soft_heap_limit(N)
  6553. ** is invoked with a value of N that is greater than the hard heap limit,
  6554. ** the the soft heap limit is set to the value of the hard heap limit.
  6555. ** ^The soft heap limit is automatically enabled whenever the hard heap
  6556. ** limit is enabled. ^When sqlite3_hard_heap_limit64(N) is invoked and
  6557. ** the soft heap limit is outside the range of 1..N, then the soft heap
  6558. ** limit is set to N. ^Invoking sqlite3_soft_heap_limit64(0) when the
  6559. ** hard heap limit is enabled makes the soft heap limit equal to the
  6560. ** hard heap limit.
  6561. **
  6562. ** The memory allocation limits can also be adjusted using
  6563. ** [PRAGMA soft_heap_limit] and [PRAGMA hard_heap_limit].
  6564. **
  6565. ** ^(The heap limits are not enforced in the current implementation
  6566. ** if one or more of following conditions are true:
  6567. **
  6568. ** <ul>
  6569. ** <li> The limit value is set to zero.
  6570. ** <li> Memory accounting is disabled using a combination of the
  6571. ** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and
  6572. ** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.
  6573. ** <li> An alternative page cache implementation is specified using
  6574. ** [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...).
  6575. ** <li> The page cache allocates from its own memory pool supplied
  6576. ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
  6577. ** from the heap.
  6578. ** </ul>)^
  6579. **
  6580. ** The circumstances under which SQLite will enforce the heap limits may
  6581. ** changes in future releases of SQLite.
  6582. */
  6583. SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
  6584. SQLITE_API sqlite3_int64 sqlite3_hard_heap_limit64(sqlite3_int64 N);
  6585. /*
  6586. ** CAPI3REF: Deprecated Soft Heap Limit Interface
  6587. ** DEPRECATED
  6588. **
  6589. ** This is a deprecated version of the [sqlite3_soft_heap_limit64()]
  6590. ** interface. This routine is provided for historical compatibility
  6591. ** only. All new applications should use the
  6592. ** [sqlite3_soft_heap_limit64()] interface rather than this one.
  6593. */
  6594. SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N);
  6595. /*
  6596. ** CAPI3REF: Extract Metadata About A Column Of A Table
  6597. ** METHOD: sqlite3
  6598. **
  6599. ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
  6600. ** information about column C of table T in database D
  6601. ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
  6602. ** interface returns SQLITE_OK and fills in the non-NULL pointers in
  6603. ** the final five arguments with appropriate values if the specified
  6604. ** column exists. ^The sqlite3_table_column_metadata() interface returns
  6605. ** SQLITE_ERROR if the specified column does not exist.
  6606. ** ^If the column-name parameter to sqlite3_table_column_metadata() is a
  6607. ** NULL pointer, then this routine simply checks for the existence of the
  6608. ** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
  6609. ** does not. If the table name parameter T in a call to
  6610. ** sqlite3_table_column_metadata(X,D,T,C,...) is NULL then the result is
  6611. ** undefined behavior.
  6612. **
  6613. ** ^The column is identified by the second, third and fourth parameters to
  6614. ** this function. ^(The second parameter is either the name of the database
  6615. ** (i.e. "main", "temp", or an attached database) containing the specified
  6616. ** table or NULL.)^ ^If it is NULL, then all attached databases are searched
  6617. ** for the table using the same algorithm used by the database engine to
  6618. ** resolve unqualified table references.
  6619. **
  6620. ** ^The third and fourth parameters to this function are the table and column
  6621. ** name of the desired column, respectively.
  6622. **
  6623. ** ^Metadata is returned by writing to the memory locations passed as the 5th
  6624. ** and subsequent parameters to this function. ^Any of these arguments may be
  6625. ** NULL, in which case the corresponding element of metadata is omitted.
  6626. **
  6627. ** ^(<blockquote>
  6628. ** <table border="1">
  6629. ** <tr><th> Parameter <th> Output<br>Type <th> Description
  6630. **
  6631. ** <tr><td> 5th <td> const char* <td> Data type
  6632. ** <tr><td> 6th <td> const char* <td> Name of default collation sequence
  6633. ** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint
  6634. ** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY
  6635. ** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT]
  6636. ** </table>
  6637. ** </blockquote>)^
  6638. **
  6639. ** ^The memory pointed to by the character pointers returned for the
  6640. ** declaration type and collation sequence is valid until the next
  6641. ** call to any SQLite API function.
  6642. **
  6643. ** ^If the specified table is actually a view, an [error code] is returned.
  6644. **
  6645. ** ^If the specified column is "rowid", "oid" or "_rowid_" and the table
  6646. ** is not a [WITHOUT ROWID] table and an
  6647. ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
  6648. ** parameters are set for the explicitly declared column. ^(If there is no
  6649. ** [INTEGER PRIMARY KEY] column, then the outputs
  6650. ** for the [rowid] are set as follows:
  6651. **
  6652. ** <pre>
  6653. ** data type: "INTEGER"
  6654. ** collation sequence: "BINARY"
  6655. ** not null: 0
  6656. ** primary key: 1
  6657. ** auto increment: 0
  6658. ** </pre>)^
  6659. **
  6660. ** ^This function causes all database schemas to be read from disk and
  6661. ** parsed, if that has not already been done, and returns an error if
  6662. ** any errors are encountered while loading the schema.
  6663. */
  6664. SQLITE_API int sqlite3_table_column_metadata(
  6665. sqlite3 *db, /* Connection handle */
  6666. const char *zDbName, /* Database name or NULL */
  6667. const char *zTableName, /* Table name */
  6668. const char *zColumnName, /* Column name */
  6669. char const **pzDataType, /* OUTPUT: Declared data type */
  6670. char const **pzCollSeq, /* OUTPUT: Collation sequence name */
  6671. int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */
  6672. int *pPrimaryKey, /* OUTPUT: True if column part of PK */
  6673. int *pAutoinc /* OUTPUT: True if column is auto-increment */
  6674. );
  6675. /*
  6676. ** CAPI3REF: Load An Extension
  6677. ** METHOD: sqlite3
  6678. **
  6679. ** ^This interface loads an SQLite extension library from the named file.
  6680. **
  6681. ** ^The sqlite3_load_extension() interface attempts to load an
  6682. ** [SQLite extension] library contained in the file zFile. If
  6683. ** the file cannot be loaded directly, attempts are made to load
  6684. ** with various operating-system specific extensions added.
  6685. ** So for example, if "samplelib" cannot be loaded, then names like
  6686. ** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might
  6687. ** be tried also.
  6688. **
  6689. ** ^The entry point is zProc.
  6690. ** ^(zProc may be 0, in which case SQLite will try to come up with an
  6691. ** entry point name on its own. It first tries "sqlite3_extension_init".
  6692. ** If that does not work, it constructs a name "sqlite3_X_init" where the
  6693. ** X is consists of the lower-case equivalent of all ASCII alphabetic
  6694. ** characters in the filename from the last "/" to the first following
  6695. ** "." and omitting any initial "lib".)^
  6696. ** ^The sqlite3_load_extension() interface returns
  6697. ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
  6698. ** ^If an error occurs and pzErrMsg is not 0, then the
  6699. ** [sqlite3_load_extension()] interface shall attempt to
  6700. ** fill *pzErrMsg with error message text stored in memory
  6701. ** obtained from [sqlite3_malloc()]. The calling function
  6702. ** should free this memory by calling [sqlite3_free()].
  6703. **
  6704. ** ^Extension loading must be enabled using
  6705. ** [sqlite3_enable_load_extension()] or
  6706. ** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL)
  6707. ** prior to calling this API,
  6708. ** otherwise an error will be returned.
  6709. **
  6710. ** <b>Security warning:</b> It is recommended that the
  6711. ** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this
  6712. ** interface. The use of the [sqlite3_enable_load_extension()] interface
  6713. ** should be avoided. This will keep the SQL function [load_extension()]
  6714. ** disabled and prevent SQL injections from giving attackers
  6715. ** access to extension loading capabilities.
  6716. **
  6717. ** See also the [load_extension() SQL function].
  6718. */
  6719. SQLITE_API int sqlite3_load_extension(
  6720. sqlite3 *db, /* Load the extension into this database connection */
  6721. const char *zFile, /* Name of the shared library containing extension */
  6722. const char *zProc, /* Entry point. Derived from zFile if 0 */
  6723. char **pzErrMsg /* Put error message here if not 0 */
  6724. );
  6725. /*
  6726. ** CAPI3REF: Enable Or Disable Extension Loading
  6727. ** METHOD: sqlite3
  6728. **
  6729. ** ^So as not to open security holes in older applications that are
  6730. ** unprepared to deal with [extension loading], and as a means of disabling
  6731. ** [extension loading] while evaluating user-entered SQL, the following API
  6732. ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
  6733. **
  6734. ** ^Extension loading is off by default.
  6735. ** ^Call the sqlite3_enable_load_extension() routine with onoff==1
  6736. ** to turn extension loading on and call it with onoff==0 to turn
  6737. ** it back off again.
  6738. **
  6739. ** ^This interface enables or disables both the C-API
  6740. ** [sqlite3_load_extension()] and the SQL function [load_extension()].
  6741. ** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
  6742. ** to enable or disable only the C-API.)^
  6743. **
  6744. ** <b>Security warning:</b> It is recommended that extension loading
  6745. ** be enabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
  6746. ** rather than this interface, so the [load_extension()] SQL function
  6747. ** remains disabled. This will prevent SQL injections from giving attackers
  6748. ** access to extension loading capabilities.
  6749. */
  6750. SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
  6751. /*
  6752. ** CAPI3REF: Automatically Load Statically Linked Extensions
  6753. **
  6754. ** ^This interface causes the xEntryPoint() function to be invoked for
  6755. ** each new [database connection] that is created. The idea here is that
  6756. ** xEntryPoint() is the entry point for a statically linked [SQLite extension]
  6757. ** that is to be automatically loaded into all new database connections.
  6758. **
  6759. ** ^(Even though the function prototype shows that xEntryPoint() takes
  6760. ** no arguments and returns void, SQLite invokes xEntryPoint() with three
  6761. ** arguments and expects an integer result as if the signature of the
  6762. ** entry point where as follows:
  6763. **
  6764. ** <blockquote><pre>
  6765. ** &nbsp; int xEntryPoint(
  6766. ** &nbsp; sqlite3 *db,
  6767. ** &nbsp; const char **pzErrMsg,
  6768. ** &nbsp; const struct sqlite3_api_routines *pThunk
  6769. ** &nbsp; );
  6770. ** </pre></blockquote>)^
  6771. **
  6772. ** If the xEntryPoint routine encounters an error, it should make *pzErrMsg
  6773. ** point to an appropriate error message (obtained from [sqlite3_mprintf()])
  6774. ** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg
  6775. ** is NULL before calling the xEntryPoint(). ^SQLite will invoke
  6776. ** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any
  6777. ** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()],
  6778. ** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail.
  6779. **
  6780. ** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
  6781. ** on the list of automatic extensions is a harmless no-op. ^No entry point
  6782. ** will be called more than once for each database connection that is opened.
  6783. **
  6784. ** See also: [sqlite3_reset_auto_extension()]
  6785. ** and [sqlite3_cancel_auto_extension()]
  6786. */
  6787. SQLITE_API int sqlite3_auto_extension(void(*xEntryPoint)(void));
  6788. /*
  6789. ** CAPI3REF: Cancel Automatic Extension Loading
  6790. **
  6791. ** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the
  6792. ** initialization routine X that was registered using a prior call to
  6793. ** [sqlite3_auto_extension(X)]. ^The [sqlite3_cancel_auto_extension(X)]
  6794. ** routine returns 1 if initialization routine X was successfully
  6795. ** unregistered and it returns 0 if X was not on the list of initialization
  6796. ** routines.
  6797. */
  6798. SQLITE_API int sqlite3_cancel_auto_extension(void(*xEntryPoint)(void));
  6799. /*
  6800. ** CAPI3REF: Reset Automatic Extension Loading
  6801. **
  6802. ** ^This interface disables all automatic extensions previously
  6803. ** registered using [sqlite3_auto_extension()].
  6804. */
  6805. SQLITE_API void sqlite3_reset_auto_extension(void);
  6806. /*
  6807. ** The interface to the virtual-table mechanism is currently considered
  6808. ** to be experimental. The interface might change in incompatible ways.
  6809. ** If this is a problem for you, do not use the interface at this time.
  6810. **
  6811. ** When the virtual-table mechanism stabilizes, we will declare the
  6812. ** interface fixed, support it indefinitely, and remove this comment.
  6813. */
  6814. /*
  6815. ** Structures used by the virtual table interface
  6816. */
  6817. typedef struct sqlite3_vtab sqlite3_vtab;
  6818. typedef struct sqlite3_index_info sqlite3_index_info;
  6819. typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;
  6820. typedef struct sqlite3_module sqlite3_module;
  6821. /*
  6822. ** CAPI3REF: Virtual Table Object
  6823. ** KEYWORDS: sqlite3_module {virtual table module}
  6824. **
  6825. ** This structure, sometimes called a "virtual table module",
  6826. ** defines the implementation of a [virtual table].
  6827. ** This structure consists mostly of methods for the module.
  6828. **
  6829. ** ^A virtual table module is created by filling in a persistent
  6830. ** instance of this structure and passing a pointer to that instance
  6831. ** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].
  6832. ** ^The registration remains valid until it is replaced by a different
  6833. ** module or until the [database connection] closes. The content
  6834. ** of this structure must not change while it is registered with
  6835. ** any database connection.
  6836. */
  6837. struct sqlite3_module {
  6838. int iVersion;
  6839. int (*xCreate)(sqlite3*, void *pAux,
  6840. int argc, const char *const*argv,
  6841. sqlite3_vtab **ppVTab, char**);
  6842. int (*xConnect)(sqlite3*, void *pAux,
  6843. int argc, const char *const*argv,
  6844. sqlite3_vtab **ppVTab, char**);
  6845. int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
  6846. int (*xDisconnect)(sqlite3_vtab *pVTab);
  6847. int (*xDestroy)(sqlite3_vtab *pVTab);
  6848. int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);
  6849. int (*xClose)(sqlite3_vtab_cursor*);
  6850. int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
  6851. int argc, sqlite3_value **argv);
  6852. int (*xNext)(sqlite3_vtab_cursor*);
  6853. int (*xEof)(sqlite3_vtab_cursor*);
  6854. int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int);
  6855. int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid);
  6856. int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *);
  6857. int (*xBegin)(sqlite3_vtab *pVTab);
  6858. int (*xSync)(sqlite3_vtab *pVTab);
  6859. int (*xCommit)(sqlite3_vtab *pVTab);
  6860. int (*xRollback)(sqlite3_vtab *pVTab);
  6861. int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
  6862. void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
  6863. void **ppArg);
  6864. int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
  6865. /* The methods above are in version 1 of the sqlite_module object. Those
  6866. ** below are for version 2 and greater. */
  6867. int (*xSavepoint)(sqlite3_vtab *pVTab, int);
  6868. int (*xRelease)(sqlite3_vtab *pVTab, int);
  6869. int (*xRollbackTo)(sqlite3_vtab *pVTab, int);
  6870. /* The methods above are in versions 1 and 2 of the sqlite_module object.
  6871. ** Those below are for version 3 and greater. */
  6872. int (*xShadowName)(const char*);
  6873. };
  6874. /*
  6875. ** CAPI3REF: Virtual Table Indexing Information
  6876. ** KEYWORDS: sqlite3_index_info
  6877. **
  6878. ** The sqlite3_index_info structure and its substructures is used as part
  6879. ** of the [virtual table] interface to
  6880. ** pass information into and receive the reply from the [xBestIndex]
  6881. ** method of a [virtual table module]. The fields under **Inputs** are the
  6882. ** inputs to xBestIndex and are read-only. xBestIndex inserts its
  6883. ** results into the **Outputs** fields.
  6884. **
  6885. ** ^(The aConstraint[] array records WHERE clause constraints of the form:
  6886. **
  6887. ** <blockquote>column OP expr</blockquote>
  6888. **
  6889. ** where OP is =, &lt;, &lt;=, &gt;, or &gt;=.)^ ^(The particular operator is
  6890. ** stored in aConstraint[].op using one of the
  6891. ** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^
  6892. ** ^(The index of the column is stored in
  6893. ** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the
  6894. ** expr on the right-hand side can be evaluated (and thus the constraint
  6895. ** is usable) and false if it cannot.)^
  6896. **
  6897. ** ^The optimizer automatically inverts terms of the form "expr OP column"
  6898. ** and makes other simplifications to the WHERE clause in an attempt to
  6899. ** get as many WHERE clause terms into the form shown above as possible.
  6900. ** ^The aConstraint[] array only reports WHERE clause terms that are
  6901. ** relevant to the particular virtual table being queried.
  6902. **
  6903. ** ^Information about the ORDER BY clause is stored in aOrderBy[].
  6904. ** ^Each term of aOrderBy records a column of the ORDER BY clause.
  6905. **
  6906. ** The colUsed field indicates which columns of the virtual table may be
  6907. ** required by the current scan. Virtual table columns are numbered from
  6908. ** zero in the order in which they appear within the CREATE TABLE statement
  6909. ** passed to sqlite3_declare_vtab(). For the first 63 columns (columns 0-62),
  6910. ** the corresponding bit is set within the colUsed mask if the column may be
  6911. ** required by SQLite. If the table has at least 64 columns and any column
  6912. ** to the right of the first 63 is required, then bit 63 of colUsed is also
  6913. ** set. In other words, column iCol may be required if the expression
  6914. ** (colUsed & ((sqlite3_uint64)1 << (iCol>=63 ? 63 : iCol))) evaluates to
  6915. ** non-zero.
  6916. **
  6917. ** The [xBestIndex] method must fill aConstraintUsage[] with information
  6918. ** about what parameters to pass to xFilter. ^If argvIndex>0 then
  6919. ** the right-hand side of the corresponding aConstraint[] is evaluated
  6920. ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
  6921. ** is true, then the constraint is assumed to be fully handled by the
  6922. ** virtual table and might not be checked again by the byte code.)^ ^(The
  6923. ** aConstraintUsage[].omit flag is an optimization hint. When the omit flag
  6924. ** is left in its default setting of false, the constraint will always be
  6925. ** checked separately in byte code. If the omit flag is change to true, then
  6926. ** the constraint may or may not be checked in byte code. In other words,
  6927. ** when the omit flag is true there is no guarantee that the constraint will
  6928. ** not be checked again using byte code.)^
  6929. **
  6930. ** ^The idxNum and idxPtr values are recorded and passed into the
  6931. ** [xFilter] method.
  6932. ** ^[sqlite3_free()] is used to free idxPtr if and only if
  6933. ** needToFreeIdxPtr is true.
  6934. **
  6935. ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
  6936. ** the correct order to satisfy the ORDER BY clause so that no separate
  6937. ** sorting step is required.
  6938. **
  6939. ** ^The estimatedCost value is an estimate of the cost of a particular
  6940. ** strategy. A cost of N indicates that the cost of the strategy is similar
  6941. ** to a linear scan of an SQLite table with N rows. A cost of log(N)
  6942. ** indicates that the expense of the operation is similar to that of a
  6943. ** binary search on a unique indexed field of an SQLite table with N rows.
  6944. **
  6945. ** ^The estimatedRows value is an estimate of the number of rows that
  6946. ** will be returned by the strategy.
  6947. **
  6948. ** The xBestIndex method may optionally populate the idxFlags field with a
  6949. ** mask of SQLITE_INDEX_SCAN_* flags. Currently there is only one such flag -
  6950. ** SQLITE_INDEX_SCAN_UNIQUE. If the xBestIndex method sets this flag, SQLite
  6951. ** assumes that the strategy may visit at most one row.
  6952. **
  6953. ** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then
  6954. ** SQLite also assumes that if a call to the xUpdate() method is made as
  6955. ** part of the same statement to delete or update a virtual table row and the
  6956. ** implementation returns SQLITE_CONSTRAINT, then there is no need to rollback
  6957. ** any database changes. In other words, if the xUpdate() returns
  6958. ** SQLITE_CONSTRAINT, the database contents must be exactly as they were
  6959. ** before xUpdate was called. By contrast, if SQLITE_INDEX_SCAN_UNIQUE is not
  6960. ** set and xUpdate returns SQLITE_CONSTRAINT, any database changes made by
  6961. ** the xUpdate method are automatically rolled back by SQLite.
  6962. **
  6963. ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
  6964. ** structure for SQLite [version 3.8.2] ([dateof:3.8.2]).
  6965. ** If a virtual table extension is
  6966. ** used with an SQLite version earlier than 3.8.2, the results of attempting
  6967. ** to read or write the estimatedRows field are undefined (but are likely
  6968. ** to include crashing the application). The estimatedRows field should
  6969. ** therefore only be used if [sqlite3_libversion_number()] returns a
  6970. ** value greater than or equal to 3008002. Similarly, the idxFlags field
  6971. ** was added for [version 3.9.0] ([dateof:3.9.0]).
  6972. ** It may therefore only be used if
  6973. ** sqlite3_libversion_number() returns a value greater than or equal to
  6974. ** 3009000.
  6975. */
  6976. struct sqlite3_index_info {
  6977. /* Inputs */
  6978. int nConstraint; /* Number of entries in aConstraint */
  6979. struct sqlite3_index_constraint {
  6980. int iColumn; /* Column constrained. -1 for ROWID */
  6981. unsigned char op; /* Constraint operator */
  6982. unsigned char usable; /* True if this constraint is usable */
  6983. int iTermOffset; /* Used internally - xBestIndex should ignore */
  6984. } *aConstraint; /* Table of WHERE clause constraints */
  6985. int nOrderBy; /* Number of terms in the ORDER BY clause */
  6986. struct sqlite3_index_orderby {
  6987. int iColumn; /* Column number */
  6988. unsigned char desc; /* True for DESC. False for ASC. */
  6989. } *aOrderBy; /* The ORDER BY clause */
  6990. /* Outputs */
  6991. struct sqlite3_index_constraint_usage {
  6992. int argvIndex; /* if >0, constraint is part of argv to xFilter */
  6993. unsigned char omit; /* Do not code a test for this constraint */
  6994. } *aConstraintUsage;
  6995. int idxNum; /* Number used to identify the index */
  6996. char *idxStr; /* String, possibly obtained from sqlite3_malloc */
  6997. int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
  6998. int orderByConsumed; /* True if output is already ordered */
  6999. double estimatedCost; /* Estimated cost of using this index */
  7000. /* Fields below are only available in SQLite 3.8.2 and later */
  7001. sqlite3_int64 estimatedRows; /* Estimated number of rows returned */
  7002. /* Fields below are only available in SQLite 3.9.0 and later */
  7003. int idxFlags; /* Mask of SQLITE_INDEX_SCAN_* flags */
  7004. /* Fields below are only available in SQLite 3.10.0 and later */
  7005. sqlite3_uint64 colUsed; /* Input: Mask of columns used by statement */
  7006. };
  7007. /*
  7008. ** CAPI3REF: Virtual Table Scan Flags
  7009. **
  7010. ** Virtual table implementations are allowed to set the
  7011. ** [sqlite3_index_info].idxFlags field to some combination of
  7012. ** these bits.
  7013. */
  7014. #define SQLITE_INDEX_SCAN_UNIQUE 1 /* Scan visits at most 1 row */
  7015. /*
  7016. ** CAPI3REF: Virtual Table Constraint Operator Codes
  7017. **
  7018. ** These macros define the allowed values for the
  7019. ** [sqlite3_index_info].aConstraint[].op field. Each value represents
  7020. ** an operator that is part of a constraint term in the WHERE clause of
  7021. ** a query that uses a [virtual table].
  7022. **
  7023. ** ^The left-hand operand of the operator is given by the corresponding
  7024. ** aConstraint[].iColumn field. ^An iColumn of -1 indicates the left-hand
  7025. ** operand is the rowid.
  7026. ** The SQLITE_INDEX_CONSTRAINT_LIMIT and SQLITE_INDEX_CONSTRAINT_OFFSET
  7027. ** operators have no left-hand operand, and so for those operators the
  7028. ** corresponding aConstraint[].iColumn is meaningless and should not be
  7029. ** used.
  7030. **
  7031. ** All operator values from SQLITE_INDEX_CONSTRAINT_FUNCTION through
  7032. ** value 255 are reserved to represent functions that are overloaded
  7033. ** by the [xFindFunction|xFindFunction method] of the virtual table
  7034. ** implementation.
  7035. **
  7036. ** The right-hand operands for each constraint might be accessible using
  7037. ** the [sqlite3_vtab_rhs_value()] interface. Usually the right-hand
  7038. ** operand is only available if it appears as a single constant literal
  7039. ** in the input SQL. If the right-hand operand is another column or an
  7040. ** expression (even a constant expression) or a parameter, then the
  7041. ** sqlite3_vtab_rhs_value() probably will not be able to extract it.
  7042. ** ^The SQLITE_INDEX_CONSTRAINT_ISNULL and
  7043. ** SQLITE_INDEX_CONSTRAINT_ISNOTNULL operators have no right-hand operand
  7044. ** and hence calls to sqlite3_vtab_rhs_value() for those operators will
  7045. ** always return SQLITE_NOTFOUND.
  7046. **
  7047. ** The collating sequence to be used for comparison can be found using
  7048. ** the [sqlite3_vtab_collation()] interface. For most real-world virtual
  7049. ** tables, the collating sequence of constraints does not matter (for example
  7050. ** because the constraints are numeric) and so the sqlite3_vtab_collation()
  7051. ** interface is no commonly needed.
  7052. */
  7053. #define SQLITE_INDEX_CONSTRAINT_EQ 2
  7054. #define SQLITE_INDEX_CONSTRAINT_GT 4
  7055. #define SQLITE_INDEX_CONSTRAINT_LE 8
  7056. #define SQLITE_INDEX_CONSTRAINT_LT 16
  7057. #define SQLITE_INDEX_CONSTRAINT_GE 32
  7058. #define SQLITE_INDEX_CONSTRAINT_MATCH 64
  7059. #define SQLITE_INDEX_CONSTRAINT_LIKE 65
  7060. #define SQLITE_INDEX_CONSTRAINT_GLOB 66
  7061. #define SQLITE_INDEX_CONSTRAINT_REGEXP 67
  7062. #define SQLITE_INDEX_CONSTRAINT_NE 68
  7063. #define SQLITE_INDEX_CONSTRAINT_ISNOT 69
  7064. #define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70
  7065. #define SQLITE_INDEX_CONSTRAINT_ISNULL 71
  7066. #define SQLITE_INDEX_CONSTRAINT_IS 72
  7067. #define SQLITE_INDEX_CONSTRAINT_LIMIT 73
  7068. #define SQLITE_INDEX_CONSTRAINT_OFFSET 74
  7069. #define SQLITE_INDEX_CONSTRAINT_FUNCTION 150
  7070. /*
  7071. ** CAPI3REF: Register A Virtual Table Implementation
  7072. ** METHOD: sqlite3
  7073. **
  7074. ** ^These routines are used to register a new [virtual table module] name.
  7075. ** ^Module names must be registered before
  7076. ** creating a new [virtual table] using the module and before using a
  7077. ** preexisting [virtual table] for the module.
  7078. **
  7079. ** ^The module name is registered on the [database connection] specified
  7080. ** by the first parameter. ^The name of the module is given by the
  7081. ** second parameter. ^The third parameter is a pointer to
  7082. ** the implementation of the [virtual table module]. ^The fourth
  7083. ** parameter is an arbitrary client data pointer that is passed through
  7084. ** into the [xCreate] and [xConnect] methods of the virtual table module
  7085. ** when a new virtual table is be being created or reinitialized.
  7086. **
  7087. ** ^The sqlite3_create_module_v2() interface has a fifth parameter which
  7088. ** is a pointer to a destructor for the pClientData. ^SQLite will
  7089. ** invoke the destructor function (if it is not NULL) when SQLite
  7090. ** no longer needs the pClientData pointer. ^The destructor will also
  7091. ** be invoked if the call to sqlite3_create_module_v2() fails.
  7092. ** ^The sqlite3_create_module()
  7093. ** interface is equivalent to sqlite3_create_module_v2() with a NULL
  7094. ** destructor.
  7095. **
  7096. ** ^If the third parameter (the pointer to the sqlite3_module object) is
  7097. ** NULL then no new module is created and any existing modules with the
  7098. ** same name are dropped.
  7099. **
  7100. ** See also: [sqlite3_drop_modules()]
  7101. */
  7102. SQLITE_API int sqlite3_create_module(
  7103. sqlite3 *db, /* SQLite connection to register module with */
  7104. const char *zName, /* Name of the module */
  7105. const sqlite3_module *p, /* Methods for the module */
  7106. void *pClientData /* Client data for xCreate/xConnect */
  7107. );
  7108. SQLITE_API int sqlite3_create_module_v2(
  7109. sqlite3 *db, /* SQLite connection to register module with */
  7110. const char *zName, /* Name of the module */
  7111. const sqlite3_module *p, /* Methods for the module */
  7112. void *pClientData, /* Client data for xCreate/xConnect */
  7113. void(*xDestroy)(void*) /* Module destructor function */
  7114. );
  7115. /*
  7116. ** CAPI3REF: Remove Unnecessary Virtual Table Implementations
  7117. ** METHOD: sqlite3
  7118. **
  7119. ** ^The sqlite3_drop_modules(D,L) interface removes all virtual
  7120. ** table modules from database connection D except those named on list L.
  7121. ** The L parameter must be either NULL or a pointer to an array of pointers
  7122. ** to strings where the array is terminated by a single NULL pointer.
  7123. ** ^If the L parameter is NULL, then all virtual table modules are removed.
  7124. **
  7125. ** See also: [sqlite3_create_module()]
  7126. */
  7127. SQLITE_API int sqlite3_drop_modules(
  7128. sqlite3 *db, /* Remove modules from this connection */
  7129. const char **azKeep /* Except, do not remove the ones named here */
  7130. );
  7131. /*
  7132. ** CAPI3REF: Virtual Table Instance Object
  7133. ** KEYWORDS: sqlite3_vtab
  7134. **
  7135. ** Every [virtual table module] implementation uses a subclass
  7136. ** of this object to describe a particular instance
  7137. ** of the [virtual table]. Each subclass will
  7138. ** be tailored to the specific needs of the module implementation.
  7139. ** The purpose of this superclass is to define certain fields that are
  7140. ** common to all module implementations.
  7141. **
  7142. ** ^Virtual tables methods can set an error message by assigning a
  7143. ** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should
  7144. ** take care that any prior string is freed by a call to [sqlite3_free()]
  7145. ** prior to assigning a new string to zErrMsg. ^After the error message
  7146. ** is delivered up to the client application, the string will be automatically
  7147. ** freed by sqlite3_free() and the zErrMsg field will be zeroed.
  7148. */
  7149. struct sqlite3_vtab {
  7150. const sqlite3_module *pModule; /* The module for this virtual table */
  7151. int nRef; /* Number of open cursors */
  7152. char *zErrMsg; /* Error message from sqlite3_mprintf() */
  7153. /* Virtual table implementations will typically add additional fields */
  7154. };
  7155. /*
  7156. ** CAPI3REF: Virtual Table Cursor Object
  7157. ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
  7158. **
  7159. ** Every [virtual table module] implementation uses a subclass of the
  7160. ** following structure to describe cursors that point into the
  7161. ** [virtual table] and are used
  7162. ** to loop through the virtual table. Cursors are created using the
  7163. ** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed
  7164. ** by the [sqlite3_module.xClose | xClose] method. Cursors are used
  7165. ** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods
  7166. ** of the module. Each module implementation will define
  7167. ** the content of a cursor structure to suit its own needs.
  7168. **
  7169. ** This superclass exists in order to define fields of the cursor that
  7170. ** are common to all implementations.
  7171. */
  7172. struct sqlite3_vtab_cursor {
  7173. sqlite3_vtab *pVtab; /* Virtual table of this cursor */
  7174. /* Virtual table implementations will typically add additional fields */
  7175. };
  7176. /*
  7177. ** CAPI3REF: Declare The Schema Of A Virtual Table
  7178. **
  7179. ** ^The [xCreate] and [xConnect] methods of a
  7180. ** [virtual table module] call this interface
  7181. ** to declare the format (the names and datatypes of the columns) of
  7182. ** the virtual tables they implement.
  7183. */
  7184. SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
  7185. /*
  7186. ** CAPI3REF: Overload A Function For A Virtual Table
  7187. ** METHOD: sqlite3
  7188. **
  7189. ** ^(Virtual tables can provide alternative implementations of functions
  7190. ** using the [xFindFunction] method of the [virtual table module].
  7191. ** But global versions of those functions
  7192. ** must exist in order to be overloaded.)^
  7193. **
  7194. ** ^(This API makes sure a global version of a function with a particular
  7195. ** name and number of parameters exists. If no such function exists
  7196. ** before this API is called, a new function is created.)^ ^The implementation
  7197. ** of the new function always causes an exception to be thrown. So
  7198. ** the new function is not good for anything by itself. Its only
  7199. ** purpose is to be a placeholder function that can be overloaded
  7200. ** by a [virtual table].
  7201. */
  7202. SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
  7203. /*
  7204. ** The interface to the virtual-table mechanism defined above (back up
  7205. ** to a comment remarkably similar to this one) is currently considered
  7206. ** to be experimental. The interface might change in incompatible ways.
  7207. ** If this is a problem for you, do not use the interface at this time.
  7208. **
  7209. ** When the virtual-table mechanism stabilizes, we will declare the
  7210. ** interface fixed, support it indefinitely, and remove this comment.
  7211. */
  7212. /*
  7213. ** CAPI3REF: A Handle To An Open BLOB
  7214. ** KEYWORDS: {BLOB handle} {BLOB handles}
  7215. **
  7216. ** An instance of this object represents an open BLOB on which
  7217. ** [sqlite3_blob_open | incremental BLOB I/O] can be performed.
  7218. ** ^Objects of this type are created by [sqlite3_blob_open()]
  7219. ** and destroyed by [sqlite3_blob_close()].
  7220. ** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces
  7221. ** can be used to read or write small subsections of the BLOB.
  7222. ** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes.
  7223. */
  7224. typedef struct sqlite3_blob sqlite3_blob;
  7225. /*
  7226. ** CAPI3REF: Open A BLOB For Incremental I/O
  7227. ** METHOD: sqlite3
  7228. ** CONSTRUCTOR: sqlite3_blob
  7229. **
  7230. ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
  7231. ** in row iRow, column zColumn, table zTable in database zDb;
  7232. ** in other words, the same BLOB that would be selected by:
  7233. **
  7234. ** <pre>
  7235. ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
  7236. ** </pre>)^
  7237. **
  7238. ** ^(Parameter zDb is not the filename that contains the database, but
  7239. ** rather the symbolic name of the database. For attached databases, this is
  7240. ** the name that appears after the AS keyword in the [ATTACH] statement.
  7241. ** For the main database file, the database name is "main". For TEMP
  7242. ** tables, the database name is "temp".)^
  7243. **
  7244. ** ^If the flags parameter is non-zero, then the BLOB is opened for read
  7245. ** and write access. ^If the flags parameter is zero, the BLOB is opened for
  7246. ** read-only access.
  7247. **
  7248. ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
  7249. ** in *ppBlob. Otherwise an [error code] is returned and, unless the error
  7250. ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
  7251. ** the API is not misused, it is always safe to call [sqlite3_blob_close()]
  7252. ** on *ppBlob after this function it returns.
  7253. **
  7254. ** This function fails with SQLITE_ERROR if any of the following are true:
  7255. ** <ul>
  7256. ** <li> ^(Database zDb does not exist)^,
  7257. ** <li> ^(Table zTable does not exist within database zDb)^,
  7258. ** <li> ^(Table zTable is a WITHOUT ROWID table)^,
  7259. ** <li> ^(Column zColumn does not exist)^,
  7260. ** <li> ^(Row iRow is not present in the table)^,
  7261. ** <li> ^(The specified column of row iRow contains a value that is not
  7262. ** a TEXT or BLOB value)^,
  7263. ** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE
  7264. ** constraint and the blob is being opened for read/write access)^,
  7265. ** <li> ^([foreign key constraints | Foreign key constraints] are enabled,
  7266. ** column zColumn is part of a [child key] definition and the blob is
  7267. ** being opened for read/write access)^.
  7268. ** </ul>
  7269. **
  7270. ** ^Unless it returns SQLITE_MISUSE, this function sets the
  7271. ** [database connection] error code and message accessible via
  7272. ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
  7273. **
  7274. ** A BLOB referenced by sqlite3_blob_open() may be read using the
  7275. ** [sqlite3_blob_read()] interface and modified by using
  7276. ** [sqlite3_blob_write()]. The [BLOB handle] can be moved to a
  7277. ** different row of the same table using the [sqlite3_blob_reopen()]
  7278. ** interface. However, the column, table, or database of a [BLOB handle]
  7279. ** cannot be changed after the [BLOB handle] is opened.
  7280. **
  7281. ** ^(If the row that a BLOB handle points to is modified by an
  7282. ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
  7283. ** then the BLOB handle is marked as "expired".
  7284. ** This is true if any column of the row is changed, even a column
  7285. ** other than the one the BLOB handle is open on.)^
  7286. ** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for
  7287. ** an expired BLOB handle fail with a return code of [SQLITE_ABORT].
  7288. ** ^(Changes written into a BLOB prior to the BLOB expiring are not
  7289. ** rolled back by the expiration of the BLOB. Such changes will eventually
  7290. ** commit if the transaction continues to completion.)^
  7291. **
  7292. ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
  7293. ** the opened blob. ^The size of a blob may not be changed by this
  7294. ** interface. Use the [UPDATE] SQL command to change the size of a
  7295. ** blob.
  7296. **
  7297. ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
  7298. ** and the built-in [zeroblob] SQL function may be used to create a
  7299. ** zero-filled blob to read or write using the incremental-blob interface.
  7300. **
  7301. ** To avoid a resource leak, every open [BLOB handle] should eventually
  7302. ** be released by a call to [sqlite3_blob_close()].
  7303. **
  7304. ** See also: [sqlite3_blob_close()],
  7305. ** [sqlite3_blob_reopen()], [sqlite3_blob_read()],
  7306. ** [sqlite3_blob_bytes()], [sqlite3_blob_write()].
  7307. */
  7308. SQLITE_API int sqlite3_blob_open(
  7309. sqlite3*,
  7310. const char *zDb,
  7311. const char *zTable,
  7312. const char *zColumn,
  7313. sqlite3_int64 iRow,
  7314. int flags,
  7315. sqlite3_blob **ppBlob
  7316. );
  7317. /*
  7318. ** CAPI3REF: Move a BLOB Handle to a New Row
  7319. ** METHOD: sqlite3_blob
  7320. **
  7321. ** ^This function is used to move an existing [BLOB handle] so that it points
  7322. ** to a different row of the same database table. ^The new row is identified
  7323. ** by the rowid value passed as the second argument. Only the row can be
  7324. ** changed. ^The database, table and column on which the blob handle is open
  7325. ** remain the same. Moving an existing [BLOB handle] to a new row is
  7326. ** faster than closing the existing handle and opening a new one.
  7327. **
  7328. ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] -
  7329. ** it must exist and there must be either a blob or text value stored in
  7330. ** the nominated column.)^ ^If the new row is not present in the table, or if
  7331. ** it does not contain a blob or text value, or if another error occurs, an
  7332. ** SQLite error code is returned and the blob handle is considered aborted.
  7333. ** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or
  7334. ** [sqlite3_blob_reopen()] on an aborted blob handle immediately return
  7335. ** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle
  7336. ** always returns zero.
  7337. **
  7338. ** ^This function sets the database handle error code and message.
  7339. */
  7340. SQLITE_API int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
  7341. /*
  7342. ** CAPI3REF: Close A BLOB Handle
  7343. ** DESTRUCTOR: sqlite3_blob
  7344. **
  7345. ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
  7346. ** unconditionally. Even if this routine returns an error code, the
  7347. ** handle is still closed.)^
  7348. **
  7349. ** ^If the blob handle being closed was opened for read-write access, and if
  7350. ** the database is in auto-commit mode and there are no other open read-write
  7351. ** blob handles or active write statements, the current transaction is
  7352. ** committed. ^If an error occurs while committing the transaction, an error
  7353. ** code is returned and the transaction rolled back.
  7354. **
  7355. ** Calling this function with an argument that is not a NULL pointer or an
  7356. ** open blob handle results in undefined behaviour. ^Calling this routine
  7357. ** with a null pointer (such as would be returned by a failed call to
  7358. ** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
  7359. ** is passed a valid open blob handle, the values returned by the
  7360. ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
  7361. */
  7362. SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
  7363. /*
  7364. ** CAPI3REF: Return The Size Of An Open BLOB
  7365. ** METHOD: sqlite3_blob
  7366. **
  7367. ** ^Returns the size in bytes of the BLOB accessible via the
  7368. ** successfully opened [BLOB handle] in its only argument. ^The
  7369. ** incremental blob I/O routines can only read or overwriting existing
  7370. ** blob content; they cannot change the size of a blob.
  7371. **
  7372. ** This routine only works on a [BLOB handle] which has been created
  7373. ** by a prior successful call to [sqlite3_blob_open()] and which has not
  7374. ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
  7375. ** to this routine results in undefined and probably undesirable behavior.
  7376. */
  7377. SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *);
  7378. /*
  7379. ** CAPI3REF: Read Data From A BLOB Incrementally
  7380. ** METHOD: sqlite3_blob
  7381. **
  7382. ** ^(This function is used to read data from an open [BLOB handle] into a
  7383. ** caller-supplied buffer. N bytes of data are copied into buffer Z
  7384. ** from the open BLOB, starting at offset iOffset.)^
  7385. **
  7386. ** ^If offset iOffset is less than N bytes from the end of the BLOB,
  7387. ** [SQLITE_ERROR] is returned and no data is read. ^If N or iOffset is
  7388. ** less than zero, [SQLITE_ERROR] is returned and no data is read.
  7389. ** ^The size of the blob (and hence the maximum value of N+iOffset)
  7390. ** can be determined using the [sqlite3_blob_bytes()] interface.
  7391. **
  7392. ** ^An attempt to read from an expired [BLOB handle] fails with an
  7393. ** error code of [SQLITE_ABORT].
  7394. **
  7395. ** ^(On success, sqlite3_blob_read() returns SQLITE_OK.
  7396. ** Otherwise, an [error code] or an [extended error code] is returned.)^
  7397. **
  7398. ** This routine only works on a [BLOB handle] which has been created
  7399. ** by a prior successful call to [sqlite3_blob_open()] and which has not
  7400. ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
  7401. ** to this routine results in undefined and probably undesirable behavior.
  7402. **
  7403. ** See also: [sqlite3_blob_write()].
  7404. */
  7405. SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
  7406. /*
  7407. ** CAPI3REF: Write Data Into A BLOB Incrementally
  7408. ** METHOD: sqlite3_blob
  7409. **
  7410. ** ^(This function is used to write data into an open [BLOB handle] from a
  7411. ** caller-supplied buffer. N bytes of data are copied from the buffer Z
  7412. ** into the open BLOB, starting at offset iOffset.)^
  7413. **
  7414. ** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
  7415. ** Otherwise, an [error code] or an [extended error code] is returned.)^
  7416. ** ^Unless SQLITE_MISUSE is returned, this function sets the
  7417. ** [database connection] error code and message accessible via
  7418. ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
  7419. **
  7420. ** ^If the [BLOB handle] passed as the first argument was not opened for
  7421. ** writing (the flags parameter to [sqlite3_blob_open()] was zero),
  7422. ** this function returns [SQLITE_READONLY].
  7423. **
  7424. ** This function may only modify the contents of the BLOB; it is
  7425. ** not possible to increase the size of a BLOB using this API.
  7426. ** ^If offset iOffset is less than N bytes from the end of the BLOB,
  7427. ** [SQLITE_ERROR] is returned and no data is written. The size of the
  7428. ** BLOB (and hence the maximum value of N+iOffset) can be determined
  7429. ** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less
  7430. ** than zero [SQLITE_ERROR] is returned and no data is written.
  7431. **
  7432. ** ^An attempt to write to an expired [BLOB handle] fails with an
  7433. ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred
  7434. ** before the [BLOB handle] expired are not rolled back by the
  7435. ** expiration of the handle, though of course those changes might
  7436. ** have been overwritten by the statement that expired the BLOB handle
  7437. ** or by other independent statements.
  7438. **
  7439. ** This routine only works on a [BLOB handle] which has been created
  7440. ** by a prior successful call to [sqlite3_blob_open()] and which has not
  7441. ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
  7442. ** to this routine results in undefined and probably undesirable behavior.
  7443. **
  7444. ** See also: [sqlite3_blob_read()].
  7445. */
  7446. SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
  7447. /*
  7448. ** CAPI3REF: Virtual File System Objects
  7449. **
  7450. ** A virtual filesystem (VFS) is an [sqlite3_vfs] object
  7451. ** that SQLite uses to interact
  7452. ** with the underlying operating system. Most SQLite builds come with a
  7453. ** single default VFS that is appropriate for the host computer.
  7454. ** New VFSes can be registered and existing VFSes can be unregistered.
  7455. ** The following interfaces are provided.
  7456. **
  7457. ** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name.
  7458. ** ^Names are case sensitive.
  7459. ** ^Names are zero-terminated UTF-8 strings.
  7460. ** ^If there is no match, a NULL pointer is returned.
  7461. ** ^If zVfsName is NULL then the default VFS is returned.
  7462. **
  7463. ** ^New VFSes are registered with sqlite3_vfs_register().
  7464. ** ^Each new VFS becomes the default VFS if the makeDflt flag is set.
  7465. ** ^The same VFS can be registered multiple times without injury.
  7466. ** ^To make an existing VFS into the default VFS, register it again
  7467. ** with the makeDflt flag set. If two different VFSes with the
  7468. ** same name are registered, the behavior is undefined. If a
  7469. ** VFS is registered with a name that is NULL or an empty string,
  7470. ** then the behavior is undefined.
  7471. **
  7472. ** ^Unregister a VFS with the sqlite3_vfs_unregister() interface.
  7473. ** ^(If the default VFS is unregistered, another VFS is chosen as
  7474. ** the default. The choice for the new VFS is arbitrary.)^
  7475. */
  7476. SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName);
  7477. SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
  7478. SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*);
  7479. /*
  7480. ** CAPI3REF: Mutexes
  7481. **
  7482. ** The SQLite core uses these routines for thread
  7483. ** synchronization. Though they are intended for internal
  7484. ** use by SQLite, code that links against SQLite is
  7485. ** permitted to use any of these routines.
  7486. **
  7487. ** The SQLite source code contains multiple implementations
  7488. ** of these mutex routines. An appropriate implementation
  7489. ** is selected automatically at compile-time. The following
  7490. ** implementations are available in the SQLite core:
  7491. **
  7492. ** <ul>
  7493. ** <li> SQLITE_MUTEX_PTHREADS
  7494. ** <li> SQLITE_MUTEX_W32
  7495. ** <li> SQLITE_MUTEX_NOOP
  7496. ** </ul>
  7497. **
  7498. ** The SQLITE_MUTEX_NOOP implementation is a set of routines
  7499. ** that does no real locking and is appropriate for use in
  7500. ** a single-threaded application. The SQLITE_MUTEX_PTHREADS and
  7501. ** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
  7502. ** and Windows.
  7503. **
  7504. ** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
  7505. ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
  7506. ** implementation is included with the library. In this case the
  7507. ** application must supply a custom mutex implementation using the
  7508. ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
  7509. ** before calling sqlite3_initialize() or any other public sqlite3_
  7510. ** function that calls sqlite3_initialize().
  7511. **
  7512. ** ^The sqlite3_mutex_alloc() routine allocates a new
  7513. ** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
  7514. ** routine returns NULL if it is unable to allocate the requested
  7515. ** mutex. The argument to sqlite3_mutex_alloc() must one of these
  7516. ** integer constants:
  7517. **
  7518. ** <ul>
  7519. ** <li> SQLITE_MUTEX_FAST
  7520. ** <li> SQLITE_MUTEX_RECURSIVE
  7521. ** <li> SQLITE_MUTEX_STATIC_MAIN
  7522. ** <li> SQLITE_MUTEX_STATIC_MEM
  7523. ** <li> SQLITE_MUTEX_STATIC_OPEN
  7524. ** <li> SQLITE_MUTEX_STATIC_PRNG
  7525. ** <li> SQLITE_MUTEX_STATIC_LRU
  7526. ** <li> SQLITE_MUTEX_STATIC_PMEM
  7527. ** <li> SQLITE_MUTEX_STATIC_APP1
  7528. ** <li> SQLITE_MUTEX_STATIC_APP2
  7529. ** <li> SQLITE_MUTEX_STATIC_APP3
  7530. ** <li> SQLITE_MUTEX_STATIC_VFS1
  7531. ** <li> SQLITE_MUTEX_STATIC_VFS2
  7532. ** <li> SQLITE_MUTEX_STATIC_VFS3
  7533. ** </ul>
  7534. **
  7535. ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
  7536. ** cause sqlite3_mutex_alloc() to create
  7537. ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
  7538. ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
  7539. ** The mutex implementation does not need to make a distinction
  7540. ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
  7541. ** not want to. SQLite will only request a recursive mutex in
  7542. ** cases where it really needs one. If a faster non-recursive mutex
  7543. ** implementation is available on the host platform, the mutex subsystem
  7544. ** might return such a mutex in response to SQLITE_MUTEX_FAST.
  7545. **
  7546. ** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other
  7547. ** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return
  7548. ** a pointer to a static preexisting mutex. ^Nine static mutexes are
  7549. ** used by the current version of SQLite. Future versions of SQLite
  7550. ** may add additional static mutexes. Static mutexes are for internal
  7551. ** use by SQLite only. Applications that use SQLite mutexes should
  7552. ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
  7553. ** SQLITE_MUTEX_RECURSIVE.
  7554. **
  7555. ** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
  7556. ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
  7557. ** returns a different mutex on every call. ^For the static
  7558. ** mutex types, the same mutex is returned on every call that has
  7559. ** the same type number.
  7560. **
  7561. ** ^The sqlite3_mutex_free() routine deallocates a previously
  7562. ** allocated dynamic mutex. Attempting to deallocate a static
  7563. ** mutex results in undefined behavior.
  7564. **
  7565. ** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
  7566. ** to enter a mutex. ^If another thread is already within the mutex,
  7567. ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
  7568. ** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK]
  7569. ** upon successful entry. ^(Mutexes created using
  7570. ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
  7571. ** In such cases, the
  7572. ** mutex must be exited an equal number of times before another thread
  7573. ** can enter.)^ If the same thread tries to enter any mutex other
  7574. ** than an SQLITE_MUTEX_RECURSIVE more than once, the behavior is undefined.
  7575. **
  7576. ** ^(Some systems (for example, Windows 95) do not support the operation
  7577. ** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try()
  7578. ** will always return SQLITE_BUSY. The SQLite core only ever uses
  7579. ** sqlite3_mutex_try() as an optimization so this is acceptable
  7580. ** behavior.)^
  7581. **
  7582. ** ^The sqlite3_mutex_leave() routine exits a mutex that was
  7583. ** previously entered by the same thread. The behavior
  7584. ** is undefined if the mutex is not currently entered by the
  7585. ** calling thread or is not currently allocated.
  7586. **
  7587. ** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
  7588. ** sqlite3_mutex_leave() is a NULL pointer, then all three routines
  7589. ** behave as no-ops.
  7590. **
  7591. ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].
  7592. */
  7593. SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int);
  7594. SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*);
  7595. SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*);
  7596. SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
  7597. SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
  7598. /*
  7599. ** CAPI3REF: Mutex Methods Object
  7600. **
  7601. ** An instance of this structure defines the low-level routines
  7602. ** used to allocate and use mutexes.
  7603. **
  7604. ** Usually, the default mutex implementations provided by SQLite are
  7605. ** sufficient, however the application has the option of substituting a custom
  7606. ** implementation for specialized deployments or systems for which SQLite
  7607. ** does not provide a suitable implementation. In this case, the application
  7608. ** creates and populates an instance of this structure to pass
  7609. ** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
  7610. ** Additionally, an instance of this structure can be used as an
  7611. ** output variable when querying the system for the current mutex
  7612. ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
  7613. **
  7614. ** ^The xMutexInit method defined by this structure is invoked as
  7615. ** part of system initialization by the sqlite3_initialize() function.
  7616. ** ^The xMutexInit routine is called by SQLite exactly once for each
  7617. ** effective call to [sqlite3_initialize()].
  7618. **
  7619. ** ^The xMutexEnd method defined by this structure is invoked as
  7620. ** part of system shutdown by the sqlite3_shutdown() function. The
  7621. ** implementation of this method is expected to release all outstanding
  7622. ** resources obtained by the mutex methods implementation, especially
  7623. ** those obtained by the xMutexInit method. ^The xMutexEnd()
  7624. ** interface is invoked exactly once for each call to [sqlite3_shutdown()].
  7625. **
  7626. ** ^(The remaining seven methods defined by this structure (xMutexAlloc,
  7627. ** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and
  7628. ** xMutexNotheld) implement the following interfaces (respectively):
  7629. **
  7630. ** <ul>
  7631. ** <li> [sqlite3_mutex_alloc()] </li>
  7632. ** <li> [sqlite3_mutex_free()] </li>
  7633. ** <li> [sqlite3_mutex_enter()] </li>
  7634. ** <li> [sqlite3_mutex_try()] </li>
  7635. ** <li> [sqlite3_mutex_leave()] </li>
  7636. ** <li> [sqlite3_mutex_held()] </li>
  7637. ** <li> [sqlite3_mutex_notheld()] </li>
  7638. ** </ul>)^
  7639. **
  7640. ** The only difference is that the public sqlite3_XXX functions enumerated
  7641. ** above silently ignore any invocations that pass a NULL pointer instead
  7642. ** of a valid mutex handle. The implementations of the methods defined
  7643. ** by this structure are not required to handle this case. The results
  7644. ** of passing a NULL pointer instead of a valid mutex handle are undefined
  7645. ** (i.e. it is acceptable to provide an implementation that segfaults if
  7646. ** it is passed a NULL pointer).
  7647. **
  7648. ** The xMutexInit() method must be threadsafe. It must be harmless to
  7649. ** invoke xMutexInit() multiple times within the same process and without
  7650. ** intervening calls to xMutexEnd(). Second and subsequent calls to
  7651. ** xMutexInit() must be no-ops.
  7652. **
  7653. ** xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
  7654. ** and its associates). Similarly, xMutexAlloc() must not use SQLite memory
  7655. ** allocation for a static mutex. ^However xMutexAlloc() may use SQLite
  7656. ** memory allocation for a fast or recursive mutex.
  7657. **
  7658. ** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is
  7659. ** called, but only if the prior call to xMutexInit returned SQLITE_OK.
  7660. ** If xMutexInit fails in any way, it is expected to clean up after itself
  7661. ** prior to returning.
  7662. */
  7663. typedef struct sqlite3_mutex_methods sqlite3_mutex_methods;
  7664. struct sqlite3_mutex_methods {
  7665. int (*xMutexInit)(void);
  7666. int (*xMutexEnd)(void);
  7667. sqlite3_mutex *(*xMutexAlloc)(int);
  7668. void (*xMutexFree)(sqlite3_mutex *);
  7669. void (*xMutexEnter)(sqlite3_mutex *);
  7670. int (*xMutexTry)(sqlite3_mutex *);
  7671. void (*xMutexLeave)(sqlite3_mutex *);
  7672. int (*xMutexHeld)(sqlite3_mutex *);
  7673. int (*xMutexNotheld)(sqlite3_mutex *);
  7674. };
  7675. /*
  7676. ** CAPI3REF: Mutex Verification Routines
  7677. **
  7678. ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
  7679. ** are intended for use inside assert() statements. The SQLite core
  7680. ** never uses these routines except inside an assert() and applications
  7681. ** are advised to follow the lead of the core. The SQLite core only
  7682. ** provides implementations for these routines when it is compiled
  7683. ** with the SQLITE_DEBUG flag. External mutex implementations
  7684. ** are only required to provide these routines if SQLITE_DEBUG is
  7685. ** defined and if NDEBUG is not defined.
  7686. **
  7687. ** These routines should return true if the mutex in their argument
  7688. ** is held or not held, respectively, by the calling thread.
  7689. **
  7690. ** The implementation is not required to provide versions of these
  7691. ** routines that actually work. If the implementation does not provide working
  7692. ** versions of these routines, it should at least provide stubs that always
  7693. ** return true so that one does not get spurious assertion failures.
  7694. **
  7695. ** If the argument to sqlite3_mutex_held() is a NULL pointer then
  7696. ** the routine should return 1. This seems counter-intuitive since
  7697. ** clearly the mutex cannot be held if it does not exist. But
  7698. ** the reason the mutex does not exist is because the build is not
  7699. ** using mutexes. And we do not want the assert() containing the
  7700. ** call to sqlite3_mutex_held() to fail, so a non-zero return is
  7701. ** the appropriate thing to do. The sqlite3_mutex_notheld()
  7702. ** interface should also return 1 when given a NULL pointer.
  7703. */
  7704. #ifndef NDEBUG
  7705. SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);
  7706. SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
  7707. #endif
  7708. /*
  7709. ** CAPI3REF: Mutex Types
  7710. **
  7711. ** The [sqlite3_mutex_alloc()] interface takes a single argument
  7712. ** which is one of these integer constants.
  7713. **
  7714. ** The set of static mutexes may change from one SQLite release to the
  7715. ** next. Applications that override the built-in mutex logic must be
  7716. ** prepared to accommodate additional static mutexes.
  7717. */
  7718. #define SQLITE_MUTEX_FAST 0
  7719. #define SQLITE_MUTEX_RECURSIVE 1
  7720. #define SQLITE_MUTEX_STATIC_MAIN 2
  7721. #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */
  7722. #define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */
  7723. #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */
  7724. #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_randomness() */
  7725. #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
  7726. #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */
  7727. #define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */
  7728. #define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */
  7729. #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
  7730. #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
  7731. #define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */
  7732. #define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */
  7733. #define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */
  7734. /* Legacy compatibility: */
  7735. #define SQLITE_MUTEX_STATIC_MASTER 2
  7736. /*
  7737. ** CAPI3REF: Retrieve the mutex for a database connection
  7738. ** METHOD: sqlite3
  7739. **
  7740. ** ^This interface returns a pointer the [sqlite3_mutex] object that
  7741. ** serializes access to the [database connection] given in the argument
  7742. ** when the [threading mode] is Serialized.
  7743. ** ^If the [threading mode] is Single-thread or Multi-thread then this
  7744. ** routine returns a NULL pointer.
  7745. */
  7746. SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*);
  7747. /*
  7748. ** CAPI3REF: Low-Level Control Of Database Files
  7749. ** METHOD: sqlite3
  7750. ** KEYWORDS: {file control}
  7751. **
  7752. ** ^The [sqlite3_file_control()] interface makes a direct call to the
  7753. ** xFileControl method for the [sqlite3_io_methods] object associated
  7754. ** with a particular database identified by the second argument. ^The
  7755. ** name of the database is "main" for the main database or "temp" for the
  7756. ** TEMP database, or the name that appears after the AS keyword for
  7757. ** databases that are added using the [ATTACH] SQL command.
  7758. ** ^A NULL pointer can be used in place of "main" to refer to the
  7759. ** main database file.
  7760. ** ^The third and fourth parameters to this routine
  7761. ** are passed directly through to the second and third parameters of
  7762. ** the xFileControl method. ^The return value of the xFileControl
  7763. ** method becomes the return value of this routine.
  7764. **
  7765. ** A few opcodes for [sqlite3_file_control()] are handled directly
  7766. ** by the SQLite core and never invoke the
  7767. ** sqlite3_io_methods.xFileControl method.
  7768. ** ^The [SQLITE_FCNTL_FILE_POINTER] value for the op parameter causes
  7769. ** a pointer to the underlying [sqlite3_file] object to be written into
  7770. ** the space pointed to by the 4th parameter. The
  7771. ** [SQLITE_FCNTL_JOURNAL_POINTER] works similarly except that it returns
  7772. ** the [sqlite3_file] object associated with the journal file instead of
  7773. ** the main database. The [SQLITE_FCNTL_VFS_POINTER] opcode returns
  7774. ** a pointer to the underlying [sqlite3_vfs] object for the file.
  7775. ** The [SQLITE_FCNTL_DATA_VERSION] returns the data version counter
  7776. ** from the pager.
  7777. **
  7778. ** ^If the second parameter (zDbName) does not match the name of any
  7779. ** open database file, then SQLITE_ERROR is returned. ^This error
  7780. ** code is not remembered and will not be recalled by [sqlite3_errcode()]
  7781. ** or [sqlite3_errmsg()]. The underlying xFileControl method might
  7782. ** also return SQLITE_ERROR. There is no way to distinguish between
  7783. ** an incorrect zDbName and an SQLITE_ERROR return from the underlying
  7784. ** xFileControl method.
  7785. **
  7786. ** See also: [file control opcodes]
  7787. */
  7788. SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
  7789. /*
  7790. ** CAPI3REF: Testing Interface
  7791. **
  7792. ** ^The sqlite3_test_control() interface is used to read out internal
  7793. ** state of SQLite and to inject faults into SQLite for testing
  7794. ** purposes. ^The first parameter is an operation code that determines
  7795. ** the number, meaning, and operation of all subsequent parameters.
  7796. **
  7797. ** This interface is not for use by applications. It exists solely
  7798. ** for verifying the correct operation of the SQLite library. Depending
  7799. ** on how the SQLite library is compiled, this interface might not exist.
  7800. **
  7801. ** The details of the operation codes, their meanings, the parameters
  7802. ** they take, and what they do are all subject to change without notice.
  7803. ** Unlike most of the SQLite API, this function is not guaranteed to
  7804. ** operate consistently from one release to the next.
  7805. */
  7806. SQLITE_API int sqlite3_test_control(int op, ...);
  7807. /*
  7808. ** CAPI3REF: Testing Interface Operation Codes
  7809. **
  7810. ** These constants are the valid operation code parameters used
  7811. ** as the first argument to [sqlite3_test_control()].
  7812. **
  7813. ** These parameters and their meanings are subject to change
  7814. ** without notice. These values are for testing purposes only.
  7815. ** Applications should not use any of these parameters or the
  7816. ** [sqlite3_test_control()] interface.
  7817. */
  7818. #define SQLITE_TESTCTRL_FIRST 5
  7819. #define SQLITE_TESTCTRL_PRNG_SAVE 5
  7820. #define SQLITE_TESTCTRL_PRNG_RESTORE 6
  7821. #define SQLITE_TESTCTRL_PRNG_RESET 7 /* NOT USED */
  7822. #define SQLITE_TESTCTRL_BITVEC_TEST 8
  7823. #define SQLITE_TESTCTRL_FAULT_INSTALL 9
  7824. #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10
  7825. #define SQLITE_TESTCTRL_PENDING_BYTE 11
  7826. #define SQLITE_TESTCTRL_ASSERT 12
  7827. #define SQLITE_TESTCTRL_ALWAYS 13
  7828. #define SQLITE_TESTCTRL_RESERVE 14 /* NOT USED */
  7829. #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
  7830. #define SQLITE_TESTCTRL_ISKEYWORD 16 /* NOT USED */
  7831. #define SQLITE_TESTCTRL_SCRATCHMALLOC 17 /* NOT USED */
  7832. #define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 17
  7833. #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
  7834. #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */
  7835. #define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD 19
  7836. #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
  7837. #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
  7838. #define SQLITE_TESTCTRL_BYTEORDER 22
  7839. #define SQLITE_TESTCTRL_ISINIT 23
  7840. #define SQLITE_TESTCTRL_SORTER_MMAP 24
  7841. #define SQLITE_TESTCTRL_IMPOSTER 25
  7842. #define SQLITE_TESTCTRL_PARSER_COVERAGE 26
  7843. #define SQLITE_TESTCTRL_RESULT_INTREAL 27
  7844. #define SQLITE_TESTCTRL_PRNG_SEED 28
  7845. #define SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS 29
  7846. #define SQLITE_TESTCTRL_SEEK_COUNT 30
  7847. #define SQLITE_TESTCTRL_TRACEFLAGS 31
  7848. #define SQLITE_TESTCTRL_TUNE 32
  7849. #define SQLITE_TESTCTRL_LOGEST 33
  7850. #define SQLITE_TESTCTRL_LAST 33 /* Largest TESTCTRL */
  7851. /*
  7852. ** CAPI3REF: SQL Keyword Checking
  7853. **
  7854. ** These routines provide access to the set of SQL language keywords
  7855. ** recognized by SQLite. Applications can uses these routines to determine
  7856. ** whether or not a specific identifier needs to be escaped (for example,
  7857. ** by enclosing in double-quotes) so as not to confuse the parser.
  7858. **
  7859. ** The sqlite3_keyword_count() interface returns the number of distinct
  7860. ** keywords understood by SQLite.
  7861. **
  7862. ** The sqlite3_keyword_name(N,Z,L) interface finds the N-th keyword and
  7863. ** makes *Z point to that keyword expressed as UTF8 and writes the number
  7864. ** of bytes in the keyword into *L. The string that *Z points to is not
  7865. ** zero-terminated. The sqlite3_keyword_name(N,Z,L) routine returns
  7866. ** SQLITE_OK if N is within bounds and SQLITE_ERROR if not. If either Z
  7867. ** or L are NULL or invalid pointers then calls to
  7868. ** sqlite3_keyword_name(N,Z,L) result in undefined behavior.
  7869. **
  7870. ** The sqlite3_keyword_check(Z,L) interface checks to see whether or not
  7871. ** the L-byte UTF8 identifier that Z points to is a keyword, returning non-zero
  7872. ** if it is and zero if not.
  7873. **
  7874. ** The parser used by SQLite is forgiving. It is often possible to use
  7875. ** a keyword as an identifier as long as such use does not result in a
  7876. ** parsing ambiguity. For example, the statement
  7877. ** "CREATE TABLE BEGIN(REPLACE,PRAGMA,END);" is accepted by SQLite, and
  7878. ** creates a new table named "BEGIN" with three columns named
  7879. ** "REPLACE", "PRAGMA", and "END". Nevertheless, best practice is to avoid
  7880. ** using keywords as identifiers. Common techniques used to avoid keyword
  7881. ** name collisions include:
  7882. ** <ul>
  7883. ** <li> Put all identifier names inside double-quotes. This is the official
  7884. ** SQL way to escape identifier names.
  7885. ** <li> Put identifier names inside &#91;...&#93;. This is not standard SQL,
  7886. ** but it is what SQL Server does and so lots of programmers use this
  7887. ** technique.
  7888. ** <li> Begin every identifier with the letter "Z" as no SQL keywords start
  7889. ** with "Z".
  7890. ** <li> Include a digit somewhere in every identifier name.
  7891. ** </ul>
  7892. **
  7893. ** Note that the number of keywords understood by SQLite can depend on
  7894. ** compile-time options. For example, "VACUUM" is not a keyword if
  7895. ** SQLite is compiled with the [-DSQLITE_OMIT_VACUUM] option. Also,
  7896. ** new keywords may be added to future releases of SQLite.
  7897. */
  7898. SQLITE_API int sqlite3_keyword_count(void);
  7899. SQLITE_API int sqlite3_keyword_name(int,const char**,int*);
  7900. SQLITE_API int sqlite3_keyword_check(const char*,int);
  7901. /*
  7902. ** CAPI3REF: Dynamic String Object
  7903. ** KEYWORDS: {dynamic string}
  7904. **
  7905. ** An instance of the sqlite3_str object contains a dynamically-sized
  7906. ** string under construction.
  7907. **
  7908. ** The lifecycle of an sqlite3_str object is as follows:
  7909. ** <ol>
  7910. ** <li> ^The sqlite3_str object is created using [sqlite3_str_new()].
  7911. ** <li> ^Text is appended to the sqlite3_str object using various
  7912. ** methods, such as [sqlite3_str_appendf()].
  7913. ** <li> ^The sqlite3_str object is destroyed and the string it created
  7914. ** is returned using the [sqlite3_str_finish()] interface.
  7915. ** </ol>
  7916. */
  7917. typedef struct sqlite3_str sqlite3_str;
  7918. /*
  7919. ** CAPI3REF: Create A New Dynamic String Object
  7920. ** CONSTRUCTOR: sqlite3_str
  7921. **
  7922. ** ^The [sqlite3_str_new(D)] interface allocates and initializes
  7923. ** a new [sqlite3_str] object. To avoid memory leaks, the object returned by
  7924. ** [sqlite3_str_new()] must be freed by a subsequent call to
  7925. ** [sqlite3_str_finish(X)].
  7926. **
  7927. ** ^The [sqlite3_str_new(D)] interface always returns a pointer to a
  7928. ** valid [sqlite3_str] object, though in the event of an out-of-memory
  7929. ** error the returned object might be a special singleton that will
  7930. ** silently reject new text, always return SQLITE_NOMEM from
  7931. ** [sqlite3_str_errcode()], always return 0 for
  7932. ** [sqlite3_str_length()], and always return NULL from
  7933. ** [sqlite3_str_finish(X)]. It is always safe to use the value
  7934. ** returned by [sqlite3_str_new(D)] as the sqlite3_str parameter
  7935. ** to any of the other [sqlite3_str] methods.
  7936. **
  7937. ** The D parameter to [sqlite3_str_new(D)] may be NULL. If the
  7938. ** D parameter in [sqlite3_str_new(D)] is not NULL, then the maximum
  7939. ** length of the string contained in the [sqlite3_str] object will be
  7940. ** the value set for [sqlite3_limit](D,[SQLITE_LIMIT_LENGTH]) instead
  7941. ** of [SQLITE_MAX_LENGTH].
  7942. */
  7943. SQLITE_API sqlite3_str *sqlite3_str_new(sqlite3*);
  7944. /*
  7945. ** CAPI3REF: Finalize A Dynamic String
  7946. ** DESTRUCTOR: sqlite3_str
  7947. **
  7948. ** ^The [sqlite3_str_finish(X)] interface destroys the sqlite3_str object X
  7949. ** and returns a pointer to a memory buffer obtained from [sqlite3_malloc64()]
  7950. ** that contains the constructed string. The calling application should
  7951. ** pass the returned value to [sqlite3_free()] to avoid a memory leak.
  7952. ** ^The [sqlite3_str_finish(X)] interface may return a NULL pointer if any
  7953. ** errors were encountered during construction of the string. ^The
  7954. ** [sqlite3_str_finish(X)] interface will also return a NULL pointer if the
  7955. ** string in [sqlite3_str] object X is zero bytes long.
  7956. */
  7957. SQLITE_API char *sqlite3_str_finish(sqlite3_str*);
  7958. /*
  7959. ** CAPI3REF: Add Content To A Dynamic String
  7960. ** METHOD: sqlite3_str
  7961. **
  7962. ** These interfaces add content to an sqlite3_str object previously obtained
  7963. ** from [sqlite3_str_new()].
  7964. **
  7965. ** ^The [sqlite3_str_appendf(X,F,...)] and
  7966. ** [sqlite3_str_vappendf(X,F,V)] interfaces uses the [built-in printf]
  7967. ** functionality of SQLite to append formatted text onto the end of
  7968. ** [sqlite3_str] object X.
  7969. **
  7970. ** ^The [sqlite3_str_append(X,S,N)] method appends exactly N bytes from string S
  7971. ** onto the end of the [sqlite3_str] object X. N must be non-negative.
  7972. ** S must contain at least N non-zero bytes of content. To append a
  7973. ** zero-terminated string in its entirety, use the [sqlite3_str_appendall()]
  7974. ** method instead.
  7975. **
  7976. ** ^The [sqlite3_str_appendall(X,S)] method appends the complete content of
  7977. ** zero-terminated string S onto the end of [sqlite3_str] object X.
  7978. **
  7979. ** ^The [sqlite3_str_appendchar(X,N,C)] method appends N copies of the
  7980. ** single-byte character C onto the end of [sqlite3_str] object X.
  7981. ** ^This method can be used, for example, to add whitespace indentation.
  7982. **
  7983. ** ^The [sqlite3_str_reset(X)] method resets the string under construction
  7984. ** inside [sqlite3_str] object X back to zero bytes in length.
  7985. **
  7986. ** These methods do not return a result code. ^If an error occurs, that fact
  7987. ** is recorded in the [sqlite3_str] object and can be recovered by a
  7988. ** subsequent call to [sqlite3_str_errcode(X)].
  7989. */
  7990. SQLITE_API void sqlite3_str_appendf(sqlite3_str*, const char *zFormat, ...);
  7991. SQLITE_API void sqlite3_str_vappendf(sqlite3_str*, const char *zFormat, va_list);
  7992. SQLITE_API void sqlite3_str_append(sqlite3_str*, const char *zIn, int N);
  7993. SQLITE_API void sqlite3_str_appendall(sqlite3_str*, const char *zIn);
  7994. SQLITE_API void sqlite3_str_appendchar(sqlite3_str*, int N, char C);
  7995. SQLITE_API void sqlite3_str_reset(sqlite3_str*);
  7996. /*
  7997. ** CAPI3REF: Status Of A Dynamic String
  7998. ** METHOD: sqlite3_str
  7999. **
  8000. ** These interfaces return the current status of an [sqlite3_str] object.
  8001. **
  8002. ** ^If any prior errors have occurred while constructing the dynamic string
  8003. ** in sqlite3_str X, then the [sqlite3_str_errcode(X)] method will return
  8004. ** an appropriate error code. ^The [sqlite3_str_errcode(X)] method returns
  8005. ** [SQLITE_NOMEM] following any out-of-memory error, or
  8006. ** [SQLITE_TOOBIG] if the size of the dynamic string exceeds
  8007. ** [SQLITE_MAX_LENGTH], or [SQLITE_OK] if there have been no errors.
  8008. **
  8009. ** ^The [sqlite3_str_length(X)] method returns the current length, in bytes,
  8010. ** of the dynamic string under construction in [sqlite3_str] object X.
  8011. ** ^The length returned by [sqlite3_str_length(X)] does not include the
  8012. ** zero-termination byte.
  8013. **
  8014. ** ^The [sqlite3_str_value(X)] method returns a pointer to the current
  8015. ** content of the dynamic string under construction in X. The value
  8016. ** returned by [sqlite3_str_value(X)] is managed by the sqlite3_str object X
  8017. ** and might be freed or altered by any subsequent method on the same
  8018. ** [sqlite3_str] object. Applications must not used the pointer returned
  8019. ** [sqlite3_str_value(X)] after any subsequent method call on the same
  8020. ** object. ^Applications may change the content of the string returned
  8021. ** by [sqlite3_str_value(X)] as long as they do not write into any bytes
  8022. ** outside the range of 0 to [sqlite3_str_length(X)] and do not read or
  8023. ** write any byte after any subsequent sqlite3_str method call.
  8024. */
  8025. SQLITE_API int sqlite3_str_errcode(sqlite3_str*);
  8026. SQLITE_API int sqlite3_str_length(sqlite3_str*);
  8027. SQLITE_API char *sqlite3_str_value(sqlite3_str*);
  8028. /*
  8029. ** CAPI3REF: SQLite Runtime Status
  8030. **
  8031. ** ^These interfaces are used to retrieve runtime status information
  8032. ** about the performance of SQLite, and optionally to reset various
  8033. ** highwater marks. ^The first argument is an integer code for
  8034. ** the specific parameter to measure. ^(Recognized integer codes
  8035. ** are of the form [status parameters | SQLITE_STATUS_...].)^
  8036. ** ^The current value of the parameter is returned into *pCurrent.
  8037. ** ^The highest recorded value is returned in *pHighwater. ^If the
  8038. ** resetFlag is true, then the highest record value is reset after
  8039. ** *pHighwater is written. ^(Some parameters do not record the highest
  8040. ** value. For those parameters
  8041. ** nothing is written into *pHighwater and the resetFlag is ignored.)^
  8042. ** ^(Other parameters record only the highwater mark and not the current
  8043. ** value. For these latter parameters nothing is written into *pCurrent.)^
  8044. **
  8045. ** ^The sqlite3_status() and sqlite3_status64() routines return
  8046. ** SQLITE_OK on success and a non-zero [error code] on failure.
  8047. **
  8048. ** If either the current value or the highwater mark is too large to
  8049. ** be represented by a 32-bit integer, then the values returned by
  8050. ** sqlite3_status() are undefined.
  8051. **
  8052. ** See also: [sqlite3_db_status()]
  8053. */
  8054. SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
  8055. SQLITE_API int sqlite3_status64(
  8056. int op,
  8057. sqlite3_int64 *pCurrent,
  8058. sqlite3_int64 *pHighwater,
  8059. int resetFlag
  8060. );
  8061. /*
  8062. ** CAPI3REF: Status Parameters
  8063. ** KEYWORDS: {status parameters}
  8064. **
  8065. ** These integer constants designate various run-time status parameters
  8066. ** that can be returned by [sqlite3_status()].
  8067. **
  8068. ** <dl>
  8069. ** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
  8070. ** <dd>This parameter is the current amount of memory checked out
  8071. ** using [sqlite3_malloc()], either directly or indirectly. The
  8072. ** figure includes calls made to [sqlite3_malloc()] by the application
  8073. ** and internal memory usage by the SQLite library. Auxiliary page-cache
  8074. ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
  8075. ** this parameter. The amount returned is the sum of the allocation
  8076. ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
  8077. **
  8078. ** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
  8079. ** <dd>This parameter records the largest memory allocation request
  8080. ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
  8081. ** internal equivalents). Only the value returned in the
  8082. ** *pHighwater parameter to [sqlite3_status()] is of interest.
  8083. ** The value written into the *pCurrent parameter is undefined.</dd>)^
  8084. **
  8085. ** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
  8086. ** <dd>This parameter records the number of separate memory allocations
  8087. ** currently checked out.</dd>)^
  8088. **
  8089. ** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
  8090. ** <dd>This parameter returns the number of pages used out of the
  8091. ** [pagecache memory allocator] that was configured using
  8092. ** [SQLITE_CONFIG_PAGECACHE]. The
  8093. ** value returned is in pages, not in bytes.</dd>)^
  8094. **
  8095. ** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]]
  8096. ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
  8097. ** <dd>This parameter returns the number of bytes of page cache
  8098. ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
  8099. ** buffer and where forced to overflow to [sqlite3_malloc()]. The
  8100. ** returned value includes allocations that overflowed because they
  8101. ** where too large (they were larger than the "sz" parameter to
  8102. ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
  8103. ** no space was left in the page cache.</dd>)^
  8104. **
  8105. ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
  8106. ** <dd>This parameter records the largest memory allocation request
  8107. ** handed to the [pagecache memory allocator]. Only the value returned in the
  8108. ** *pHighwater parameter to [sqlite3_status()] is of interest.
  8109. ** The value written into the *pCurrent parameter is undefined.</dd>)^
  8110. **
  8111. ** [[SQLITE_STATUS_SCRATCH_USED]] <dt>SQLITE_STATUS_SCRATCH_USED</dt>
  8112. ** <dd>No longer used.</dd>
  8113. **
  8114. ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
  8115. ** <dd>No longer used.</dd>
  8116. **
  8117. ** [[SQLITE_STATUS_SCRATCH_SIZE]] <dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
  8118. ** <dd>No longer used.</dd>
  8119. **
  8120. ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
  8121. ** <dd>The *pHighwater parameter records the deepest parser stack.
  8122. ** The *pCurrent value is undefined. The *pHighwater value is only
  8123. ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
  8124. ** </dl>
  8125. **
  8126. ** New status parameters may be added from time to time.
  8127. */
  8128. #define SQLITE_STATUS_MEMORY_USED 0
  8129. #define SQLITE_STATUS_PAGECACHE_USED 1
  8130. #define SQLITE_STATUS_PAGECACHE_OVERFLOW 2
  8131. #define SQLITE_STATUS_SCRATCH_USED 3 /* NOT USED */
  8132. #define SQLITE_STATUS_SCRATCH_OVERFLOW 4 /* NOT USED */
  8133. #define SQLITE_STATUS_MALLOC_SIZE 5
  8134. #define SQLITE_STATUS_PARSER_STACK 6
  8135. #define SQLITE_STATUS_PAGECACHE_SIZE 7
  8136. #define SQLITE_STATUS_SCRATCH_SIZE 8 /* NOT USED */
  8137. #define SQLITE_STATUS_MALLOC_COUNT 9
  8138. /*
  8139. ** CAPI3REF: Database Connection Status
  8140. ** METHOD: sqlite3
  8141. **
  8142. ** ^This interface is used to retrieve runtime status information
  8143. ** about a single [database connection]. ^The first argument is the
  8144. ** database connection object to be interrogated. ^The second argument
  8145. ** is an integer constant, taken from the set of
  8146. ** [SQLITE_DBSTATUS options], that
  8147. ** determines the parameter to interrogate. The set of
  8148. ** [SQLITE_DBSTATUS options] is likely
  8149. ** to grow in future releases of SQLite.
  8150. **
  8151. ** ^The current value of the requested parameter is written into *pCur
  8152. ** and the highest instantaneous value is written into *pHiwtr. ^If
  8153. ** the resetFlg is true, then the highest instantaneous value is
  8154. ** reset back down to the current value.
  8155. **
  8156. ** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
  8157. ** non-zero [error code] on failure.
  8158. **
  8159. ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
  8160. */
  8161. SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
  8162. /*
  8163. ** CAPI3REF: Status Parameters for database connections
  8164. ** KEYWORDS: {SQLITE_DBSTATUS options}
  8165. **
  8166. ** These constants are the available integer "verbs" that can be passed as
  8167. ** the second argument to the [sqlite3_db_status()] interface.
  8168. **
  8169. ** New verbs may be added in future releases of SQLite. Existing verbs
  8170. ** might be discontinued. Applications should check the return code from
  8171. ** [sqlite3_db_status()] to make sure that the call worked.
  8172. ** The [sqlite3_db_status()] interface will return a non-zero error code
  8173. ** if a discontinued or unsupported verb is invoked.
  8174. **
  8175. ** <dl>
  8176. ** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
  8177. ** <dd>This parameter returns the number of lookaside memory slots currently
  8178. ** checked out.</dd>)^
  8179. **
  8180. ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
  8181. ** <dd>This parameter returns the number of malloc attempts that were
  8182. ** satisfied using lookaside memory. Only the high-water value is meaningful;
  8183. ** the current value is always zero.)^
  8184. **
  8185. ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
  8186. ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
  8187. ** <dd>This parameter returns the number malloc attempts that might have
  8188. ** been satisfied using lookaside memory but failed due to the amount of
  8189. ** memory requested being larger than the lookaside slot size.
  8190. ** Only the high-water value is meaningful;
  8191. ** the current value is always zero.)^
  8192. **
  8193. ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
  8194. ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
  8195. ** <dd>This parameter returns the number malloc attempts that might have
  8196. ** been satisfied using lookaside memory but failed due to all lookaside
  8197. ** memory already being in use.
  8198. ** Only the high-water value is meaningful;
  8199. ** the current value is always zero.)^
  8200. **
  8201. ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
  8202. ** <dd>This parameter returns the approximate number of bytes of heap
  8203. ** memory used by all pager caches associated with the database connection.)^
  8204. ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
  8205. **
  8206. ** [[SQLITE_DBSTATUS_CACHE_USED_SHARED]]
  8207. ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED_SHARED</dt>
  8208. ** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a
  8209. ** pager cache is shared between two or more connections the bytes of heap
  8210. ** memory used by that pager cache is divided evenly between the attached
  8211. ** connections.)^ In other words, if none of the pager caches associated
  8212. ** with the database connection are shared, this request returns the same
  8213. ** value as DBSTATUS_CACHE_USED. Or, if one or more or the pager caches are
  8214. ** shared, the value returned by this call will be smaller than that returned
  8215. ** by DBSTATUS_CACHE_USED. ^The highwater mark associated with
  8216. ** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.
  8217. **
  8218. ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
  8219. ** <dd>This parameter returns the approximate number of bytes of heap
  8220. ** memory used to store the schema for all databases associated
  8221. ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
  8222. ** ^The full amount of memory used by the schemas is reported, even if the
  8223. ** schema memory is shared with other database connections due to
  8224. ** [shared cache mode] being enabled.
  8225. ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
  8226. **
  8227. ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
  8228. ** <dd>This parameter returns the approximate number of bytes of heap
  8229. ** and lookaside memory used by all prepared statements associated with
  8230. ** the database connection.)^
  8231. ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
  8232. ** </dd>
  8233. **
  8234. ** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt>
  8235. ** <dd>This parameter returns the number of pager cache hits that have
  8236. ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT
  8237. ** is always 0.
  8238. ** </dd>
  8239. **
  8240. ** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt>
  8241. ** <dd>This parameter returns the number of pager cache misses that have
  8242. ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS
  8243. ** is always 0.
  8244. ** </dd>
  8245. **
  8246. ** [[SQLITE_DBSTATUS_CACHE_WRITE]] ^(<dt>SQLITE_DBSTATUS_CACHE_WRITE</dt>
  8247. ** <dd>This parameter returns the number of dirty cache entries that have
  8248. ** been written to disk. Specifically, the number of pages written to the
  8249. ** wal file in wal mode databases, or the number of pages written to the
  8250. ** database file in rollback mode databases. Any pages written as part of
  8251. ** transaction rollback or database recovery operations are not included.
  8252. ** If an IO or other error occurs while writing a page to disk, the effect
  8253. ** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The
  8254. ** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0.
  8255. ** </dd>
  8256. **
  8257. ** [[SQLITE_DBSTATUS_CACHE_SPILL]] ^(<dt>SQLITE_DBSTATUS_CACHE_SPILL</dt>
  8258. ** <dd>This parameter returns the number of dirty cache entries that have
  8259. ** been written to disk in the middle of a transaction due to the page
  8260. ** cache overflowing. Transactions are more efficient if they are written
  8261. ** to disk all at once. When pages spill mid-transaction, that introduces
  8262. ** additional overhead. This parameter can be used help identify
  8263. ** inefficiencies that can be resolved by increasing the cache size.
  8264. ** </dd>
  8265. **
  8266. ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
  8267. ** <dd>This parameter returns zero for the current value if and only if
  8268. ** all foreign key constraints (deferred or immediate) have been
  8269. ** resolved.)^ ^The highwater mark is always 0.
  8270. ** </dd>
  8271. ** </dl>
  8272. */
  8273. #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
  8274. #define SQLITE_DBSTATUS_CACHE_USED 1
  8275. #define SQLITE_DBSTATUS_SCHEMA_USED 2
  8276. #define SQLITE_DBSTATUS_STMT_USED 3
  8277. #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4
  8278. #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
  8279. #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
  8280. #define SQLITE_DBSTATUS_CACHE_HIT 7
  8281. #define SQLITE_DBSTATUS_CACHE_MISS 8
  8282. #define SQLITE_DBSTATUS_CACHE_WRITE 9
  8283. #define SQLITE_DBSTATUS_DEFERRED_FKS 10
  8284. #define SQLITE_DBSTATUS_CACHE_USED_SHARED 11
  8285. #define SQLITE_DBSTATUS_CACHE_SPILL 12
  8286. #define SQLITE_DBSTATUS_MAX 12 /* Largest defined DBSTATUS */
  8287. /*
  8288. ** CAPI3REF: Prepared Statement Status
  8289. ** METHOD: sqlite3_stmt
  8290. **
  8291. ** ^(Each prepared statement maintains various
  8292. ** [SQLITE_STMTSTATUS counters] that measure the number
  8293. ** of times it has performed specific operations.)^ These counters can
  8294. ** be used to monitor the performance characteristics of the prepared
  8295. ** statements. For example, if the number of table steps greatly exceeds
  8296. ** the number of table searches or result rows, that would tend to indicate
  8297. ** that the prepared statement is using a full table scan rather than
  8298. ** an index.
  8299. **
  8300. ** ^(This interface is used to retrieve and reset counter values from
  8301. ** a [prepared statement]. The first argument is the prepared statement
  8302. ** object to be interrogated. The second argument
  8303. ** is an integer code for a specific [SQLITE_STMTSTATUS counter]
  8304. ** to be interrogated.)^
  8305. ** ^The current value of the requested counter is returned.
  8306. ** ^If the resetFlg is true, then the counter is reset to zero after this
  8307. ** interface call returns.
  8308. **
  8309. ** See also: [sqlite3_status()] and [sqlite3_db_status()].
  8310. */
  8311. SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
  8312. /*
  8313. ** CAPI3REF: Status Parameters for prepared statements
  8314. ** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters}
  8315. **
  8316. ** These preprocessor macros define integer codes that name counter
  8317. ** values associated with the [sqlite3_stmt_status()] interface.
  8318. ** The meanings of the various counters are as follows:
  8319. **
  8320. ** <dl>
  8321. ** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
  8322. ** <dd>^This is the number of times that SQLite has stepped forward in
  8323. ** a table as part of a full table scan. Large numbers for this counter
  8324. ** may indicate opportunities for performance improvement through
  8325. ** careful use of indices.</dd>
  8326. **
  8327. ** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
  8328. ** <dd>^This is the number of sort operations that have occurred.
  8329. ** A non-zero value in this counter may indicate an opportunity to
  8330. ** improvement performance through careful use of indices.</dd>
  8331. **
  8332. ** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
  8333. ** <dd>^This is the number of rows inserted into transient indices that
  8334. ** were created automatically in order to help joins run faster.
  8335. ** A non-zero value in this counter may indicate an opportunity to
  8336. ** improvement performance by adding permanent indices that do not
  8337. ** need to be reinitialized each time the statement is run.</dd>
  8338. **
  8339. ** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
  8340. ** <dd>^This is the number of virtual machine operations executed
  8341. ** by the prepared statement if that number is less than or equal
  8342. ** to 2147483647. The number of virtual machine operations can be
  8343. ** used as a proxy for the total work done by the prepared statement.
  8344. ** If the number of virtual machine operations exceeds 2147483647
  8345. ** then the value returned by this statement status code is undefined.
  8346. **
  8347. ** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>
  8348. ** <dd>^This is the number of times that the prepare statement has been
  8349. ** automatically regenerated due to schema changes or changes to
  8350. ** [bound parameters] that might affect the query plan.
  8351. **
  8352. ** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>
  8353. ** <dd>^This is the number of times that the prepared statement has
  8354. ** been run. A single "run" for the purposes of this counter is one
  8355. ** or more calls to [sqlite3_step()] followed by a call to [sqlite3_reset()].
  8356. ** The counter is incremented on the first [sqlite3_step()] call of each
  8357. ** cycle.
  8358. **
  8359. ** [[SQLITE_STMTSTATUS_FILTER_MISS]]
  8360. ** [[SQLITE_STMTSTATUS_FILTER HIT]]
  8361. ** <dt>SQLITE_STMTSTATUS_FILTER_HIT<br>
  8362. ** SQLITE_STMTSTATUS_FILTER_MISS</dt>
  8363. ** <dd>^SQLITE_STMTSTATUS_FILTER_HIT is the number of times that a join
  8364. ** step was bypassed because a Bloom filter returned not-found. The
  8365. ** corresponding SQLITE_STMTSTATUS_FILTER_MISS value is the number of
  8366. ** times that the Bloom filter returned a find, and thus the join step
  8367. ** had to be processed as normal.
  8368. **
  8369. ** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt>
  8370. ** <dd>^This is the approximate number of bytes of heap memory
  8371. ** used to store the prepared statement. ^This value is not actually
  8372. ** a counter, and so the resetFlg parameter to sqlite3_stmt_status()
  8373. ** is ignored when the opcode is SQLITE_STMTSTATUS_MEMUSED.
  8374. ** </dd>
  8375. ** </dl>
  8376. */
  8377. #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
  8378. #define SQLITE_STMTSTATUS_SORT 2
  8379. #define SQLITE_STMTSTATUS_AUTOINDEX 3
  8380. #define SQLITE_STMTSTATUS_VM_STEP 4
  8381. #define SQLITE_STMTSTATUS_REPREPARE 5
  8382. #define SQLITE_STMTSTATUS_RUN 6
  8383. #define SQLITE_STMTSTATUS_FILTER_MISS 7
  8384. #define SQLITE_STMTSTATUS_FILTER_HIT 8
  8385. #define SQLITE_STMTSTATUS_MEMUSED 99
  8386. /*
  8387. ** CAPI3REF: Custom Page Cache Object
  8388. **
  8389. ** The sqlite3_pcache type is opaque. It is implemented by
  8390. ** the pluggable module. The SQLite core has no knowledge of
  8391. ** its size or internal structure and never deals with the
  8392. ** sqlite3_pcache object except by holding and passing pointers
  8393. ** to the object.
  8394. **
  8395. ** See [sqlite3_pcache_methods2] for additional information.
  8396. */
  8397. typedef struct sqlite3_pcache sqlite3_pcache;
  8398. /*
  8399. ** CAPI3REF: Custom Page Cache Object
  8400. **
  8401. ** The sqlite3_pcache_page object represents a single page in the
  8402. ** page cache. The page cache will allocate instances of this
  8403. ** object. Various methods of the page cache use pointers to instances
  8404. ** of this object as parameters or as their return value.
  8405. **
  8406. ** See [sqlite3_pcache_methods2] for additional information.
  8407. */
  8408. typedef struct sqlite3_pcache_page sqlite3_pcache_page;
  8409. struct sqlite3_pcache_page {
  8410. void *pBuf; /* The content of the page */
  8411. void *pExtra; /* Extra information associated with the page */
  8412. };
  8413. /*
  8414. ** CAPI3REF: Application Defined Page Cache.
  8415. ** KEYWORDS: {page cache}
  8416. **
  8417. ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE2], ...) interface can
  8418. ** register an alternative page cache implementation by passing in an
  8419. ** instance of the sqlite3_pcache_methods2 structure.)^
  8420. ** In many applications, most of the heap memory allocated by
  8421. ** SQLite is used for the page cache.
  8422. ** By implementing a
  8423. ** custom page cache using this API, an application can better control
  8424. ** the amount of memory consumed by SQLite, the way in which
  8425. ** that memory is allocated and released, and the policies used to
  8426. ** determine exactly which parts of a database file are cached and for
  8427. ** how long.
  8428. **
  8429. ** The alternative page cache mechanism is an
  8430. ** extreme measure that is only needed by the most demanding applications.
  8431. ** The built-in page cache is recommended for most uses.
  8432. **
  8433. ** ^(The contents of the sqlite3_pcache_methods2 structure are copied to an
  8434. ** internal buffer by SQLite within the call to [sqlite3_config]. Hence
  8435. ** the application may discard the parameter after the call to
  8436. ** [sqlite3_config()] returns.)^
  8437. **
  8438. ** [[the xInit() page cache method]]
  8439. ** ^(The xInit() method is called once for each effective
  8440. ** call to [sqlite3_initialize()])^
  8441. ** (usually only once during the lifetime of the process). ^(The xInit()
  8442. ** method is passed a copy of the sqlite3_pcache_methods2.pArg value.)^
  8443. ** The intent of the xInit() method is to set up global data structures
  8444. ** required by the custom page cache implementation.
  8445. ** ^(If the xInit() method is NULL, then the
  8446. ** built-in default page cache is used instead of the application defined
  8447. ** page cache.)^
  8448. **
  8449. ** [[the xShutdown() page cache method]]
  8450. ** ^The xShutdown() method is called by [sqlite3_shutdown()].
  8451. ** It can be used to clean up
  8452. ** any outstanding resources before process shutdown, if required.
  8453. ** ^The xShutdown() method may be NULL.
  8454. **
  8455. ** ^SQLite automatically serializes calls to the xInit method,
  8456. ** so the xInit method need not be threadsafe. ^The
  8457. ** xShutdown method is only called from [sqlite3_shutdown()] so it does
  8458. ** not need to be threadsafe either. All other methods must be threadsafe
  8459. ** in multithreaded applications.
  8460. **
  8461. ** ^SQLite will never invoke xInit() more than once without an intervening
  8462. ** call to xShutdown().
  8463. **
  8464. ** [[the xCreate() page cache methods]]
  8465. ** ^SQLite invokes the xCreate() method to construct a new cache instance.
  8466. ** SQLite will typically create one cache instance for each open database file,
  8467. ** though this is not guaranteed. ^The
  8468. ** first parameter, szPage, is the size in bytes of the pages that must
  8469. ** be allocated by the cache. ^szPage will always a power of two. ^The
  8470. ** second parameter szExtra is a number of bytes of extra storage
  8471. ** associated with each page cache entry. ^The szExtra parameter will
  8472. ** a number less than 250. SQLite will use the
  8473. ** extra szExtra bytes on each page to store metadata about the underlying
  8474. ** database page on disk. The value passed into szExtra depends
  8475. ** on the SQLite version, the target platform, and how SQLite was compiled.
  8476. ** ^The third argument to xCreate(), bPurgeable, is true if the cache being
  8477. ** created will be used to cache database pages of a file stored on disk, or
  8478. ** false if it is used for an in-memory database. The cache implementation
  8479. ** does not have to do anything special based with the value of bPurgeable;
  8480. ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
  8481. ** never invoke xUnpin() except to deliberately delete a page.
  8482. ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
  8483. ** false will always have the "discard" flag set to true.
  8484. ** ^Hence, a cache created with bPurgeable false will
  8485. ** never contain any unpinned pages.
  8486. **
  8487. ** [[the xCachesize() page cache method]]
  8488. ** ^(The xCachesize() method may be called at any time by SQLite to set the
  8489. ** suggested maximum cache-size (number of pages stored by) the cache
  8490. ** instance passed as the first argument. This is the value configured using
  8491. ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
  8492. ** parameter, the implementation is not required to do anything with this
  8493. ** value; it is advisory only.
  8494. **
  8495. ** [[the xPagecount() page cache methods]]
  8496. ** The xPagecount() method must return the number of pages currently
  8497. ** stored in the cache, both pinned and unpinned.
  8498. **
  8499. ** [[the xFetch() page cache methods]]
  8500. ** The xFetch() method locates a page in the cache and returns a pointer to
  8501. ** an sqlite3_pcache_page object associated with that page, or a NULL pointer.
  8502. ** The pBuf element of the returned sqlite3_pcache_page object will be a
  8503. ** pointer to a buffer of szPage bytes used to store the content of a
  8504. ** single database page. The pExtra element of sqlite3_pcache_page will be
  8505. ** a pointer to the szExtra bytes of extra storage that SQLite has requested
  8506. ** for each entry in the page cache.
  8507. **
  8508. ** The page to be fetched is determined by the key. ^The minimum key value
  8509. ** is 1. After it has been retrieved using xFetch, the page is considered
  8510. ** to be "pinned".
  8511. **
  8512. ** If the requested page is already in the page cache, then the page cache
  8513. ** implementation must return a pointer to the page buffer with its content
  8514. ** intact. If the requested page is not already in the cache, then the
  8515. ** cache implementation should use the value of the createFlag
  8516. ** parameter to help it determined what action to take:
  8517. **
  8518. ** <table border=1 width=85% align=center>
  8519. ** <tr><th> createFlag <th> Behavior when page is not already in cache
  8520. ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
  8521. ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
  8522. ** Otherwise return NULL.
  8523. ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
  8524. ** NULL if allocating a new page is effectively impossible.
  8525. ** </table>
  8526. **
  8527. ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite
  8528. ** will only use a createFlag of 2 after a prior call with a createFlag of 1
  8529. ** failed.)^ In between the xFetch() calls, SQLite may
  8530. ** attempt to unpin one or more cache pages by spilling the content of
  8531. ** pinned pages to disk and synching the operating system disk cache.
  8532. **
  8533. ** [[the xUnpin() page cache method]]
  8534. ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
  8535. ** as its second argument. If the third parameter, discard, is non-zero,
  8536. ** then the page must be evicted from the cache.
  8537. ** ^If the discard parameter is
  8538. ** zero, then the page may be discarded or retained at the discretion of
  8539. ** page cache implementation. ^The page cache implementation
  8540. ** may choose to evict unpinned pages at any time.
  8541. **
  8542. ** The cache must not perform any reference counting. A single
  8543. ** call to xUnpin() unpins the page regardless of the number of prior calls
  8544. ** to xFetch().
  8545. **
  8546. ** [[the xRekey() page cache methods]]
  8547. ** The xRekey() method is used to change the key value associated with the
  8548. ** page passed as the second argument. If the cache
  8549. ** previously contains an entry associated with newKey, it must be
  8550. ** discarded. ^Any prior cache entry associated with newKey is guaranteed not
  8551. ** to be pinned.
  8552. **
  8553. ** When SQLite calls the xTruncate() method, the cache must discard all
  8554. ** existing cache entries with page numbers (keys) greater than or equal
  8555. ** to the value of the iLimit parameter passed to xTruncate(). If any
  8556. ** of these pages are pinned, they are implicitly unpinned, meaning that
  8557. ** they can be safely discarded.
  8558. **
  8559. ** [[the xDestroy() page cache method]]
  8560. ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
  8561. ** All resources associated with the specified cache should be freed. ^After
  8562. ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
  8563. ** handle invalid, and will not use it with any other sqlite3_pcache_methods2
  8564. ** functions.
  8565. **
  8566. ** [[the xShrink() page cache method]]
  8567. ** ^SQLite invokes the xShrink() method when it wants the page cache to
  8568. ** free up as much of heap memory as possible. The page cache implementation
  8569. ** is not obligated to free any memory, but well-behaved implementations should
  8570. ** do their best.
  8571. */
  8572. typedef struct sqlite3_pcache_methods2 sqlite3_pcache_methods2;
  8573. struct sqlite3_pcache_methods2 {
  8574. int iVersion;
  8575. void *pArg;
  8576. int (*xInit)(void*);
  8577. void (*xShutdown)(void*);
  8578. sqlite3_pcache *(*xCreate)(int szPage, int szExtra, int bPurgeable);
  8579. void (*xCachesize)(sqlite3_pcache*, int nCachesize);
  8580. int (*xPagecount)(sqlite3_pcache*);
  8581. sqlite3_pcache_page *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
  8582. void (*xUnpin)(sqlite3_pcache*, sqlite3_pcache_page*, int discard);
  8583. void (*xRekey)(sqlite3_pcache*, sqlite3_pcache_page*,
  8584. unsigned oldKey, unsigned newKey);
  8585. void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
  8586. void (*xDestroy)(sqlite3_pcache*);
  8587. void (*xShrink)(sqlite3_pcache*);
  8588. };
  8589. /*
  8590. ** This is the obsolete pcache_methods object that has now been replaced
  8591. ** by sqlite3_pcache_methods2. This object is not used by SQLite. It is
  8592. ** retained in the header file for backwards compatibility only.
  8593. */
  8594. typedef struct sqlite3_pcache_methods sqlite3_pcache_methods;
  8595. struct sqlite3_pcache_methods {
  8596. void *pArg;
  8597. int (*xInit)(void*);
  8598. void (*xShutdown)(void*);
  8599. sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable);
  8600. void (*xCachesize)(sqlite3_pcache*, int nCachesize);
  8601. int (*xPagecount)(sqlite3_pcache*);
  8602. void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
  8603. void (*xUnpin)(sqlite3_pcache*, void*, int discard);
  8604. void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey);
  8605. void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
  8606. void (*xDestroy)(sqlite3_pcache*);
  8607. };
  8608. /*
  8609. ** CAPI3REF: Online Backup Object
  8610. **
  8611. ** The sqlite3_backup object records state information about an ongoing
  8612. ** online backup operation. ^The sqlite3_backup object is created by
  8613. ** a call to [sqlite3_backup_init()] and is destroyed by a call to
  8614. ** [sqlite3_backup_finish()].
  8615. **
  8616. ** See Also: [Using the SQLite Online Backup API]
  8617. */
  8618. typedef struct sqlite3_backup sqlite3_backup;
  8619. /*
  8620. ** CAPI3REF: Online Backup API.
  8621. **
  8622. ** The backup API copies the content of one database into another.
  8623. ** It is useful either for creating backups of databases or
  8624. ** for copying in-memory databases to or from persistent files.
  8625. **
  8626. ** See Also: [Using the SQLite Online Backup API]
  8627. **
  8628. ** ^SQLite holds a write transaction open on the destination database file
  8629. ** for the duration of the backup operation.
  8630. ** ^The source database is read-locked only while it is being read;
  8631. ** it is not locked continuously for the entire backup operation.
  8632. ** ^Thus, the backup may be performed on a live source database without
  8633. ** preventing other database connections from
  8634. ** reading or writing to the source database while the backup is underway.
  8635. **
  8636. ** ^(To perform a backup operation:
  8637. ** <ol>
  8638. ** <li><b>sqlite3_backup_init()</b> is called once to initialize the
  8639. ** backup,
  8640. ** <li><b>sqlite3_backup_step()</b> is called one or more times to transfer
  8641. ** the data between the two databases, and finally
  8642. ** <li><b>sqlite3_backup_finish()</b> is called to release all resources
  8643. ** associated with the backup operation.
  8644. ** </ol>)^
  8645. ** There should be exactly one call to sqlite3_backup_finish() for each
  8646. ** successful call to sqlite3_backup_init().
  8647. **
  8648. ** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b>
  8649. **
  8650. ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the
  8651. ** [database connection] associated with the destination database
  8652. ** and the database name, respectively.
  8653. ** ^The database name is "main" for the main database, "temp" for the
  8654. ** temporary database, or the name specified after the AS keyword in
  8655. ** an [ATTACH] statement for an attached database.
  8656. ** ^The S and M arguments passed to
  8657. ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
  8658. ** and database name of the source database, respectively.
  8659. ** ^The source and destination [database connections] (parameters S and D)
  8660. ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
  8661. ** an error.
  8662. **
  8663. ** ^A call to sqlite3_backup_init() will fail, returning NULL, if
  8664. ** there is already a read or read-write transaction open on the
  8665. ** destination database.
  8666. **
  8667. ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
  8668. ** returned and an error code and error message are stored in the
  8669. ** destination [database connection] D.
  8670. ** ^The error code and message for the failed call to sqlite3_backup_init()
  8671. ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
  8672. ** [sqlite3_errmsg16()] functions.
  8673. ** ^A successful call to sqlite3_backup_init() returns a pointer to an
  8674. ** [sqlite3_backup] object.
  8675. ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
  8676. ** sqlite3_backup_finish() functions to perform the specified backup
  8677. ** operation.
  8678. **
  8679. ** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b>
  8680. **
  8681. ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
  8682. ** the source and destination databases specified by [sqlite3_backup] object B.
  8683. ** ^If N is negative, all remaining source pages are copied.
  8684. ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
  8685. ** are still more pages to be copied, then the function returns [SQLITE_OK].
  8686. ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
  8687. ** from source to destination, then it returns [SQLITE_DONE].
  8688. ** ^If an error occurs while running sqlite3_backup_step(B,N),
  8689. ** then an [error code] is returned. ^As well as [SQLITE_OK] and
  8690. ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
  8691. ** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an
  8692. ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code.
  8693. **
  8694. ** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
  8695. ** <ol>
  8696. ** <li> the destination database was opened read-only, or
  8697. ** <li> the destination database is using write-ahead-log journaling
  8698. ** and the destination and source page sizes differ, or
  8699. ** <li> the destination database is an in-memory database and the
  8700. ** destination and source page sizes differ.
  8701. ** </ol>)^
  8702. **
  8703. ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
  8704. ** the [sqlite3_busy_handler | busy-handler function]
  8705. ** is invoked (if one is specified). ^If the
  8706. ** busy-handler returns non-zero before the lock is available, then
  8707. ** [SQLITE_BUSY] is returned to the caller. ^In this case the call to
  8708. ** sqlite3_backup_step() can be retried later. ^If the source
  8709. ** [database connection]
  8710. ** is being used to write to the source database when sqlite3_backup_step()
  8711. ** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this
  8712. ** case the call to sqlite3_backup_step() can be retried later on. ^(If
  8713. ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or
  8714. ** [SQLITE_READONLY] is returned, then
  8715. ** there is no point in retrying the call to sqlite3_backup_step(). These
  8716. ** errors are considered fatal.)^ The application must accept
  8717. ** that the backup operation has failed and pass the backup operation handle
  8718. ** to the sqlite3_backup_finish() to release associated resources.
  8719. **
  8720. ** ^The first call to sqlite3_backup_step() obtains an exclusive lock
  8721. ** on the destination file. ^The exclusive lock is not released until either
  8722. ** sqlite3_backup_finish() is called or the backup operation is complete
  8723. ** and sqlite3_backup_step() returns [SQLITE_DONE]. ^Every call to
  8724. ** sqlite3_backup_step() obtains a [shared lock] on the source database that
  8725. ** lasts for the duration of the sqlite3_backup_step() call.
  8726. ** ^Because the source database is not locked between calls to
  8727. ** sqlite3_backup_step(), the source database may be modified mid-way
  8728. ** through the backup process. ^If the source database is modified by an
  8729. ** external process or via a database connection other than the one being
  8730. ** used by the backup operation, then the backup will be automatically
  8731. ** restarted by the next call to sqlite3_backup_step(). ^If the source
  8732. ** database is modified by the using the same database connection as is used
  8733. ** by the backup operation, then the backup database is automatically
  8734. ** updated at the same time.
  8735. **
  8736. ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
  8737. **
  8738. ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the
  8739. ** application wishes to abandon the backup operation, the application
  8740. ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().
  8741. ** ^The sqlite3_backup_finish() interfaces releases all
  8742. ** resources associated with the [sqlite3_backup] object.
  8743. ** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any
  8744. ** active write-transaction on the destination database is rolled back.
  8745. ** The [sqlite3_backup] object is invalid
  8746. ** and may not be used following a call to sqlite3_backup_finish().
  8747. **
  8748. ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
  8749. ** sqlite3_backup_step() errors occurred, regardless or whether or not
  8750. ** sqlite3_backup_step() completed.
  8751. ** ^If an out-of-memory condition or IO error occurred during any prior
  8752. ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
  8753. ** sqlite3_backup_finish() returns the corresponding [error code].
  8754. **
  8755. ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
  8756. ** is not a permanent error and does not affect the return value of
  8757. ** sqlite3_backup_finish().
  8758. **
  8759. ** [[sqlite3_backup_remaining()]] [[sqlite3_backup_pagecount()]]
  8760. ** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>
  8761. **
  8762. ** ^The sqlite3_backup_remaining() routine returns the number of pages still
  8763. ** to be backed up at the conclusion of the most recent sqlite3_backup_step().
  8764. ** ^The sqlite3_backup_pagecount() routine returns the total number of pages
  8765. ** in the source database at the conclusion of the most recent
  8766. ** sqlite3_backup_step().
  8767. ** ^(The values returned by these functions are only updated by
  8768. ** sqlite3_backup_step(). If the source database is modified in a way that
  8769. ** changes the size of the source database or the number of pages remaining,
  8770. ** those changes are not reflected in the output of sqlite3_backup_pagecount()
  8771. ** and sqlite3_backup_remaining() until after the next
  8772. ** sqlite3_backup_step().)^
  8773. **
  8774. ** <b>Concurrent Usage of Database Handles</b>
  8775. **
  8776. ** ^The source [database connection] may be used by the application for other
  8777. ** purposes while a backup operation is underway or being initialized.
  8778. ** ^If SQLite is compiled and configured to support threadsafe database
  8779. ** connections, then the source database connection may be used concurrently
  8780. ** from within other threads.
  8781. **
  8782. ** However, the application must guarantee that the destination
  8783. ** [database connection] is not passed to any other API (by any thread) after
  8784. ** sqlite3_backup_init() is called and before the corresponding call to
  8785. ** sqlite3_backup_finish(). SQLite does not currently check to see
  8786. ** if the application incorrectly accesses the destination [database connection]
  8787. ** and so no error code is reported, but the operations may malfunction
  8788. ** nevertheless. Use of the destination database connection while a
  8789. ** backup is in progress might also also cause a mutex deadlock.
  8790. **
  8791. ** If running in [shared cache mode], the application must
  8792. ** guarantee that the shared cache used by the destination database
  8793. ** is not accessed while the backup is running. In practice this means
  8794. ** that the application must guarantee that the disk file being
  8795. ** backed up to is not accessed by any connection within the process,
  8796. ** not just the specific connection that was passed to sqlite3_backup_init().
  8797. **
  8798. ** The [sqlite3_backup] object itself is partially threadsafe. Multiple
  8799. ** threads may safely make multiple concurrent calls to sqlite3_backup_step().
  8800. ** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount()
  8801. ** APIs are not strictly speaking threadsafe. If they are invoked at the
  8802. ** same time as another thread is invoking sqlite3_backup_step() it is
  8803. ** possible that they return invalid values.
  8804. */
  8805. SQLITE_API sqlite3_backup *sqlite3_backup_init(
  8806. sqlite3 *pDest, /* Destination database handle */
  8807. const char *zDestName, /* Destination database name */
  8808. sqlite3 *pSource, /* Source database handle */
  8809. const char *zSourceName /* Source database name */
  8810. );
  8811. SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage);
  8812. SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p);
  8813. SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
  8814. SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
  8815. /*
  8816. ** CAPI3REF: Unlock Notification
  8817. ** METHOD: sqlite3
  8818. **
  8819. ** ^When running in shared-cache mode, a database operation may fail with
  8820. ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
  8821. ** individual tables within the shared-cache cannot be obtained. See
  8822. ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
  8823. ** ^This API may be used to register a callback that SQLite will invoke
  8824. ** when the connection currently holding the required lock relinquishes it.
  8825. ** ^This API is only available if the library was compiled with the
  8826. ** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined.
  8827. **
  8828. ** See Also: [Using the SQLite Unlock Notification Feature].
  8829. **
  8830. ** ^Shared-cache locks are released when a database connection concludes
  8831. ** its current transaction, either by committing it or rolling it back.
  8832. **
  8833. ** ^When a connection (known as the blocked connection) fails to obtain a
  8834. ** shared-cache lock and SQLITE_LOCKED is returned to the caller, the
  8835. ** identity of the database connection (the blocking connection) that
  8836. ** has locked the required resource is stored internally. ^After an
  8837. ** application receives an SQLITE_LOCKED error, it may call the
  8838. ** sqlite3_unlock_notify() method with the blocked connection handle as
  8839. ** the first argument to register for a callback that will be invoked
  8840. ** when the blocking connections current transaction is concluded. ^The
  8841. ** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
  8842. ** call that concludes the blocking connection's transaction.
  8843. **
  8844. ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
  8845. ** there is a chance that the blocking connection will have already
  8846. ** concluded its transaction by the time sqlite3_unlock_notify() is invoked.
  8847. ** If this happens, then the specified callback is invoked immediately,
  8848. ** from within the call to sqlite3_unlock_notify().)^
  8849. **
  8850. ** ^If the blocked connection is attempting to obtain a write-lock on a
  8851. ** shared-cache table, and more than one other connection currently holds
  8852. ** a read-lock on the same table, then SQLite arbitrarily selects one of
  8853. ** the other connections to use as the blocking connection.
  8854. **
  8855. ** ^(There may be at most one unlock-notify callback registered by a
  8856. ** blocked connection. If sqlite3_unlock_notify() is called when the
  8857. ** blocked connection already has a registered unlock-notify callback,
  8858. ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
  8859. ** called with a NULL pointer as its second argument, then any existing
  8860. ** unlock-notify callback is canceled. ^The blocked connections
  8861. ** unlock-notify callback may also be canceled by closing the blocked
  8862. ** connection using [sqlite3_close()].
  8863. **
  8864. ** The unlock-notify callback is not reentrant. If an application invokes
  8865. ** any sqlite3_xxx API functions from within an unlock-notify callback, a
  8866. ** crash or deadlock may be the result.
  8867. **
  8868. ** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always
  8869. ** returns SQLITE_OK.
  8870. **
  8871. ** <b>Callback Invocation Details</b>
  8872. **
  8873. ** When an unlock-notify callback is registered, the application provides a
  8874. ** single void* pointer that is passed to the callback when it is invoked.
  8875. ** However, the signature of the callback function allows SQLite to pass
  8876. ** it an array of void* context pointers. The first argument passed to
  8877. ** an unlock-notify callback is a pointer to an array of void* pointers,
  8878. ** and the second is the number of entries in the array.
  8879. **
  8880. ** When a blocking connection's transaction is concluded, there may be
  8881. ** more than one blocked connection that has registered for an unlock-notify
  8882. ** callback. ^If two or more such blocked connections have specified the
  8883. ** same callback function, then instead of invoking the callback function
  8884. ** multiple times, it is invoked once with the set of void* context pointers
  8885. ** specified by the blocked connections bundled together into an array.
  8886. ** This gives the application an opportunity to prioritize any actions
  8887. ** related to the set of unblocked database connections.
  8888. **
  8889. ** <b>Deadlock Detection</b>
  8890. **
  8891. ** Assuming that after registering for an unlock-notify callback a
  8892. ** database waits for the callback to be issued before taking any further
  8893. ** action (a reasonable assumption), then using this API may cause the
  8894. ** application to deadlock. For example, if connection X is waiting for
  8895. ** connection Y's transaction to be concluded, and similarly connection
  8896. ** Y is waiting on connection X's transaction, then neither connection
  8897. ** will proceed and the system may remain deadlocked indefinitely.
  8898. **
  8899. ** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock
  8900. ** detection. ^If a given call to sqlite3_unlock_notify() would put the
  8901. ** system in a deadlocked state, then SQLITE_LOCKED is returned and no
  8902. ** unlock-notify callback is registered. The system is said to be in
  8903. ** a deadlocked state if connection A has registered for an unlock-notify
  8904. ** callback on the conclusion of connection B's transaction, and connection
  8905. ** B has itself registered for an unlock-notify callback when connection
  8906. ** A's transaction is concluded. ^Indirect deadlock is also detected, so
  8907. ** the system is also considered to be deadlocked if connection B has
  8908. ** registered for an unlock-notify callback on the conclusion of connection
  8909. ** C's transaction, where connection C is waiting on connection A. ^Any
  8910. ** number of levels of indirection are allowed.
  8911. **
  8912. ** <b>The "DROP TABLE" Exception</b>
  8913. **
  8914. ** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost
  8915. ** always appropriate to call sqlite3_unlock_notify(). There is however,
  8916. ** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement,
  8917. ** SQLite checks if there are any currently executing SELECT statements
  8918. ** that belong to the same connection. If there are, SQLITE_LOCKED is
  8919. ** returned. In this case there is no "blocking connection", so invoking
  8920. ** sqlite3_unlock_notify() results in the unlock-notify callback being
  8921. ** invoked immediately. If the application then re-attempts the "DROP TABLE"
  8922. ** or "DROP INDEX" query, an infinite loop might be the result.
  8923. **
  8924. ** One way around this problem is to check the extended error code returned
  8925. ** by an sqlite3_step() call. ^(If there is a blocking connection, then the
  8926. ** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in
  8927. ** the special "DROP TABLE/INDEX" case, the extended error code is just
  8928. ** SQLITE_LOCKED.)^
  8929. */
  8930. SQLITE_API int sqlite3_unlock_notify(
  8931. sqlite3 *pBlocked, /* Waiting connection */
  8932. void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */
  8933. void *pNotifyArg /* Argument to pass to xNotify */
  8934. );
  8935. /*
  8936. ** CAPI3REF: String Comparison
  8937. **
  8938. ** ^The [sqlite3_stricmp()] and [sqlite3_strnicmp()] APIs allow applications
  8939. ** and extensions to compare the contents of two buffers containing UTF-8
  8940. ** strings in a case-independent fashion, using the same definition of "case
  8941. ** independence" that SQLite uses internally when comparing identifiers.
  8942. */
  8943. SQLITE_API int sqlite3_stricmp(const char *, const char *);
  8944. SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
  8945. /*
  8946. ** CAPI3REF: String Globbing
  8947. *
  8948. ** ^The [sqlite3_strglob(P,X)] interface returns zero if and only if
  8949. ** string X matches the [GLOB] pattern P.
  8950. ** ^The definition of [GLOB] pattern matching used in
  8951. ** [sqlite3_strglob(P,X)] is the same as for the "X GLOB P" operator in the
  8952. ** SQL dialect understood by SQLite. ^The [sqlite3_strglob(P,X)] function
  8953. ** is case sensitive.
  8954. **
  8955. ** Note that this routine returns zero on a match and non-zero if the strings
  8956. ** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].
  8957. **
  8958. ** See also: [sqlite3_strlike()].
  8959. */
  8960. SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr);
  8961. /*
  8962. ** CAPI3REF: String LIKE Matching
  8963. *
  8964. ** ^The [sqlite3_strlike(P,X,E)] interface returns zero if and only if
  8965. ** string X matches the [LIKE] pattern P with escape character E.
  8966. ** ^The definition of [LIKE] pattern matching used in
  8967. ** [sqlite3_strlike(P,X,E)] is the same as for the "X LIKE P ESCAPE E"
  8968. ** operator in the SQL dialect understood by SQLite. ^For "X LIKE P" without
  8969. ** the ESCAPE clause, set the E parameter of [sqlite3_strlike(P,X,E)] to 0.
  8970. ** ^As with the LIKE operator, the [sqlite3_strlike(P,X,E)] function is case
  8971. ** insensitive - equivalent upper and lower case ASCII characters match
  8972. ** one another.
  8973. **
  8974. ** ^The [sqlite3_strlike(P,X,E)] function matches Unicode characters, though
  8975. ** only ASCII characters are case folded.
  8976. **
  8977. ** Note that this routine returns zero on a match and non-zero if the strings
  8978. ** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].
  8979. **
  8980. ** See also: [sqlite3_strglob()].
  8981. */
  8982. SQLITE_API int sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int cEsc);
  8983. /*
  8984. ** CAPI3REF: Error Logging Interface
  8985. **
  8986. ** ^The [sqlite3_log()] interface writes a message into the [error log]
  8987. ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
  8988. ** ^If logging is enabled, the zFormat string and subsequent arguments are
  8989. ** used with [sqlite3_snprintf()] to generate the final output string.
  8990. **
  8991. ** The sqlite3_log() interface is intended for use by extensions such as
  8992. ** virtual tables, collating functions, and SQL functions. While there is
  8993. ** nothing to prevent an application from calling sqlite3_log(), doing so
  8994. ** is considered bad form.
  8995. **
  8996. ** The zFormat string must not be NULL.
  8997. **
  8998. ** To avoid deadlocks and other threading problems, the sqlite3_log() routine
  8999. ** will not use dynamically allocated memory. The log message is stored in
  9000. ** a fixed-length buffer on the stack. If the log message is longer than
  9001. ** a few hundred characters, it will be truncated to the length of the
  9002. ** buffer.
  9003. */
  9004. SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...);
  9005. /*
  9006. ** CAPI3REF: Write-Ahead Log Commit Hook
  9007. ** METHOD: sqlite3
  9008. **
  9009. ** ^The [sqlite3_wal_hook()] function is used to register a callback that
  9010. ** is invoked each time data is committed to a database in wal mode.
  9011. **
  9012. ** ^(The callback is invoked by SQLite after the commit has taken place and
  9013. ** the associated write-lock on the database released)^, so the implementation
  9014. ** may read, write or [checkpoint] the database as required.
  9015. **
  9016. ** ^The first parameter passed to the callback function when it is invoked
  9017. ** is a copy of the third parameter passed to sqlite3_wal_hook() when
  9018. ** registering the callback. ^The second is a copy of the database handle.
  9019. ** ^The third parameter is the name of the database that was written to -
  9020. ** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter
  9021. ** is the number of pages currently in the write-ahead log file,
  9022. ** including those that were just committed.
  9023. **
  9024. ** The callback function should normally return [SQLITE_OK]. ^If an error
  9025. ** code is returned, that error will propagate back up through the
  9026. ** SQLite code base to cause the statement that provoked the callback
  9027. ** to report an error, though the commit will have still occurred. If the
  9028. ** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value
  9029. ** that does not correspond to any valid SQLite error code, the results
  9030. ** are undefined.
  9031. **
  9032. ** A single database handle may have at most a single write-ahead log callback
  9033. ** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any
  9034. ** previously registered write-ahead log callback. ^The return value is
  9035. ** a copy of the third parameter from the previous call, if any, or 0.
  9036. ** ^Note that the [sqlite3_wal_autocheckpoint()] interface and the
  9037. ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will
  9038. ** overwrite any prior [sqlite3_wal_hook()] settings.
  9039. */
  9040. SQLITE_API void *sqlite3_wal_hook(
  9041. sqlite3*,
  9042. int(*)(void *,sqlite3*,const char*,int),
  9043. void*
  9044. );
  9045. /*
  9046. ** CAPI3REF: Configure an auto-checkpoint
  9047. ** METHOD: sqlite3
  9048. **
  9049. ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
  9050. ** [sqlite3_wal_hook()] that causes any database on [database connection] D
  9051. ** to automatically [checkpoint]
  9052. ** after committing a transaction if there are N or
  9053. ** more frames in the [write-ahead log] file. ^Passing zero or
  9054. ** a negative value as the nFrame parameter disables automatic
  9055. ** checkpoints entirely.
  9056. **
  9057. ** ^The callback registered by this function replaces any existing callback
  9058. ** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback
  9059. ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
  9060. ** configured by this function.
  9061. **
  9062. ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
  9063. ** from SQL.
  9064. **
  9065. ** ^Checkpoints initiated by this mechanism are
  9066. ** [sqlite3_wal_checkpoint_v2|PASSIVE].
  9067. **
  9068. ** ^Every new [database connection] defaults to having the auto-checkpoint
  9069. ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
  9070. ** pages. The use of this interface
  9071. ** is only necessary if the default setting is found to be suboptimal
  9072. ** for a particular application.
  9073. */
  9074. SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
  9075. /*
  9076. ** CAPI3REF: Checkpoint a database
  9077. ** METHOD: sqlite3
  9078. **
  9079. ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
  9080. ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
  9081. **
  9082. ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
  9083. ** [write-ahead log] for database X on [database connection] D to be
  9084. ** transferred into the database file and for the write-ahead log to
  9085. ** be reset. See the [checkpointing] documentation for addition
  9086. ** information.
  9087. **
  9088. ** This interface used to be the only way to cause a checkpoint to
  9089. ** occur. But then the newer and more powerful [sqlite3_wal_checkpoint_v2()]
  9090. ** interface was added. This interface is retained for backwards
  9091. ** compatibility and as a convenience for applications that need to manually
  9092. ** start a callback but which do not need the full power (and corresponding
  9093. ** complication) of [sqlite3_wal_checkpoint_v2()].
  9094. */
  9095. SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
  9096. /*
  9097. ** CAPI3REF: Checkpoint a database
  9098. ** METHOD: sqlite3
  9099. **
  9100. ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
  9101. ** operation on database X of [database connection] D in mode M. Status
  9102. ** information is written back into integers pointed to by L and C.)^
  9103. ** ^(The M parameter must be a valid [checkpoint mode]:)^
  9104. **
  9105. ** <dl>
  9106. ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
  9107. ** ^Checkpoint as many frames as possible without waiting for any database
  9108. ** readers or writers to finish, then sync the database file if all frames
  9109. ** in the log were checkpointed. ^The [busy-handler callback]
  9110. ** is never invoked in the SQLITE_CHECKPOINT_PASSIVE mode.
  9111. ** ^On the other hand, passive mode might leave the checkpoint unfinished
  9112. ** if there are concurrent readers or writers.
  9113. **
  9114. ** <dt>SQLITE_CHECKPOINT_FULL<dd>
  9115. ** ^This mode blocks (it invokes the
  9116. ** [sqlite3_busy_handler|busy-handler callback]) until there is no
  9117. ** database writer and all readers are reading from the most recent database
  9118. ** snapshot. ^It then checkpoints all frames in the log file and syncs the
  9119. ** database file. ^This mode blocks new database writers while it is pending,
  9120. ** but new database readers are allowed to continue unimpeded.
  9121. **
  9122. ** <dt>SQLITE_CHECKPOINT_RESTART<dd>
  9123. ** ^This mode works the same way as SQLITE_CHECKPOINT_FULL with the addition
  9124. ** that after checkpointing the log file it blocks (calls the
  9125. ** [busy-handler callback])
  9126. ** until all readers are reading from the database file only. ^This ensures
  9127. ** that the next writer will restart the log file from the beginning.
  9128. ** ^Like SQLITE_CHECKPOINT_FULL, this mode blocks new
  9129. ** database writer attempts while it is pending, but does not impede readers.
  9130. **
  9131. ** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd>
  9132. ** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the
  9133. ** addition that it also truncates the log file to zero bytes just prior
  9134. ** to a successful return.
  9135. ** </dl>
  9136. **
  9137. ** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in
  9138. ** the log file or to -1 if the checkpoint could not run because
  9139. ** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not
  9140. ** NULL,then *pnCkpt is set to the total number of checkpointed frames in the
  9141. ** log file (including any that were already checkpointed before the function
  9142. ** was called) or to -1 if the checkpoint could not run due to an error or
  9143. ** because the database is not in WAL mode. ^Note that upon successful
  9144. ** completion of an SQLITE_CHECKPOINT_TRUNCATE, the log file will have been
  9145. ** truncated to zero bytes and so both *pnLog and *pnCkpt will be set to zero.
  9146. **
  9147. ** ^All calls obtain an exclusive "checkpoint" lock on the database file. ^If
  9148. ** any other process is running a checkpoint operation at the same time, the
  9149. ** lock cannot be obtained and SQLITE_BUSY is returned. ^Even if there is a
  9150. ** busy-handler configured, it will not be invoked in this case.
  9151. **
  9152. ** ^The SQLITE_CHECKPOINT_FULL, RESTART and TRUNCATE modes also obtain the
  9153. ** exclusive "writer" lock on the database file. ^If the writer lock cannot be
  9154. ** obtained immediately, and a busy-handler is configured, it is invoked and
  9155. ** the writer lock retried until either the busy-handler returns 0 or the lock
  9156. ** is successfully obtained. ^The busy-handler is also invoked while waiting for
  9157. ** database readers as described above. ^If the busy-handler returns 0 before
  9158. ** the writer lock is obtained or while waiting for database readers, the
  9159. ** checkpoint operation proceeds from that point in the same way as
  9160. ** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible
  9161. ** without blocking any further. ^SQLITE_BUSY is returned in this case.
  9162. **
  9163. ** ^If parameter zDb is NULL or points to a zero length string, then the
  9164. ** specified operation is attempted on all WAL databases [attached] to
  9165. ** [database connection] db. In this case the
  9166. ** values written to output parameters *pnLog and *pnCkpt are undefined. ^If
  9167. ** an SQLITE_BUSY error is encountered when processing one or more of the
  9168. ** attached WAL databases, the operation is still attempted on any remaining
  9169. ** attached databases and SQLITE_BUSY is returned at the end. ^If any other
  9170. ** error occurs while processing an attached database, processing is abandoned
  9171. ** and the error code is returned to the caller immediately. ^If no error
  9172. ** (SQLITE_BUSY or otherwise) is encountered while processing the attached
  9173. ** databases, SQLITE_OK is returned.
  9174. **
  9175. ** ^If database zDb is the name of an attached database that is not in WAL
  9176. ** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. ^If
  9177. ** zDb is not NULL (or a zero length string) and is not the name of any
  9178. ** attached database, SQLITE_ERROR is returned to the caller.
  9179. **
  9180. ** ^Unless it returns SQLITE_MISUSE,
  9181. ** the sqlite3_wal_checkpoint_v2() interface
  9182. ** sets the error information that is queried by
  9183. ** [sqlite3_errcode()] and [sqlite3_errmsg()].
  9184. **
  9185. ** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface
  9186. ** from SQL.
  9187. */
  9188. SQLITE_API int sqlite3_wal_checkpoint_v2(
  9189. sqlite3 *db, /* Database handle */
  9190. const char *zDb, /* Name of attached database (or NULL) */
  9191. int eMode, /* SQLITE_CHECKPOINT_* value */
  9192. int *pnLog, /* OUT: Size of WAL log in frames */
  9193. int *pnCkpt /* OUT: Total number of frames checkpointed */
  9194. );
  9195. /*
  9196. ** CAPI3REF: Checkpoint Mode Values
  9197. ** KEYWORDS: {checkpoint mode}
  9198. **
  9199. ** These constants define all valid values for the "checkpoint mode" passed
  9200. ** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface.
  9201. ** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
  9202. ** meaning of each of these checkpoint modes.
  9203. */
  9204. #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
  9205. #define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */
  9206. #define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for for readers */
  9207. #define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */
  9208. /*
  9209. ** CAPI3REF: Virtual Table Interface Configuration
  9210. **
  9211. ** This function may be called by either the [xConnect] or [xCreate] method
  9212. ** of a [virtual table] implementation to configure
  9213. ** various facets of the virtual table interface.
  9214. **
  9215. ** If this interface is invoked outside the context of an xConnect or
  9216. ** xCreate virtual table method then the behavior is undefined.
  9217. **
  9218. ** In the call sqlite3_vtab_config(D,C,...) the D parameter is the
  9219. ** [database connection] in which the virtual table is being created and
  9220. ** which is passed in as the first argument to the [xConnect] or [xCreate]
  9221. ** method that is invoking sqlite3_vtab_config(). The C parameter is one
  9222. ** of the [virtual table configuration options]. The presence and meaning
  9223. ** of parameters after C depend on which [virtual table configuration option]
  9224. ** is used.
  9225. */
  9226. SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...);
  9227. /*
  9228. ** CAPI3REF: Virtual Table Configuration Options
  9229. ** KEYWORDS: {virtual table configuration options}
  9230. ** KEYWORDS: {virtual table configuration option}
  9231. **
  9232. ** These macros define the various options to the
  9233. ** [sqlite3_vtab_config()] interface that [virtual table] implementations
  9234. ** can use to customize and optimize their behavior.
  9235. **
  9236. ** <dl>
  9237. ** [[SQLITE_VTAB_CONSTRAINT_SUPPORT]]
  9238. ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT</dt>
  9239. ** <dd>Calls of the form
  9240. ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
  9241. ** where X is an integer. If X is zero, then the [virtual table] whose
  9242. ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
  9243. ** support constraints. In this configuration (which is the default) if
  9244. ** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire
  9245. ** statement is rolled back as if [ON CONFLICT | OR ABORT] had been
  9246. ** specified as part of the users SQL statement, regardless of the actual
  9247. ** ON CONFLICT mode specified.
  9248. **
  9249. ** If X is non-zero, then the virtual table implementation guarantees
  9250. ** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before
  9251. ** any modifications to internal or persistent data structures have been made.
  9252. ** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite
  9253. ** is able to roll back a statement or database transaction, and abandon
  9254. ** or continue processing the current SQL statement as appropriate.
  9255. ** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns
  9256. ** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode
  9257. ** had been ABORT.
  9258. **
  9259. ** Virtual table implementations that are required to handle OR REPLACE
  9260. ** must do so within the [xUpdate] method. If a call to the
  9261. ** [sqlite3_vtab_on_conflict()] function indicates that the current ON
  9262. ** CONFLICT policy is REPLACE, the virtual table implementation should
  9263. ** silently replace the appropriate rows within the xUpdate callback and
  9264. ** return SQLITE_OK. Or, if this is not possible, it may return
  9265. ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
  9266. ** constraint handling.
  9267. ** </dd>
  9268. **
  9269. ** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt>
  9270. ** <dd>Calls of the form
  9271. ** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the
  9272. ** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
  9273. ** prohibits that virtual table from being used from within triggers and
  9274. ** views.
  9275. ** </dd>
  9276. **
  9277. ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
  9278. ** <dd>Calls of the form
  9279. ** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the
  9280. ** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
  9281. ** identify that virtual table as being safe to use from within triggers
  9282. ** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the
  9283. ** virtual table can do no serious harm even if it is controlled by a
  9284. ** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS
  9285. ** flag unless absolutely necessary.
  9286. ** </dd>
  9287. ** </dl>
  9288. */
  9289. #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
  9290. #define SQLITE_VTAB_INNOCUOUS 2
  9291. #define SQLITE_VTAB_DIRECTONLY 3
  9292. /*
  9293. ** CAPI3REF: Determine The Virtual Table Conflict Policy
  9294. **
  9295. ** This function may only be called from within a call to the [xUpdate] method
  9296. ** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The
  9297. ** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL],
  9298. ** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode
  9299. ** of the SQL statement that triggered the call to the [xUpdate] method of the
  9300. ** [virtual table].
  9301. */
  9302. SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
  9303. /*
  9304. ** CAPI3REF: Determine If Virtual Table Column Access Is For UPDATE
  9305. **
  9306. ** If the sqlite3_vtab_nochange(X) routine is called within the [xColumn]
  9307. ** method of a [virtual table], then it might return true if the
  9308. ** column is being fetched as part of an UPDATE operation during which the
  9309. ** column value will not change. The virtual table implementation can use
  9310. ** this hint as permission to substitute a return value that is less
  9311. ** expensive to compute and that the corresponding
  9312. ** [xUpdate] method understands as a "no-change" value.
  9313. **
  9314. ** If the [xColumn] method calls sqlite3_vtab_nochange() and finds that
  9315. ** the column is not changed by the UPDATE statement, then the xColumn
  9316. ** method can optionally return without setting a result, without calling
  9317. ** any of the [sqlite3_result_int|sqlite3_result_xxxxx() interfaces].
  9318. ** In that case, [sqlite3_value_nochange(X)] will return true for the
  9319. ** same column in the [xUpdate] method.
  9320. **
  9321. ** The sqlite3_vtab_nochange() routine is an optimization. Virtual table
  9322. ** implementations should continue to give a correct answer even if the
  9323. ** sqlite3_vtab_nochange() interface were to always return false. In the
  9324. ** current implementation, the sqlite3_vtab_nochange() interface does always
  9325. ** returns false for the enhanced [UPDATE FROM] statement.
  9326. */
  9327. SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
  9328. /*
  9329. ** CAPI3REF: Determine The Collation For a Virtual Table Constraint
  9330. ** METHOD: sqlite3_index_info
  9331. **
  9332. ** This function may only be called from within a call to the [xBestIndex]
  9333. ** method of a [virtual table]. This function returns a pointer to a string
  9334. ** that is the name of the appropriate collation sequence to use for text
  9335. ** comparisons on the constraint identified by its arguments.
  9336. **
  9337. ** The first argument must be the pointer to the [sqlite3_index_info] object
  9338. ** that is the first parameter to the xBestIndex() method. The second argument
  9339. ** must be an index into the aConstraint[] array belonging to the
  9340. ** sqlite3_index_info structure passed to xBestIndex.
  9341. **
  9342. ** Important:
  9343. ** The first parameter must be the same pointer that is passed into the
  9344. ** xBestMethod() method. The first parameter may not be a pointer to a
  9345. ** different [sqlite3_index_info] object, even an exact copy.
  9346. **
  9347. ** The return value is computed as follows:
  9348. **
  9349. ** <ol>
  9350. ** <li><p> If the constraint comes from a WHERE clause expression that contains
  9351. ** a [COLLATE operator], then the name of the collation specified by
  9352. ** that COLLATE operator is returned.
  9353. ** <li><p> If there is no COLLATE operator, but the column that is the subject
  9354. ** of the constraint specifies an alternative collating sequence via
  9355. ** a [COLLATE clause] on the column definition within the CREATE TABLE
  9356. ** statement that was passed into [sqlite3_declare_vtab()], then the
  9357. ** name of that alternative collating sequence is returned.
  9358. ** <li><p> Otherwise, "BINARY" is returned.
  9359. ** </ol>
  9360. */
  9361. SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
  9362. /*
  9363. ** CAPI3REF: Determine if a virtual table query is DISTINCT
  9364. ** METHOD: sqlite3_index_info
  9365. **
  9366. ** This API may only be used from within an [xBestIndex|xBestIndex method]
  9367. ** of a [virtual table] implementation. The result of calling this
  9368. ** interface from outside of xBestIndex() is undefined and probably harmful.
  9369. **
  9370. ** ^The sqlite3_vtab_distinct() interface returns an integer between 0 and
  9371. ** 3. The integer returned by sqlite3_vtab_distinct()
  9372. ** gives the virtual table additional information about how the query
  9373. ** planner wants the output to be ordered. As long as the virtual table
  9374. ** can meet the ordering requirements of the query planner, it may set
  9375. ** the "orderByConsumed" flag.
  9376. **
  9377. ** <ol><li value="0"><p>
  9378. ** ^If the sqlite3_vtab_distinct() interface returns 0, that means
  9379. ** that the query planner needs the virtual table to return all rows in the
  9380. ** sort order defined by the "nOrderBy" and "aOrderBy" fields of the
  9381. ** [sqlite3_index_info] object. This is the default expectation. If the
  9382. ** virtual table outputs all rows in sorted order, then it is always safe for
  9383. ** the xBestIndex method to set the "orderByConsumed" flag, regardless of
  9384. ** the return value from sqlite3_vtab_distinct().
  9385. ** <li value="1"><p>
  9386. ** ^(If the sqlite3_vtab_distinct() interface returns 1, that means
  9387. ** that the query planner does not need the rows to be returned in sorted order
  9388. ** as long as all rows with the same values in all columns identified by the
  9389. ** "aOrderBy" field are adjacent.)^ This mode is used when the query planner
  9390. ** is doing a GROUP BY.
  9391. ** <li value="2"><p>
  9392. ** ^(If the sqlite3_vtab_distinct() interface returns 2, that means
  9393. ** that the query planner does not need the rows returned in any particular
  9394. ** order, as long as rows with the same values in all "aOrderBy" columns
  9395. ** are adjacent.)^ ^(Furthermore, only a single row for each particular
  9396. ** combination of values in the columns identified by the "aOrderBy" field
  9397. ** needs to be returned.)^ ^It is always ok for two or more rows with the same
  9398. ** values in all "aOrderBy" columns to be returned, as long as all such rows
  9399. ** are adjacent. ^The virtual table may, if it chooses, omit extra rows
  9400. ** that have the same value for all columns identified by "aOrderBy".
  9401. ** ^However omitting the extra rows is optional.
  9402. ** This mode is used for a DISTINCT query.
  9403. ** <li value="3"><p>
  9404. ** ^(If the sqlite3_vtab_distinct() interface returns 3, that means
  9405. ** that the query planner needs only distinct rows but it does need the
  9406. ** rows to be sorted.)^ ^The virtual table implementation is free to omit
  9407. ** rows that are identical in all aOrderBy columns, if it wants to, but
  9408. ** it is not required to omit any rows. This mode is used for queries
  9409. ** that have both DISTINCT and ORDER BY clauses.
  9410. ** </ol>
  9411. **
  9412. ** ^For the purposes of comparing virtual table output values to see if the
  9413. ** values are same value for sorting purposes, two NULL values are considered
  9414. ** to be the same. In other words, the comparison operator is "IS"
  9415. ** (or "IS NOT DISTINCT FROM") and not "==".
  9416. **
  9417. ** If a virtual table implementation is unable to meet the requirements
  9418. ** specified above, then it must not set the "orderByConsumed" flag in the
  9419. ** [sqlite3_index_info] object or an incorrect answer may result.
  9420. **
  9421. ** ^A virtual table implementation is always free to return rows in any order
  9422. ** it wants, as long as the "orderByConsumed" flag is not set. ^When the
  9423. ** the "orderByConsumed" flag is unset, the query planner will add extra
  9424. ** [bytecode] to ensure that the final results returned by the SQL query are
  9425. ** ordered correctly. The use of the "orderByConsumed" flag and the
  9426. ** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful
  9427. ** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed"
  9428. ** flag might help queries against a virtual table to run faster. Being
  9429. ** overly aggressive and setting the "orderByConsumed" flag when it is not
  9430. ** valid to do so, on the other hand, might cause SQLite to return incorrect
  9431. ** results.
  9432. */
  9433. SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*);
  9434. /*
  9435. ** CAPI3REF: Identify and handle IN constraints in xBestIndex
  9436. **
  9437. ** This interface may only be used from within an
  9438. ** [xBestIndex|xBestIndex() method] of a [virtual table] implementation.
  9439. ** The result of invoking this interface from any other context is
  9440. ** undefined and probably harmful.
  9441. **
  9442. ** ^(A constraint on a virtual table of the form
  9443. ** "[IN operator|column IN (...)]" is
  9444. ** communicated to the xBestIndex method as a
  9445. ** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use
  9446. ** this constraint, it must set the corresponding
  9447. ** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under
  9448. ** the usual mode of handling IN operators, SQLite generates [bytecode]
  9449. ** that invokes the [xFilter|xFilter() method] once for each value
  9450. ** on the right-hand side of the IN operator.)^ Thus the virtual table
  9451. ** only sees a single value from the right-hand side of the IN operator
  9452. ** at a time.
  9453. **
  9454. ** In some cases, however, it would be advantageous for the virtual
  9455. ** table to see all values on the right-hand of the IN operator all at
  9456. ** once. The sqlite3_vtab_in() interfaces facilitates this in two ways:
  9457. **
  9458. ** <ol>
  9459. ** <li><p>
  9460. ** ^A call to sqlite3_vtab_in(P,N,-1) will return true (non-zero)
  9461. ** if and only if the [sqlite3_index_info|P->aConstraint][N] constraint
  9462. ** is an [IN operator] that can be processed all at once. ^In other words,
  9463. ** sqlite3_vtab_in() with -1 in the third argument is a mechanism
  9464. ** by which the virtual table can ask SQLite if all-at-once processing
  9465. ** of the IN operator is even possible.
  9466. **
  9467. ** <li><p>
  9468. ** ^A call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates
  9469. ** to SQLite that the virtual table does or does not want to process
  9470. ** the IN operator all-at-once, respectively. ^Thus when the third
  9471. ** parameter (F) is non-negative, this interface is the mechanism by
  9472. ** which the virtual table tells SQLite how it wants to process the
  9473. ** IN operator.
  9474. ** </ol>
  9475. **
  9476. ** ^The sqlite3_vtab_in(P,N,F) interface can be invoked multiple times
  9477. ** within the same xBestIndex method call. ^For any given P,N pair,
  9478. ** the return value from sqlite3_vtab_in(P,N,F) will always be the same
  9479. ** within the same xBestIndex call. ^If the interface returns true
  9480. ** (non-zero), that means that the constraint is an IN operator
  9481. ** that can be processed all-at-once. ^If the constraint is not an IN
  9482. ** operator or cannot be processed all-at-once, then the interface returns
  9483. ** false.
  9484. **
  9485. ** ^(All-at-once processing of the IN operator is selected if both of the
  9486. ** following conditions are met:
  9487. **
  9488. ** <ol>
  9489. ** <li><p> The P->aConstraintUsage[N].argvIndex value is set to a positive
  9490. ** integer. This is how the virtual table tells SQLite that it wants to
  9491. ** use the N-th constraint.
  9492. **
  9493. ** <li><p> The last call to sqlite3_vtab_in(P,N,F) for which F was
  9494. ** non-negative had F>=1.
  9495. ** </ol>)^
  9496. **
  9497. ** ^If either or both of the conditions above are false, then SQLite uses
  9498. ** the traditional one-at-a-time processing strategy for the IN constraint.
  9499. ** ^If both conditions are true, then the argvIndex-th parameter to the
  9500. ** xFilter method will be an [sqlite3_value] that appears to be NULL,
  9501. ** but which can be passed to [sqlite3_vtab_in_first()] and
  9502. ** [sqlite3_vtab_in_next()] to find all values on the right-hand side
  9503. ** of the IN constraint.
  9504. */
  9505. SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle);
  9506. /*
  9507. ** CAPI3REF: Find all elements on the right-hand side of an IN constraint.
  9508. **
  9509. ** These interfaces are only useful from within the
  9510. ** [xFilter|xFilter() method] of a [virtual table] implementation.
  9511. ** The result of invoking these interfaces from any other context
  9512. ** is undefined and probably harmful.
  9513. **
  9514. ** The X parameter in a call to sqlite3_vtab_in_first(X,P) or
  9515. ** sqlite3_vtab_in_next(X,P) must be one of the parameters to the
  9516. ** xFilter method which invokes these routines, and specifically
  9517. ** a parameter that was previously selected for all-at-once IN constraint
  9518. ** processing use the [sqlite3_vtab_in()] interface in the
  9519. ** [xBestIndex|xBestIndex method]. ^(If the X parameter is not
  9520. ** an xFilter argument that was selected for all-at-once IN constraint
  9521. ** processing, then these routines return [SQLITE_MISUSE])^ or perhaps
  9522. ** exhibit some other undefined or harmful behavior.
  9523. **
  9524. ** ^(Use these routines to access all values on the right-hand side
  9525. ** of the IN constraint using code like the following:
  9526. **
  9527. ** <blockquote><pre>
  9528. ** &nbsp; for(rc=sqlite3_vtab_in_first(pList, &pVal);
  9529. ** &nbsp; rc==SQLITE_OK && pVal
  9530. ** &nbsp; rc=sqlite3_vtab_in_next(pList, &pVal)
  9531. ** &nbsp; ){
  9532. ** &nbsp; // do something with pVal
  9533. ** &nbsp; }
  9534. ** &nbsp; if( rc!=SQLITE_OK ){
  9535. ** &nbsp; // an error has occurred
  9536. ** &nbsp; }
  9537. ** </pre></blockquote>)^
  9538. **
  9539. ** ^On success, the sqlite3_vtab_in_first(X,P) and sqlite3_vtab_in_next(X,P)
  9540. ** routines return SQLITE_OK and set *P to point to the first or next value
  9541. ** on the RHS of the IN constraint. ^If there are no more values on the
  9542. ** right hand side of the IN constraint, then *P is set to NULL and these
  9543. ** routines return [SQLITE_DONE]. ^The return value might be
  9544. ** some other value, such as SQLITE_NOMEM, in the event of a malfunction.
  9545. **
  9546. ** The *ppOut values returned by these routines are only valid until the
  9547. ** next call to either of these routines or until the end of the xFilter
  9548. ** method from which these routines were called. If the virtual table
  9549. ** implementation needs to retain the *ppOut values for longer, it must make
  9550. ** copies. The *ppOut values are [protected sqlite3_value|protected].
  9551. */
  9552. SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut);
  9553. SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut);
  9554. /*
  9555. ** CAPI3REF: Constraint values in xBestIndex()
  9556. ** METHOD: sqlite3_index_info
  9557. **
  9558. ** This API may only be used from within the [xBestIndex|xBestIndex method]
  9559. ** of a [virtual table] implementation. The result of calling this interface
  9560. ** from outside of an xBestIndex method are undefined and probably harmful.
  9561. **
  9562. ** ^When the sqlite3_vtab_rhs_value(P,J,V) interface is invoked from within
  9563. ** the [xBestIndex] method of a [virtual table] implementation, with P being
  9564. ** a copy of the [sqlite3_index_info] object pointer passed into xBestIndex and
  9565. ** J being a 0-based index into P->aConstraint[], then this routine
  9566. ** attempts to set *V to the value of the right-hand operand of
  9567. ** that constraint if the right-hand operand is known. ^If the
  9568. ** right-hand operand is not known, then *V is set to a NULL pointer.
  9569. ** ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if
  9570. ** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V)
  9571. ** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th
  9572. ** constraint is not available. ^The sqlite3_vtab_rhs_value() interface
  9573. ** can return an result code other than SQLITE_OK or SQLITE_NOTFOUND if
  9574. ** something goes wrong.
  9575. **
  9576. ** The sqlite3_vtab_rhs_value() interface is usually only successful if
  9577. ** the right-hand operand of a constraint is a literal value in the original
  9578. ** SQL statement. If the right-hand operand is an expression or a reference
  9579. ** to some other column or a [host parameter], then sqlite3_vtab_rhs_value()
  9580. ** will probably return [SQLITE_NOTFOUND].
  9581. **
  9582. ** ^(Some constraints, such as [SQLITE_INDEX_CONSTRAINT_ISNULL] and
  9583. ** [SQLITE_INDEX_CONSTRAINT_ISNOTNULL], have no right-hand operand. For such
  9584. ** constraints, sqlite3_vtab_rhs_value() always returns SQLITE_NOTFOUND.)^
  9585. **
  9586. ** ^The [sqlite3_value] object returned in *V is a protected sqlite3_value
  9587. ** and remains valid for the duration of the xBestIndex method call.
  9588. ** ^When xBestIndex returns, the sqlite3_value object returned by
  9589. ** sqlite3_vtab_rhs_value() is automatically deallocated.
  9590. **
  9591. ** The "_rhs_" in the name of this routine is an abbreviation for
  9592. ** "Right-Hand Side".
  9593. */
  9594. SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal);
  9595. /*
  9596. ** CAPI3REF: Conflict resolution modes
  9597. ** KEYWORDS: {conflict resolution mode}
  9598. **
  9599. ** These constants are returned by [sqlite3_vtab_on_conflict()] to
  9600. ** inform a [virtual table] implementation what the [ON CONFLICT] mode
  9601. ** is for the SQL statement being evaluated.
  9602. **
  9603. ** Note that the [SQLITE_IGNORE] constant is also used as a potential
  9604. ** return value from the [sqlite3_set_authorizer()] callback and that
  9605. ** [SQLITE_ABORT] is also a [result code].
  9606. */
  9607. #define SQLITE_ROLLBACK 1
  9608. /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
  9609. #define SQLITE_FAIL 3
  9610. /* #define SQLITE_ABORT 4 // Also an error code */
  9611. #define SQLITE_REPLACE 5
  9612. /*
  9613. ** CAPI3REF: Prepared Statement Scan Status Opcodes
  9614. ** KEYWORDS: {scanstatus options}
  9615. **
  9616. ** The following constants can be used for the T parameter to the
  9617. ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
  9618. ** different metric for sqlite3_stmt_scanstatus() to return.
  9619. **
  9620. ** When the value returned to V is a string, space to hold that string is
  9621. ** managed by the prepared statement S and will be automatically freed when
  9622. ** S is finalized.
  9623. **
  9624. ** <dl>
  9625. ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
  9626. ** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be
  9627. ** set to the total number of times that the X-th loop has run.</dd>
  9628. **
  9629. ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
  9630. ** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be set
  9631. ** to the total number of rows examined by all iterations of the X-th loop.</dd>
  9632. **
  9633. ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
  9634. ** <dd>^The "double" variable pointed to by the V parameter will be set to the
  9635. ** query planner's estimate for the average number of rows output from each
  9636. ** iteration of the X-th loop. If the query planner's estimates was accurate,
  9637. ** then this value will approximate the quotient NVISIT/NLOOP and the
  9638. ** product of this value for all prior loops with the same SELECTID will
  9639. ** be the NLOOP value for the current loop.
  9640. **
  9641. ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
  9642. ** <dd>^The "const char *" variable pointed to by the V parameter will be set
  9643. ** to a zero-terminated UTF-8 string containing the name of the index or table
  9644. ** used for the X-th loop.
  9645. **
  9646. ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
  9647. ** <dd>^The "const char *" variable pointed to by the V parameter will be set
  9648. ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
  9649. ** description for the X-th loop.
  9650. **
  9651. ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
  9652. ** <dd>^The "int" variable pointed to by the V parameter will be set to the
  9653. ** "select-id" for the X-th loop. The select-id identifies which query or
  9654. ** subquery the loop is part of. The main query has a select-id of zero.
  9655. ** The select-id is the same value as is output in the first column
  9656. ** of an [EXPLAIN QUERY PLAN] query.
  9657. ** </dl>
  9658. */
  9659. #define SQLITE_SCANSTAT_NLOOP 0
  9660. #define SQLITE_SCANSTAT_NVISIT 1
  9661. #define SQLITE_SCANSTAT_EST 2
  9662. #define SQLITE_SCANSTAT_NAME 3
  9663. #define SQLITE_SCANSTAT_EXPLAIN 4
  9664. #define SQLITE_SCANSTAT_SELECTID 5
  9665. /*
  9666. ** CAPI3REF: Prepared Statement Scan Status
  9667. ** METHOD: sqlite3_stmt
  9668. **
  9669. ** This interface returns information about the predicted and measured
  9670. ** performance for pStmt. Advanced applications can use this
  9671. ** interface to compare the predicted and the measured performance and
  9672. ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
  9673. **
  9674. ** Since this interface is expected to be rarely used, it is only
  9675. ** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]
  9676. ** compile-time option.
  9677. **
  9678. ** The "iScanStatusOp" parameter determines which status information to return.
  9679. ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
  9680. ** of this interface is undefined.
  9681. ** ^The requested measurement is written into a variable pointed to by
  9682. ** the "pOut" parameter.
  9683. ** Parameter "idx" identifies the specific loop to retrieve statistics for.
  9684. ** Loops are numbered starting from zero. ^If idx is out of range - less than
  9685. ** zero or greater than or equal to the total number of loops used to implement
  9686. ** the statement - a non-zero value is returned and the variable that pOut
  9687. ** points to is unchanged.
  9688. **
  9689. ** ^Statistics might not be available for all loops in all statements. ^In cases
  9690. ** where there exist loops with no available statistics, this function behaves
  9691. ** as if the loop did not exist - it returns non-zero and leave the variable
  9692. ** that pOut points to unchanged.
  9693. **
  9694. ** See also: [sqlite3_stmt_scanstatus_reset()]
  9695. */
  9696. SQLITE_API int sqlite3_stmt_scanstatus(
  9697. sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
  9698. int idx, /* Index of loop to report on */
  9699. int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
  9700. void *pOut /* Result written here */
  9701. );
  9702. /*
  9703. ** CAPI3REF: Zero Scan-Status Counters
  9704. ** METHOD: sqlite3_stmt
  9705. **
  9706. ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
  9707. **
  9708. ** This API is only available if the library is built with pre-processor
  9709. ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
  9710. */
  9711. SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
  9712. /*
  9713. ** CAPI3REF: Flush caches to disk mid-transaction
  9714. ** METHOD: sqlite3
  9715. **
  9716. ** ^If a write-transaction is open on [database connection] D when the
  9717. ** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
  9718. ** pages in the pager-cache that are not currently in use are written out
  9719. ** to disk. A dirty page may be in use if a database cursor created by an
  9720. ** active SQL statement is reading from it, or if it is page 1 of a database
  9721. ** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)]
  9722. ** interface flushes caches for all schemas - "main", "temp", and
  9723. ** any [attached] databases.
  9724. **
  9725. ** ^If this function needs to obtain extra database locks before dirty pages
  9726. ** can be flushed to disk, it does so. ^If those locks cannot be obtained
  9727. ** immediately and there is a busy-handler callback configured, it is invoked
  9728. ** in the usual manner. ^If the required lock still cannot be obtained, then
  9729. ** the database is skipped and an attempt made to flush any dirty pages
  9730. ** belonging to the next (if any) database. ^If any databases are skipped
  9731. ** because locks cannot be obtained, but no other error occurs, this
  9732. ** function returns SQLITE_BUSY.
  9733. **
  9734. ** ^If any other error occurs while flushing dirty pages to disk (for
  9735. ** example an IO error or out-of-memory condition), then processing is
  9736. ** abandoned and an SQLite [error code] is returned to the caller immediately.
  9737. **
  9738. ** ^Otherwise, if no error occurs, [sqlite3_db_cacheflush()] returns SQLITE_OK.
  9739. **
  9740. ** ^This function does not set the database handle error code or message
  9741. ** returned by the [sqlite3_errcode()] and [sqlite3_errmsg()] functions.
  9742. */
  9743. SQLITE_API int sqlite3_db_cacheflush(sqlite3*);
  9744. /*
  9745. ** CAPI3REF: The pre-update hook.
  9746. ** METHOD: sqlite3
  9747. **
  9748. ** ^These interfaces are only available if SQLite is compiled using the
  9749. ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
  9750. **
  9751. ** ^The [sqlite3_preupdate_hook()] interface registers a callback function
  9752. ** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation
  9753. ** on a database table.
  9754. ** ^At most one preupdate hook may be registered at a time on a single
  9755. ** [database connection]; each call to [sqlite3_preupdate_hook()] overrides
  9756. ** the previous setting.
  9757. ** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()]
  9758. ** with a NULL pointer as the second parameter.
  9759. ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
  9760. ** the first parameter to callbacks.
  9761. **
  9762. ** ^The preupdate hook only fires for changes to real database tables; the
  9763. ** preupdate hook is not invoked for changes to [virtual tables] or to
  9764. ** system tables like sqlite_sequence or sqlite_stat1.
  9765. **
  9766. ** ^The second parameter to the preupdate callback is a pointer to
  9767. ** the [database connection] that registered the preupdate hook.
  9768. ** ^The third parameter to the preupdate callback is one of the constants
  9769. ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
  9770. ** kind of update operation that is about to occur.
  9771. ** ^(The fourth parameter to the preupdate callback is the name of the
  9772. ** database within the database connection that is being modified. This
  9773. ** will be "main" for the main database or "temp" for TEMP tables or
  9774. ** the name given after the AS keyword in the [ATTACH] statement for attached
  9775. ** databases.)^
  9776. ** ^The fifth parameter to the preupdate callback is the name of the
  9777. ** table that is being modified.
  9778. **
  9779. ** For an UPDATE or DELETE operation on a [rowid table], the sixth
  9780. ** parameter passed to the preupdate callback is the initial [rowid] of the
  9781. ** row being modified or deleted. For an INSERT operation on a rowid table,
  9782. ** or any operation on a WITHOUT ROWID table, the value of the sixth
  9783. ** parameter is undefined. For an INSERT or UPDATE on a rowid table the
  9784. ** seventh parameter is the final rowid value of the row being inserted
  9785. ** or updated. The value of the seventh parameter passed to the callback
  9786. ** function is not defined for operations on WITHOUT ROWID tables, or for
  9787. ** DELETE operations on rowid tables.
  9788. **
  9789. ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
  9790. ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
  9791. ** provide additional information about a preupdate event. These routines
  9792. ** may only be called from within a preupdate callback. Invoking any of
  9793. ** these routines from outside of a preupdate callback or with a
  9794. ** [database connection] pointer that is different from the one supplied
  9795. ** to the preupdate callback results in undefined and probably undesirable
  9796. ** behavior.
  9797. **
  9798. ** ^The [sqlite3_preupdate_count(D)] interface returns the number of columns
  9799. ** in the row that is being inserted, updated, or deleted.
  9800. **
  9801. ** ^The [sqlite3_preupdate_old(D,N,P)] interface writes into P a pointer to
  9802. ** a [protected sqlite3_value] that contains the value of the Nth column of
  9803. ** the table row before it is updated. The N parameter must be between 0
  9804. ** and one less than the number of columns or the behavior will be
  9805. ** undefined. This must only be used within SQLITE_UPDATE and SQLITE_DELETE
  9806. ** preupdate callbacks; if it is used by an SQLITE_INSERT callback then the
  9807. ** behavior is undefined. The [sqlite3_value] that P points to
  9808. ** will be destroyed when the preupdate callback returns.
  9809. **
  9810. ** ^The [sqlite3_preupdate_new(D,N,P)] interface writes into P a pointer to
  9811. ** a [protected sqlite3_value] that contains the value of the Nth column of
  9812. ** the table row after it is updated. The N parameter must be between 0
  9813. ** and one less than the number of columns or the behavior will be
  9814. ** undefined. This must only be used within SQLITE_INSERT and SQLITE_UPDATE
  9815. ** preupdate callbacks; if it is used by an SQLITE_DELETE callback then the
  9816. ** behavior is undefined. The [sqlite3_value] that P points to
  9817. ** will be destroyed when the preupdate callback returns.
  9818. **
  9819. ** ^The [sqlite3_preupdate_depth(D)] interface returns 0 if the preupdate
  9820. ** callback was invoked as a result of a direct insert, update, or delete
  9821. ** operation; or 1 for inserts, updates, or deletes invoked by top-level
  9822. ** triggers; or 2 for changes resulting from triggers called by top-level
  9823. ** triggers; and so forth.
  9824. **
  9825. ** When the [sqlite3_blob_write()] API is used to update a blob column,
  9826. ** the pre-update hook is invoked with SQLITE_DELETE. This is because the
  9827. ** in this case the new values are not available. In this case, when a
  9828. ** callback made with op==SQLITE_DELETE is actuall a write using the
  9829. ** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns
  9830. ** the index of the column being written. In other cases, where the
  9831. ** pre-update hook is being invoked for some other reason, including a
  9832. ** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.
  9833. **
  9834. ** See also: [sqlite3_update_hook()]
  9835. */
  9836. #if defined(SQLITE_ENABLE_PREUPDATE_HOOK)
  9837. SQLITE_API void *sqlite3_preupdate_hook(
  9838. sqlite3 *db,
  9839. void(*xPreUpdate)(
  9840. void *pCtx, /* Copy of third arg to preupdate_hook() */
  9841. sqlite3 *db, /* Database handle */
  9842. int op, /* SQLITE_UPDATE, DELETE or INSERT */
  9843. char const *zDb, /* Database name */
  9844. char const *zName, /* Table name */
  9845. sqlite3_int64 iKey1, /* Rowid of row about to be deleted/updated */
  9846. sqlite3_int64 iKey2 /* New rowid value (for a rowid UPDATE) */
  9847. ),
  9848. void*
  9849. );
  9850. SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
  9851. SQLITE_API int sqlite3_preupdate_count(sqlite3 *);
  9852. SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);
  9853. SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
  9854. SQLITE_API int sqlite3_preupdate_blobwrite(sqlite3 *);
  9855. #endif
  9856. /*
  9857. ** CAPI3REF: Low-level system error code
  9858. ** METHOD: sqlite3
  9859. **
  9860. ** ^Attempt to return the underlying operating system error code or error
  9861. ** number that caused the most recent I/O error or failure to open a file.
  9862. ** The return value is OS-dependent. For example, on unix systems, after
  9863. ** [sqlite3_open_v2()] returns [SQLITE_CANTOPEN], this interface could be
  9864. ** called to get back the underlying "errno" that caused the problem, such
  9865. ** as ENOSPC, EAUTH, EISDIR, and so forth.
  9866. */
  9867. SQLITE_API int sqlite3_system_errno(sqlite3*);
  9868. /*
  9869. ** CAPI3REF: Database Snapshot
  9870. ** KEYWORDS: {snapshot} {sqlite3_snapshot}
  9871. **
  9872. ** An instance of the snapshot object records the state of a [WAL mode]
  9873. ** database for some specific point in history.
  9874. **
  9875. ** In [WAL mode], multiple [database connections] that are open on the
  9876. ** same database file can each be reading a different historical version
  9877. ** of the database file. When a [database connection] begins a read
  9878. ** transaction, that connection sees an unchanging copy of the database
  9879. ** as it existed for the point in time when the transaction first started.
  9880. ** Subsequent changes to the database from other connections are not seen
  9881. ** by the reader until a new read transaction is started.
  9882. **
  9883. ** The sqlite3_snapshot object records state information about an historical
  9884. ** version of the database file so that it is possible to later open a new read
  9885. ** transaction that sees that historical version of the database rather than
  9886. ** the most recent version.
  9887. */
  9888. typedef struct sqlite3_snapshot {
  9889. unsigned char hidden[48];
  9890. } sqlite3_snapshot;
  9891. /*
  9892. ** CAPI3REF: Record A Database Snapshot
  9893. ** CONSTRUCTOR: sqlite3_snapshot
  9894. **
  9895. ** ^The [sqlite3_snapshot_get(D,S,P)] interface attempts to make a
  9896. ** new [sqlite3_snapshot] object that records the current state of
  9897. ** schema S in database connection D. ^On success, the
  9898. ** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly
  9899. ** created [sqlite3_snapshot] object into *P and returns SQLITE_OK.
  9900. ** If there is not already a read-transaction open on schema S when
  9901. ** this function is called, one is opened automatically.
  9902. **
  9903. ** The following must be true for this function to succeed. If any of
  9904. ** the following statements are false when sqlite3_snapshot_get() is
  9905. ** called, SQLITE_ERROR is returned. The final value of *P is undefined
  9906. ** in this case.
  9907. **
  9908. ** <ul>
  9909. ** <li> The database handle must not be in [autocommit mode].
  9910. **
  9911. ** <li> Schema S of [database connection] D must be a [WAL mode] database.
  9912. **
  9913. ** <li> There must not be a write transaction open on schema S of database
  9914. ** connection D.
  9915. **
  9916. ** <li> One or more transactions must have been written to the current wal
  9917. ** file since it was created on disk (by any connection). This means
  9918. ** that a snapshot cannot be taken on a wal mode database with no wal
  9919. ** file immediately after it is first opened. At least one transaction
  9920. ** must be written to it first.
  9921. ** </ul>
  9922. **
  9923. ** This function may also return SQLITE_NOMEM. If it is called with the
  9924. ** database handle in autocommit mode but fails for some other reason,
  9925. ** whether or not a read transaction is opened on schema S is undefined.
  9926. **
  9927. ** The [sqlite3_snapshot] object returned from a successful call to
  9928. ** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()]
  9929. ** to avoid a memory leak.
  9930. **
  9931. ** The [sqlite3_snapshot_get()] interface is only available when the
  9932. ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
  9933. */
  9934. SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_get(
  9935. sqlite3 *db,
  9936. const char *zSchema,
  9937. sqlite3_snapshot **ppSnapshot
  9938. );
  9939. /*
  9940. ** CAPI3REF: Start a read transaction on an historical snapshot
  9941. ** METHOD: sqlite3_snapshot
  9942. **
  9943. ** ^The [sqlite3_snapshot_open(D,S,P)] interface either starts a new read
  9944. ** transaction or upgrades an existing one for schema S of
  9945. ** [database connection] D such that the read transaction refers to
  9946. ** historical [snapshot] P, rather than the most recent change to the
  9947. ** database. ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK
  9948. ** on success or an appropriate [error code] if it fails.
  9949. **
  9950. ** ^In order to succeed, the database connection must not be in
  9951. ** [autocommit mode] when [sqlite3_snapshot_open(D,S,P)] is called. If there
  9952. ** is already a read transaction open on schema S, then the database handle
  9953. ** must have no active statements (SELECT statements that have been passed
  9954. ** to sqlite3_step() but not sqlite3_reset() or sqlite3_finalize()).
  9955. ** SQLITE_ERROR is returned if either of these conditions is violated, or
  9956. ** if schema S does not exist, or if the snapshot object is invalid.
  9957. **
  9958. ** ^A call to sqlite3_snapshot_open() will fail to open if the specified
  9959. ** snapshot has been overwritten by a [checkpoint]. In this case
  9960. ** SQLITE_ERROR_SNAPSHOT is returned.
  9961. **
  9962. ** If there is already a read transaction open when this function is
  9963. ** invoked, then the same read transaction remains open (on the same
  9964. ** database snapshot) if SQLITE_ERROR, SQLITE_BUSY or SQLITE_ERROR_SNAPSHOT
  9965. ** is returned. If another error code - for example SQLITE_PROTOCOL or an
  9966. ** SQLITE_IOERR error code - is returned, then the final state of the
  9967. ** read transaction is undefined. If SQLITE_OK is returned, then the
  9968. ** read transaction is now open on database snapshot P.
  9969. **
  9970. ** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the
  9971. ** database connection D does not know that the database file for
  9972. ** schema S is in [WAL mode]. A database connection might not know
  9973. ** that the database file is in [WAL mode] if there has been no prior
  9974. ** I/O on that database connection, or if the database entered [WAL mode]
  9975. ** after the most recent I/O on the database connection.)^
  9976. ** (Hint: Run "[PRAGMA application_id]" against a newly opened
  9977. ** database connection in order to make it ready to use snapshots.)
  9978. **
  9979. ** The [sqlite3_snapshot_open()] interface is only available when the
  9980. ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
  9981. */
  9982. SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_open(
  9983. sqlite3 *db,
  9984. const char *zSchema,
  9985. sqlite3_snapshot *pSnapshot
  9986. );
  9987. /*
  9988. ** CAPI3REF: Destroy a snapshot
  9989. ** DESTRUCTOR: sqlite3_snapshot
  9990. **
  9991. ** ^The [sqlite3_snapshot_free(P)] interface destroys [sqlite3_snapshot] P.
  9992. ** The application must eventually free every [sqlite3_snapshot] object
  9993. ** using this routine to avoid a memory leak.
  9994. **
  9995. ** The [sqlite3_snapshot_free()] interface is only available when the
  9996. ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
  9997. */
  9998. SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_snapshot_free(sqlite3_snapshot*);
  9999. /*
  10000. ** CAPI3REF: Compare the ages of two snapshot handles.
  10001. ** METHOD: sqlite3_snapshot
  10002. **
  10003. ** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages
  10004. ** of two valid snapshot handles.
  10005. **
  10006. ** If the two snapshot handles are not associated with the same database
  10007. ** file, the result of the comparison is undefined.
  10008. **
  10009. ** Additionally, the result of the comparison is only valid if both of the
  10010. ** snapshot handles were obtained by calling sqlite3_snapshot_get() since the
  10011. ** last time the wal file was deleted. The wal file is deleted when the
  10012. ** database is changed back to rollback mode or when the number of database
  10013. ** clients drops to zero. If either snapshot handle was obtained before the
  10014. ** wal file was last deleted, the value returned by this function
  10015. ** is undefined.
  10016. **
  10017. ** Otherwise, this API returns a negative value if P1 refers to an older
  10018. ** snapshot than P2, zero if the two handles refer to the same database
  10019. ** snapshot, and a positive value if P1 is a newer snapshot than P2.
  10020. **
  10021. ** This interface is only available if SQLite is compiled with the
  10022. ** [SQLITE_ENABLE_SNAPSHOT] option.
  10023. */
  10024. SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp(
  10025. sqlite3_snapshot *p1,
  10026. sqlite3_snapshot *p2
  10027. );
  10028. /*
  10029. ** CAPI3REF: Recover snapshots from a wal file
  10030. ** METHOD: sqlite3_snapshot
  10031. **
  10032. ** If a [WAL file] remains on disk after all database connections close
  10033. ** (either through the use of the [SQLITE_FCNTL_PERSIST_WAL] [file control]
  10034. ** or because the last process to have the database opened exited without
  10035. ** calling [sqlite3_close()]) and a new connection is subsequently opened
  10036. ** on that database and [WAL file], the [sqlite3_snapshot_open()] interface
  10037. ** will only be able to open the last transaction added to the WAL file
  10038. ** even though the WAL file contains other valid transactions.
  10039. **
  10040. ** This function attempts to scan the WAL file associated with database zDb
  10041. ** of database handle db and make all valid snapshots available to
  10042. ** sqlite3_snapshot_open(). It is an error if there is already a read
  10043. ** transaction open on the database, or if the database is not a WAL mode
  10044. ** database.
  10045. **
  10046. ** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
  10047. **
  10048. ** This interface is only available if SQLite is compiled with the
  10049. ** [SQLITE_ENABLE_SNAPSHOT] option.
  10050. */
  10051. SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
  10052. /*
  10053. ** CAPI3REF: Serialize a database
  10054. **
  10055. ** The sqlite3_serialize(D,S,P,F) interface returns a pointer to memory
  10056. ** that is a serialization of the S database on [database connection] D.
  10057. ** If P is not a NULL pointer, then the size of the database in bytes
  10058. ** is written into *P.
  10059. **
  10060. ** For an ordinary on-disk database file, the serialization is just a
  10061. ** copy of the disk file. For an in-memory database or a "TEMP" database,
  10062. ** the serialization is the same sequence of bytes which would be written
  10063. ** to disk if that database where backed up to disk.
  10064. **
  10065. ** The usual case is that sqlite3_serialize() copies the serialization of
  10066. ** the database into memory obtained from [sqlite3_malloc64()] and returns
  10067. ** a pointer to that memory. The caller is responsible for freeing the
  10068. ** returned value to avoid a memory leak. However, if the F argument
  10069. ** contains the SQLITE_SERIALIZE_NOCOPY bit, then no memory allocations
  10070. ** are made, and the sqlite3_serialize() function will return a pointer
  10071. ** to the contiguous memory representation of the database that SQLite
  10072. ** is currently using for that database, or NULL if the no such contiguous
  10073. ** memory representation of the database exists. A contiguous memory
  10074. ** representation of the database will usually only exist if there has
  10075. ** been a prior call to [sqlite3_deserialize(D,S,...)] with the same
  10076. ** values of D and S.
  10077. ** The size of the database is written into *P even if the
  10078. ** SQLITE_SERIALIZE_NOCOPY bit is set but no contiguous copy
  10079. ** of the database exists.
  10080. **
  10081. ** A call to sqlite3_serialize(D,S,P,F) might return NULL even if the
  10082. ** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory
  10083. ** allocation error occurs.
  10084. **
  10085. ** This interface is omitted if SQLite is compiled with the
  10086. ** [SQLITE_OMIT_DESERIALIZE] option.
  10087. */
  10088. SQLITE_API unsigned char *sqlite3_serialize(
  10089. sqlite3 *db, /* The database connection */
  10090. const char *zSchema, /* Which DB to serialize. ex: "main", "temp", ... */
  10091. sqlite3_int64 *piSize, /* Write size of the DB here, if not NULL */
  10092. unsigned int mFlags /* Zero or more SQLITE_SERIALIZE_* flags */
  10093. );
  10094. /*
  10095. ** CAPI3REF: Flags for sqlite3_serialize
  10096. **
  10097. ** Zero or more of the following constants can be OR-ed together for
  10098. ** the F argument to [sqlite3_serialize(D,S,P,F)].
  10099. **
  10100. ** SQLITE_SERIALIZE_NOCOPY means that [sqlite3_serialize()] will return
  10101. ** a pointer to contiguous in-memory database that it is currently using,
  10102. ** without making a copy of the database. If SQLite is not currently using
  10103. ** a contiguous in-memory database, then this option causes
  10104. ** [sqlite3_serialize()] to return a NULL pointer. SQLite will only be
  10105. ** using a contiguous in-memory database if it has been initialized by a
  10106. ** prior call to [sqlite3_deserialize()].
  10107. */
  10108. #define SQLITE_SERIALIZE_NOCOPY 0x001 /* Do no memory allocations */
  10109. /*
  10110. ** CAPI3REF: Deserialize a database
  10111. **
  10112. ** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the
  10113. ** [database connection] D to disconnect from database S and then
  10114. ** reopen S as an in-memory database based on the serialization contained
  10115. ** in P. The serialized database P is N bytes in size. M is the size of
  10116. ** the buffer P, which might be larger than N. If M is larger than N, and
  10117. ** the SQLITE_DESERIALIZE_READONLY bit is not set in F, then SQLite is
  10118. ** permitted to add content to the in-memory database as long as the total
  10119. ** size does not exceed M bytes.
  10120. **
  10121. ** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will
  10122. ** invoke sqlite3_free() on the serialization buffer when the database
  10123. ** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then
  10124. ** SQLite will try to increase the buffer size using sqlite3_realloc64()
  10125. ** if writes on the database cause it to grow larger than M bytes.
  10126. **
  10127. ** The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the
  10128. ** database is currently in a read transaction or is involved in a backup
  10129. ** operation.
  10130. **
  10131. ** It is not possible to deserialized into the TEMP database. If the
  10132. ** S argument to sqlite3_deserialize(D,S,P,N,M,F) is "temp" then the
  10133. ** function returns SQLITE_ERROR.
  10134. **
  10135. ** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the
  10136. ** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then
  10137. ** [sqlite3_free()] is invoked on argument P prior to returning.
  10138. **
  10139. ** This interface is omitted if SQLite is compiled with the
  10140. ** [SQLITE_OMIT_DESERIALIZE] option.
  10141. */
  10142. SQLITE_API int sqlite3_deserialize(
  10143. sqlite3 *db, /* The database connection */
  10144. const char *zSchema, /* Which DB to reopen with the deserialization */
  10145. unsigned char *pData, /* The serialized database content */
  10146. sqlite3_int64 szDb, /* Number bytes in the deserialization */
  10147. sqlite3_int64 szBuf, /* Total size of buffer pData[] */
  10148. unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */
  10149. );
  10150. /*
  10151. ** CAPI3REF: Flags for sqlite3_deserialize()
  10152. **
  10153. ** The following are allowed values for 6th argument (the F argument) to
  10154. ** the [sqlite3_deserialize(D,S,P,N,M,F)] interface.
  10155. **
  10156. ** The SQLITE_DESERIALIZE_FREEONCLOSE means that the database serialization
  10157. ** in the P argument is held in memory obtained from [sqlite3_malloc64()]
  10158. ** and that SQLite should take ownership of this memory and automatically
  10159. ** free it when it has finished using it. Without this flag, the caller
  10160. ** is responsible for freeing any dynamically allocated memory.
  10161. **
  10162. ** The SQLITE_DESERIALIZE_RESIZEABLE flag means that SQLite is allowed to
  10163. ** grow the size of the database using calls to [sqlite3_realloc64()]. This
  10164. ** flag should only be used if SQLITE_DESERIALIZE_FREEONCLOSE is also used.
  10165. ** Without this flag, the deserialized database cannot increase in size beyond
  10166. ** the number of bytes specified by the M parameter.
  10167. **
  10168. ** The SQLITE_DESERIALIZE_READONLY flag means that the deserialized database
  10169. ** should be treated as read-only.
  10170. */
  10171. #define SQLITE_DESERIALIZE_FREEONCLOSE 1 /* Call sqlite3_free() on close */
  10172. #define SQLITE_DESERIALIZE_RESIZEABLE 2 /* Resize using sqlite3_realloc64() */
  10173. #define SQLITE_DESERIALIZE_READONLY 4 /* Database is read-only */
  10174. /*
  10175. ** Undo the hack that converts floating point types to integer for
  10176. ** builds on processors without floating point support.
  10177. */
  10178. #ifdef SQLITE_OMIT_FLOATING_POINT
  10179. # undef double
  10180. #endif
  10181. #ifdef __cplusplus
  10182. } /* End of the 'extern "C"' block */
  10183. #endif
  10184. #endif /* SQLITE3_H */
  10185. /******** Begin file sqlite3rtree.h *********/
  10186. /*
  10187. ** 2010 August 30
  10188. **
  10189. ** The author disclaims copyright to this source code. In place of
  10190. ** a legal notice, here is a blessing:
  10191. **
  10192. ** May you do good and not evil.
  10193. ** May you find forgiveness for yourself and forgive others.
  10194. ** May you share freely, never taking more than you give.
  10195. **
  10196. *************************************************************************
  10197. */
  10198. #ifndef _SQLITE3RTREE_H_
  10199. #define _SQLITE3RTREE_H_
  10200. #ifdef __cplusplus
  10201. extern "C" {
  10202. #endif
  10203. typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry;
  10204. typedef struct sqlite3_rtree_query_info sqlite3_rtree_query_info;
  10205. /* The double-precision datatype used by RTree depends on the
  10206. ** SQLITE_RTREE_INT_ONLY compile-time option.
  10207. */
  10208. #ifdef SQLITE_RTREE_INT_ONLY
  10209. typedef sqlite3_int64 sqlite3_rtree_dbl;
  10210. #else
  10211. typedef double sqlite3_rtree_dbl;
  10212. #endif
  10213. /*
  10214. ** Register a geometry callback named zGeom that can be used as part of an
  10215. ** R-Tree geometry query as follows:
  10216. **
  10217. ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)
  10218. */
  10219. SQLITE_API int sqlite3_rtree_geometry_callback(
  10220. sqlite3 *db,
  10221. const char *zGeom,
  10222. int (*xGeom)(sqlite3_rtree_geometry*, int, sqlite3_rtree_dbl*,int*),
  10223. void *pContext
  10224. );
  10225. /*
  10226. ** A pointer to a structure of the following type is passed as the first
  10227. ** argument to callbacks registered using rtree_geometry_callback().
  10228. */
  10229. struct sqlite3_rtree_geometry {
  10230. void *pContext; /* Copy of pContext passed to s_r_g_c() */
  10231. int nParam; /* Size of array aParam[] */
  10232. sqlite3_rtree_dbl *aParam; /* Parameters passed to SQL geom function */
  10233. void *pUser; /* Callback implementation user data */
  10234. void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */
  10235. };
  10236. /*
  10237. ** Register a 2nd-generation geometry callback named zScore that can be
  10238. ** used as part of an R-Tree geometry query as follows:
  10239. **
  10240. ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zQueryFunc(... params ...)
  10241. */
  10242. SQLITE_API int sqlite3_rtree_query_callback(
  10243. sqlite3 *db,
  10244. const char *zQueryFunc,
  10245. int (*xQueryFunc)(sqlite3_rtree_query_info*),
  10246. void *pContext,
  10247. void (*xDestructor)(void*)
  10248. );
  10249. /*
  10250. ** A pointer to a structure of the following type is passed as the
  10251. ** argument to scored geometry callback registered using
  10252. ** sqlite3_rtree_query_callback().
  10253. **
  10254. ** Note that the first 5 fields of this structure are identical to
  10255. ** sqlite3_rtree_geometry. This structure is a subclass of
  10256. ** sqlite3_rtree_geometry.
  10257. */
  10258. struct sqlite3_rtree_query_info {
  10259. void *pContext; /* pContext from when function registered */
  10260. int nParam; /* Number of function parameters */
  10261. sqlite3_rtree_dbl *aParam; /* value of function parameters */
  10262. void *pUser; /* callback can use this, if desired */
  10263. void (*xDelUser)(void*); /* function to free pUser */
  10264. sqlite3_rtree_dbl *aCoord; /* Coordinates of node or entry to check */
  10265. unsigned int *anQueue; /* Number of pending entries in the queue */
  10266. int nCoord; /* Number of coordinates */
  10267. int iLevel; /* Level of current node or entry */
  10268. int mxLevel; /* The largest iLevel value in the tree */
  10269. sqlite3_int64 iRowid; /* Rowid for current entry */
  10270. sqlite3_rtree_dbl rParentScore; /* Score of parent node */
  10271. int eParentWithin; /* Visibility of parent node */
  10272. int eWithin; /* OUT: Visibility */
  10273. sqlite3_rtree_dbl rScore; /* OUT: Write the score here */
  10274. /* The following fields are only available in 3.8.11 and later */
  10275. sqlite3_value **apSqlParam; /* Original SQL values of parameters */
  10276. };
  10277. /*
  10278. ** Allowed values for sqlite3_rtree_query.eWithin and .eParentWithin.
  10279. */
  10280. #define NOT_WITHIN 0 /* Object completely outside of query region */
  10281. #define PARTLY_WITHIN 1 /* Object partially overlaps query region */
  10282. #define FULLY_WITHIN 2 /* Object fully contained within query region */
  10283. #ifdef __cplusplus
  10284. } /* end of the 'extern "C"' block */
  10285. #endif
  10286. #endif /* ifndef _SQLITE3RTREE_H_ */
  10287. /******** End of sqlite3rtree.h *********/
  10288. /******** Begin file sqlite3session.h *********/
  10289. #if !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION)
  10290. #define __SQLITESESSION_H_ 1
  10291. /*
  10292. ** Make sure we can call this stuff from C++.
  10293. */
  10294. #ifdef __cplusplus
  10295. extern "C" {
  10296. #endif
  10297. /*
  10298. ** CAPI3REF: Session Object Handle
  10299. **
  10300. ** An instance of this object is a [session] that can be used to
  10301. ** record changes to a database.
  10302. */
  10303. typedef struct sqlite3_session sqlite3_session;
  10304. /*
  10305. ** CAPI3REF: Changeset Iterator Handle
  10306. **
  10307. ** An instance of this object acts as a cursor for iterating
  10308. ** over the elements of a [changeset] or [patchset].
  10309. */
  10310. typedef struct sqlite3_changeset_iter sqlite3_changeset_iter;
  10311. /*
  10312. ** CAPI3REF: Create A New Session Object
  10313. ** CONSTRUCTOR: sqlite3_session
  10314. **
  10315. ** Create a new session object attached to database handle db. If successful,
  10316. ** a pointer to the new object is written to *ppSession and SQLITE_OK is
  10317. ** returned. If an error occurs, *ppSession is set to NULL and an SQLite
  10318. ** error code (e.g. SQLITE_NOMEM) is returned.
  10319. **
  10320. ** It is possible to create multiple session objects attached to a single
  10321. ** database handle.
  10322. **
  10323. ** Session objects created using this function should be deleted using the
  10324. ** [sqlite3session_delete()] function before the database handle that they
  10325. ** are attached to is itself closed. If the database handle is closed before
  10326. ** the session object is deleted, then the results of calling any session
  10327. ** module function, including [sqlite3session_delete()] on the session object
  10328. ** are undefined.
  10329. **
  10330. ** Because the session module uses the [sqlite3_preupdate_hook()] API, it
  10331. ** is not possible for an application to register a pre-update hook on a
  10332. ** database handle that has one or more session objects attached. Nor is
  10333. ** it possible to create a session object attached to a database handle for
  10334. ** which a pre-update hook is already defined. The results of attempting
  10335. ** either of these things are undefined.
  10336. **
  10337. ** The session object will be used to create changesets for tables in
  10338. ** database zDb, where zDb is either "main", or "temp", or the name of an
  10339. ** attached database. It is not an error if database zDb is not attached
  10340. ** to the database when the session object is created.
  10341. */
  10342. SQLITE_API int sqlite3session_create(
  10343. sqlite3 *db, /* Database handle */
  10344. const char *zDb, /* Name of db (e.g. "main") */
  10345. sqlite3_session **ppSession /* OUT: New session object */
  10346. );
  10347. /*
  10348. ** CAPI3REF: Delete A Session Object
  10349. ** DESTRUCTOR: sqlite3_session
  10350. **
  10351. ** Delete a session object previously allocated using
  10352. ** [sqlite3session_create()]. Once a session object has been deleted, the
  10353. ** results of attempting to use pSession with any other session module
  10354. ** function are undefined.
  10355. **
  10356. ** Session objects must be deleted before the database handle to which they
  10357. ** are attached is closed. Refer to the documentation for
  10358. ** [sqlite3session_create()] for details.
  10359. */
  10360. SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
  10361. /*
  10362. ** CAPIREF: Conigure a Session Object
  10363. ** METHOD: sqlite3_session
  10364. **
  10365. ** This method is used to configure a session object after it has been
  10366. ** created. At present the only valid value for the second parameter is
  10367. ** [SQLITE_SESSION_OBJCONFIG_SIZE].
  10368. **
  10369. ** Arguments for sqlite3session_object_config()
  10370. **
  10371. ** The following values may passed as the the 4th parameter to
  10372. ** sqlite3session_object_config().
  10373. **
  10374. ** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
  10375. ** This option is used to set, clear or query the flag that enables
  10376. ** the [sqlite3session_changeset_size()] API. Because it imposes some
  10377. ** computational overhead, this API is disabled by default. Argument
  10378. ** pArg must point to a value of type (int). If the value is initially
  10379. ** 0, then the sqlite3session_changeset_size() API is disabled. If it
  10380. ** is greater than 0, then the same API is enabled. Or, if the initial
  10381. ** value is less than zero, no change is made. In all cases the (int)
  10382. ** variable is set to 1 if the sqlite3session_changeset_size() API is
  10383. ** enabled following the current call, or 0 otherwise.
  10384. **
  10385. ** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
  10386. ** the first table has been attached to the session object.
  10387. */
  10388. SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
  10389. /*
  10390. */
  10391. #define SQLITE_SESSION_OBJCONFIG_SIZE 1
  10392. /*
  10393. ** CAPI3REF: Enable Or Disable A Session Object
  10394. ** METHOD: sqlite3_session
  10395. **
  10396. ** Enable or disable the recording of changes by a session object. When
  10397. ** enabled, a session object records changes made to the database. When
  10398. ** disabled - it does not. A newly created session object is enabled.
  10399. ** Refer to the documentation for [sqlite3session_changeset()] for further
  10400. ** details regarding how enabling and disabling a session object affects
  10401. ** the eventual changesets.
  10402. **
  10403. ** Passing zero to this function disables the session. Passing a value
  10404. ** greater than zero enables it. Passing a value less than zero is a
  10405. ** no-op, and may be used to query the current state of the session.
  10406. **
  10407. ** The return value indicates the final state of the session object: 0 if
  10408. ** the session is disabled, or 1 if it is enabled.
  10409. */
  10410. SQLITE_API int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
  10411. /*
  10412. ** CAPI3REF: Set Or Clear the Indirect Change Flag
  10413. ** METHOD: sqlite3_session
  10414. **
  10415. ** Each change recorded by a session object is marked as either direct or
  10416. ** indirect. A change is marked as indirect if either:
  10417. **
  10418. ** <ul>
  10419. ** <li> The session object "indirect" flag is set when the change is
  10420. ** made, or
  10421. ** <li> The change is made by an SQL trigger or foreign key action
  10422. ** instead of directly as a result of a users SQL statement.
  10423. ** </ul>
  10424. **
  10425. ** If a single row is affected by more than one operation within a session,
  10426. ** then the change is considered indirect if all operations meet the criteria
  10427. ** for an indirect change above, or direct otherwise.
  10428. **
  10429. ** This function is used to set, clear or query the session object indirect
  10430. ** flag. If the second argument passed to this function is zero, then the
  10431. ** indirect flag is cleared. If it is greater than zero, the indirect flag
  10432. ** is set. Passing a value less than zero does not modify the current value
  10433. ** of the indirect flag, and may be used to query the current state of the
  10434. ** indirect flag for the specified session object.
  10435. **
  10436. ** The return value indicates the final state of the indirect flag: 0 if
  10437. ** it is clear, or 1 if it is set.
  10438. */
  10439. SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
  10440. /*
  10441. ** CAPI3REF: Attach A Table To A Session Object
  10442. ** METHOD: sqlite3_session
  10443. **
  10444. ** If argument zTab is not NULL, then it is the name of a table to attach
  10445. ** to the session object passed as the first argument. All subsequent changes
  10446. ** made to the table while the session object is enabled will be recorded. See
  10447. ** documentation for [sqlite3session_changeset()] for further details.
  10448. **
  10449. ** Or, if argument zTab is NULL, then changes are recorded for all tables
  10450. ** in the database. If additional tables are added to the database (by
  10451. ** executing "CREATE TABLE" statements) after this call is made, changes for
  10452. ** the new tables are also recorded.
  10453. **
  10454. ** Changes can only be recorded for tables that have a PRIMARY KEY explicitly
  10455. ** defined as part of their CREATE TABLE statement. It does not matter if the
  10456. ** PRIMARY KEY is an "INTEGER PRIMARY KEY" (rowid alias) or not. The PRIMARY
  10457. ** KEY may consist of a single column, or may be a composite key.
  10458. **
  10459. ** It is not an error if the named table does not exist in the database. Nor
  10460. ** is it an error if the named table does not have a PRIMARY KEY. However,
  10461. ** no changes will be recorded in either of these scenarios.
  10462. **
  10463. ** Changes are not recorded for individual rows that have NULL values stored
  10464. ** in one or more of their PRIMARY KEY columns.
  10465. **
  10466. ** SQLITE_OK is returned if the call completes without error. Or, if an error
  10467. ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
  10468. **
  10469. ** <h3>Special sqlite_stat1 Handling</h3>
  10470. **
  10471. ** As of SQLite version 3.22.0, the "sqlite_stat1" table is an exception to
  10472. ** some of the rules above. In SQLite, the schema of sqlite_stat1 is:
  10473. ** <pre>
  10474. ** &nbsp; CREATE TABLE sqlite_stat1(tbl,idx,stat)
  10475. ** </pre>
  10476. **
  10477. ** Even though sqlite_stat1 does not have a PRIMARY KEY, changes are
  10478. ** recorded for it as if the PRIMARY KEY is (tbl,idx). Additionally, changes
  10479. ** are recorded for rows for which (idx IS NULL) is true. However, for such
  10480. ** rows a zero-length blob (SQL value X'') is stored in the changeset or
  10481. ** patchset instead of a NULL value. This allows such changesets to be
  10482. ** manipulated by legacy implementations of sqlite3changeset_invert(),
  10483. ** concat() and similar.
  10484. **
  10485. ** The sqlite3changeset_apply() function automatically converts the
  10486. ** zero-length blob back to a NULL value when updating the sqlite_stat1
  10487. ** table. However, if the application calls sqlite3changeset_new(),
  10488. ** sqlite3changeset_old() or sqlite3changeset_conflict on a changeset
  10489. ** iterator directly (including on a changeset iterator passed to a
  10490. ** conflict-handler callback) then the X'' value is returned. The application
  10491. ** must translate X'' to NULL itself if required.
  10492. **
  10493. ** Legacy (older than 3.22.0) versions of the sessions module cannot capture
  10494. ** changes made to the sqlite_stat1 table. Legacy versions of the
  10495. ** sqlite3changeset_apply() function silently ignore any modifications to the
  10496. ** sqlite_stat1 table that are part of a changeset or patchset.
  10497. */
  10498. SQLITE_API int sqlite3session_attach(
  10499. sqlite3_session *pSession, /* Session object */
  10500. const char *zTab /* Table name */
  10501. );
  10502. /*
  10503. ** CAPI3REF: Set a table filter on a Session Object.
  10504. ** METHOD: sqlite3_session
  10505. **
  10506. ** The second argument (xFilter) is the "filter callback". For changes to rows
  10507. ** in tables that are not attached to the Session object, the filter is called
  10508. ** to determine whether changes to the table's rows should be tracked or not.
  10509. ** If xFilter returns 0, changes are not tracked. Note that once a table is
  10510. ** attached, xFilter will not be called again.
  10511. */
  10512. SQLITE_API void sqlite3session_table_filter(
  10513. sqlite3_session *pSession, /* Session object */
  10514. int(*xFilter)(
  10515. void *pCtx, /* Copy of third arg to _filter_table() */
  10516. const char *zTab /* Table name */
  10517. ),
  10518. void *pCtx /* First argument passed to xFilter */
  10519. );
  10520. /*
  10521. ** CAPI3REF: Generate A Changeset From A Session Object
  10522. ** METHOD: sqlite3_session
  10523. **
  10524. ** Obtain a changeset containing changes to the tables attached to the
  10525. ** session object passed as the first argument. If successful,
  10526. ** set *ppChangeset to point to a buffer containing the changeset
  10527. ** and *pnChangeset to the size of the changeset in bytes before returning
  10528. ** SQLITE_OK. If an error occurs, set both *ppChangeset and *pnChangeset to
  10529. ** zero and return an SQLite error code.
  10530. **
  10531. ** A changeset consists of zero or more INSERT, UPDATE and/or DELETE changes,
  10532. ** each representing a change to a single row of an attached table. An INSERT
  10533. ** change contains the values of each field of a new database row. A DELETE
  10534. ** contains the original values of each field of a deleted database row. An
  10535. ** UPDATE change contains the original values of each field of an updated
  10536. ** database row along with the updated values for each updated non-primary-key
  10537. ** column. It is not possible for an UPDATE change to represent a change that
  10538. ** modifies the values of primary key columns. If such a change is made, it
  10539. ** is represented in a changeset as a DELETE followed by an INSERT.
  10540. **
  10541. ** Changes are not recorded for rows that have NULL values stored in one or
  10542. ** more of their PRIMARY KEY columns. If such a row is inserted or deleted,
  10543. ** no corresponding change is present in the changesets returned by this
  10544. ** function. If an existing row with one or more NULL values stored in
  10545. ** PRIMARY KEY columns is updated so that all PRIMARY KEY columns are non-NULL,
  10546. ** only an INSERT is appears in the changeset. Similarly, if an existing row
  10547. ** with non-NULL PRIMARY KEY values is updated so that one or more of its
  10548. ** PRIMARY KEY columns are set to NULL, the resulting changeset contains a
  10549. ** DELETE change only.
  10550. **
  10551. ** The contents of a changeset may be traversed using an iterator created
  10552. ** using the [sqlite3changeset_start()] API. A changeset may be applied to
  10553. ** a database with a compatible schema using the [sqlite3changeset_apply()]
  10554. ** API.
  10555. **
  10556. ** Within a changeset generated by this function, all changes related to a
  10557. ** single table are grouped together. In other words, when iterating through
  10558. ** a changeset or when applying a changeset to a database, all changes related
  10559. ** to a single table are processed before moving on to the next table. Tables
  10560. ** are sorted in the same order in which they were attached (or auto-attached)
  10561. ** to the sqlite3_session object. The order in which the changes related to
  10562. ** a single table are stored is undefined.
  10563. **
  10564. ** Following a successful call to this function, it is the responsibility of
  10565. ** the caller to eventually free the buffer that *ppChangeset points to using
  10566. ** [sqlite3_free()].
  10567. **
  10568. ** <h3>Changeset Generation</h3>
  10569. **
  10570. ** Once a table has been attached to a session object, the session object
  10571. ** records the primary key values of all new rows inserted into the table.
  10572. ** It also records the original primary key and other column values of any
  10573. ** deleted or updated rows. For each unique primary key value, data is only
  10574. ** recorded once - the first time a row with said primary key is inserted,
  10575. ** updated or deleted in the lifetime of the session.
  10576. **
  10577. ** There is one exception to the previous paragraph: when a row is inserted,
  10578. ** updated or deleted, if one or more of its primary key columns contain a
  10579. ** NULL value, no record of the change is made.
  10580. **
  10581. ** The session object therefore accumulates two types of records - those
  10582. ** that consist of primary key values only (created when the user inserts
  10583. ** a new record) and those that consist of the primary key values and the
  10584. ** original values of other table columns (created when the users deletes
  10585. ** or updates a record).
  10586. **
  10587. ** When this function is called, the requested changeset is created using
  10588. ** both the accumulated records and the current contents of the database
  10589. ** file. Specifically:
  10590. **
  10591. ** <ul>
  10592. ** <li> For each record generated by an insert, the database is queried
  10593. ** for a row with a matching primary key. If one is found, an INSERT
  10594. ** change is added to the changeset. If no such row is found, no change
  10595. ** is added to the changeset.
  10596. **
  10597. ** <li> For each record generated by an update or delete, the database is
  10598. ** queried for a row with a matching primary key. If such a row is
  10599. ** found and one or more of the non-primary key fields have been
  10600. ** modified from their original values, an UPDATE change is added to
  10601. ** the changeset. Or, if no such row is found in the table, a DELETE
  10602. ** change is added to the changeset. If there is a row with a matching
  10603. ** primary key in the database, but all fields contain their original
  10604. ** values, no change is added to the changeset.
  10605. ** </ul>
  10606. **
  10607. ** This means, amongst other things, that if a row is inserted and then later
  10608. ** deleted while a session object is active, neither the insert nor the delete
  10609. ** will be present in the changeset. Or if a row is deleted and then later a
  10610. ** row with the same primary key values inserted while a session object is
  10611. ** active, the resulting changeset will contain an UPDATE change instead of
  10612. ** a DELETE and an INSERT.
  10613. **
  10614. ** When a session object is disabled (see the [sqlite3session_enable()] API),
  10615. ** it does not accumulate records when rows are inserted, updated or deleted.
  10616. ** This may appear to have some counter-intuitive effects if a single row
  10617. ** is written to more than once during a session. For example, if a row
  10618. ** is inserted while a session object is enabled, then later deleted while
  10619. ** the same session object is disabled, no INSERT record will appear in the
  10620. ** changeset, even though the delete took place while the session was disabled.
  10621. ** Or, if one field of a row is updated while a session is disabled, and
  10622. ** another field of the same row is updated while the session is enabled, the
  10623. ** resulting changeset will contain an UPDATE change that updates both fields.
  10624. */
  10625. SQLITE_API int sqlite3session_changeset(
  10626. sqlite3_session *pSession, /* Session object */
  10627. int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */
  10628. void **ppChangeset /* OUT: Buffer containing changeset */
  10629. );
  10630. /*
  10631. ** CAPI3REF: Return An Upper-limit For The Size Of The Changeset
  10632. ** METHOD: sqlite3_session
  10633. **
  10634. ** By default, this function always returns 0. For it to return
  10635. ** a useful result, the sqlite3_session object must have been configured
  10636. ** to enable this API using sqlite3session_object_config() with the
  10637. ** SQLITE_SESSION_OBJCONFIG_SIZE verb.
  10638. **
  10639. ** When enabled, this function returns an upper limit, in bytes, for the size
  10640. ** of the changeset that might be produced if sqlite3session_changeset() were
  10641. ** called. The final changeset size might be equal to or smaller than the
  10642. ** size in bytes returned by this function.
  10643. */
  10644. SQLITE_API sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession);
  10645. /*
  10646. ** CAPI3REF: Load The Difference Between Tables Into A Session
  10647. ** METHOD: sqlite3_session
  10648. **
  10649. ** If it is not already attached to the session object passed as the first
  10650. ** argument, this function attaches table zTbl in the same manner as the
  10651. ** [sqlite3session_attach()] function. If zTbl does not exist, or if it
  10652. ** does not have a primary key, this function is a no-op (but does not return
  10653. ** an error).
  10654. **
  10655. ** Argument zFromDb must be the name of a database ("main", "temp" etc.)
  10656. ** attached to the same database handle as the session object that contains
  10657. ** a table compatible with the table attached to the session by this function.
  10658. ** A table is considered compatible if it:
  10659. **
  10660. ** <ul>
  10661. ** <li> Has the same name,
  10662. ** <li> Has the same set of columns declared in the same order, and
  10663. ** <li> Has the same PRIMARY KEY definition.
  10664. ** </ul>
  10665. **
  10666. ** If the tables are not compatible, SQLITE_SCHEMA is returned. If the tables
  10667. ** are compatible but do not have any PRIMARY KEY columns, it is not an error
  10668. ** but no changes are added to the session object. As with other session
  10669. ** APIs, tables without PRIMARY KEYs are simply ignored.
  10670. **
  10671. ** This function adds a set of changes to the session object that could be
  10672. ** used to update the table in database zFrom (call this the "from-table")
  10673. ** so that its content is the same as the table attached to the session
  10674. ** object (call this the "to-table"). Specifically:
  10675. **
  10676. ** <ul>
  10677. ** <li> For each row (primary key) that exists in the to-table but not in
  10678. ** the from-table, an INSERT record is added to the session object.
  10679. **
  10680. ** <li> For each row (primary key) that exists in the to-table but not in
  10681. ** the from-table, a DELETE record is added to the session object.
  10682. **
  10683. ** <li> For each row (primary key) that exists in both tables, but features
  10684. ** different non-PK values in each, an UPDATE record is added to the
  10685. ** session.
  10686. ** </ul>
  10687. **
  10688. ** To clarify, if this function is called and then a changeset constructed
  10689. ** using [sqlite3session_changeset()], then after applying that changeset to
  10690. ** database zFrom the contents of the two compatible tables would be
  10691. ** identical.
  10692. **
  10693. ** It an error if database zFrom does not exist or does not contain the
  10694. ** required compatible table.
  10695. **
  10696. ** If the operation is successful, SQLITE_OK is returned. Otherwise, an SQLite
  10697. ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
  10698. ** may be set to point to a buffer containing an English language error
  10699. ** message. It is the responsibility of the caller to free this buffer using
  10700. ** sqlite3_free().
  10701. */
  10702. SQLITE_API int sqlite3session_diff(
  10703. sqlite3_session *pSession,
  10704. const char *zFromDb,
  10705. const char *zTbl,
  10706. char **pzErrMsg
  10707. );
  10708. /*
  10709. ** CAPI3REF: Generate A Patchset From A Session Object
  10710. ** METHOD: sqlite3_session
  10711. **
  10712. ** The differences between a patchset and a changeset are that:
  10713. **
  10714. ** <ul>
  10715. ** <li> DELETE records consist of the primary key fields only. The
  10716. ** original values of other fields are omitted.
  10717. ** <li> The original values of any modified fields are omitted from
  10718. ** UPDATE records.
  10719. ** </ul>
  10720. **
  10721. ** A patchset blob may be used with up to date versions of all
  10722. ** sqlite3changeset_xxx API functions except for sqlite3changeset_invert(),
  10723. ** which returns SQLITE_CORRUPT if it is passed a patchset. Similarly,
  10724. ** attempting to use a patchset blob with old versions of the
  10725. ** sqlite3changeset_xxx APIs also provokes an SQLITE_CORRUPT error.
  10726. **
  10727. ** Because the non-primary key "old.*" fields are omitted, no
  10728. ** SQLITE_CHANGESET_DATA conflicts can be detected or reported if a patchset
  10729. ** is passed to the sqlite3changeset_apply() API. Other conflict types work
  10730. ** in the same way as for changesets.
  10731. **
  10732. ** Changes within a patchset are ordered in the same way as for changesets
  10733. ** generated by the sqlite3session_changeset() function (i.e. all changes for
  10734. ** a single table are grouped together, tables appear in the order in which
  10735. ** they were attached to the session object).
  10736. */
  10737. SQLITE_API int sqlite3session_patchset(
  10738. sqlite3_session *pSession, /* Session object */
  10739. int *pnPatchset, /* OUT: Size of buffer at *ppPatchset */
  10740. void **ppPatchset /* OUT: Buffer containing patchset */
  10741. );
  10742. /*
  10743. ** CAPI3REF: Test if a changeset has recorded any changes.
  10744. **
  10745. ** Return non-zero if no changes to attached tables have been recorded by
  10746. ** the session object passed as the first argument. Otherwise, if one or
  10747. ** more changes have been recorded, return zero.
  10748. **
  10749. ** Even if this function returns zero, it is possible that calling
  10750. ** [sqlite3session_changeset()] on the session handle may still return a
  10751. ** changeset that contains no changes. This can happen when a row in
  10752. ** an attached table is modified and then later on the original values
  10753. ** are restored. However, if this function returns non-zero, then it is
  10754. ** guaranteed that a call to sqlite3session_changeset() will return a
  10755. ** changeset containing zero changes.
  10756. */
  10757. SQLITE_API int sqlite3session_isempty(sqlite3_session *pSession);
  10758. /*
  10759. ** CAPI3REF: Query for the amount of heap memory used by a session object.
  10760. **
  10761. ** This API returns the total amount of heap memory in bytes currently
  10762. ** used by the session object passed as the only argument.
  10763. */
  10764. SQLITE_API sqlite3_int64 sqlite3session_memory_used(sqlite3_session *pSession);
  10765. /*
  10766. ** CAPI3REF: Create An Iterator To Traverse A Changeset
  10767. ** CONSTRUCTOR: sqlite3_changeset_iter
  10768. **
  10769. ** Create an iterator used to iterate through the contents of a changeset.
  10770. ** If successful, *pp is set to point to the iterator handle and SQLITE_OK
  10771. ** is returned. Otherwise, if an error occurs, *pp is set to zero and an
  10772. ** SQLite error code is returned.
  10773. **
  10774. ** The following functions can be used to advance and query a changeset
  10775. ** iterator created by this function:
  10776. **
  10777. ** <ul>
  10778. ** <li> [sqlite3changeset_next()]
  10779. ** <li> [sqlite3changeset_op()]
  10780. ** <li> [sqlite3changeset_new()]
  10781. ** <li> [sqlite3changeset_old()]
  10782. ** </ul>
  10783. **
  10784. ** It is the responsibility of the caller to eventually destroy the iterator
  10785. ** by passing it to [sqlite3changeset_finalize()]. The buffer containing the
  10786. ** changeset (pChangeset) must remain valid until after the iterator is
  10787. ** destroyed.
  10788. **
  10789. ** Assuming the changeset blob was created by one of the
  10790. ** [sqlite3session_changeset()], [sqlite3changeset_concat()] or
  10791. ** [sqlite3changeset_invert()] functions, all changes within the changeset
  10792. ** that apply to a single table are grouped together. This means that when
  10793. ** an application iterates through a changeset using an iterator created by
  10794. ** this function, all changes that relate to a single table are visited
  10795. ** consecutively. There is no chance that the iterator will visit a change
  10796. ** the applies to table X, then one for table Y, and then later on visit
  10797. ** another change for table X.
  10798. **
  10799. ** The behavior of sqlite3changeset_start_v2() and its streaming equivalent
  10800. ** may be modified by passing a combination of
  10801. ** [SQLITE_CHANGESETSTART_INVERT | supported flags] as the 4th parameter.
  10802. **
  10803. ** Note that the sqlite3changeset_start_v2() API is still <b>experimental</b>
  10804. ** and therefore subject to change.
  10805. */
  10806. SQLITE_API int sqlite3changeset_start(
  10807. sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */
  10808. int nChangeset, /* Size of changeset blob in bytes */
  10809. void *pChangeset /* Pointer to blob containing changeset */
  10810. );
  10811. SQLITE_API int sqlite3changeset_start_v2(
  10812. sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */
  10813. int nChangeset, /* Size of changeset blob in bytes */
  10814. void *pChangeset, /* Pointer to blob containing changeset */
  10815. int flags /* SESSION_CHANGESETSTART_* flags */
  10816. );
  10817. /*
  10818. ** CAPI3REF: Flags for sqlite3changeset_start_v2
  10819. **
  10820. ** The following flags may passed via the 4th parameter to
  10821. ** [sqlite3changeset_start_v2] and [sqlite3changeset_start_v2_strm]:
  10822. **
  10823. ** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd>
  10824. ** Invert the changeset while iterating through it. This is equivalent to
  10825. ** inverting a changeset using sqlite3changeset_invert() before applying it.
  10826. ** It is an error to specify this flag with a patchset.
  10827. */
  10828. #define SQLITE_CHANGESETSTART_INVERT 0x0002
  10829. /*
  10830. ** CAPI3REF: Advance A Changeset Iterator
  10831. ** METHOD: sqlite3_changeset_iter
  10832. **
  10833. ** This function may only be used with iterators created by the function
  10834. ** [sqlite3changeset_start()]. If it is called on an iterator passed to
  10835. ** a conflict-handler callback by [sqlite3changeset_apply()], SQLITE_MISUSE
  10836. ** is returned and the call has no effect.
  10837. **
  10838. ** Immediately after an iterator is created by sqlite3changeset_start(), it
  10839. ** does not point to any change in the changeset. Assuming the changeset
  10840. ** is not empty, the first call to this function advances the iterator to
  10841. ** point to the first change in the changeset. Each subsequent call advances
  10842. ** the iterator to point to the next change in the changeset (if any). If
  10843. ** no error occurs and the iterator points to a valid change after a call
  10844. ** to sqlite3changeset_next() has advanced it, SQLITE_ROW is returned.
  10845. ** Otherwise, if all changes in the changeset have already been visited,
  10846. ** SQLITE_DONE is returned.
  10847. **
  10848. ** If an error occurs, an SQLite error code is returned. Possible error
  10849. ** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or
  10850. ** SQLITE_NOMEM.
  10851. */
  10852. SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
  10853. /*
  10854. ** CAPI3REF: Obtain The Current Operation From A Changeset Iterator
  10855. ** METHOD: sqlite3_changeset_iter
  10856. **
  10857. ** The pIter argument passed to this function may either be an iterator
  10858. ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
  10859. ** created by [sqlite3changeset_start()]. In the latter case, the most recent
  10860. ** call to [sqlite3changeset_next()] must have returned [SQLITE_ROW]. If this
  10861. ** is not the case, this function returns [SQLITE_MISUSE].
  10862. **
  10863. ** Arguments pOp, pnCol and pzTab may not be NULL. Upon return, three
  10864. ** outputs are set through these pointers:
  10865. **
  10866. ** *pOp is set to one of [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE],
  10867. ** depending on the type of change that the iterator currently points to;
  10868. **
  10869. ** *pnCol is set to the number of columns in the table affected by the change; and
  10870. **
  10871. ** *pzTab is set to point to a nul-terminated utf-8 encoded string containing
  10872. ** the name of the table affected by the current change. The buffer remains
  10873. ** valid until either sqlite3changeset_next() is called on the iterator
  10874. ** or until the conflict-handler function returns.
  10875. **
  10876. ** If pbIndirect is not NULL, then *pbIndirect is set to true (1) if the change
  10877. ** is an indirect change, or false (0) otherwise. See the documentation for
  10878. ** [sqlite3session_indirect()] for a description of direct and indirect
  10879. ** changes.
  10880. **
  10881. ** If no error occurs, SQLITE_OK is returned. If an error does occur, an
  10882. ** SQLite error code is returned. The values of the output variables may not
  10883. ** be trusted in this case.
  10884. */
  10885. SQLITE_API int sqlite3changeset_op(
  10886. sqlite3_changeset_iter *pIter, /* Iterator object */
  10887. const char **pzTab, /* OUT: Pointer to table name */
  10888. int *pnCol, /* OUT: Number of columns in table */
  10889. int *pOp, /* OUT: SQLITE_INSERT, DELETE or UPDATE */
  10890. int *pbIndirect /* OUT: True for an 'indirect' change */
  10891. );
  10892. /*
  10893. ** CAPI3REF: Obtain The Primary Key Definition Of A Table
  10894. ** METHOD: sqlite3_changeset_iter
  10895. **
  10896. ** For each modified table, a changeset includes the following:
  10897. **
  10898. ** <ul>
  10899. ** <li> The number of columns in the table, and
  10900. ** <li> Which of those columns make up the tables PRIMARY KEY.
  10901. ** </ul>
  10902. **
  10903. ** This function is used to find which columns comprise the PRIMARY KEY of
  10904. ** the table modified by the change that iterator pIter currently points to.
  10905. ** If successful, *pabPK is set to point to an array of nCol entries, where
  10906. ** nCol is the number of columns in the table. Elements of *pabPK are set to
  10907. ** 0x01 if the corresponding column is part of the tables primary key, or
  10908. ** 0x00 if it is not.
  10909. **
  10910. ** If argument pnCol is not NULL, then *pnCol is set to the number of columns
  10911. ** in the table.
  10912. **
  10913. ** If this function is called when the iterator does not point to a valid
  10914. ** entry, SQLITE_MISUSE is returned and the output variables zeroed. Otherwise,
  10915. ** SQLITE_OK is returned and the output variables populated as described
  10916. ** above.
  10917. */
  10918. SQLITE_API int sqlite3changeset_pk(
  10919. sqlite3_changeset_iter *pIter, /* Iterator object */
  10920. unsigned char **pabPK, /* OUT: Array of boolean - true for PK cols */
  10921. int *pnCol /* OUT: Number of entries in output array */
  10922. );
  10923. /*
  10924. ** CAPI3REF: Obtain old.* Values From A Changeset Iterator
  10925. ** METHOD: sqlite3_changeset_iter
  10926. **
  10927. ** The pIter argument passed to this function may either be an iterator
  10928. ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
  10929. ** created by [sqlite3changeset_start()]. In the latter case, the most recent
  10930. ** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.
  10931. ** Furthermore, it may only be called if the type of change that the iterator
  10932. ** currently points to is either [SQLITE_DELETE] or [SQLITE_UPDATE]. Otherwise,
  10933. ** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.
  10934. **
  10935. ** Argument iVal must be greater than or equal to 0, and less than the number
  10936. ** of columns in the table affected by the current change. Otherwise,
  10937. ** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
  10938. **
  10939. ** If successful, this function sets *ppValue to point to a protected
  10940. ** sqlite3_value object containing the iVal'th value from the vector of
  10941. ** original row values stored as part of the UPDATE or DELETE change and
  10942. ** returns SQLITE_OK. The name of the function comes from the fact that this
  10943. ** is similar to the "old.*" columns available to update or delete triggers.
  10944. **
  10945. ** If some other error occurs (e.g. an OOM condition), an SQLite error code
  10946. ** is returned and *ppValue is set to NULL.
  10947. */
  10948. SQLITE_API int sqlite3changeset_old(
  10949. sqlite3_changeset_iter *pIter, /* Changeset iterator */
  10950. int iVal, /* Column number */
  10951. sqlite3_value **ppValue /* OUT: Old value (or NULL pointer) */
  10952. );
  10953. /*
  10954. ** CAPI3REF: Obtain new.* Values From A Changeset Iterator
  10955. ** METHOD: sqlite3_changeset_iter
  10956. **
  10957. ** The pIter argument passed to this function may either be an iterator
  10958. ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
  10959. ** created by [sqlite3changeset_start()]. In the latter case, the most recent
  10960. ** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.
  10961. ** Furthermore, it may only be called if the type of change that the iterator
  10962. ** currently points to is either [SQLITE_UPDATE] or [SQLITE_INSERT]. Otherwise,
  10963. ** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.
  10964. **
  10965. ** Argument iVal must be greater than or equal to 0, and less than the number
  10966. ** of columns in the table affected by the current change. Otherwise,
  10967. ** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
  10968. **
  10969. ** If successful, this function sets *ppValue to point to a protected
  10970. ** sqlite3_value object containing the iVal'th value from the vector of
  10971. ** new row values stored as part of the UPDATE or INSERT change and
  10972. ** returns SQLITE_OK. If the change is an UPDATE and does not include
  10973. ** a new value for the requested column, *ppValue is set to NULL and
  10974. ** SQLITE_OK returned. The name of the function comes from the fact that
  10975. ** this is similar to the "new.*" columns available to update or delete
  10976. ** triggers.
  10977. **
  10978. ** If some other error occurs (e.g. an OOM condition), an SQLite error code
  10979. ** is returned and *ppValue is set to NULL.
  10980. */
  10981. SQLITE_API int sqlite3changeset_new(
  10982. sqlite3_changeset_iter *pIter, /* Changeset iterator */
  10983. int iVal, /* Column number */
  10984. sqlite3_value **ppValue /* OUT: New value (or NULL pointer) */
  10985. );
  10986. /*
  10987. ** CAPI3REF: Obtain Conflicting Row Values From A Changeset Iterator
  10988. ** METHOD: sqlite3_changeset_iter
  10989. **
  10990. ** This function should only be used with iterator objects passed to a
  10991. ** conflict-handler callback by [sqlite3changeset_apply()] with either
  10992. ** [SQLITE_CHANGESET_DATA] or [SQLITE_CHANGESET_CONFLICT]. If this function
  10993. ** is called on any other iterator, [SQLITE_MISUSE] is returned and *ppValue
  10994. ** is set to NULL.
  10995. **
  10996. ** Argument iVal must be greater than or equal to 0, and less than the number
  10997. ** of columns in the table affected by the current change. Otherwise,
  10998. ** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
  10999. **
  11000. ** If successful, this function sets *ppValue to point to a protected
  11001. ** sqlite3_value object containing the iVal'th value from the
  11002. ** "conflicting row" associated with the current conflict-handler callback
  11003. ** and returns SQLITE_OK.
  11004. **
  11005. ** If some other error occurs (e.g. an OOM condition), an SQLite error code
  11006. ** is returned and *ppValue is set to NULL.
  11007. */
  11008. SQLITE_API int sqlite3changeset_conflict(
  11009. sqlite3_changeset_iter *pIter, /* Changeset iterator */
  11010. int iVal, /* Column number */
  11011. sqlite3_value **ppValue /* OUT: Value from conflicting row */
  11012. );
  11013. /*
  11014. ** CAPI3REF: Determine The Number Of Foreign Key Constraint Violations
  11015. ** METHOD: sqlite3_changeset_iter
  11016. **
  11017. ** This function may only be called with an iterator passed to an
  11018. ** SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case
  11019. ** it sets the output variable to the total number of known foreign key
  11020. ** violations in the destination database and returns SQLITE_OK.
  11021. **
  11022. ** In all other cases this function returns SQLITE_MISUSE.
  11023. */
  11024. SQLITE_API int sqlite3changeset_fk_conflicts(
  11025. sqlite3_changeset_iter *pIter, /* Changeset iterator */
  11026. int *pnOut /* OUT: Number of FK violations */
  11027. );
  11028. /*
  11029. ** CAPI3REF: Finalize A Changeset Iterator
  11030. ** METHOD: sqlite3_changeset_iter
  11031. **
  11032. ** This function is used to finalize an iterator allocated with
  11033. ** [sqlite3changeset_start()].
  11034. **
  11035. ** This function should only be called on iterators created using the
  11036. ** [sqlite3changeset_start()] function. If an application calls this
  11037. ** function with an iterator passed to a conflict-handler by
  11038. ** [sqlite3changeset_apply()], [SQLITE_MISUSE] is immediately returned and the
  11039. ** call has no effect.
  11040. **
  11041. ** If an error was encountered within a call to an sqlite3changeset_xxx()
  11042. ** function (for example an [SQLITE_CORRUPT] in [sqlite3changeset_next()] or an
  11043. ** [SQLITE_NOMEM] in [sqlite3changeset_new()]) then an error code corresponding
  11044. ** to that error is returned by this function. Otherwise, SQLITE_OK is
  11045. ** returned. This is to allow the following pattern (pseudo-code):
  11046. **
  11047. ** <pre>
  11048. ** sqlite3changeset_start();
  11049. ** while( SQLITE_ROW==sqlite3changeset_next() ){
  11050. ** // Do something with change.
  11051. ** }
  11052. ** rc = sqlite3changeset_finalize();
  11053. ** if( rc!=SQLITE_OK ){
  11054. ** // An error has occurred
  11055. ** }
  11056. ** </pre>
  11057. */
  11058. SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
  11059. /*
  11060. ** CAPI3REF: Invert A Changeset
  11061. **
  11062. ** This function is used to "invert" a changeset object. Applying an inverted
  11063. ** changeset to a database reverses the effects of applying the uninverted
  11064. ** changeset. Specifically:
  11065. **
  11066. ** <ul>
  11067. ** <li> Each DELETE change is changed to an INSERT, and
  11068. ** <li> Each INSERT change is changed to a DELETE, and
  11069. ** <li> For each UPDATE change, the old.* and new.* values are exchanged.
  11070. ** </ul>
  11071. **
  11072. ** This function does not change the order in which changes appear within
  11073. ** the changeset. It merely reverses the sense of each individual change.
  11074. **
  11075. ** If successful, a pointer to a buffer containing the inverted changeset
  11076. ** is stored in *ppOut, the size of the same buffer is stored in *pnOut, and
  11077. ** SQLITE_OK is returned. If an error occurs, both *pnOut and *ppOut are
  11078. ** zeroed and an SQLite error code returned.
  11079. **
  11080. ** It is the responsibility of the caller to eventually call sqlite3_free()
  11081. ** on the *ppOut pointer to free the buffer allocation following a successful
  11082. ** call to this function.
  11083. **
  11084. ** WARNING/TODO: This function currently assumes that the input is a valid
  11085. ** changeset. If it is not, the results are undefined.
  11086. */
  11087. SQLITE_API int sqlite3changeset_invert(
  11088. int nIn, const void *pIn, /* Input changeset */
  11089. int *pnOut, void **ppOut /* OUT: Inverse of input */
  11090. );
  11091. /*
  11092. ** CAPI3REF: Concatenate Two Changeset Objects
  11093. **
  11094. ** This function is used to concatenate two changesets, A and B, into a
  11095. ** single changeset. The result is a changeset equivalent to applying
  11096. ** changeset A followed by changeset B.
  11097. **
  11098. ** This function combines the two input changesets using an
  11099. ** sqlite3_changegroup object. Calling it produces similar results as the
  11100. ** following code fragment:
  11101. **
  11102. ** <pre>
  11103. ** sqlite3_changegroup *pGrp;
  11104. ** rc = sqlite3_changegroup_new(&pGrp);
  11105. ** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nA, pA);
  11106. ** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nB, pB);
  11107. ** if( rc==SQLITE_OK ){
  11108. ** rc = sqlite3changegroup_output(pGrp, pnOut, ppOut);
  11109. ** }else{
  11110. ** *ppOut = 0;
  11111. ** *pnOut = 0;
  11112. ** }
  11113. ** </pre>
  11114. **
  11115. ** Refer to the sqlite3_changegroup documentation below for details.
  11116. */
  11117. SQLITE_API int sqlite3changeset_concat(
  11118. int nA, /* Number of bytes in buffer pA */
  11119. void *pA, /* Pointer to buffer containing changeset A */
  11120. int nB, /* Number of bytes in buffer pB */
  11121. void *pB, /* Pointer to buffer containing changeset B */
  11122. int *pnOut, /* OUT: Number of bytes in output changeset */
  11123. void **ppOut /* OUT: Buffer containing output changeset */
  11124. );
  11125. /*
  11126. ** CAPI3REF: Changegroup Handle
  11127. **
  11128. ** A changegroup is an object used to combine two or more
  11129. ** [changesets] or [patchsets]
  11130. */
  11131. typedef struct sqlite3_changegroup sqlite3_changegroup;
  11132. /*
  11133. ** CAPI3REF: Create A New Changegroup Object
  11134. ** CONSTRUCTOR: sqlite3_changegroup
  11135. **
  11136. ** An sqlite3_changegroup object is used to combine two or more changesets
  11137. ** (or patchsets) into a single changeset (or patchset). A single changegroup
  11138. ** object may combine changesets or patchsets, but not both. The output is
  11139. ** always in the same format as the input.
  11140. **
  11141. ** If successful, this function returns SQLITE_OK and populates (*pp) with
  11142. ** a pointer to a new sqlite3_changegroup object before returning. The caller
  11143. ** should eventually free the returned object using a call to
  11144. ** sqlite3changegroup_delete(). If an error occurs, an SQLite error code
  11145. ** (i.e. SQLITE_NOMEM) is returned and *pp is set to NULL.
  11146. **
  11147. ** The usual usage pattern for an sqlite3_changegroup object is as follows:
  11148. **
  11149. ** <ul>
  11150. ** <li> It is created using a call to sqlite3changegroup_new().
  11151. **
  11152. ** <li> Zero or more changesets (or patchsets) are added to the object
  11153. ** by calling sqlite3changegroup_add().
  11154. **
  11155. ** <li> The result of combining all input changesets together is obtained
  11156. ** by the application via a call to sqlite3changegroup_output().
  11157. **
  11158. ** <li> The object is deleted using a call to sqlite3changegroup_delete().
  11159. ** </ul>
  11160. **
  11161. ** Any number of calls to add() and output() may be made between the calls to
  11162. ** new() and delete(), and in any order.
  11163. **
  11164. ** As well as the regular sqlite3changegroup_add() and
  11165. ** sqlite3changegroup_output() functions, also available are the streaming
  11166. ** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().
  11167. */
  11168. SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp);
  11169. /*
  11170. ** CAPI3REF: Add A Changeset To A Changegroup
  11171. ** METHOD: sqlite3_changegroup
  11172. **
  11173. ** Add all changes within the changeset (or patchset) in buffer pData (size
  11174. ** nData bytes) to the changegroup.
  11175. **
  11176. ** If the buffer contains a patchset, then all prior calls to this function
  11177. ** on the same changegroup object must also have specified patchsets. Or, if
  11178. ** the buffer contains a changeset, so must have the earlier calls to this
  11179. ** function. Otherwise, SQLITE_ERROR is returned and no changes are added
  11180. ** to the changegroup.
  11181. **
  11182. ** Rows within the changeset and changegroup are identified by the values in
  11183. ** their PRIMARY KEY columns. A change in the changeset is considered to
  11184. ** apply to the same row as a change already present in the changegroup if
  11185. ** the two rows have the same primary key.
  11186. **
  11187. ** Changes to rows that do not already appear in the changegroup are
  11188. ** simply copied into it. Or, if both the new changeset and the changegroup
  11189. ** contain changes that apply to a single row, the final contents of the
  11190. ** changegroup depends on the type of each change, as follows:
  11191. **
  11192. ** <table border=1 style="margin-left:8ex;margin-right:8ex">
  11193. ** <tr><th style="white-space:pre">Existing Change </th>
  11194. ** <th style="white-space:pre">New Change </th>
  11195. ** <th>Output Change
  11196. ** <tr><td>INSERT <td>INSERT <td>
  11197. ** The new change is ignored. This case does not occur if the new
  11198. ** changeset was recorded immediately after the changesets already
  11199. ** added to the changegroup.
  11200. ** <tr><td>INSERT <td>UPDATE <td>
  11201. ** The INSERT change remains in the changegroup. The values in the
  11202. ** INSERT change are modified as if the row was inserted by the
  11203. ** existing change and then updated according to the new change.
  11204. ** <tr><td>INSERT <td>DELETE <td>
  11205. ** The existing INSERT is removed from the changegroup. The DELETE is
  11206. ** not added.
  11207. ** <tr><td>UPDATE <td>INSERT <td>
  11208. ** The new change is ignored. This case does not occur if the new
  11209. ** changeset was recorded immediately after the changesets already
  11210. ** added to the changegroup.
  11211. ** <tr><td>UPDATE <td>UPDATE <td>
  11212. ** The existing UPDATE remains within the changegroup. It is amended
  11213. ** so that the accompanying values are as if the row was updated once
  11214. ** by the existing change and then again by the new change.
  11215. ** <tr><td>UPDATE <td>DELETE <td>
  11216. ** The existing UPDATE is replaced by the new DELETE within the
  11217. ** changegroup.
  11218. ** <tr><td>DELETE <td>INSERT <td>
  11219. ** If one or more of the column values in the row inserted by the
  11220. ** new change differ from those in the row deleted by the existing
  11221. ** change, the existing DELETE is replaced by an UPDATE within the
  11222. ** changegroup. Otherwise, if the inserted row is exactly the same
  11223. ** as the deleted row, the existing DELETE is simply discarded.
  11224. ** <tr><td>DELETE <td>UPDATE <td>
  11225. ** The new change is ignored. This case does not occur if the new
  11226. ** changeset was recorded immediately after the changesets already
  11227. ** added to the changegroup.
  11228. ** <tr><td>DELETE <td>DELETE <td>
  11229. ** The new change is ignored. This case does not occur if the new
  11230. ** changeset was recorded immediately after the changesets already
  11231. ** added to the changegroup.
  11232. ** </table>
  11233. **
  11234. ** If the new changeset contains changes to a table that is already present
  11235. ** in the changegroup, then the number of columns and the position of the
  11236. ** primary key columns for the table must be consistent. If this is not the
  11237. ** case, this function fails with SQLITE_SCHEMA. If the input changeset
  11238. ** appears to be corrupt and the corruption is detected, SQLITE_CORRUPT is
  11239. ** returned. Or, if an out-of-memory condition occurs during processing, this
  11240. ** function returns SQLITE_NOMEM. In all cases, if an error occurs the state
  11241. ** of the final contents of the changegroup is undefined.
  11242. **
  11243. ** If no error occurs, SQLITE_OK is returned.
  11244. */
  11245. SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
  11246. /*
  11247. ** CAPI3REF: Obtain A Composite Changeset From A Changegroup
  11248. ** METHOD: sqlite3_changegroup
  11249. **
  11250. ** Obtain a buffer containing a changeset (or patchset) representing the
  11251. ** current contents of the changegroup. If the inputs to the changegroup
  11252. ** were themselves changesets, the output is a changeset. Or, if the
  11253. ** inputs were patchsets, the output is also a patchset.
  11254. **
  11255. ** As with the output of the sqlite3session_changeset() and
  11256. ** sqlite3session_patchset() functions, all changes related to a single
  11257. ** table are grouped together in the output of this function. Tables appear
  11258. ** in the same order as for the very first changeset added to the changegroup.
  11259. ** If the second or subsequent changesets added to the changegroup contain
  11260. ** changes for tables that do not appear in the first changeset, they are
  11261. ** appended onto the end of the output changeset, again in the order in
  11262. ** which they are first encountered.
  11263. **
  11264. ** If an error occurs, an SQLite error code is returned and the output
  11265. ** variables (*pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK
  11266. ** is returned and the output variables are set to the size of and a
  11267. ** pointer to the output buffer, respectively. In this case it is the
  11268. ** responsibility of the caller to eventually free the buffer using a
  11269. ** call to sqlite3_free().
  11270. */
  11271. SQLITE_API int sqlite3changegroup_output(
  11272. sqlite3_changegroup*,
  11273. int *pnData, /* OUT: Size of output buffer in bytes */
  11274. void **ppData /* OUT: Pointer to output buffer */
  11275. );
  11276. /*
  11277. ** CAPI3REF: Delete A Changegroup Object
  11278. ** DESTRUCTOR: sqlite3_changegroup
  11279. */
  11280. SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*);
  11281. /*
  11282. ** CAPI3REF: Apply A Changeset To A Database
  11283. **
  11284. ** Apply a changeset or patchset to a database. These functions attempt to
  11285. ** update the "main" database attached to handle db with the changes found in
  11286. ** the changeset passed via the second and third arguments.
  11287. **
  11288. ** The fourth argument (xFilter) passed to these functions is the "filter
  11289. ** callback". If it is not NULL, then for each table affected by at least one
  11290. ** change in the changeset, the filter callback is invoked with
  11291. ** the table name as the second argument, and a copy of the context pointer
  11292. ** passed as the sixth argument as the first. If the "filter callback"
  11293. ** returns zero, then no attempt is made to apply any changes to the table.
  11294. ** Otherwise, if the return value is non-zero or the xFilter argument to
  11295. ** is NULL, all changes related to the table are attempted.
  11296. **
  11297. ** For each table that is not excluded by the filter callback, this function
  11298. ** tests that the target database contains a compatible table. A table is
  11299. ** considered compatible if all of the following are true:
  11300. **
  11301. ** <ul>
  11302. ** <li> The table has the same name as the name recorded in the
  11303. ** changeset, and
  11304. ** <li> The table has at least as many columns as recorded in the
  11305. ** changeset, and
  11306. ** <li> The table has primary key columns in the same position as
  11307. ** recorded in the changeset.
  11308. ** </ul>
  11309. **
  11310. ** If there is no compatible table, it is not an error, but none of the
  11311. ** changes associated with the table are applied. A warning message is issued
  11312. ** via the sqlite3_log() mechanism with the error code SQLITE_SCHEMA. At most
  11313. ** one such warning is issued for each table in the changeset.
  11314. **
  11315. ** For each change for which there is a compatible table, an attempt is made
  11316. ** to modify the table contents according to the UPDATE, INSERT or DELETE
  11317. ** change. If a change cannot be applied cleanly, the conflict handler
  11318. ** function passed as the fifth argument to sqlite3changeset_apply() may be
  11319. ** invoked. A description of exactly when the conflict handler is invoked for
  11320. ** each type of change is below.
  11321. **
  11322. ** Unlike the xFilter argument, xConflict may not be passed NULL. The results
  11323. ** of passing anything other than a valid function pointer as the xConflict
  11324. ** argument are undefined.
  11325. **
  11326. ** Each time the conflict handler function is invoked, it must return one
  11327. ** of [SQLITE_CHANGESET_OMIT], [SQLITE_CHANGESET_ABORT] or
  11328. ** [SQLITE_CHANGESET_REPLACE]. SQLITE_CHANGESET_REPLACE may only be returned
  11329. ** if the second argument passed to the conflict handler is either
  11330. ** SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If the conflict-handler
  11331. ** returns an illegal value, any changes already made are rolled back and
  11332. ** the call to sqlite3changeset_apply() returns SQLITE_MISUSE. Different
  11333. ** actions are taken by sqlite3changeset_apply() depending on the value
  11334. ** returned by each invocation of the conflict-handler function. Refer to
  11335. ** the documentation for the three
  11336. ** [SQLITE_CHANGESET_OMIT|available return values] for details.
  11337. **
  11338. ** <dl>
  11339. ** <dt>DELETE Changes<dd>
  11340. ** For each DELETE change, the function checks if the target database
  11341. ** contains a row with the same primary key value (or values) as the
  11342. ** original row values stored in the changeset. If it does, and the values
  11343. ** stored in all non-primary key columns also match the values stored in
  11344. ** the changeset the row is deleted from the target database.
  11345. **
  11346. ** If a row with matching primary key values is found, but one or more of
  11347. ** the non-primary key fields contains a value different from the original
  11348. ** row value stored in the changeset, the conflict-handler function is
  11349. ** invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the
  11350. ** database table has more columns than are recorded in the changeset,
  11351. ** only the values of those non-primary key fields are compared against
  11352. ** the current database contents - any trailing database table columns
  11353. ** are ignored.
  11354. **
  11355. ** If no row with matching primary key values is found in the database,
  11356. ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
  11357. ** passed as the second argument.
  11358. **
  11359. ** If the DELETE operation is attempted, but SQLite returns SQLITE_CONSTRAINT
  11360. ** (which can only happen if a foreign key constraint is violated), the
  11361. ** conflict-handler function is invoked with [SQLITE_CHANGESET_CONSTRAINT]
  11362. ** passed as the second argument. This includes the case where the DELETE
  11363. ** operation is attempted because an earlier call to the conflict handler
  11364. ** function returned [SQLITE_CHANGESET_REPLACE].
  11365. **
  11366. ** <dt>INSERT Changes<dd>
  11367. ** For each INSERT change, an attempt is made to insert the new row into
  11368. ** the database. If the changeset row contains fewer fields than the
  11369. ** database table, the trailing fields are populated with their default
  11370. ** values.
  11371. **
  11372. ** If the attempt to insert the row fails because the database already
  11373. ** contains a row with the same primary key values, the conflict handler
  11374. ** function is invoked with the second argument set to
  11375. ** [SQLITE_CHANGESET_CONFLICT].
  11376. **
  11377. ** If the attempt to insert the row fails because of some other constraint
  11378. ** violation (e.g. NOT NULL or UNIQUE), the conflict handler function is
  11379. ** invoked with the second argument set to [SQLITE_CHANGESET_CONSTRAINT].
  11380. ** This includes the case where the INSERT operation is re-attempted because
  11381. ** an earlier call to the conflict handler function returned
  11382. ** [SQLITE_CHANGESET_REPLACE].
  11383. **
  11384. ** <dt>UPDATE Changes<dd>
  11385. ** For each UPDATE change, the function checks if the target database
  11386. ** contains a row with the same primary key value (or values) as the
  11387. ** original row values stored in the changeset. If it does, and the values
  11388. ** stored in all modified non-primary key columns also match the values
  11389. ** stored in the changeset the row is updated within the target database.
  11390. **
  11391. ** If a row with matching primary key values is found, but one or more of
  11392. ** the modified non-primary key fields contains a value different from an
  11393. ** original row value stored in the changeset, the conflict-handler function
  11394. ** is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
  11395. ** UPDATE changes only contain values for non-primary key fields that are
  11396. ** to be modified, only those fields need to match the original values to
  11397. ** avoid the SQLITE_CHANGESET_DATA conflict-handler callback.
  11398. **
  11399. ** If no row with matching primary key values is found in the database,
  11400. ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
  11401. ** passed as the second argument.
  11402. **
  11403. ** If the UPDATE operation is attempted, but SQLite returns
  11404. ** SQLITE_CONSTRAINT, the conflict-handler function is invoked with
  11405. ** [SQLITE_CHANGESET_CONSTRAINT] passed as the second argument.
  11406. ** This includes the case where the UPDATE operation is attempted after
  11407. ** an earlier call to the conflict handler function returned
  11408. ** [SQLITE_CHANGESET_REPLACE].
  11409. ** </dl>
  11410. **
  11411. ** It is safe to execute SQL statements, including those that write to the
  11412. ** table that the callback related to, from within the xConflict callback.
  11413. ** This can be used to further customize the application's conflict
  11414. ** resolution strategy.
  11415. **
  11416. ** All changes made by these functions are enclosed in a savepoint transaction.
  11417. ** If any other error (aside from a constraint failure when attempting to
  11418. ** write to the target database) occurs, then the savepoint transaction is
  11419. ** rolled back, restoring the target database to its original state, and an
  11420. ** SQLite error code returned.
  11421. **
  11422. ** If the output parameters (ppRebase) and (pnRebase) are non-NULL and
  11423. ** the input is a changeset (not a patchset), then sqlite3changeset_apply_v2()
  11424. ** may set (*ppRebase) to point to a "rebase" that may be used with the
  11425. ** sqlite3_rebaser APIs buffer before returning. In this case (*pnRebase)
  11426. ** is set to the size of the buffer in bytes. It is the responsibility of the
  11427. ** caller to eventually free any such buffer using sqlite3_free(). The buffer
  11428. ** is only allocated and populated if one or more conflicts were encountered
  11429. ** while applying the patchset. See comments surrounding the sqlite3_rebaser
  11430. ** APIs for further details.
  11431. **
  11432. ** The behavior of sqlite3changeset_apply_v2() and its streaming equivalent
  11433. ** may be modified by passing a combination of
  11434. ** [SQLITE_CHANGESETAPPLY_NOSAVEPOINT | supported flags] as the 9th parameter.
  11435. **
  11436. ** Note that the sqlite3changeset_apply_v2() API is still <b>experimental</b>
  11437. ** and therefore subject to change.
  11438. */
  11439. SQLITE_API int sqlite3changeset_apply(
  11440. sqlite3 *db, /* Apply change to "main" db of this handle */
  11441. int nChangeset, /* Size of changeset in bytes */
  11442. void *pChangeset, /* Changeset blob */
  11443. int(*xFilter)(
  11444. void *pCtx, /* Copy of sixth arg to _apply() */
  11445. const char *zTab /* Table name */
  11446. ),
  11447. int(*xConflict)(
  11448. void *pCtx, /* Copy of sixth arg to _apply() */
  11449. int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
  11450. sqlite3_changeset_iter *p /* Handle describing change and conflict */
  11451. ),
  11452. void *pCtx /* First argument passed to xConflict */
  11453. );
  11454. SQLITE_API int sqlite3changeset_apply_v2(
  11455. sqlite3 *db, /* Apply change to "main" db of this handle */
  11456. int nChangeset, /* Size of changeset in bytes */
  11457. void *pChangeset, /* Changeset blob */
  11458. int(*xFilter)(
  11459. void *pCtx, /* Copy of sixth arg to _apply() */
  11460. const char *zTab /* Table name */
  11461. ),
  11462. int(*xConflict)(
  11463. void *pCtx, /* Copy of sixth arg to _apply() */
  11464. int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
  11465. sqlite3_changeset_iter *p /* Handle describing change and conflict */
  11466. ),
  11467. void *pCtx, /* First argument passed to xConflict */
  11468. void **ppRebase, int *pnRebase, /* OUT: Rebase data */
  11469. int flags /* SESSION_CHANGESETAPPLY_* flags */
  11470. );
  11471. /*
  11472. ** CAPI3REF: Flags for sqlite3changeset_apply_v2
  11473. **
  11474. ** The following flags may passed via the 9th parameter to
  11475. ** [sqlite3changeset_apply_v2] and [sqlite3changeset_apply_v2_strm]:
  11476. **
  11477. ** <dl>
  11478. ** <dt>SQLITE_CHANGESETAPPLY_NOSAVEPOINT <dd>
  11479. ** Usually, the sessions module encloses all operations performed by
  11480. ** a single call to apply_v2() or apply_v2_strm() in a [SAVEPOINT]. The
  11481. ** SAVEPOINT is committed if the changeset or patchset is successfully
  11482. ** applied, or rolled back if an error occurs. Specifying this flag
  11483. ** causes the sessions module to omit this savepoint. In this case, if the
  11484. ** caller has an open transaction or savepoint when apply_v2() is called,
  11485. ** it may revert the partially applied changeset by rolling it back.
  11486. **
  11487. ** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd>
  11488. ** Invert the changeset before applying it. This is equivalent to inverting
  11489. ** a changeset using sqlite3changeset_invert() before applying it. It is
  11490. ** an error to specify this flag with a patchset.
  11491. */
  11492. #define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001
  11493. #define SQLITE_CHANGESETAPPLY_INVERT 0x0002
  11494. /*
  11495. ** CAPI3REF: Constants Passed To The Conflict Handler
  11496. **
  11497. ** Values that may be passed as the second argument to a conflict-handler.
  11498. **
  11499. ** <dl>
  11500. ** <dt>SQLITE_CHANGESET_DATA<dd>
  11501. ** The conflict handler is invoked with CHANGESET_DATA as the second argument
  11502. ** when processing a DELETE or UPDATE change if a row with the required
  11503. ** PRIMARY KEY fields is present in the database, but one or more other
  11504. ** (non primary-key) fields modified by the update do not contain the
  11505. ** expected "before" values.
  11506. **
  11507. ** The conflicting row, in this case, is the database row with the matching
  11508. ** primary key.
  11509. **
  11510. ** <dt>SQLITE_CHANGESET_NOTFOUND<dd>
  11511. ** The conflict handler is invoked with CHANGESET_NOTFOUND as the second
  11512. ** argument when processing a DELETE or UPDATE change if a row with the
  11513. ** required PRIMARY KEY fields is not present in the database.
  11514. **
  11515. ** There is no conflicting row in this case. The results of invoking the
  11516. ** sqlite3changeset_conflict() API are undefined.
  11517. **
  11518. ** <dt>SQLITE_CHANGESET_CONFLICT<dd>
  11519. ** CHANGESET_CONFLICT is passed as the second argument to the conflict
  11520. ** handler while processing an INSERT change if the operation would result
  11521. ** in duplicate primary key values.
  11522. **
  11523. ** The conflicting row in this case is the database row with the matching
  11524. ** primary key.
  11525. **
  11526. ** <dt>SQLITE_CHANGESET_FOREIGN_KEY<dd>
  11527. ** If foreign key handling is enabled, and applying a changeset leaves the
  11528. ** database in a state containing foreign key violations, the conflict
  11529. ** handler is invoked with CHANGESET_FOREIGN_KEY as the second argument
  11530. ** exactly once before the changeset is committed. If the conflict handler
  11531. ** returns CHANGESET_OMIT, the changes, including those that caused the
  11532. ** foreign key constraint violation, are committed. Or, if it returns
  11533. ** CHANGESET_ABORT, the changeset is rolled back.
  11534. **
  11535. ** No current or conflicting row information is provided. The only function
  11536. ** it is possible to call on the supplied sqlite3_changeset_iter handle
  11537. ** is sqlite3changeset_fk_conflicts().
  11538. **
  11539. ** <dt>SQLITE_CHANGESET_CONSTRAINT<dd>
  11540. ** If any other constraint violation occurs while applying a change (i.e.
  11541. ** a UNIQUE, CHECK or NOT NULL constraint), the conflict handler is
  11542. ** invoked with CHANGESET_CONSTRAINT as the second argument.
  11543. **
  11544. ** There is no conflicting row in this case. The results of invoking the
  11545. ** sqlite3changeset_conflict() API are undefined.
  11546. **
  11547. ** </dl>
  11548. */
  11549. #define SQLITE_CHANGESET_DATA 1
  11550. #define SQLITE_CHANGESET_NOTFOUND 2
  11551. #define SQLITE_CHANGESET_CONFLICT 3
  11552. #define SQLITE_CHANGESET_CONSTRAINT 4
  11553. #define SQLITE_CHANGESET_FOREIGN_KEY 5
  11554. /*
  11555. ** CAPI3REF: Constants Returned By The Conflict Handler
  11556. **
  11557. ** A conflict handler callback must return one of the following three values.
  11558. **
  11559. ** <dl>
  11560. ** <dt>SQLITE_CHANGESET_OMIT<dd>
  11561. ** If a conflict handler returns this value no special action is taken. The
  11562. ** change that caused the conflict is not applied. The session module
  11563. ** continues to the next change in the changeset.
  11564. **
  11565. ** <dt>SQLITE_CHANGESET_REPLACE<dd>
  11566. ** This value may only be returned if the second argument to the conflict
  11567. ** handler was SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If this
  11568. ** is not the case, any changes applied so far are rolled back and the
  11569. ** call to sqlite3changeset_apply() returns SQLITE_MISUSE.
  11570. **
  11571. ** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_DATA conflict
  11572. ** handler, then the conflicting row is either updated or deleted, depending
  11573. ** on the type of change.
  11574. **
  11575. ** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_CONFLICT conflict
  11576. ** handler, then the conflicting row is removed from the database and a
  11577. ** second attempt to apply the change is made. If this second attempt fails,
  11578. ** the original row is restored to the database before continuing.
  11579. **
  11580. ** <dt>SQLITE_CHANGESET_ABORT<dd>
  11581. ** If this value is returned, any changes applied so far are rolled back
  11582. ** and the call to sqlite3changeset_apply() returns SQLITE_ABORT.
  11583. ** </dl>
  11584. */
  11585. #define SQLITE_CHANGESET_OMIT 0
  11586. #define SQLITE_CHANGESET_REPLACE 1
  11587. #define SQLITE_CHANGESET_ABORT 2
  11588. /*
  11589. ** CAPI3REF: Rebasing changesets
  11590. ** EXPERIMENTAL
  11591. **
  11592. ** Suppose there is a site hosting a database in state S0. And that
  11593. ** modifications are made that move that database to state S1 and a
  11594. ** changeset recorded (the "local" changeset). Then, a changeset based
  11595. ** on S0 is received from another site (the "remote" changeset) and
  11596. ** applied to the database. The database is then in state
  11597. ** (S1+"remote"), where the exact state depends on any conflict
  11598. ** resolution decisions (OMIT or REPLACE) made while applying "remote".
  11599. ** Rebasing a changeset is to update it to take those conflict
  11600. ** resolution decisions into account, so that the same conflicts
  11601. ** do not have to be resolved elsewhere in the network.
  11602. **
  11603. ** For example, if both the local and remote changesets contain an
  11604. ** INSERT of the same key on "CREATE TABLE t1(a PRIMARY KEY, b)":
  11605. **
  11606. ** local: INSERT INTO t1 VALUES(1, 'v1');
  11607. ** remote: INSERT INTO t1 VALUES(1, 'v2');
  11608. **
  11609. ** and the conflict resolution is REPLACE, then the INSERT change is
  11610. ** removed from the local changeset (it was overridden). Or, if the
  11611. ** conflict resolution was "OMIT", then the local changeset is modified
  11612. ** to instead contain:
  11613. **
  11614. ** UPDATE t1 SET b = 'v2' WHERE a=1;
  11615. **
  11616. ** Changes within the local changeset are rebased as follows:
  11617. **
  11618. ** <dl>
  11619. ** <dt>Local INSERT<dd>
  11620. ** This may only conflict with a remote INSERT. If the conflict
  11621. ** resolution was OMIT, then add an UPDATE change to the rebased
  11622. ** changeset. Or, if the conflict resolution was REPLACE, add
  11623. ** nothing to the rebased changeset.
  11624. **
  11625. ** <dt>Local DELETE<dd>
  11626. ** This may conflict with a remote UPDATE or DELETE. In both cases the
  11627. ** only possible resolution is OMIT. If the remote operation was a
  11628. ** DELETE, then add no change to the rebased changeset. If the remote
  11629. ** operation was an UPDATE, then the old.* fields of change are updated
  11630. ** to reflect the new.* values in the UPDATE.
  11631. **
  11632. ** <dt>Local UPDATE<dd>
  11633. ** This may conflict with a remote UPDATE or DELETE. If it conflicts
  11634. ** with a DELETE, and the conflict resolution was OMIT, then the update
  11635. ** is changed into an INSERT. Any undefined values in the new.* record
  11636. ** from the update change are filled in using the old.* values from
  11637. ** the conflicting DELETE. Or, if the conflict resolution was REPLACE,
  11638. ** the UPDATE change is simply omitted from the rebased changeset.
  11639. **
  11640. ** If conflict is with a remote UPDATE and the resolution is OMIT, then
  11641. ** the old.* values are rebased using the new.* values in the remote
  11642. ** change. Or, if the resolution is REPLACE, then the change is copied
  11643. ** into the rebased changeset with updates to columns also updated by
  11644. ** the conflicting remote UPDATE removed. If this means no columns would
  11645. ** be updated, the change is omitted.
  11646. ** </dl>
  11647. **
  11648. ** A local change may be rebased against multiple remote changes
  11649. ** simultaneously. If a single key is modified by multiple remote
  11650. ** changesets, they are combined as follows before the local changeset
  11651. ** is rebased:
  11652. **
  11653. ** <ul>
  11654. ** <li> If there has been one or more REPLACE resolutions on a
  11655. ** key, it is rebased according to a REPLACE.
  11656. **
  11657. ** <li> If there have been no REPLACE resolutions on a key, then
  11658. ** the local changeset is rebased according to the most recent
  11659. ** of the OMIT resolutions.
  11660. ** </ul>
  11661. **
  11662. ** Note that conflict resolutions from multiple remote changesets are
  11663. ** combined on a per-field basis, not per-row. This means that in the
  11664. ** case of multiple remote UPDATE operations, some fields of a single
  11665. ** local change may be rebased for REPLACE while others are rebased for
  11666. ** OMIT.
  11667. **
  11668. ** In order to rebase a local changeset, the remote changeset must first
  11669. ** be applied to the local database using sqlite3changeset_apply_v2() and
  11670. ** the buffer of rebase information captured. Then:
  11671. **
  11672. ** <ol>
  11673. ** <li> An sqlite3_rebaser object is created by calling
  11674. ** sqlite3rebaser_create().
  11675. ** <li> The new object is configured with the rebase buffer obtained from
  11676. ** sqlite3changeset_apply_v2() by calling sqlite3rebaser_configure().
  11677. ** If the local changeset is to be rebased against multiple remote
  11678. ** changesets, then sqlite3rebaser_configure() should be called
  11679. ** multiple times, in the same order that the multiple
  11680. ** sqlite3changeset_apply_v2() calls were made.
  11681. ** <li> Each local changeset is rebased by calling sqlite3rebaser_rebase().
  11682. ** <li> The sqlite3_rebaser object is deleted by calling
  11683. ** sqlite3rebaser_delete().
  11684. ** </ol>
  11685. */
  11686. typedef struct sqlite3_rebaser sqlite3_rebaser;
  11687. /*
  11688. ** CAPI3REF: Create a changeset rebaser object.
  11689. ** EXPERIMENTAL
  11690. **
  11691. ** Allocate a new changeset rebaser object. If successful, set (*ppNew) to
  11692. ** point to the new object and return SQLITE_OK. Otherwise, if an error
  11693. ** occurs, return an SQLite error code (e.g. SQLITE_NOMEM) and set (*ppNew)
  11694. ** to NULL.
  11695. */
  11696. SQLITE_API int sqlite3rebaser_create(sqlite3_rebaser **ppNew);
  11697. /*
  11698. ** CAPI3REF: Configure a changeset rebaser object.
  11699. ** EXPERIMENTAL
  11700. **
  11701. ** Configure the changeset rebaser object to rebase changesets according
  11702. ** to the conflict resolutions described by buffer pRebase (size nRebase
  11703. ** bytes), which must have been obtained from a previous call to
  11704. ** sqlite3changeset_apply_v2().
  11705. */
  11706. SQLITE_API int sqlite3rebaser_configure(
  11707. sqlite3_rebaser*,
  11708. int nRebase, const void *pRebase
  11709. );
  11710. /*
  11711. ** CAPI3REF: Rebase a changeset
  11712. ** EXPERIMENTAL
  11713. **
  11714. ** Argument pIn must point to a buffer containing a changeset nIn bytes
  11715. ** in size. This function allocates and populates a buffer with a copy
  11716. ** of the changeset rebased according to the configuration of the
  11717. ** rebaser object passed as the first argument. If successful, (*ppOut)
  11718. ** is set to point to the new buffer containing the rebased changeset and
  11719. ** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
  11720. ** responsibility of the caller to eventually free the new buffer using
  11721. ** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
  11722. ** are set to zero and an SQLite error code returned.
  11723. */
  11724. SQLITE_API int sqlite3rebaser_rebase(
  11725. sqlite3_rebaser*,
  11726. int nIn, const void *pIn,
  11727. int *pnOut, void **ppOut
  11728. );
  11729. /*
  11730. ** CAPI3REF: Delete a changeset rebaser object.
  11731. ** EXPERIMENTAL
  11732. **
  11733. ** Delete the changeset rebaser object and all associated resources. There
  11734. ** should be one call to this function for each successful invocation
  11735. ** of sqlite3rebaser_create().
  11736. */
  11737. SQLITE_API void sqlite3rebaser_delete(sqlite3_rebaser *p);
  11738. /*
  11739. ** CAPI3REF: Streaming Versions of API functions.
  11740. **
  11741. ** The six streaming API xxx_strm() functions serve similar purposes to the
  11742. ** corresponding non-streaming API functions:
  11743. **
  11744. ** <table border=1 style="margin-left:8ex;margin-right:8ex">
  11745. ** <tr><th>Streaming function<th>Non-streaming equivalent</th>
  11746. ** <tr><td>sqlite3changeset_apply_strm<td>[sqlite3changeset_apply]
  11747. ** <tr><td>sqlite3changeset_apply_strm_v2<td>[sqlite3changeset_apply_v2]
  11748. ** <tr><td>sqlite3changeset_concat_strm<td>[sqlite3changeset_concat]
  11749. ** <tr><td>sqlite3changeset_invert_strm<td>[sqlite3changeset_invert]
  11750. ** <tr><td>sqlite3changeset_start_strm<td>[sqlite3changeset_start]
  11751. ** <tr><td>sqlite3session_changeset_strm<td>[sqlite3session_changeset]
  11752. ** <tr><td>sqlite3session_patchset_strm<td>[sqlite3session_patchset]
  11753. ** </table>
  11754. **
  11755. ** Non-streaming functions that accept changesets (or patchsets) as input
  11756. ** require that the entire changeset be stored in a single buffer in memory.
  11757. ** Similarly, those that return a changeset or patchset do so by returning
  11758. ** a pointer to a single large buffer allocated using sqlite3_malloc().
  11759. ** Normally this is convenient. However, if an application running in a
  11760. ** low-memory environment is required to handle very large changesets, the
  11761. ** large contiguous memory allocations required can become onerous.
  11762. **
  11763. ** In order to avoid this problem, instead of a single large buffer, input
  11764. ** is passed to a streaming API functions by way of a callback function that
  11765. ** the sessions module invokes to incrementally request input data as it is
  11766. ** required. In all cases, a pair of API function parameters such as
  11767. **
  11768. ** <pre>
  11769. ** &nbsp; int nChangeset,
  11770. ** &nbsp; void *pChangeset,
  11771. ** </pre>
  11772. **
  11773. ** Is replaced by:
  11774. **
  11775. ** <pre>
  11776. ** &nbsp; int (*xInput)(void *pIn, void *pData, int *pnData),
  11777. ** &nbsp; void *pIn,
  11778. ** </pre>
  11779. **
  11780. ** Each time the xInput callback is invoked by the sessions module, the first
  11781. ** argument passed is a copy of the supplied pIn context pointer. The second
  11782. ** argument, pData, points to a buffer (*pnData) bytes in size. Assuming no
  11783. ** error occurs the xInput method should copy up to (*pnData) bytes of data
  11784. ** into the buffer and set (*pnData) to the actual number of bytes copied
  11785. ** before returning SQLITE_OK. If the input is completely exhausted, (*pnData)
  11786. ** should be set to zero to indicate this. Or, if an error occurs, an SQLite
  11787. ** error code should be returned. In all cases, if an xInput callback returns
  11788. ** an error, all processing is abandoned and the streaming API function
  11789. ** returns a copy of the error code to the caller.
  11790. **
  11791. ** In the case of sqlite3changeset_start_strm(), the xInput callback may be
  11792. ** invoked by the sessions module at any point during the lifetime of the
  11793. ** iterator. If such an xInput callback returns an error, the iterator enters
  11794. ** an error state, whereby all subsequent calls to iterator functions
  11795. ** immediately fail with the same error code as returned by xInput.
  11796. **
  11797. ** Similarly, streaming API functions that return changesets (or patchsets)
  11798. ** return them in chunks by way of a callback function instead of via a
  11799. ** pointer to a single large buffer. In this case, a pair of parameters such
  11800. ** as:
  11801. **
  11802. ** <pre>
  11803. ** &nbsp; int *pnChangeset,
  11804. ** &nbsp; void **ppChangeset,
  11805. ** </pre>
  11806. **
  11807. ** Is replaced by:
  11808. **
  11809. ** <pre>
  11810. ** &nbsp; int (*xOutput)(void *pOut, const void *pData, int nData),
  11811. ** &nbsp; void *pOut
  11812. ** </pre>
  11813. **
  11814. ** The xOutput callback is invoked zero or more times to return data to
  11815. ** the application. The first parameter passed to each call is a copy of the
  11816. ** pOut pointer supplied by the application. The second parameter, pData,
  11817. ** points to a buffer nData bytes in size containing the chunk of output
  11818. ** data being returned. If the xOutput callback successfully processes the
  11819. ** supplied data, it should return SQLITE_OK to indicate success. Otherwise,
  11820. ** it should return some other SQLite error code. In this case processing
  11821. ** is immediately abandoned and the streaming API function returns a copy
  11822. ** of the xOutput error code to the application.
  11823. **
  11824. ** The sessions module never invokes an xOutput callback with the third
  11825. ** parameter set to a value less than or equal to zero. Other than this,
  11826. ** no guarantees are made as to the size of the chunks of data returned.
  11827. */
  11828. SQLITE_API int sqlite3changeset_apply_strm(
  11829. sqlite3 *db, /* Apply change to "main" db of this handle */
  11830. int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
  11831. void *pIn, /* First arg for xInput */
  11832. int(*xFilter)(
  11833. void *pCtx, /* Copy of sixth arg to _apply() */
  11834. const char *zTab /* Table name */
  11835. ),
  11836. int(*xConflict)(
  11837. void *pCtx, /* Copy of sixth arg to _apply() */
  11838. int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
  11839. sqlite3_changeset_iter *p /* Handle describing change and conflict */
  11840. ),
  11841. void *pCtx /* First argument passed to xConflict */
  11842. );
  11843. SQLITE_API int sqlite3changeset_apply_v2_strm(
  11844. sqlite3 *db, /* Apply change to "main" db of this handle */
  11845. int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
  11846. void *pIn, /* First arg for xInput */
  11847. int(*xFilter)(
  11848. void *pCtx, /* Copy of sixth arg to _apply() */
  11849. const char *zTab /* Table name */
  11850. ),
  11851. int(*xConflict)(
  11852. void *pCtx, /* Copy of sixth arg to _apply() */
  11853. int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
  11854. sqlite3_changeset_iter *p /* Handle describing change and conflict */
  11855. ),
  11856. void *pCtx, /* First argument passed to xConflict */
  11857. void **ppRebase, int *pnRebase,
  11858. int flags
  11859. );
  11860. SQLITE_API int sqlite3changeset_concat_strm(
  11861. int (*xInputA)(void *pIn, void *pData, int *pnData),
  11862. void *pInA,
  11863. int (*xInputB)(void *pIn, void *pData, int *pnData),
  11864. void *pInB,
  11865. int (*xOutput)(void *pOut, const void *pData, int nData),
  11866. void *pOut
  11867. );
  11868. SQLITE_API int sqlite3changeset_invert_strm(
  11869. int (*xInput)(void *pIn, void *pData, int *pnData),
  11870. void *pIn,
  11871. int (*xOutput)(void *pOut, const void *pData, int nData),
  11872. void *pOut
  11873. );
  11874. SQLITE_API int sqlite3changeset_start_strm(
  11875. sqlite3_changeset_iter **pp,
  11876. int (*xInput)(void *pIn, void *pData, int *pnData),
  11877. void *pIn
  11878. );
  11879. SQLITE_API int sqlite3changeset_start_v2_strm(
  11880. sqlite3_changeset_iter **pp,
  11881. int (*xInput)(void *pIn, void *pData, int *pnData),
  11882. void *pIn,
  11883. int flags
  11884. );
  11885. SQLITE_API int sqlite3session_changeset_strm(
  11886. sqlite3_session *pSession,
  11887. int (*xOutput)(void *pOut, const void *pData, int nData),
  11888. void *pOut
  11889. );
  11890. SQLITE_API int sqlite3session_patchset_strm(
  11891. sqlite3_session *pSession,
  11892. int (*xOutput)(void *pOut, const void *pData, int nData),
  11893. void *pOut
  11894. );
  11895. SQLITE_API int sqlite3changegroup_add_strm(sqlite3_changegroup*,
  11896. int (*xInput)(void *pIn, void *pData, int *pnData),
  11897. void *pIn
  11898. );
  11899. SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup*,
  11900. int (*xOutput)(void *pOut, const void *pData, int nData),
  11901. void *pOut
  11902. );
  11903. SQLITE_API int sqlite3rebaser_rebase_strm(
  11904. sqlite3_rebaser *pRebaser,
  11905. int (*xInput)(void *pIn, void *pData, int *pnData),
  11906. void *pIn,
  11907. int (*xOutput)(void *pOut, const void *pData, int nData),
  11908. void *pOut
  11909. );
  11910. /*
  11911. ** CAPI3REF: Configure global parameters
  11912. **
  11913. ** The sqlite3session_config() interface is used to make global configuration
  11914. ** changes to the sessions module in order to tune it to the specific needs
  11915. ** of the application.
  11916. **
  11917. ** The sqlite3session_config() interface is not threadsafe. If it is invoked
  11918. ** while any other thread is inside any other sessions method then the
  11919. ** results are undefined. Furthermore, if it is invoked after any sessions
  11920. ** related objects have been created, the results are also undefined.
  11921. **
  11922. ** The first argument to the sqlite3session_config() function must be one
  11923. ** of the SQLITE_SESSION_CONFIG_XXX constants defined below. The
  11924. ** interpretation of the (void*) value passed as the second parameter and
  11925. ** the effect of calling this function depends on the value of the first
  11926. ** parameter.
  11927. **
  11928. ** <dl>
  11929. ** <dt>SQLITE_SESSION_CONFIG_STRMSIZE<dd>
  11930. ** By default, the sessions module streaming interfaces attempt to input
  11931. ** and output data in approximately 1 KiB chunks. This operand may be used
  11932. ** to set and query the value of this configuration setting. The pointer
  11933. ** passed as the second argument must point to a value of type (int).
  11934. ** If this value is greater than 0, it is used as the new streaming data
  11935. ** chunk size for both input and output. Before returning, the (int) value
  11936. ** pointed to by pArg is set to the final value of the streaming interface
  11937. ** chunk size.
  11938. ** </dl>
  11939. **
  11940. ** This function returns SQLITE_OK if successful, or an SQLite error code
  11941. ** otherwise.
  11942. */
  11943. SQLITE_API int sqlite3session_config(int op, void *pArg);
  11944. /*
  11945. ** CAPI3REF: Values for sqlite3session_config().
  11946. */
  11947. #define SQLITE_SESSION_CONFIG_STRMSIZE 1
  11948. /*
  11949. ** Make sure we can call this stuff from C++.
  11950. */
  11951. #ifdef __cplusplus
  11952. }
  11953. #endif
  11954. #endif /* !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) */
  11955. /******** End of sqlite3session.h *********/
  11956. /******** Begin file fts5.h *********/
  11957. /*
  11958. ** 2014 May 31
  11959. **
  11960. ** The author disclaims copyright to this source code. In place of
  11961. ** a legal notice, here is a blessing:
  11962. **
  11963. ** May you do good and not evil.
  11964. ** May you find forgiveness for yourself and forgive others.
  11965. ** May you share freely, never taking more than you give.
  11966. **
  11967. ******************************************************************************
  11968. **
  11969. ** Interfaces to extend FTS5. Using the interfaces defined in this file,
  11970. ** FTS5 may be extended with:
  11971. **
  11972. ** * custom tokenizers, and
  11973. ** * custom auxiliary functions.
  11974. */
  11975. #ifndef _FTS5_H
  11976. #define _FTS5_H
  11977. #ifdef __cplusplus
  11978. extern "C" {
  11979. #endif
  11980. /*************************************************************************
  11981. ** CUSTOM AUXILIARY FUNCTIONS
  11982. **
  11983. ** Virtual table implementations may overload SQL functions by implementing
  11984. ** the sqlite3_module.xFindFunction() method.
  11985. */
  11986. typedef struct Fts5ExtensionApi Fts5ExtensionApi;
  11987. typedef struct Fts5Context Fts5Context;
  11988. typedef struct Fts5PhraseIter Fts5PhraseIter;
  11989. typedef void (*fts5_extension_function)(
  11990. const Fts5ExtensionApi *pApi, /* API offered by current FTS version */
  11991. Fts5Context *pFts, /* First arg to pass to pApi functions */
  11992. sqlite3_context *pCtx, /* Context for returning result/error */
  11993. int nVal, /* Number of values in apVal[] array */
  11994. sqlite3_value **apVal /* Array of trailing arguments */
  11995. );
  11996. struct Fts5PhraseIter {
  11997. const unsigned char *a;
  11998. const unsigned char *b;
  11999. };
  12000. /*
  12001. ** EXTENSION API FUNCTIONS
  12002. **
  12003. ** xUserData(pFts):
  12004. ** Return a copy of the context pointer the extension function was
  12005. ** registered with.
  12006. **
  12007. ** xColumnTotalSize(pFts, iCol, pnToken):
  12008. ** If parameter iCol is less than zero, set output variable *pnToken
  12009. ** to the total number of tokens in the FTS5 table. Or, if iCol is
  12010. ** non-negative but less than the number of columns in the table, return
  12011. ** the total number of tokens in column iCol, considering all rows in
  12012. ** the FTS5 table.
  12013. **
  12014. ** If parameter iCol is greater than or equal to the number of columns
  12015. ** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
  12016. ** an OOM condition or IO error), an appropriate SQLite error code is
  12017. ** returned.
  12018. **
  12019. ** xColumnCount(pFts):
  12020. ** Return the number of columns in the table.
  12021. **
  12022. ** xColumnSize(pFts, iCol, pnToken):
  12023. ** If parameter iCol is less than zero, set output variable *pnToken
  12024. ** to the total number of tokens in the current row. Or, if iCol is
  12025. ** non-negative but less than the number of columns in the table, set
  12026. ** *pnToken to the number of tokens in column iCol of the current row.
  12027. **
  12028. ** If parameter iCol is greater than or equal to the number of columns
  12029. ** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
  12030. ** an OOM condition or IO error), an appropriate SQLite error code is
  12031. ** returned.
  12032. **
  12033. ** This function may be quite inefficient if used with an FTS5 table
  12034. ** created with the "columnsize=0" option.
  12035. **
  12036. ** xColumnText:
  12037. ** This function attempts to retrieve the text of column iCol of the
  12038. ** current document. If successful, (*pz) is set to point to a buffer
  12039. ** containing the text in utf-8 encoding, (*pn) is set to the size in bytes
  12040. ** (not characters) of the buffer and SQLITE_OK is returned. Otherwise,
  12041. ** if an error occurs, an SQLite error code is returned and the final values
  12042. ** of (*pz) and (*pn) are undefined.
  12043. **
  12044. ** xPhraseCount:
  12045. ** Returns the number of phrases in the current query expression.
  12046. **
  12047. ** xPhraseSize:
  12048. ** Returns the number of tokens in phrase iPhrase of the query. Phrases
  12049. ** are numbered starting from zero.
  12050. **
  12051. ** xInstCount:
  12052. ** Set *pnInst to the total number of occurrences of all phrases within
  12053. ** the query within the current row. Return SQLITE_OK if successful, or
  12054. ** an error code (i.e. SQLITE_NOMEM) if an error occurs.
  12055. **
  12056. ** This API can be quite slow if used with an FTS5 table created with the
  12057. ** "detail=none" or "detail=column" option. If the FTS5 table is created
  12058. ** with either "detail=none" or "detail=column" and "content=" option
  12059. ** (i.e. if it is a contentless table), then this API always returns 0.
  12060. **
  12061. ** xInst:
  12062. ** Query for the details of phrase match iIdx within the current row.
  12063. ** Phrase matches are numbered starting from zero, so the iIdx argument
  12064. ** should be greater than or equal to zero and smaller than the value
  12065. ** output by xInstCount().
  12066. **
  12067. ** Usually, output parameter *piPhrase is set to the phrase number, *piCol
  12068. ** to the column in which it occurs and *piOff the token offset of the
  12069. ** first token of the phrase. Returns SQLITE_OK if successful, or an error
  12070. ** code (i.e. SQLITE_NOMEM) if an error occurs.
  12071. **
  12072. ** This API can be quite slow if used with an FTS5 table created with the
  12073. ** "detail=none" or "detail=column" option.
  12074. **
  12075. ** xRowid:
  12076. ** Returns the rowid of the current row.
  12077. **
  12078. ** xTokenize:
  12079. ** Tokenize text using the tokenizer belonging to the FTS5 table.
  12080. **
  12081. ** xQueryPhrase(pFts5, iPhrase, pUserData, xCallback):
  12082. ** This API function is used to query the FTS table for phrase iPhrase
  12083. ** of the current query. Specifically, a query equivalent to:
  12084. **
  12085. ** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid
  12086. **
  12087. ** with $p set to a phrase equivalent to the phrase iPhrase of the
  12088. ** current query is executed. Any column filter that applies to
  12089. ** phrase iPhrase of the current query is included in $p. For each
  12090. ** row visited, the callback function passed as the fourth argument
  12091. ** is invoked. The context and API objects passed to the callback
  12092. ** function may be used to access the properties of each matched row.
  12093. ** Invoking Api.xUserData() returns a copy of the pointer passed as
  12094. ** the third argument to pUserData.
  12095. **
  12096. ** If the callback function returns any value other than SQLITE_OK, the
  12097. ** query is abandoned and the xQueryPhrase function returns immediately.
  12098. ** If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK.
  12099. ** Otherwise, the error code is propagated upwards.
  12100. **
  12101. ** If the query runs to completion without incident, SQLITE_OK is returned.
  12102. ** Or, if some error occurs before the query completes or is aborted by
  12103. ** the callback, an SQLite error code is returned.
  12104. **
  12105. **
  12106. ** xSetAuxdata(pFts5, pAux, xDelete)
  12107. **
  12108. ** Save the pointer passed as the second argument as the extension function's
  12109. ** "auxiliary data". The pointer may then be retrieved by the current or any
  12110. ** future invocation of the same fts5 extension function made as part of
  12111. ** the same MATCH query using the xGetAuxdata() API.
  12112. **
  12113. ** Each extension function is allocated a single auxiliary data slot for
  12114. ** each FTS query (MATCH expression). If the extension function is invoked
  12115. ** more than once for a single FTS query, then all invocations share a
  12116. ** single auxiliary data context.
  12117. **
  12118. ** If there is already an auxiliary data pointer when this function is
  12119. ** invoked, then it is replaced by the new pointer. If an xDelete callback
  12120. ** was specified along with the original pointer, it is invoked at this
  12121. ** point.
  12122. **
  12123. ** The xDelete callback, if one is specified, is also invoked on the
  12124. ** auxiliary data pointer after the FTS5 query has finished.
  12125. **
  12126. ** If an error (e.g. an OOM condition) occurs within this function,
  12127. ** the auxiliary data is set to NULL and an error code returned. If the
  12128. ** xDelete parameter was not NULL, it is invoked on the auxiliary data
  12129. ** pointer before returning.
  12130. **
  12131. **
  12132. ** xGetAuxdata(pFts5, bClear)
  12133. **
  12134. ** Returns the current auxiliary data pointer for the fts5 extension
  12135. ** function. See the xSetAuxdata() method for details.
  12136. **
  12137. ** If the bClear argument is non-zero, then the auxiliary data is cleared
  12138. ** (set to NULL) before this function returns. In this case the xDelete,
  12139. ** if any, is not invoked.
  12140. **
  12141. **
  12142. ** xRowCount(pFts5, pnRow)
  12143. **
  12144. ** This function is used to retrieve the total number of rows in the table.
  12145. ** In other words, the same value that would be returned by:
  12146. **
  12147. ** SELECT count(*) FROM ftstable;
  12148. **
  12149. ** xPhraseFirst()
  12150. ** This function is used, along with type Fts5PhraseIter and the xPhraseNext
  12151. ** method, to iterate through all instances of a single query phrase within
  12152. ** the current row. This is the same information as is accessible via the
  12153. ** xInstCount/xInst APIs. While the xInstCount/xInst APIs are more convenient
  12154. ** to use, this API may be faster under some circumstances. To iterate
  12155. ** through instances of phrase iPhrase, use the following code:
  12156. **
  12157. ** Fts5PhraseIter iter;
  12158. ** int iCol, iOff;
  12159. ** for(pApi->xPhraseFirst(pFts, iPhrase, &iter, &iCol, &iOff);
  12160. ** iCol>=0;
  12161. ** pApi->xPhraseNext(pFts, &iter, &iCol, &iOff)
  12162. ** ){
  12163. ** // An instance of phrase iPhrase at offset iOff of column iCol
  12164. ** }
  12165. **
  12166. ** The Fts5PhraseIter structure is defined above. Applications should not
  12167. ** modify this structure directly - it should only be used as shown above
  12168. ** with the xPhraseFirst() and xPhraseNext() API methods (and by
  12169. ** xPhraseFirstColumn() and xPhraseNextColumn() as illustrated below).
  12170. **
  12171. ** This API can be quite slow if used with an FTS5 table created with the
  12172. ** "detail=none" or "detail=column" option. If the FTS5 table is created
  12173. ** with either "detail=none" or "detail=column" and "content=" option
  12174. ** (i.e. if it is a contentless table), then this API always iterates
  12175. ** through an empty set (all calls to xPhraseFirst() set iCol to -1).
  12176. **
  12177. ** xPhraseNext()
  12178. ** See xPhraseFirst above.
  12179. **
  12180. ** xPhraseFirstColumn()
  12181. ** This function and xPhraseNextColumn() are similar to the xPhraseFirst()
  12182. ** and xPhraseNext() APIs described above. The difference is that instead
  12183. ** of iterating through all instances of a phrase in the current row, these
  12184. ** APIs are used to iterate through the set of columns in the current row
  12185. ** that contain one or more instances of a specified phrase. For example:
  12186. **
  12187. ** Fts5PhraseIter iter;
  12188. ** int iCol;
  12189. ** for(pApi->xPhraseFirstColumn(pFts, iPhrase, &iter, &iCol);
  12190. ** iCol>=0;
  12191. ** pApi->xPhraseNextColumn(pFts, &iter, &iCol)
  12192. ** ){
  12193. ** // Column iCol contains at least one instance of phrase iPhrase
  12194. ** }
  12195. **
  12196. ** This API can be quite slow if used with an FTS5 table created with the
  12197. ** "detail=none" option. If the FTS5 table is created with either
  12198. ** "detail=none" "content=" option (i.e. if it is a contentless table),
  12199. ** then this API always iterates through an empty set (all calls to
  12200. ** xPhraseFirstColumn() set iCol to -1).
  12201. **
  12202. ** The information accessed using this API and its companion
  12203. ** xPhraseFirstColumn() may also be obtained using xPhraseFirst/xPhraseNext
  12204. ** (or xInst/xInstCount). The chief advantage of this API is that it is
  12205. ** significantly more efficient than those alternatives when used with
  12206. ** "detail=column" tables.
  12207. **
  12208. ** xPhraseNextColumn()
  12209. ** See xPhraseFirstColumn above.
  12210. */
  12211. struct Fts5ExtensionApi {
  12212. int iVersion; /* Currently always set to 3 */
  12213. void *(*xUserData)(Fts5Context*);
  12214. int (*xColumnCount)(Fts5Context*);
  12215. int (*xRowCount)(Fts5Context*, sqlite3_int64 *pnRow);
  12216. int (*xColumnTotalSize)(Fts5Context*, int iCol, sqlite3_int64 *pnToken);
  12217. int (*xTokenize)(Fts5Context*,
  12218. const char *pText, int nText, /* Text to tokenize */
  12219. void *pCtx, /* Context passed to xToken() */
  12220. int (*xToken)(void*, int, const char*, int, int, int) /* Callback */
  12221. );
  12222. int (*xPhraseCount)(Fts5Context*);
  12223. int (*xPhraseSize)(Fts5Context*, int iPhrase);
  12224. int (*xInstCount)(Fts5Context*, int *pnInst);
  12225. int (*xInst)(Fts5Context*, int iIdx, int *piPhrase, int *piCol, int *piOff);
  12226. sqlite3_int64 (*xRowid)(Fts5Context*);
  12227. int (*xColumnText)(Fts5Context*, int iCol, const char **pz, int *pn);
  12228. int (*xColumnSize)(Fts5Context*, int iCol, int *pnToken);
  12229. int (*xQueryPhrase)(Fts5Context*, int iPhrase, void *pUserData,
  12230. int(*)(const Fts5ExtensionApi*,Fts5Context*,void*)
  12231. );
  12232. int (*xSetAuxdata)(Fts5Context*, void *pAux, void(*xDelete)(void*));
  12233. void *(*xGetAuxdata)(Fts5Context*, int bClear);
  12234. int (*xPhraseFirst)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*, int*);
  12235. void (*xPhraseNext)(Fts5Context*, Fts5PhraseIter*, int *piCol, int *piOff);
  12236. int (*xPhraseFirstColumn)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*);
  12237. void (*xPhraseNextColumn)(Fts5Context*, Fts5PhraseIter*, int *piCol);
  12238. };
  12239. /*
  12240. ** CUSTOM AUXILIARY FUNCTIONS
  12241. *************************************************************************/
  12242. /*************************************************************************
  12243. ** CUSTOM TOKENIZERS
  12244. **
  12245. ** Applications may also register custom tokenizer types. A tokenizer
  12246. ** is registered by providing fts5 with a populated instance of the
  12247. ** following structure. All structure methods must be defined, setting
  12248. ** any member of the fts5_tokenizer struct to NULL leads to undefined
  12249. ** behaviour. The structure methods are expected to function as follows:
  12250. **
  12251. ** xCreate:
  12252. ** This function is used to allocate and initialize a tokenizer instance.
  12253. ** A tokenizer instance is required to actually tokenize text.
  12254. **
  12255. ** The first argument passed to this function is a copy of the (void*)
  12256. ** pointer provided by the application when the fts5_tokenizer object
  12257. ** was registered with FTS5 (the third argument to xCreateTokenizer()).
  12258. ** The second and third arguments are an array of nul-terminated strings
  12259. ** containing the tokenizer arguments, if any, specified following the
  12260. ** tokenizer name as part of the CREATE VIRTUAL TABLE statement used
  12261. ** to create the FTS5 table.
  12262. **
  12263. ** The final argument is an output variable. If successful, (*ppOut)
  12264. ** should be set to point to the new tokenizer handle and SQLITE_OK
  12265. ** returned. If an error occurs, some value other than SQLITE_OK should
  12266. ** be returned. In this case, fts5 assumes that the final value of *ppOut
  12267. ** is undefined.
  12268. **
  12269. ** xDelete:
  12270. ** This function is invoked to delete a tokenizer handle previously
  12271. ** allocated using xCreate(). Fts5 guarantees that this function will
  12272. ** be invoked exactly once for each successful call to xCreate().
  12273. **
  12274. ** xTokenize:
  12275. ** This function is expected to tokenize the nText byte string indicated
  12276. ** by argument pText. pText may or may not be nul-terminated. The first
  12277. ** argument passed to this function is a pointer to an Fts5Tokenizer object
  12278. ** returned by an earlier call to xCreate().
  12279. **
  12280. ** The second argument indicates the reason that FTS5 is requesting
  12281. ** tokenization of the supplied text. This is always one of the following
  12282. ** four values:
  12283. **
  12284. ** <ul><li> <b>FTS5_TOKENIZE_DOCUMENT</b> - A document is being inserted into
  12285. ** or removed from the FTS table. The tokenizer is being invoked to
  12286. ** determine the set of tokens to add to (or delete from) the
  12287. ** FTS index.
  12288. **
  12289. ** <li> <b>FTS5_TOKENIZE_QUERY</b> - A MATCH query is being executed
  12290. ** against the FTS index. The tokenizer is being called to tokenize
  12291. ** a bareword or quoted string specified as part of the query.
  12292. **
  12293. ** <li> <b>(FTS5_TOKENIZE_QUERY | FTS5_TOKENIZE_PREFIX)</b> - Same as
  12294. ** FTS5_TOKENIZE_QUERY, except that the bareword or quoted string is
  12295. ** followed by a "*" character, indicating that the last token
  12296. ** returned by the tokenizer will be treated as a token prefix.
  12297. **
  12298. ** <li> <b>FTS5_TOKENIZE_AUX</b> - The tokenizer is being invoked to
  12299. ** satisfy an fts5_api.xTokenize() request made by an auxiliary
  12300. ** function. Or an fts5_api.xColumnSize() request made by the same
  12301. ** on a columnsize=0 database.
  12302. ** </ul>
  12303. **
  12304. ** For each token in the input string, the supplied callback xToken() must
  12305. ** be invoked. The first argument to it should be a copy of the pointer
  12306. ** passed as the second argument to xTokenize(). The third and fourth
  12307. ** arguments are a pointer to a buffer containing the token text, and the
  12308. ** size of the token in bytes. The 4th and 5th arguments are the byte offsets
  12309. ** of the first byte of and first byte immediately following the text from
  12310. ** which the token is derived within the input.
  12311. **
  12312. ** The second argument passed to the xToken() callback ("tflags") should
  12313. ** normally be set to 0. The exception is if the tokenizer supports
  12314. ** synonyms. In this case see the discussion below for details.
  12315. **
  12316. ** FTS5 assumes the xToken() callback is invoked for each token in the
  12317. ** order that they occur within the input text.
  12318. **
  12319. ** If an xToken() callback returns any value other than SQLITE_OK, then
  12320. ** the tokenization should be abandoned and the xTokenize() method should
  12321. ** immediately return a copy of the xToken() return value. Or, if the
  12322. ** input buffer is exhausted, xTokenize() should return SQLITE_OK. Finally,
  12323. ** if an error occurs with the xTokenize() implementation itself, it
  12324. ** may abandon the tokenization and return any error code other than
  12325. ** SQLITE_OK or SQLITE_DONE.
  12326. **
  12327. ** SYNONYM SUPPORT
  12328. **
  12329. ** Custom tokenizers may also support synonyms. Consider a case in which a
  12330. ** user wishes to query for a phrase such as "first place". Using the
  12331. ** built-in tokenizers, the FTS5 query 'first + place' will match instances
  12332. ** of "first place" within the document set, but not alternative forms
  12333. ** such as "1st place". In some applications, it would be better to match
  12334. ** all instances of "first place" or "1st place" regardless of which form
  12335. ** the user specified in the MATCH query text.
  12336. **
  12337. ** There are several ways to approach this in FTS5:
  12338. **
  12339. ** <ol><li> By mapping all synonyms to a single token. In this case, using
  12340. ** the above example, this means that the tokenizer returns the
  12341. ** same token for inputs "first" and "1st". Say that token is in
  12342. ** fact "first", so that when the user inserts the document "I won
  12343. ** 1st place" entries are added to the index for tokens "i", "won",
  12344. ** "first" and "place". If the user then queries for '1st + place',
  12345. ** the tokenizer substitutes "first" for "1st" and the query works
  12346. ** as expected.
  12347. **
  12348. ** <li> By querying the index for all synonyms of each query term
  12349. ** separately. In this case, when tokenizing query text, the
  12350. ** tokenizer may provide multiple synonyms for a single term
  12351. ** within the document. FTS5 then queries the index for each
  12352. ** synonym individually. For example, faced with the query:
  12353. **
  12354. ** <codeblock>
  12355. ** ... MATCH 'first place'</codeblock>
  12356. **
  12357. ** the tokenizer offers both "1st" and "first" as synonyms for the
  12358. ** first token in the MATCH query and FTS5 effectively runs a query
  12359. ** similar to:
  12360. **
  12361. ** <codeblock>
  12362. ** ... MATCH '(first OR 1st) place'</codeblock>
  12363. **
  12364. ** except that, for the purposes of auxiliary functions, the query
  12365. ** still appears to contain just two phrases - "(first OR 1st)"
  12366. ** being treated as a single phrase.
  12367. **
  12368. ** <li> By adding multiple synonyms for a single term to the FTS index.
  12369. ** Using this method, when tokenizing document text, the tokenizer
  12370. ** provides multiple synonyms for each token. So that when a
  12371. ** document such as "I won first place" is tokenized, entries are
  12372. ** added to the FTS index for "i", "won", "first", "1st" and
  12373. ** "place".
  12374. **
  12375. ** This way, even if the tokenizer does not provide synonyms
  12376. ** when tokenizing query text (it should not - to do so would be
  12377. ** inefficient), it doesn't matter if the user queries for
  12378. ** 'first + place' or '1st + place', as there are entries in the
  12379. ** FTS index corresponding to both forms of the first token.
  12380. ** </ol>
  12381. **
  12382. ** Whether it is parsing document or query text, any call to xToken that
  12383. ** specifies a <i>tflags</i> argument with the FTS5_TOKEN_COLOCATED bit
  12384. ** is considered to supply a synonym for the previous token. For example,
  12385. ** when parsing the document "I won first place", a tokenizer that supports
  12386. ** synonyms would call xToken() 5 times, as follows:
  12387. **
  12388. ** <codeblock>
  12389. ** xToken(pCtx, 0, "i", 1, 0, 1);
  12390. ** xToken(pCtx, 0, "won", 3, 2, 5);
  12391. ** xToken(pCtx, 0, "first", 5, 6, 11);
  12392. ** xToken(pCtx, FTS5_TOKEN_COLOCATED, "1st", 3, 6, 11);
  12393. ** xToken(pCtx, 0, "place", 5, 12, 17);
  12394. **</codeblock>
  12395. **
  12396. ** It is an error to specify the FTS5_TOKEN_COLOCATED flag the first time
  12397. ** xToken() is called. Multiple synonyms may be specified for a single token
  12398. ** by making multiple calls to xToken(FTS5_TOKEN_COLOCATED) in sequence.
  12399. ** There is no limit to the number of synonyms that may be provided for a
  12400. ** single token.
  12401. **
  12402. ** In many cases, method (1) above is the best approach. It does not add
  12403. ** extra data to the FTS index or require FTS5 to query for multiple terms,
  12404. ** so it is efficient in terms of disk space and query speed. However, it
  12405. ** does not support prefix queries very well. If, as suggested above, the
  12406. ** token "first" is substituted for "1st" by the tokenizer, then the query:
  12407. **
  12408. ** <codeblock>
  12409. ** ... MATCH '1s*'</codeblock>
  12410. **
  12411. ** will not match documents that contain the token "1st" (as the tokenizer
  12412. ** will probably not map "1s" to any prefix of "first").
  12413. **
  12414. ** For full prefix support, method (3) may be preferred. In this case,
  12415. ** because the index contains entries for both "first" and "1st", prefix
  12416. ** queries such as 'fi*' or '1s*' will match correctly. However, because
  12417. ** extra entries are added to the FTS index, this method uses more space
  12418. ** within the database.
  12419. **
  12420. ** Method (2) offers a midpoint between (1) and (3). Using this method,
  12421. ** a query such as '1s*' will match documents that contain the literal
  12422. ** token "1st", but not "first" (assuming the tokenizer is not able to
  12423. ** provide synonyms for prefixes). However, a non-prefix query like '1st'
  12424. ** will match against "1st" and "first". This method does not require
  12425. ** extra disk space, as no extra entries are added to the FTS index.
  12426. ** On the other hand, it may require more CPU cycles to run MATCH queries,
  12427. ** as separate queries of the FTS index are required for each synonym.
  12428. **
  12429. ** When using methods (2) or (3), it is important that the tokenizer only
  12430. ** provide synonyms when tokenizing document text (method (2)) or query
  12431. ** text (method (3)), not both. Doing so will not cause any errors, but is
  12432. ** inefficient.
  12433. */
  12434. typedef struct Fts5Tokenizer Fts5Tokenizer;
  12435. typedef struct fts5_tokenizer fts5_tokenizer;
  12436. struct fts5_tokenizer {
  12437. int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut);
  12438. void (*xDelete)(Fts5Tokenizer*);
  12439. int (*xTokenize)(Fts5Tokenizer*,
  12440. void *pCtx,
  12441. int flags, /* Mask of FTS5_TOKENIZE_* flags */
  12442. const char *pText, int nText,
  12443. int (*xToken)(
  12444. void *pCtx, /* Copy of 2nd argument to xTokenize() */
  12445. int tflags, /* Mask of FTS5_TOKEN_* flags */
  12446. const char *pToken, /* Pointer to buffer containing token */
  12447. int nToken, /* Size of token in bytes */
  12448. int iStart, /* Byte offset of token within input text */
  12449. int iEnd /* Byte offset of end of token within input text */
  12450. )
  12451. );
  12452. };
  12453. /* Flags that may be passed as the third argument to xTokenize() */
  12454. #define FTS5_TOKENIZE_QUERY 0x0001
  12455. #define FTS5_TOKENIZE_PREFIX 0x0002
  12456. #define FTS5_TOKENIZE_DOCUMENT 0x0004
  12457. #define FTS5_TOKENIZE_AUX 0x0008
  12458. /* Flags that may be passed by the tokenizer implementation back to FTS5
  12459. ** as the third argument to the supplied xToken callback. */
  12460. #define FTS5_TOKEN_COLOCATED 0x0001 /* Same position as prev. token */
  12461. /*
  12462. ** END OF CUSTOM TOKENIZERS
  12463. *************************************************************************/
  12464. /*************************************************************************
  12465. ** FTS5 EXTENSION REGISTRATION API
  12466. */
  12467. typedef struct fts5_api fts5_api;
  12468. struct fts5_api {
  12469. int iVersion; /* Currently always set to 2 */
  12470. /* Create a new tokenizer */
  12471. int (*xCreateTokenizer)(
  12472. fts5_api *pApi,
  12473. const char *zName,
  12474. void *pContext,
  12475. fts5_tokenizer *pTokenizer,
  12476. void (*xDestroy)(void*)
  12477. );
  12478. /* Find an existing tokenizer */
  12479. int (*xFindTokenizer)(
  12480. fts5_api *pApi,
  12481. const char *zName,
  12482. void **ppContext,
  12483. fts5_tokenizer *pTokenizer
  12484. );
  12485. /* Create a new auxiliary function */
  12486. int (*xCreateFunction)(
  12487. fts5_api *pApi,
  12488. const char *zName,
  12489. void *pContext,
  12490. fts5_extension_function xFunction,
  12491. void (*xDestroy)(void*)
  12492. );
  12493. };
  12494. /*
  12495. ** END OF REGISTRATION API
  12496. *************************************************************************/
  12497. #ifdef __cplusplus
  12498. } /* end of the 'extern "C"' block */
  12499. #endif
  12500. #endif /* _FTS5_H */
  12501. /******** End of fts5.h *********/
  12502. #else // USE_LIBSQLITE3
  12503. // If users really want to link against the system sqlite3 we
  12504. // need to make this file a noop.
  12505. #endif
  12506. /*
  12507. ** 2014-09-08
  12508. **
  12509. ** The author disclaims copyright to this source code. In place of
  12510. ** a legal notice, here is a blessing:
  12511. **
  12512. ** May you do good and not evil.
  12513. ** May you find forgiveness for yourself and forgive others.
  12514. ** May you share freely, never taking more than you give.
  12515. **
  12516. *************************************************************************
  12517. **
  12518. ** This file contains the application interface definitions for the
  12519. ** user-authentication extension feature.
  12520. **
  12521. ** To compile with the user-authentication feature, append this file to
  12522. ** end of an SQLite amalgamation header file ("sqlite3.h"), then add
  12523. ** the SQLITE_USER_AUTHENTICATION compile-time option. See the
  12524. ** user-auth.txt file in the same source directory as this file for
  12525. ** additional information.
  12526. */
  12527. #ifdef SQLITE_USER_AUTHENTICATION
  12528. #ifdef __cplusplus
  12529. extern "C" {
  12530. #endif
  12531. /*
  12532. ** If a database contains the SQLITE_USER table, then the
  12533. ** sqlite3_user_authenticate() interface must be invoked with an
  12534. ** appropriate username and password prior to enable read and write
  12535. ** access to the database.
  12536. **
  12537. ** Return SQLITE_OK on success or SQLITE_ERROR if the username/password
  12538. ** combination is incorrect or unknown.
  12539. **
  12540. ** If the SQLITE_USER table is not present in the database file, then
  12541. ** this interface is a harmless no-op returnning SQLITE_OK.
  12542. */
  12543. int sqlite3_user_authenticate(
  12544. sqlite3 *db, /* The database connection */
  12545. const char *zUsername, /* Username */
  12546. const char *aPW, /* Password or credentials */
  12547. int nPW /* Number of bytes in aPW[] */
  12548. );
  12549. /*
  12550. ** The sqlite3_user_add() interface can be used (by an admin user only)
  12551. ** to create a new user. When called on a no-authentication-required
  12552. ** database, this routine converts the database into an authentication-
  12553. ** required database, automatically makes the added user an
  12554. ** administrator, and logs in the current connection as that user.
  12555. ** The sqlite3_user_add() interface only works for the "main" database, not
  12556. ** for any ATTACH-ed databases. Any call to sqlite3_user_add() by a
  12557. ** non-admin user results in an error.
  12558. */
  12559. int sqlite3_user_add(
  12560. sqlite3 *db, /* Database connection */
  12561. const char *zUsername, /* Username to be added */
  12562. const char *aPW, /* Password or credentials */
  12563. int nPW, /* Number of bytes in aPW[] */
  12564. int isAdmin /* True to give new user admin privilege */
  12565. );
  12566. /*
  12567. ** The sqlite3_user_change() interface can be used to change a users
  12568. ** login credentials or admin privilege. Any user can change their own
  12569. ** login credentials. Only an admin user can change another users login
  12570. ** credentials or admin privilege setting. No user may change their own
  12571. ** admin privilege setting.
  12572. */
  12573. int sqlite3_user_change(
  12574. sqlite3 *db, /* Database connection */
  12575. const char *zUsername, /* Username to change */
  12576. const char *aPW, /* New password or credentials */
  12577. int nPW, /* Number of bytes in aPW[] */
  12578. int isAdmin /* Modified admin privilege for the user */
  12579. );
  12580. /*
  12581. ** The sqlite3_user_delete() interface can be used (by an admin user only)
  12582. ** to delete a user. The currently logged-in user cannot be deleted,
  12583. ** which guarantees that there is always an admin user and hence that
  12584. ** the database cannot be converted into a no-authentication-required
  12585. ** database.
  12586. */
  12587. int sqlite3_user_delete(
  12588. sqlite3 *db, /* Database connection */
  12589. const char *zUsername /* Username to remove */
  12590. );
  12591. #ifdef __cplusplus
  12592. } /* end of the 'extern "C"' block */
  12593. #endif
  12594. #endif /* SQLITE_USER_AUTHENTICATION */