PageRenderTime 53ms CodeModel.GetById 39ms RepoModel.GetById 1ms app.codeStats 2ms

/db/sqlite3/src/sqlite3.c

https://bitbucket.org/mkato/mozilla-1.9.0-win64
C | 10964 lines | 2990 code | 425 blank | 7549 comment | 40 complexity | d8171ee7d693017778d52b17b26a1b22 MD5 | raw file
Possible License(s): LGPL-3.0, MIT, BSD-3-Clause, MPL-2.0-no-copyleft-exception, GPL-2.0, LGPL-2.1
  1. /******************************************************************************
  2. ** This file is an amalgamation of many separate C source files from SQLite
  3. ** version 3.6.10. By combining all the individual C code files into this
  4. ** single large file, the entire code can be compiled as a one translation
  5. ** unit. This allows many compilers to do optimizations that would not be
  6. ** possible if the files were compiled separately. Performance improvements
  7. ** of 5% are more are commonly seen when SQLite is compiled as a single
  8. ** translation unit.
  9. **
  10. ** This file is all you need to compile SQLite. To use SQLite in other
  11. ** programs, you need this file and the "sqlite3.h" header file that defines
  12. ** the programming interface to the SQLite library. (If you do not have
  13. ** the "sqlite3.h" header file at hand, you will find a copy in the first
  14. ** 6736 lines past this header comment.) Additional code files may be
  15. ** needed if you want a wrapper to interface SQLite with your choice of
  16. ** programming language. The code for the "sqlite3" command-line shell
  17. ** is also in a separate file. This file contains only code for the core
  18. ** SQLite library.
  19. **
  20. ** This amalgamation was generated on 2009-01-15 16:00:39 UTC.
  21. */
  22. #define SQLITE_CORE 1
  23. #define SQLITE_AMALGAMATION 1
  24. #ifndef SQLITE_PRIVATE
  25. # define SQLITE_PRIVATE static
  26. #endif
  27. #ifndef SQLITE_API
  28. # define SQLITE_API
  29. #endif
  30. /************** Begin file sqliteInt.h ***************************************/
  31. /*
  32. ** 2001 September 15
  33. **
  34. ** The author disclaims copyright to this source code. In place of
  35. ** a legal notice, here is a blessing:
  36. **
  37. ** May you do good and not evil.
  38. ** May you find forgiveness for yourself and forgive others.
  39. ** May you share freely, never taking more than you give.
  40. **
  41. *************************************************************************
  42. ** Internal interface definitions for SQLite.
  43. **
  44. ** @(#) $Id: sqliteInt.h,v 1.824 2009/01/14 23:03:41 drh Exp $
  45. */
  46. #ifndef _SQLITEINT_H_
  47. #define _SQLITEINT_H_
  48. /*
  49. ** Include the configuration header output by 'configure' if we're using the
  50. ** autoconf-based build
  51. */
  52. #ifdef _HAVE_SQLITE_CONFIG_H
  53. #include "config.h"
  54. #endif
  55. /************** Include sqliteLimit.h in the middle of sqliteInt.h ***********/
  56. /************** Begin file sqliteLimit.h *************************************/
  57. /*
  58. ** 2007 May 7
  59. **
  60. ** The author disclaims copyright to this source code. In place of
  61. ** a legal notice, here is a blessing:
  62. **
  63. ** May you do good and not evil.
  64. ** May you find forgiveness for yourself and forgive others.
  65. ** May you share freely, never taking more than you give.
  66. **
  67. *************************************************************************
  68. **
  69. ** This file defines various limits of what SQLite can process.
  70. **
  71. ** @(#) $Id: sqliteLimit.h,v 1.10 2009/01/10 16:15:09 danielk1977 Exp $
  72. */
  73. /*
  74. ** The maximum length of a TEXT or BLOB in bytes. This also
  75. ** limits the size of a row in a table or index.
  76. **
  77. ** The hard limit is the ability of a 32-bit signed integer
  78. ** to count the size: 2^31-1 or 2147483647.
  79. */
  80. #ifndef SQLITE_MAX_LENGTH
  81. # define SQLITE_MAX_LENGTH 1000000000
  82. #endif
  83. /*
  84. ** This is the maximum number of
  85. **
  86. ** * Columns in a table
  87. ** * Columns in an index
  88. ** * Columns in a view
  89. ** * Terms in the SET clause of an UPDATE statement
  90. ** * Terms in the result set of a SELECT statement
  91. ** * Terms in the GROUP BY or ORDER BY clauses of a SELECT statement.
  92. ** * Terms in the VALUES clause of an INSERT statement
  93. **
  94. ** The hard upper limit here is 32676. Most database people will
  95. ** tell you that in a well-normalized database, you usually should
  96. ** not have more than a dozen or so columns in any table. And if
  97. ** that is the case, there is no point in having more than a few
  98. ** dozen values in any of the other situations described above.
  99. */
  100. #ifndef SQLITE_MAX_COLUMN
  101. # define SQLITE_MAX_COLUMN 2000
  102. #endif
  103. /*
  104. ** The maximum length of a single SQL statement in bytes.
  105. **
  106. ** It used to be the case that setting this value to zero would
  107. ** turn the limit off. That is no longer true. It is not possible
  108. ** to turn this limit off.
  109. */
  110. #ifndef SQLITE_MAX_SQL_LENGTH
  111. # define SQLITE_MAX_SQL_LENGTH 1000000000
  112. #endif
  113. /*
  114. ** The maximum depth of an expression tree. This is limited to
  115. ** some extent by SQLITE_MAX_SQL_LENGTH. But sometime you might
  116. ** want to place more severe limits on the complexity of an
  117. ** expression.
  118. **
  119. ** A value of 0 used to mean that the limit was not enforced.
  120. ** But that is no longer true. The limit is now strictly enforced
  121. ** at all times.
  122. */
  123. #ifndef SQLITE_MAX_EXPR_DEPTH
  124. # define SQLITE_MAX_EXPR_DEPTH 1000
  125. #endif
  126. /*
  127. ** The maximum number of terms in a compound SELECT statement.
  128. ** The code generator for compound SELECT statements does one
  129. ** level of recursion for each term. A stack overflow can result
  130. ** if the number of terms is too large. In practice, most SQL
  131. ** never has more than 3 or 4 terms. Use a value of 0 to disable
  132. ** any limit on the number of terms in a compount SELECT.
  133. */
  134. #ifndef SQLITE_MAX_COMPOUND_SELECT
  135. # define SQLITE_MAX_COMPOUND_SELECT 500
  136. #endif
  137. /*
  138. ** The maximum number of opcodes in a VDBE program.
  139. ** Not currently enforced.
  140. */
  141. #ifndef SQLITE_MAX_VDBE_OP
  142. # define SQLITE_MAX_VDBE_OP 25000
  143. #endif
  144. /*
  145. ** The maximum number of arguments to an SQL function.
  146. */
  147. #ifndef SQLITE_MAX_FUNCTION_ARG
  148. # define SQLITE_MAX_FUNCTION_ARG 127
  149. #endif
  150. /*
  151. ** The maximum number of in-memory pages to use for the main database
  152. ** table and for temporary tables. The SQLITE_DEFAULT_CACHE_SIZE
  153. */
  154. #ifndef SQLITE_DEFAULT_CACHE_SIZE
  155. # define SQLITE_DEFAULT_CACHE_SIZE 2000
  156. #endif
  157. #ifndef SQLITE_DEFAULT_TEMP_CACHE_SIZE
  158. # define SQLITE_DEFAULT_TEMP_CACHE_SIZE 500
  159. #endif
  160. /*
  161. ** The maximum number of attached databases. This must be between 0
  162. ** and 30. The upper bound on 30 is because a 32-bit integer bitmap
  163. ** is used internally to track attached databases.
  164. */
  165. #ifndef SQLITE_MAX_ATTACHED
  166. # define SQLITE_MAX_ATTACHED 10
  167. #endif
  168. /*
  169. ** The maximum value of a ?nnn wildcard that the parser will accept.
  170. */
  171. #ifndef SQLITE_MAX_VARIABLE_NUMBER
  172. # define SQLITE_MAX_VARIABLE_NUMBER 999
  173. #endif
  174. /* Maximum page size. The upper bound on this value is 32768. This a limit
  175. ** imposed by the necessity of storing the value in a 2-byte unsigned integer
  176. ** and the fact that the page size must be a power of 2.
  177. **
  178. ** If this limit is changed, then the compiled library is technically
  179. ** incompatible with an SQLite library compiled with a different limit. If
  180. ** a process operating on a database with a page-size of 65536 bytes
  181. ** crashes, then an instance of SQLite compiled with the default page-size
  182. ** limit will not be able to rollback the aborted transaction. This could
  183. ** lead to database corruption.
  184. */
  185. #ifndef SQLITE_MAX_PAGE_SIZE
  186. # define SQLITE_MAX_PAGE_SIZE 32768
  187. #endif
  188. /*
  189. ** The default size of a database page.
  190. */
  191. #ifndef SQLITE_DEFAULT_PAGE_SIZE
  192. # define SQLITE_DEFAULT_PAGE_SIZE 1024
  193. #endif
  194. #if SQLITE_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE
  195. # undef SQLITE_DEFAULT_PAGE_SIZE
  196. # define SQLITE_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE
  197. #endif
  198. /*
  199. ** Ordinarily, if no value is explicitly provided, SQLite creates databases
  200. ** with page size SQLITE_DEFAULT_PAGE_SIZE. However, based on certain
  201. ** device characteristics (sector-size and atomic write() support),
  202. ** SQLite may choose a larger value. This constant is the maximum value
  203. ** SQLite will choose on its own.
  204. */
  205. #ifndef SQLITE_MAX_DEFAULT_PAGE_SIZE
  206. # define SQLITE_MAX_DEFAULT_PAGE_SIZE 8192
  207. #endif
  208. #if SQLITE_MAX_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE
  209. # undef SQLITE_MAX_DEFAULT_PAGE_SIZE
  210. # define SQLITE_MAX_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE
  211. #endif
  212. /*
  213. ** Maximum number of pages in one database file.
  214. **
  215. ** This is really just the default value for the max_page_count pragma.
  216. ** This value can be lowered (or raised) at run-time using that the
  217. ** max_page_count macro.
  218. */
  219. #ifndef SQLITE_MAX_PAGE_COUNT
  220. # define SQLITE_MAX_PAGE_COUNT 1073741823
  221. #endif
  222. /*
  223. ** Maximum length (in bytes) of the pattern in a LIKE or GLOB
  224. ** operator.
  225. */
  226. #ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH
  227. # define SQLITE_MAX_LIKE_PATTERN_LENGTH 50000
  228. #endif
  229. /************** End of sqliteLimit.h *****************************************/
  230. /************** Continuing where we left off in sqliteInt.h ******************/
  231. /* Disable nuisance warnings on Borland compilers */
  232. #if defined(__BORLANDC__)
  233. #pragma warn -rch /* unreachable code */
  234. #pragma warn -ccc /* Condition is always true or false */
  235. #pragma warn -aus /* Assigned value is never used */
  236. #pragma warn -csu /* Comparing signed and unsigned */
  237. #pragma warn -spa /* Suspicious pointer arithmetic */
  238. #endif
  239. /* Needed for various definitions... */
  240. #ifndef _GNU_SOURCE
  241. # define _GNU_SOURCE
  242. #endif
  243. /*
  244. ** Include standard header files as necessary
  245. */
  246. #ifdef HAVE_STDINT_H
  247. #include <stdint.h>
  248. #endif
  249. #ifdef HAVE_INTTYPES_H
  250. #include <inttypes.h>
  251. #endif
  252. /*
  253. * This macro is used to "hide" some ugliness in casting an int
  254. * value to a ptr value under the MSVC 64-bit compiler. Casting
  255. * non 64-bit values to ptr types results in a "hard" error with
  256. * the MSVC 64-bit compiler which this attempts to avoid.
  257. *
  258. * A simple compiler pragma or casting sequence could not be found
  259. * to correct this in all situations, so this macro was introduced.
  260. *
  261. * It could be argued that the intptr_t type could be used in this
  262. * case, but that type is not available on all compilers, or
  263. * requires the #include of specific headers which differs between
  264. * platforms.
  265. */
  266. #define SQLITE_INT_TO_PTR(X) ((void*)&((char*)0)[X])
  267. #define SQLITE_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0))
  268. /*
  269. ** These #defines should enable >2GB file support on POSIX if the
  270. ** underlying operating system supports it. If the OS lacks
  271. ** large file support, or if the OS is windows, these should be no-ops.
  272. **
  273. ** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any
  274. ** system #includes. Hence, this block of code must be the very first
  275. ** code in all source files.
  276. **
  277. ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
  278. ** on the compiler command line. This is necessary if you are compiling
  279. ** on a recent machine (ex: Red Hat 7.2) but you want your code to work
  280. ** on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2
  281. ** without this option, LFS is enable. But LFS does not exist in the kernel
  282. ** in Red Hat 6.0, so the code won't work. Hence, for maximum binary
  283. ** portability you should omit LFS.
  284. **
  285. ** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later.
  286. */
  287. #ifndef SQLITE_DISABLE_LFS
  288. # define _LARGE_FILE 1
  289. # ifndef _FILE_OFFSET_BITS
  290. # define _FILE_OFFSET_BITS 64
  291. # endif
  292. # define _LARGEFILE_SOURCE 1
  293. #endif
  294. /*
  295. ** The SQLITE_THREADSAFE macro must be defined as either 0 or 1.
  296. ** Older versions of SQLite used an optional THREADSAFE macro.
  297. ** We support that for legacy
  298. */
  299. #if !defined(SQLITE_THREADSAFE)
  300. #if defined(THREADSAFE)
  301. # define SQLITE_THREADSAFE THREADSAFE
  302. #else
  303. # define SQLITE_THREADSAFE 1
  304. #endif
  305. #endif
  306. /*
  307. ** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1.
  308. ** It determines whether or not the features related to
  309. ** SQLITE_CONFIG_MEMSTATUS are available by default or not. This value can
  310. ** be overridden at runtime using the sqlite3_config() API.
  311. */
  312. #if !defined(SQLITE_DEFAULT_MEMSTATUS)
  313. # define SQLITE_DEFAULT_MEMSTATUS 1
  314. #endif
  315. /*
  316. ** Exactly one of the following macros must be defined in order to
  317. ** specify which memory allocation subsystem to use.
  318. **
  319. ** SQLITE_SYSTEM_MALLOC // Use normal system malloc()
  320. ** SQLITE_MEMDEBUG // Debugging version of system malloc()
  321. ** SQLITE_MEMORY_SIZE // internal allocator #1
  322. ** SQLITE_MMAP_HEAP_SIZE // internal mmap() allocator
  323. ** SQLITE_POW2_MEMORY_SIZE // internal power-of-two allocator
  324. **
  325. ** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as
  326. ** the default.
  327. */
  328. #if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)+\
  329. defined(SQLITE_MEMORY_SIZE)+defined(SQLITE_MMAP_HEAP_SIZE)+\
  330. defined(SQLITE_POW2_MEMORY_SIZE)>1
  331. # error "At most one of the following compile-time configuration options\
  332. is allows: SQLITE_SYSTEM_MALLOC, SQLITE_MEMDEBUG, SQLITE_MEMORY_SIZE,\
  333. SQLITE_MMAP_HEAP_SIZE, SQLITE_POW2_MEMORY_SIZE"
  334. #endif
  335. #if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)+\
  336. defined(SQLITE_MEMORY_SIZE)+defined(SQLITE_MMAP_HEAP_SIZE)+\
  337. defined(SQLITE_POW2_MEMORY_SIZE)==0
  338. # define SQLITE_SYSTEM_MALLOC 1
  339. #endif
  340. /*
  341. ** If SQLITE_MALLOC_SOFT_LIMIT is defined, then try to keep the
  342. ** sizes of memory allocations below this value where possible.
  343. */
  344. #if defined(SQLITE_POW2_MEMORY_SIZE) && !defined(SQLITE_MALLOC_SOFT_LIMIT)
  345. # define SQLITE_MALLOC_SOFT_LIMIT 1024
  346. #endif
  347. /*
  348. ** We need to define _XOPEN_SOURCE as follows in order to enable
  349. ** recursive mutexes on most Unix systems. But Mac OS X is different.
  350. ** The _XOPEN_SOURCE define causes problems for Mac OS X we are told,
  351. ** so it is omitted there. See ticket #2673.
  352. **
  353. ** Later we learn that _XOPEN_SOURCE is poorly or incorrectly
  354. ** implemented on some systems. So we avoid defining it at all
  355. ** if it is already defined or if it is unneeded because we are
  356. ** not doing a threadsafe build. Ticket #2681.
  357. **
  358. ** See also ticket #2741.
  359. */
  360. #if !defined(_XOPEN_SOURCE) && !defined(__DARWIN__) && !defined(__APPLE__) && SQLITE_THREADSAFE
  361. # define _XOPEN_SOURCE 500 /* Needed to enable pthread recursive mutexes */
  362. #endif
  363. /*
  364. ** The TCL headers are only needed when compiling the TCL bindings.
  365. */
  366. #if defined(SQLITE_TCL) || defined(TCLSH)
  367. # include <tcl.h>
  368. #endif
  369. /*
  370. ** Many people are failing to set -DNDEBUG=1 when compiling SQLite.
  371. ** Setting NDEBUG makes the code smaller and run faster. So the following
  372. ** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1
  373. ** option is set. Thus NDEBUG becomes an opt-in rather than an opt-out
  374. ** feature.
  375. */
  376. #if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
  377. # define NDEBUG 1
  378. #endif
  379. /*
  380. ** The testcase() macro is used to aid in coverage testing. When
  381. ** doing coverage testing, the condition inside the argument to
  382. ** testcase() must be evaluated both true and false in order to
  383. ** get full branch coverage. The testcase() macro is inserted
  384. ** to help ensure adequate test coverage in places where simple
  385. ** condition/decision coverage is inadequate. For example, testcase()
  386. ** can be used to make sure boundary values are tested. For
  387. ** bitmask tests, testcase() can be used to make sure each bit
  388. ** is significant and used at least once. On switch statements
  389. ** where multiple cases go to the same block of code, testcase()
  390. ** can insure that all cases are evaluated.
  391. **
  392. */
  393. #ifdef SQLITE_COVERAGE_TEST
  394. SQLITE_PRIVATE void sqlite3Coverage(int);
  395. # define testcase(X) if( X ){ sqlite3Coverage(__LINE__); }
  396. #else
  397. # define testcase(X)
  398. #endif
  399. /*
  400. ** The TESTONLY macro is used to enclose variable declarations or
  401. ** other bits of code that are needed to support the arguments
  402. ** within testcase() and assert() macros.
  403. */
  404. #if !defined(NDEBUG) || defined(SQLITE_COVERAGE_TEST)
  405. # define TESTONLY(X) X
  406. #else
  407. # define TESTONLY(X)
  408. #endif
  409. /*
  410. ** The ALWAYS and NEVER macros surround boolean expressions which
  411. ** are intended to always be true or false, respectively. Such
  412. ** expressions could be omitted from the code completely. But they
  413. ** are included in a few cases in order to enhance the resilience
  414. ** of SQLite to unexpected behavior - to make the code "self-healing"
  415. ** or "ductile" rather than being "brittle" and crashing at the first
  416. ** hint of unplanned behavior.
  417. **
  418. ** In other words, ALWAYS and NEVER are added for defensive code.
  419. **
  420. ** When doing coverage testing ALWAYS and NEVER are hard-coded to
  421. ** be true and false so that the unreachable code then specify will
  422. ** not be counted as untested code.
  423. */
  424. #if defined(SQLITE_COVERAGE_TEST)
  425. # define ALWAYS(X) (1)
  426. # define NEVER(X) (0)
  427. #elif !defined(NDEBUG)
  428. SQLITE_PRIVATE int sqlite3Assert(void);
  429. # define ALWAYS(X) ((X)?1:sqlite3Assert())
  430. # define NEVER(X) ((X)?sqlite3Assert():0)
  431. #else
  432. # define ALWAYS(X) (X)
  433. # define NEVER(X) (X)
  434. #endif
  435. /*
  436. ** The macro unlikely() is a hint that surrounds a boolean
  437. ** expression that is usually false. Macro likely() surrounds
  438. ** a boolean expression that is usually true. GCC is able to
  439. ** use these hints to generate better code, sometimes.
  440. */
  441. #if defined(__GNUC__) && 0
  442. # define likely(X) __builtin_expect((X),1)
  443. # define unlikely(X) __builtin_expect((X),0)
  444. #else
  445. # define likely(X) !!(X)
  446. # define unlikely(X) !!(X)
  447. #endif
  448. /*
  449. ** Sometimes we need a small amount of code such as a variable initialization
  450. ** to setup for a later assert() statement. We do not want this code to
  451. ** appear when assert() is disabled. The following macro is therefore
  452. ** used to contain that setup code. The "VVA" acronym stands for
  453. ** "Verification, Validation, and Accreditation". In other words, the
  454. ** code within VVA_ONLY() will only run during verification processes.
  455. */
  456. #ifndef NDEBUG
  457. # define VVA_ONLY(X) X
  458. #else
  459. # define VVA_ONLY(X)
  460. #endif
  461. /************** Include sqlite3.h in the middle of sqliteInt.h ***************/
  462. /************** Begin file sqlite3.h *****************************************/
  463. /*
  464. ** 2001 September 15
  465. **
  466. ** The author disclaims copyright to this source code. In place of
  467. ** a legal notice, here is a blessing:
  468. **
  469. ** May you do good and not evil.
  470. ** May you find forgiveness for yourself and forgive others.
  471. ** May you share freely, never taking more than you give.
  472. **
  473. *************************************************************************
  474. ** This header file defines the interface that the SQLite library
  475. ** presents to client programs. If a C-function, structure, datatype,
  476. ** or constant definition does not appear in this file, then it is
  477. ** not a published API of SQLite, is subject to change without
  478. ** notice, and should not be referenced by programs that use SQLite.
  479. **
  480. ** Some of the definitions that are in this file are marked as
  481. ** "experimental". Experimental interfaces are normally new
  482. ** features recently added to SQLite. We do not anticipate changes
  483. ** to experimental interfaces but reserve to make minor changes if
  484. ** experience from use "in the wild" suggest such changes are prudent.
  485. **
  486. ** The official C-language API documentation for SQLite is derived
  487. ** from comments in this file. This file is the authoritative source
  488. ** on how SQLite interfaces are suppose to operate.
  489. **
  490. ** The name of this file under configuration management is "sqlite.h.in".
  491. ** The makefile makes some minor changes to this file (such as inserting
  492. ** the version number) and changes its name to "sqlite3.h" as
  493. ** part of the build process.
  494. **
  495. ** @(#) $Id: sqlite.h.in,v 1.421 2008/12/30 06:24:58 danielk1977 Exp $
  496. */
  497. #ifndef _SQLITE3_H_
  498. #define _SQLITE3_H_
  499. #include <stdarg.h> /* Needed for the definition of va_list */
  500. /*
  501. ** Make sure we can call this stuff from C++.
  502. */
  503. #if 0
  504. extern "C" {
  505. #endif
  506. /*
  507. ** Add the ability to override 'extern'
  508. */
  509. #ifndef SQLITE_EXTERN
  510. # define SQLITE_EXTERN extern
  511. #endif
  512. /*
  513. ** These no-op macros are used in front of interfaces to mark those
  514. ** interfaces as either deprecated or experimental. New applications
  515. ** should not use deprecated intrfaces - they are support for backwards
  516. ** compatibility only. Application writers should be aware that
  517. ** experimental interfaces are subject to change in point releases.
  518. **
  519. ** These macros used to resolve to various kinds of compiler magic that
  520. ** would generate warning messages when they were used. But that
  521. ** compiler magic ended up generating such a flurry of bug reports
  522. ** that we have taken it all out and gone back to using simple
  523. ** noop macros.
  524. */
  525. #define SQLITE_DEPRECATED
  526. #define SQLITE_EXPERIMENTAL
  527. /*
  528. ** Ensure these symbols were not defined by some previous header file.
  529. */
  530. #ifdef SQLITE_VERSION
  531. # undef SQLITE_VERSION
  532. #endif
  533. #ifdef SQLITE_VERSION_NUMBER
  534. # undef SQLITE_VERSION_NUMBER
  535. #endif
  536. /*
  537. ** CAPI3REF: Compile-Time Library Version Numbers {H10010} <S60100>
  538. **
  539. ** The SQLITE_VERSION and SQLITE_VERSION_NUMBER #defines in
  540. ** the sqlite3.h file specify the version of SQLite with which
  541. ** that header file is associated.
  542. **
  543. ** The "version" of SQLite is a string of the form "X.Y.Z".
  544. ** The phrase "alpha" or "beta" might be appended after the Z.
  545. ** The X value is major version number always 3 in SQLite3.
  546. ** The X value only changes when backwards compatibility is
  547. ** broken and we intend to never break backwards compatibility.
  548. ** The Y value is the minor version number and only changes when
  549. ** there are major feature enhancements that are forwards compatible
  550. ** but not backwards compatible.
  551. ** The Z value is the release number and is incremented with
  552. ** each release but resets back to 0 whenever Y is incremented.
  553. **
  554. ** See also: [sqlite3_libversion()] and [sqlite3_libversion_number()].
  555. **
  556. ** INVARIANTS:
  557. **
  558. ** {H10011} The SQLITE_VERSION #define in the sqlite3.h header file shall
  559. ** evaluate to a string literal that is the SQLite version
  560. ** with which the header file is associated.
  561. **
  562. ** {H10014} The SQLITE_VERSION_NUMBER #define shall resolve to an integer
  563. ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z
  564. ** are the major version, minor version, and release number.
  565. */
  566. #define SQLITE_VERSION "3.6.10"
  567. #define SQLITE_VERSION_NUMBER 3006010
  568. /*
  569. ** CAPI3REF: Run-Time Library Version Numbers {H10020} <S60100>
  570. ** KEYWORDS: sqlite3_version
  571. **
  572. ** These features provide the same information as the [SQLITE_VERSION]
  573. ** and [SQLITE_VERSION_NUMBER] #defines in the header, but are associated
  574. ** with the library instead of the header file. Cautious programmers might
  575. ** include a check in their application to verify that
  576. ** sqlite3_libversion_number() always returns the value
  577. ** [SQLITE_VERSION_NUMBER].
  578. **
  579. ** The sqlite3_libversion() function returns the same information as is
  580. ** in the sqlite3_version[] string constant. The function is provided
  581. ** for use in DLLs since DLL users usually do not have direct access to string
  582. ** constants within the DLL.
  583. **
  584. ** INVARIANTS:
  585. **
  586. ** {H10021} The [sqlite3_libversion_number()] interface shall return
  587. ** an integer equal to [SQLITE_VERSION_NUMBER].
  588. **
  589. ** {H10022} The [sqlite3_version] string constant shall contain
  590. ** the text of the [SQLITE_VERSION] string.
  591. **
  592. ** {H10023} The [sqlite3_libversion()] function shall return
  593. ** a pointer to the [sqlite3_version] string constant.
  594. */
  595. SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
  596. SQLITE_API const char *sqlite3_libversion(void);
  597. SQLITE_API int sqlite3_libversion_number(void);
  598. /*
  599. ** CAPI3REF: Test To See If The Library Is Threadsafe {H10100} <S60100>
  600. **
  601. ** SQLite can be compiled with or without mutexes. When
  602. ** the [SQLITE_THREADSAFE] C preprocessor macro 1 or 2, mutexes
  603. ** are enabled and SQLite is threadsafe. When the
  604. ** [SQLITE_THREADSAFE] macro is 0,
  605. ** the mutexes are omitted. Without the mutexes, it is not safe
  606. ** to use SQLite concurrently from more than one thread.
  607. **
  608. ** Enabling mutexes incurs a measurable performance penalty.
  609. ** So if speed is of utmost importance, it makes sense to disable
  610. ** the mutexes. But for maximum safety, mutexes should be enabled.
  611. ** The default behavior is for mutexes to be enabled.
  612. **
  613. ** This interface can be used by a program to make sure that the
  614. ** version of SQLite that it is linking against was compiled with
  615. ** the desired setting of the [SQLITE_THREADSAFE] macro.
  616. **
  617. ** This interface only reports on the compile-time mutex setting
  618. ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
  619. ** SQLITE_THREADSAFE=1 then mutexes are enabled by default but
  620. ** can be fully or partially disabled using a call to [sqlite3_config()]
  621. ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
  622. ** or [SQLITE_CONFIG_MUTEX]. The return value of this function shows
  623. ** only the default compile-time setting, not any run-time changes
  624. ** to that setting.
  625. **
  626. ** See the [threading mode] documentation for additional information.
  627. **
  628. ** INVARIANTS:
  629. **
  630. ** {H10101} The [sqlite3_threadsafe()] function shall return zero if
  631. ** and only if SQLite was compiled with mutexing code omitted.
  632. **
  633. ** {H10102} The value returned by the [sqlite3_threadsafe()] function
  634. ** shall remain the same across calls to [sqlite3_config()].
  635. */
  636. SQLITE_API int sqlite3_threadsafe(void);
  637. /*
  638. ** CAPI3REF: Database Connection Handle {H12000} <S40200>
  639. ** KEYWORDS: {database connection} {database connections}
  640. **
  641. ** Each open SQLite database is represented by a pointer to an instance of
  642. ** the opaque structure named "sqlite3". It is useful to think of an sqlite3
  643. ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and
  644. ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
  645. ** is its destructor. There are many other interfaces (such as
  646. ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
  647. ** [sqlite3_busy_timeout()] to name but three) that are methods on an
  648. ** sqlite3 object.
  649. */
  650. typedef struct sqlite3 sqlite3;
  651. /*
  652. ** CAPI3REF: 64-Bit Integer Types {H10200} <S10110>
  653. ** KEYWORDS: sqlite_int64 sqlite_uint64
  654. **
  655. ** Because there is no cross-platform way to specify 64-bit integer types
  656. ** SQLite includes typedefs for 64-bit signed and unsigned integers.
  657. **
  658. ** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
  659. ** The sqlite_int64 and sqlite_uint64 types are supported for backwards
  660. ** compatibility only.
  661. **
  662. ** INVARIANTS:
  663. **
  664. ** {H10201} The [sqlite_int64] and [sqlite3_int64] type shall specify
  665. ** a 64-bit signed integer.
  666. **
  667. ** {H10202} The [sqlite_uint64] and [sqlite3_uint64] type shall specify
  668. ** a 64-bit unsigned integer.
  669. */
  670. #ifdef SQLITE_INT64_TYPE
  671. typedef SQLITE_INT64_TYPE sqlite_int64;
  672. typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
  673. #elif defined(_MSC_VER) || defined(__BORLANDC__)
  674. typedef __int64 sqlite_int64;
  675. typedef unsigned __int64 sqlite_uint64;
  676. #else
  677. typedef long long int sqlite_int64;
  678. typedef unsigned long long int sqlite_uint64;
  679. #endif
  680. typedef sqlite_int64 sqlite3_int64;
  681. typedef sqlite_uint64 sqlite3_uint64;
  682. /*
  683. ** If compiling for a processor that lacks floating point support,
  684. ** substitute integer for floating-point.
  685. */
  686. #ifdef SQLITE_OMIT_FLOATING_POINT
  687. # define double sqlite3_int64
  688. #endif
  689. /*
  690. ** CAPI3REF: Closing A Database Connection {H12010} <S30100><S40200>
  691. **
  692. ** This routine is the destructor for the [sqlite3] object.
  693. **
  694. ** Applications should [sqlite3_finalize | finalize] all [prepared statements]
  695. ** and [sqlite3_blob_close | close] all [BLOB handles] associated with
  696. ** the [sqlite3] object prior to attempting to close the object.
  697. ** The [sqlite3_next_stmt()] interface can be used to locate all
  698. ** [prepared statements] associated with a [database connection] if desired.
  699. ** Typical code might look like this:
  700. **
  701. ** <blockquote><pre>
  702. ** sqlite3_stmt *pStmt;
  703. ** while( (pStmt = sqlite3_next_stmt(db, 0))!=0 ){
  704. ** &nbsp; sqlite3_finalize(pStmt);
  705. ** }
  706. ** </pre></blockquote>
  707. **
  708. ** If [sqlite3_close()] is invoked while a transaction is open,
  709. ** the transaction is automatically rolled back.
  710. **
  711. ** INVARIANTS:
  712. **
  713. ** {H12011} A successful call to [sqlite3_close(C)] shall destroy the
  714. ** [database connection] object C.
  715. **
  716. ** {H12012} A successful call to [sqlite3_close(C)] shall return SQLITE_OK.
  717. **
  718. ** {H12013} A successful call to [sqlite3_close(C)] shall release all
  719. ** memory and system resources associated with [database connection]
  720. ** C.
  721. **
  722. ** {H12014} A call to [sqlite3_close(C)] on a [database connection] C that
  723. ** has one or more open [prepared statements] shall fail with
  724. ** an [SQLITE_BUSY] error code.
  725. **
  726. ** {H12015} A call to [sqlite3_close(C)] where C is a NULL pointer shall
  727. ** be a harmless no-op returning SQLITE_OK.
  728. **
  729. ** {H12019} When [sqlite3_close(C)] is invoked on a [database connection] C
  730. ** that has a pending transaction, the transaction shall be
  731. ** rolled back.
  732. **
  733. ** ASSUMPTIONS:
  734. **
  735. ** {A12016} The C parameter to [sqlite3_close(C)] must be either a NULL
  736. ** pointer or an [sqlite3] object pointer obtained
  737. ** from [sqlite3_open()], [sqlite3_open16()], or
  738. ** [sqlite3_open_v2()], and not previously closed.
  739. */
  740. SQLITE_API int sqlite3_close(sqlite3 *);
  741. /*
  742. ** The type for a callback function.
  743. ** This is legacy and deprecated. It is included for historical
  744. ** compatibility and is not documented.
  745. */
  746. typedef int (*sqlite3_callback)(void*,int,char**, char**);
  747. /*
  748. ** CAPI3REF: One-Step Query Execution Interface {H12100} <S10000>
  749. **
  750. ** The sqlite3_exec() interface is a convenient way of running one or more
  751. ** SQL statements without having to write a lot of C code. The UTF-8 encoded
  752. ** SQL statements are passed in as the second parameter to sqlite3_exec().
  753. ** The statements are evaluated one by one until either an error or
  754. ** an interrupt is encountered, or until they are all done. The 3rd parameter
  755. ** is an optional callback that is invoked once for each row of any query
  756. ** results produced by the SQL statements. The 5th parameter tells where
  757. ** to write any error messages.
  758. **
  759. ** The error message passed back through the 5th parameter is held
  760. ** in memory obtained from [sqlite3_malloc()]. To avoid a memory leak,
  761. ** the calling application should call [sqlite3_free()] on any error
  762. ** message returned through the 5th parameter when it has finished using
  763. ** the error message.
  764. **
  765. ** If the SQL statement in the 2nd parameter is NULL or an empty string
  766. ** or a string containing only whitespace and comments, then no SQL
  767. ** statements are evaluated and the database is not changed.
  768. **
  769. ** The sqlite3_exec() interface is implemented in terms of
  770. ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()].
  771. ** The sqlite3_exec() routine does nothing to the database that cannot be done
  772. ** by [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()].
  773. **
  774. ** INVARIANTS:
  775. **
  776. ** {H12101} A successful invocation of [sqlite3_exec(D,S,C,A,E)]
  777. ** shall sequentially evaluate all of the UTF-8 encoded,
  778. ** semicolon-separated SQL statements in the zero-terminated
  779. ** string S within the context of the [database connection] D.
  780. **
  781. ** {H12102} If the S parameter to [sqlite3_exec(D,S,C,A,E)] is NULL then
  782. ** the actions of the interface shall be the same as if the
  783. ** S parameter were an empty string.
  784. **
  785. ** {H12104} The return value of [sqlite3_exec()] shall be [SQLITE_OK] if all
  786. ** SQL statements run successfully and to completion.
  787. **
  788. ** {H12105} The return value of [sqlite3_exec()] shall be an appropriate
  789. ** non-zero [error code] if any SQL statement fails.
  790. **
  791. ** {H12107} If one or more of the SQL statements handed to [sqlite3_exec()]
  792. ** return results and the 3rd parameter is not NULL, then
  793. ** the callback function specified by the 3rd parameter shall be
  794. ** invoked once for each row of result.
  795. **
  796. ** {H12110} If the callback returns a non-zero value then [sqlite3_exec()]
  797. ** shall abort the SQL statement it is currently evaluating,
  798. ** skip all subsequent SQL statements, and return [SQLITE_ABORT].
  799. **
  800. ** {H12113} The [sqlite3_exec()] routine shall pass its 4th parameter through
  801. ** as the 1st parameter of the callback.
  802. **
  803. ** {H12116} The [sqlite3_exec()] routine shall set the 2nd parameter of its
  804. ** callback to be the number of columns in the current row of
  805. ** result.
  806. **
  807. ** {H12119} The [sqlite3_exec()] routine shall set the 3rd parameter of its
  808. ** callback to be an array of pointers to strings holding the
  809. ** values for each column in the current result set row as
  810. ** obtained from [sqlite3_column_text()].
  811. **
  812. ** {H12122} The [sqlite3_exec()] routine shall set the 4th parameter of its
  813. ** callback to be an array of pointers to strings holding the
  814. ** names of result columns as obtained from [sqlite3_column_name()].
  815. **
  816. ** {H12125} If the 3rd parameter to [sqlite3_exec()] is NULL then
  817. ** [sqlite3_exec()] shall silently discard query results.
  818. **
  819. ** {H12131} If an error occurs while parsing or evaluating any of the SQL
  820. ** statements in the S parameter of [sqlite3_exec(D,S,C,A,E)] and if
  821. ** the E parameter is not NULL, then [sqlite3_exec()] shall store
  822. ** in *E an appropriate error message written into memory obtained
  823. ** from [sqlite3_malloc()].
  824. **
  825. ** {H12134} The [sqlite3_exec(D,S,C,A,E)] routine shall set the value of
  826. ** *E to NULL if E is not NULL and there are no errors.
  827. **
  828. ** {H12137} The [sqlite3_exec(D,S,C,A,E)] function shall set the [error code]
  829. ** and message accessible via [sqlite3_errcode()],
  830. ** [sqlite3_extended_errcode()],
  831. ** [sqlite3_errmsg()], and [sqlite3_errmsg16()].
  832. **
  833. ** {H12138} If the S parameter to [sqlite3_exec(D,S,C,A,E)] is NULL or an
  834. ** empty string or contains nothing other than whitespace, comments,
  835. ** and/or semicolons, then results of [sqlite3_errcode()],
  836. ** [sqlite3_extended_errcode()],
  837. ** [sqlite3_errmsg()], and [sqlite3_errmsg16()]
  838. ** shall reset to indicate no errors.
  839. **
  840. ** ASSUMPTIONS:
  841. **
  842. ** {A12141} The first parameter to [sqlite3_exec()] must be an valid and open
  843. ** [database connection].
  844. **
  845. ** {A12142} The database connection must not be closed while
  846. ** [sqlite3_exec()] is running.
  847. **
  848. ** {A12143} The calling function should use [sqlite3_free()] to free
  849. ** the memory that *errmsg is left pointing at once the error
  850. ** message is no longer needed.
  851. **
  852. ** {A12145} The SQL statement text in the 2nd parameter to [sqlite3_exec()]
  853. ** must remain unchanged while [sqlite3_exec()] is running.
  854. */
  855. SQLITE_API int sqlite3_exec(
  856. sqlite3*, /* An open database */
  857. const char *sql, /* SQL to be evaluated */
  858. int (*callback)(void*,int,char**,char**), /* Callback function */
  859. void *, /* 1st argument to callback */
  860. char **errmsg /* Error msg written here */
  861. );
  862. /*
  863. ** CAPI3REF: Result Codes {H10210} <S10700>
  864. ** KEYWORDS: SQLITE_OK {error code} {error codes}
  865. ** KEYWORDS: {result code} {result codes}
  866. **
  867. ** Many SQLite functions return an integer result code from the set shown
  868. ** here in order to indicates success or failure.
  869. **
  870. ** New error codes may be added in future versions of SQLite.
  871. **
  872. ** See also: [SQLITE_IOERR_READ | extended result codes]
  873. */
  874. #define SQLITE_OK 0 /* Successful result */
  875. /* beginning-of-error-codes */
  876. #define SQLITE_ERROR 1 /* SQL error or missing database */
  877. #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
  878. #define SQLITE_PERM 3 /* Access permission denied */
  879. #define SQLITE_ABORT 4 /* Callback routine requested an abort */
  880. #define SQLITE_BUSY 5 /* The database file is locked */
  881. #define SQLITE_LOCKED 6 /* A table in the database is locked */
  882. #define SQLITE_NOMEM 7 /* A malloc() failed */
  883. #define SQLITE_READONLY 8 /* Attempt to write a readonly database */
  884. #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
  885. #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
  886. #define SQLITE_CORRUPT 11 /* The database disk image is malformed */
  887. #define SQLITE_NOTFOUND 12 /* NOT USED. Table or record not found */
  888. #define SQLITE_FULL 13 /* Insertion failed because database is full */
  889. #define SQLITE_CANTOPEN 14 /* Unable to open the database file */
  890. #define SQLITE_PROTOCOL 15 /* NOT USED. Database lock protocol error */
  891. #define SQLITE_EMPTY 16 /* Database is empty */
  892. #define SQLITE_SCHEMA 17 /* The database schema changed */
  893. #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
  894. #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
  895. #define SQLITE_MISMATCH 20 /* Data type mismatch */
  896. #define SQLITE_MISUSE 21 /* Library used incorrectly */
  897. #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
  898. #define SQLITE_AUTH 23 /* Authorization denied */
  899. #define SQLITE_FORMAT 24 /* Auxiliary database format error */
  900. #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
  901. #define SQLITE_NOTADB 26 /* File opened that is not a database file */
  902. #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
  903. #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
  904. /* end-of-error-codes */
  905. /*
  906. ** CAPI3REF: Extended Result Codes {H10220} <S10700>
  907. ** KEYWORDS: {extended error code} {extended error codes}
  908. ** KEYWORDS: {extended result code} {extended result codes}
  909. **
  910. ** In its default configuration, SQLite API routines return one of 26 integer
  911. ** [SQLITE_OK | result codes]. However, experience has shown that many of
  912. ** these result codes are too coarse-grained. They do not provide as
  913. ** much information about problems as programmers might like. In an effort to
  914. ** address this, newer versions of SQLite (version 3.3.8 and later) include
  915. ** support for additional result codes that provide more detailed information
  916. ** about errors. The extended result codes are enabled or disabled
  917. ** on a per database connection basis using the
  918. ** [sqlite3_extended_result_codes()] API.
  919. **
  920. ** Some of the available extended result codes are listed here.
  921. ** One may expect the number of extended result codes will be expand
  922. ** over time. Software that uses extended result codes should expect
  923. ** to see new result codes in future releases of SQLite.
  924. **
  925. ** The SQLITE_OK result code will never be extended. It will always
  926. ** be exactly zero.
  927. **
  928. ** INVARIANTS:
  929. **
  930. ** {H10223} The symbolic name for an extended result code shall contains
  931. ** a related primary result code as a prefix.
  932. **
  933. ** {H10224} Primary result code names shall contain a single "_" character.
  934. **
  935. ** {H10225} Extended result code names shall contain two or more "_" characters.
  936. **
  937. ** {H10226} The numeric value of an extended result code shall contain the
  938. ** numeric value of its corresponding primary result code in
  939. ** its least significant 8 bits.
  940. */
  941. #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))
  942. #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))
  943. #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8))
  944. #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8))
  945. #define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8))
  946. #define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8))
  947. #define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8))
  948. #define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8))
  949. #define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8))
  950. #define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8))
  951. #define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8))
  952. #define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8))
  953. #define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8))
  954. #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
  955. #define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8))
  956. #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8))
  957. #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8))
  958. /*
  959. ** CAPI3REF: Flags For File Open Operations {H10230} <H11120> <H12700>
  960. **
  961. ** These bit values are intended for use in the
  962. ** 3rd parameter to the [sqlite3_open_v2()] interface and
  963. ** in the 4th parameter to the xOpen method of the
  964. ** [sqlite3_vfs] object.
  965. */
  966. #define SQLITE_OPEN_READONLY 0x00000001
  967. #define SQLITE_OPEN_READWRITE 0x00000002
  968. #define SQLITE_OPEN_CREATE 0x00000004
  969. #define SQLITE_OPEN_DELETEONCLOSE 0x00000008
  970. #define SQLITE_OPEN_EXCLUSIVE 0x00000010
  971. #define SQLITE_OPEN_MAIN_DB 0x00000100
  972. #define SQLITE_OPEN_TEMP_DB 0x00000200
  973. #define SQLITE_OPEN_TRANSIENT_DB 0x00000400
  974. #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800
  975. #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000
  976. #define SQLITE_OPEN_SUBJOURNAL 0x00002000
  977. #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000
  978. #define SQLITE_OPEN_NOMUTEX 0x00008000
  979. #define SQLITE_OPEN_FULLMUTEX 0x00010000
  980. /*
  981. ** CAPI3REF: Device Characteristics {H10240} <H11120>
  982. **
  983. ** The xDeviceCapabilities method of the [sqlite3_io_methods]
  984. ** object returns an integer which is a vector of the these
  985. ** bit values expressing I/O characteristics of the mass storage
  986. ** device that holds the file that the [sqlite3_io_methods]
  987. ** refers to.
  988. **
  989. ** The SQLITE_IOCAP_ATOMIC property means that all writes of
  990. ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
  991. ** mean that writes of blocks that are nnn bytes in size and
  992. ** are aligned to an address which is an integer multiple of
  993. ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
  994. ** that when data is appended to a file, the data is appended
  995. ** first then the size of the file is extended, never the other
  996. ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
  997. ** information is written to disk in the same order as calls
  998. ** to xWrite().
  999. */
  1000. #define SQLITE_IOCAP_ATOMIC 0x00000001
  1001. #define SQLITE_IOCAP_ATOMIC512 0x00000002
  1002. #define SQLITE_IOCAP_ATOMIC1K 0x00000004
  1003. #define SQLITE_IOCAP_ATOMIC2K 0x00000008
  1004. #define SQLITE_IOCAP_ATOMIC4K 0x00000010
  1005. #define SQLITE_IOCAP_ATOMIC8K 0x00000020
  1006. #define SQLITE_IOCAP_ATOMIC16K 0x00000040
  1007. #define SQLITE_IOCAP_ATOMIC32K 0x00000080
  1008. #define SQLITE_IOCAP_ATOMIC64K 0x00000100
  1009. #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
  1010. #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
  1011. /*
  1012. ** CAPI3REF: File Locking Levels {H10250} <H11120> <H11310>
  1013. **
  1014. ** SQLite uses one of these integer values as the second
  1015. ** argument to calls it makes to the xLock() and xUnlock() methods
  1016. ** of an [sqlite3_io_methods] object.
  1017. */
  1018. #define SQLITE_LOCK_NONE 0
  1019. #define SQLITE_LOCK_SHARED 1
  1020. #define SQLITE_LOCK_RESERVED 2
  1021. #define SQLITE_LOCK_PENDING 3
  1022. #define SQLITE_LOCK_EXCLUSIVE 4
  1023. /*
  1024. ** CAPI3REF: Synchronization Type Flags {H10260} <H11120>
  1025. **
  1026. ** When SQLite invokes the xSync() method of an
  1027. ** [sqlite3_io_methods] object it uses a combination of
  1028. ** these integer values as the second argument.
  1029. **
  1030. ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
  1031. ** sync operation only needs to flush data to mass storage. Inode
  1032. ** information need not be flushed. The SQLITE_SYNC_NORMAL flag means
  1033. ** to use normal fsync() semantics. The SQLITE_SYNC_FULL flag means
  1034. ** to use Mac OS X style fullsync instead of fsync().
  1035. */
  1036. #define SQLITE_SYNC_NORMAL 0x00002
  1037. #define SQLITE_SYNC_FULL 0x00003
  1038. #define SQLITE_SYNC_DATAONLY 0x00010
  1039. /*
  1040. ** CAPI3REF: OS Interface Open File Handle {H11110} <S20110>
  1041. **
  1042. ** An [sqlite3_file] object represents an open file in the OS
  1043. ** interface layer. Individual OS interface implementations will
  1044. ** want to subclass this object by appending additional fields
  1045. ** for their own use. The pMethods entry is a pointer to an
  1046. ** [sqlite3_io_methods] object that defines methods for performing
  1047. ** I/O operations on the open file.
  1048. */
  1049. typedef struct sqlite3_file sqlite3_file;
  1050. struct sqlite3_file {
  1051. const struct sqlite3_io_methods *pMethods; /* Methods for an open file */
  1052. };
  1053. /*
  1054. ** CAPI3REF: OS Interface File Virtual Methods Object {H11120} <S20110>
  1055. **
  1056. ** Every file opened by the [sqlite3_vfs] xOpen method populates an
  1057. ** [sqlite3_file] object (or, more commonly, a subclass of the
  1058. ** [sqlite3_file] object) with a pointer to an instance of this object.
  1059. ** This object defines the methods used to perform various operations
  1060. ** against the open file represented by the [sqlite3_file] object.
  1061. **
  1062. ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
  1063. ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
  1064. ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]
  1065. ** flag may be ORed in to indicate that only the data of the file
  1066. ** and not its inode needs to be synced.
  1067. **
  1068. ** The integer values to xLock() and xUnlock() are one of
  1069. ** <ul>
  1070. ** <li> [SQLITE_LOCK_NONE],
  1071. ** <li> [SQLITE_LOCK_SHARED],
  1072. ** <li> [SQLITE_LOCK_RESERVED],
  1073. ** <li> [SQLITE_LOCK_PENDING], or
  1074. ** <li> [SQLITE_LOCK_EXCLUSIVE].
  1075. ** </ul>
  1076. ** xLock() increases the lock. xUnlock() decreases the lock.
  1077. ** The xCheckReservedLock() method checks whether any database connection,
  1078. ** either in this process or in some other process, is holding a RESERVED,
  1079. ** PENDING, or EXCLUSIVE lock on the file. It returns true
  1080. ** if such a lock exists and false otherwise.
  1081. **
  1082. ** The xFileControl() method is a generic interface that allows custom
  1083. ** VFS implementations to directly control an open file using the
  1084. ** [sqlite3_file_control()] interface. The second "op" argument is an
  1085. ** integer opcode. The third argument is a generic pointer intended to
  1086. ** point to a structure that may contain arguments or space in which to
  1087. ** write return values. Potential uses for xFileControl() might be
  1088. ** functions to enable blocking locks with timeouts, to change the
  1089. ** locking strategy (for example to use dot-file locks), to inquire
  1090. ** about the status of a lock, or to break stale locks. The SQLite
  1091. ** core reserves all opcodes less than 100 for its own use.
  1092. ** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available.
  1093. ** Applications that define a custom xFileControl method should use opcodes
  1094. ** greater than 100 to avoid conflicts.
  1095. **
  1096. ** The xSectorSize() method returns the sector size of the
  1097. ** device that underlies the file. The sector size is the
  1098. ** minimum write that can be performed without disturbing
  1099. ** other bytes in the file. The xDeviceCharacteristics()
  1100. ** method returns a bit vector describing behaviors of the
  1101. ** underlying device:
  1102. **
  1103. ** <ul>
  1104. ** <li> [SQLITE_IOCAP_ATOMIC]
  1105. ** <li> [SQLITE_IOCAP_ATOMIC512]
  1106. ** <li> [SQLITE_IOCAP_ATOMIC1K]
  1107. ** <li> [SQLITE_IOCAP_ATOMIC2K]
  1108. ** <li> [SQLITE_IOCAP_ATOMIC4K]
  1109. ** <li> [SQLITE_IOCAP_ATOMIC8K]
  1110. ** <li> [SQLITE_IOCAP_ATOMIC16K]
  1111. ** <li> [SQLITE_IOCAP_ATOMIC32K]
  1112. ** <li> [SQLITE_IOCAP_ATOMIC64K]
  1113. ** <li> [SQLITE_IOCAP_SAFE_APPEND]
  1114. ** <li> [SQLITE_IOCAP_SEQUENTIAL]
  1115. ** </ul>
  1116. **
  1117. ** The SQLITE_IOCAP_ATOMIC property means that all writes of
  1118. ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
  1119. ** mean that writes of blocks that are nnn bytes in size and
  1120. ** are aligned to an address which is an integer multiple of
  1121. ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
  1122. ** that when data is appended to a file, the data is appended
  1123. ** first then the size of the file is extended, never the other
  1124. ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
  1125. ** information is written to disk in the same order as calls
  1126. ** to xWrite().
  1127. **
  1128. ** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
  1129. ** in the unread portions of the buffer with zeros. A VFS that
  1130. ** fails to zero-fill short reads might seem to work. However,
  1131. ** failure to zero-fill short reads will eventually lead to
  1132. ** database corruption.
  1133. */
  1134. typedef struct sqlite3_io_methods sqlite3_io_methods;
  1135. struct sqlite3_io_methods {
  1136. int iVersion;
  1137. int (*xClose)(sqlite3_file*);
  1138. int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
  1139. int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
  1140. int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
  1141. int (*xSync)(sqlite3_file*, int flags);
  1142. int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
  1143. int (*xLock)(sqlite3_file*, int);
  1144. int (*xUnlock)(sqlite3_file*, int);
  1145. int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);
  1146. int (*xFileControl)(sqlite3_file*, int op, void *pArg);
  1147. int (*xSectorSize)(sqlite3_file*);
  1148. int (*xDeviceCharacteristics)(sqlite3_file*);
  1149. /* Additional methods may be added in future releases */
  1150. };
  1151. /*
  1152. ** CAPI3REF: Standard File Control Opcodes {H11310} <S30800>
  1153. **
  1154. ** These integer constants are opcodes for the xFileControl method
  1155. ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
  1156. ** interface.
  1157. **
  1158. ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This
  1159. ** opcode causes the xFileControl method to write the current state of
  1160. ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
  1161. ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
  1162. ** into an integer that the pArg argument points to. This capability
  1163. ** is used during testing and only needs to be supported when SQLITE_TEST
  1164. ** is defined.
  1165. */
  1166. #define SQLITE_FCNTL_LOCKSTATE 1
  1167. #define SQLITE_GET_LOCKPROXYFILE 2
  1168. #define SQLITE_SET_LOCKPROXYFILE 3
  1169. #define SQLITE_LAST_ERRNO 4
  1170. /*
  1171. ** CAPI3REF: Mutex Handle {H17110} <S20130>
  1172. **
  1173. ** The mutex module within SQLite defines [sqlite3_mutex] to be an
  1174. ** abstract type for a mutex object. The SQLite core never looks
  1175. ** at the internal representation of an [sqlite3_mutex]. It only
  1176. ** deals with pointers to the [sqlite3_mutex] object.
  1177. **
  1178. ** Mutexes are created using [sqlite3_mutex_alloc()].
  1179. */
  1180. typedef struct sqlite3_mutex sqlite3_mutex;
  1181. /*
  1182. ** CAPI3REF: OS Interface Object {H11140} <S20100>
  1183. **
  1184. ** An instance of the sqlite3_vfs object defines the interface between
  1185. ** the SQLite core and the underlying operating system. The "vfs"
  1186. ** in the name of the object stands for "virtual file system".
  1187. **
  1188. ** The value of the iVersion field is initially 1 but may be larger in
  1189. ** future versions of SQLite. Additional fields may be appended to this
  1190. ** object when the iVersion value is increased. Note that the structure
  1191. ** of the sqlite3_vfs object changes in the transaction between
  1192. ** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not
  1193. ** modified.
  1194. **
  1195. ** The szOsFile field is the size of the subclassed [sqlite3_file]
  1196. ** structure used by this VFS. mxPathname is the maximum length of
  1197. ** a pathname in this VFS.
  1198. **
  1199. ** Registered sqlite3_vfs objects are kept on a linked list formed by
  1200. ** the pNext pointer. The [sqlite3_vfs_register()]
  1201. ** and [sqlite3_vfs_unregister()] interfaces manage this list
  1202. ** in a thread-safe way. The [sqlite3_vfs_find()] interface
  1203. ** searches the list. Neither the application code nor the VFS
  1204. ** implementation should use the pNext pointer.
  1205. **
  1206. ** The pNext field is the only field in the sqlite3_vfs
  1207. ** structure that SQLite will ever modify. SQLite will only access
  1208. ** or modify this field while holding a particular static mutex.
  1209. ** The application should never modify anything within the sqlite3_vfs
  1210. ** object once the object has been registered.
  1211. **
  1212. ** The zName field holds the name of the VFS module. The name must
  1213. ** be unique across all VFS modules.
  1214. **
  1215. ** SQLite will guarantee that the zFilename parameter to xOpen
  1216. ** is either a NULL pointer or string obtained
  1217. ** from xFullPathname(). SQLite further guarantees that
  1218. ** the string will be valid and unchanged until xClose() is
  1219. ** called. Because of the previous sentense,
  1220. ** the [sqlite3_file] can safely store a pointer to the
  1221. ** filename if it needs to remember the filename for some reason.
  1222. ** If the zFilename parameter is xOpen is a NULL pointer then xOpen
  1223. ** must invite its own temporary name for the file. Whenever the
  1224. ** xFilename parameter is NULL it will also be the case that the
  1225. ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
  1226. **
  1227. ** The flags argument to xOpen() includes all bits set in
  1228. ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]
  1229. ** or [sqlite3_open16()] is used, then flags includes at least
  1230. ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
  1231. ** If xOpen() opens a file read-only then it sets *pOutFlags to
  1232. ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.
  1233. **
  1234. ** SQLite will also add one of the following flags to the xOpen()
  1235. ** call, depending on the object being opened:
  1236. **
  1237. ** <ul>
  1238. ** <li> [SQLITE_OPEN_MAIN_DB]
  1239. ** <li> [SQLITE_OPEN_MAIN_JOURNAL]
  1240. ** <li> [SQLITE_OPEN_TEMP_DB]
  1241. ** <li> [SQLITE_OPEN_TEMP_JOURNAL]
  1242. ** <li> [SQLITE_OPEN_TRANSIENT_DB]
  1243. ** <li> [SQLITE_OPEN_SUBJOURNAL]
  1244. ** <li> [SQLITE_OPEN_MASTER_JOURNAL]
  1245. ** </ul>
  1246. **
  1247. ** The file I/O implementation can use the object type flags to
  1248. ** change the way it deals with files. For example, an application
  1249. ** that does not care about crash recovery or rollback might make
  1250. ** the open of a journal file a no-op. Writes to this journal would
  1251. ** also be no-ops, and any attempt to read the journal would return
  1252. ** SQLITE_IOERR. Or the implementation might recognize that a database
  1253. ** file will be doing page-aligned sector reads and writes in a random
  1254. ** order and set up its I/O subsystem accordingly.
  1255. **
  1256. ** SQLite might also add one of the following flags to the xOpen method:
  1257. **
  1258. ** <ul>
  1259. ** <li> [SQLITE_OPEN_DELETEONCLOSE]
  1260. ** <li> [SQLITE_OPEN_EXCLUSIVE]
  1261. ** </ul>
  1262. **
  1263. ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
  1264. ** deleted when it is closed. The [SQLITE_OPEN_DELETEONCLOSE]
  1265. ** will be set for TEMP databases, journals and for subjournals.
  1266. **
  1267. ** The [SQLITE_OPEN_EXCLUSIVE] flag means the file should be opened
  1268. ** for exclusive access. This flag is set for all files except
  1269. ** for the main database file.
  1270. **
  1271. ** At least szOsFile bytes of memory are allocated by SQLite
  1272. ** to hold the [sqlite3_file] structure passed as the third
  1273. ** argument to xOpen. The xOpen method does not have to
  1274. ** allocate the structure; it should just fill it in.
  1275. **
  1276. ** The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
  1277. ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
  1278. ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
  1279. ** to test whether a file is at least readable. The file can be a
  1280. ** directory.
  1281. **
  1282. ** SQLite will always allocate at least mxPathname+1 bytes for the
  1283. ** output buffer xFullPathname. The exact size of the output buffer
  1284. ** is also passed as a parameter to both methods. If the output buffer
  1285. ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
  1286. ** handled as a fatal error by SQLite, vfs implementations should endeavor
  1287. ** to prevent this by setting mxPathname to a sufficiently large value.
  1288. **
  1289. ** The xRandomness(), xSleep(), and xCurrentTime() interfaces
  1290. ** are not strictly a part of the filesystem, but they are
  1291. ** included in the VFS structure for completeness.
  1292. ** The xRandomness() function attempts to return nBytes bytes
  1293. ** of good-quality randomness into zOut. The return value is
  1294. ** the actual number of bytes of randomness obtained.
  1295. ** The xSleep() method causes the calling thread to sleep for at
  1296. ** least the number of microseconds given. The xCurrentTime()
  1297. ** method returns a Julian Day Number for the current date and time.
  1298. **
  1299. */
  1300. typedef struct sqlite3_vfs sqlite3_vfs;
  1301. struct sqlite3_vfs {
  1302. int iVersion; /* Structure version number */
  1303. int szOsFile; /* Size of subclassed sqlite3_file */
  1304. int mxPathname; /* Maximum file pathname length */
  1305. sqlite3_vfs *pNext; /* Next registered VFS */
  1306. const char *zName; /* Name of this virtual file system */
  1307. void *pAppData; /* Pointer to application-specific data */
  1308. int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*,
  1309. int flags, int *pOutFlags);
  1310. int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
  1311. int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
  1312. int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
  1313. void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
  1314. void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
  1315. void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
  1316. void (*xDlClose)(sqlite3_vfs*, void*);
  1317. int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
  1318. int (*xSleep)(sqlite3_vfs*, int microseconds);
  1319. int (*xCurrentTime)(sqlite3_vfs*, double*);
  1320. int (*xGetLastError)(sqlite3_vfs*, int, char *);
  1321. /* New fields may be appended in figure versions. The iVersion
  1322. ** value will increment whenever this happens. */
  1323. };
  1324. /*
  1325. ** CAPI3REF: Flags for the xAccess VFS method {H11190} <H11140>
  1326. **
  1327. ** These integer constants can be used as the third parameter to
  1328. ** the xAccess method of an [sqlite3_vfs] object. {END} They determine
  1329. ** what kind of permissions the xAccess method is looking for.
  1330. ** With SQLITE_ACCESS_EXISTS, the xAccess method
  1331. ** simply checks whether the file exists.
  1332. ** With SQLITE_ACCESS_READWRITE, the xAccess method
  1333. ** checks whether the file is both readable and writable.
  1334. ** With SQLITE_ACCESS_READ, the xAccess method
  1335. ** checks whether the file is readable.
  1336. */
  1337. #define SQLITE_ACCESS_EXISTS 0
  1338. #define SQLITE_ACCESS_READWRITE 1
  1339. #define SQLITE_ACCESS_READ 2
  1340. /*
  1341. ** CAPI3REF: Initialize The SQLite Library {H10130} <S20000><S30100>
  1342. **
  1343. ** The sqlite3_initialize() routine initializes the
  1344. ** SQLite library. The sqlite3_shutdown() routine
  1345. ** deallocates any resources that were allocated by sqlite3_initialize().
  1346. **
  1347. ** A call to sqlite3_initialize() is an "effective" call if it is
  1348. ** the first time sqlite3_initialize() is invoked during the lifetime of
  1349. ** the process, or if it is the first time sqlite3_initialize() is invoked
  1350. ** following a call to sqlite3_shutdown(). Only an effective call
  1351. ** of sqlite3_initialize() does any initialization. All other calls
  1352. ** are harmless no-ops.
  1353. **
  1354. ** Among other things, sqlite3_initialize() shall invoke
  1355. ** sqlite3_os_init(). Similarly, sqlite3_shutdown()
  1356. ** shall invoke sqlite3_os_end().
  1357. **
  1358. ** The sqlite3_initialize() routine returns [SQLITE_OK] on success.
  1359. ** If for some reason, sqlite3_initialize() is unable to initialize
  1360. ** the library (perhaps it is unable to allocate a needed resource such
  1361. ** as a mutex) it returns an [error code] other than [SQLITE_OK].
  1362. **
  1363. ** The sqlite3_initialize() routine is called internally by many other
  1364. ** SQLite interfaces so that an application usually does not need to
  1365. ** invoke sqlite3_initialize() directly. For example, [sqlite3_open()]
  1366. ** calls sqlite3_initialize() so the SQLite library will be automatically
  1367. ** initialized when [sqlite3_open()] is called if it has not be initialized
  1368. ** already. However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
  1369. ** compile-time option, then the automatic calls to sqlite3_initialize()
  1370. ** are omitted and the application must call sqlite3_initialize() directly
  1371. ** prior to using any other SQLite interface. For maximum portability,
  1372. ** it is recommended that applications always invoke sqlite3_initialize()
  1373. ** directly prior to using any other SQLite interface. Future releases
  1374. ** of SQLite may require this. In other words, the behavior exhibited
  1375. ** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the
  1376. ** default behavior in some future release of SQLite.
  1377. **
  1378. ** The sqlite3_os_init() routine does operating-system specific
  1379. ** initialization of the SQLite library. The sqlite3_os_end()
  1380. ** routine undoes the effect of sqlite3_os_init(). Typical tasks
  1381. ** performed by these routines include allocation or deallocation
  1382. ** of static resources, initialization of global variables,
  1383. ** setting up a default [sqlite3_vfs] module, or setting up
  1384. ** a default configuration using [sqlite3_config()].
  1385. **
  1386. ** The application should never invoke either sqlite3_os_init()
  1387. ** or sqlite3_os_end() directly. The application should only invoke
  1388. ** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init()
  1389. ** interface is called automatically by sqlite3_initialize() and
  1390. ** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate
  1391. ** implementations for sqlite3_os_init() and sqlite3_os_end()
  1392. ** are built into SQLite when it is compiled for unix, windows, or os/2.
  1393. ** When built for other platforms (using the [SQLITE_OS_OTHER=1] compile-time
  1394. ** option) the application must supply a suitable implementation for
  1395. ** sqlite3_os_init() and sqlite3_os_end(). An application-supplied
  1396. ** implementation of sqlite3_os_init() or sqlite3_os_end()
  1397. ** must return [SQLITE_OK] on success and some other [error code] upon
  1398. ** failure.
  1399. */
  1400. SQLITE_API int sqlite3_initialize(void);
  1401. SQLITE_API int sqlite3_shutdown(void);
  1402. SQLITE_API int sqlite3_os_init(void);
  1403. SQLITE_API int sqlite3_os_end(void);
  1404. /*
  1405. ** CAPI3REF: Configuring The SQLite Library {H14100} <S20000><S30200>
  1406. ** EXPERIMENTAL
  1407. **
  1408. ** The sqlite3_config() interface is used to make global configuration
  1409. ** changes to SQLite in order to tune SQLite to the specific needs of
  1410. ** the application. The default configuration is recommended for most
  1411. ** applications and so this routine is usually not necessary. It is
  1412. ** provided to support rare applications with unusual needs.
  1413. **
  1414. ** The sqlite3_config() interface is not threadsafe. The application
  1415. ** must insure that no other SQLite interfaces are invoked by other
  1416. ** threads while sqlite3_config() is running. Furthermore, sqlite3_config()
  1417. ** may only be invoked prior to library initialization using
  1418. ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
  1419. ** Note, however, that sqlite3_config() can be called as part of the
  1420. ** implementation of an application-defined [sqlite3_os_init()].
  1421. **
  1422. ** The first argument to sqlite3_config() is an integer
  1423. ** [SQLITE_CONFIG_SINGLETHREAD | configuration option] that determines
  1424. ** what property of SQLite is to be configured. Subsequent arguments
  1425. ** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option]
  1426. ** in the first argument.
  1427. **
  1428. ** When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
  1429. ** If the option is unknown or SQLite is unable to set the option
  1430. ** then this routine returns a non-zero [error code].
  1431. **
  1432. ** INVARIANTS:
  1433. **
  1434. ** {H14103} A successful invocation of [sqlite3_config()] shall return
  1435. ** [SQLITE_OK].
  1436. **
  1437. ** {H14106} The [sqlite3_config()] interface shall return [SQLITE_MISUSE]
  1438. ** if it is invoked in between calls to [sqlite3_initialize()] and
  1439. ** [sqlite3_shutdown()].
  1440. **
  1441. ** {H14120} A successful call to [sqlite3_config]([SQLITE_CONFIG_SINGLETHREAD])
  1442. ** shall set the default [threading mode] to Single-thread.
  1443. **
  1444. ** {H14123} A successful call to [sqlite3_config]([SQLITE_CONFIG_MULTITHREAD])
  1445. ** shall set the default [threading mode] to Multi-thread.
  1446. **
  1447. ** {H14126} A successful call to [sqlite3_config]([SQLITE_CONFIG_SERIALIZED])
  1448. ** shall set the default [threading mode] to Serialized.
  1449. **
  1450. ** {H14129} A successful call to [sqlite3_config]([SQLITE_CONFIG_MUTEX],X)
  1451. ** where X is a pointer to an initialized [sqlite3_mutex_methods]
  1452. ** object shall cause all subsequent mutex operations performed
  1453. ** by SQLite to use the mutex methods that were present in X
  1454. ** during the call to [sqlite3_config()].
  1455. **
  1456. ** {H14132} A successful call to [sqlite3_config]([SQLITE_CONFIG_GETMUTEX],X)
  1457. ** where X is a pointer to an [sqlite3_mutex_methods] object
  1458. ** shall overwrite the content of [sqlite3_mutex_methods] object
  1459. ** with the mutex methods currently in use by SQLite.
  1460. **
  1461. ** {H14135} A successful call to [sqlite3_config]([SQLITE_CONFIG_MALLOC],M)
  1462. ** where M is a pointer to an initialized [sqlite3_mem_methods]
  1463. ** object shall cause all subsequent memory allocation operations
  1464. ** performed by SQLite to use the methods that were present in
  1465. ** M during the call to [sqlite3_config()].
  1466. **
  1467. ** {H14138} A successful call to [sqlite3_config]([SQLITE_CONFIG_GETMALLOC],M)
  1468. ** where M is a pointer to an [sqlite3_mem_methods] object shall
  1469. ** overwrite the content of [sqlite3_mem_methods] object with
  1470. ** the memory allocation methods currently in use by
  1471. ** SQLite.
  1472. **
  1473. ** {H14141} A successful call to [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],1)
  1474. ** shall enable the memory allocation status collection logic.
  1475. **
  1476. ** {H14144} A successful call to [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],0)
  1477. ** shall disable the memory allocation status collection logic.
  1478. **
  1479. ** {H14147} The memory allocation status collection logic shall be
  1480. ** enabled by default.
  1481. **
  1482. ** {H14150} A successful call to [sqlite3_config]([SQLITE_CONFIG_SCRATCH],S,Z,N)
  1483. ** where Z and N are non-negative integers and
  1484. ** S is a pointer to an aligned memory buffer not less than
  1485. ** Z*N bytes in size shall cause S to be used by the
  1486. ** [scratch memory allocator] for as many as N simulataneous
  1487. ** allocations each of size (Z & ~7).
  1488. **
  1489. ** {H14153} A successful call to [sqlite3_config]([SQLITE_CONFIG_SCRATCH],S,Z,N)
  1490. ** where S is a NULL pointer shall disable the
  1491. ** [scratch memory allocator].
  1492. **
  1493. ** {H14156} A successful call to
  1494. ** [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],S,Z,N)
  1495. ** where Z and N are non-negative integers and
  1496. ** S is a pointer to an aligned memory buffer not less than
  1497. ** Z*N bytes in size shall cause S to be used by the
  1498. ** [pagecache memory allocator] for as many as N simulataneous
  1499. ** allocations each of size (Z & ~7).
  1500. **
  1501. ** {H14159} A successful call to
  1502. ** [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],S,Z,N)
  1503. ** where S is a NULL pointer shall disable the
  1504. ** [pagecache memory allocator].
  1505. **
  1506. ** {H14162} A successful call to [sqlite3_config]([SQLITE_CONFIG_HEAP],H,Z,N)
  1507. ** where Z and N are non-negative integers and
  1508. ** H is a pointer to an aligned memory buffer not less than
  1509. ** Z bytes in size shall enable the [memsys5] memory allocator
  1510. ** and cause it to use buffer S as its memory source and to use
  1511. ** a minimum allocation size of N.
  1512. **
  1513. ** {H14165} A successful call to [sqlite3_config]([SQLITE_CONFIG_HEAP],H,Z,N)
  1514. ** where H is a NULL pointer shall disable the
  1515. ** [memsys5] memory allocator.
  1516. **
  1517. ** {H14168} A successful call to [sqlite3_config]([SQLITE_CONFIG_LOOKASIDE],Z,N)
  1518. ** shall cause the default [lookaside memory allocator] configuration
  1519. ** for new [database connections] to be N slots of Z bytes each.
  1520. */
  1521. SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_config(int, ...);
  1522. /*
  1523. ** CAPI3REF: Configure database connections {H14200} <S20000>
  1524. ** EXPERIMENTAL
  1525. **
  1526. ** The sqlite3_db_config() interface is used to make configuration
  1527. ** changes to a [database connection]. The interface is similar to
  1528. ** [sqlite3_config()] except that the changes apply to a single
  1529. ** [database connection] (specified in the first argument). The
  1530. ** sqlite3_db_config() interface can only be used immediately after
  1531. ** the database connection is created using [sqlite3_open()],
  1532. ** [sqlite3_open16()], or [sqlite3_open_v2()].
  1533. **
  1534. ** The second argument to sqlite3_db_config(D,V,...) is the
  1535. ** configuration verb - an integer code that indicates what
  1536. ** aspect of the [database connection] is being configured.
  1537. ** The only choice for this value is [SQLITE_DBCONFIG_LOOKASIDE].
  1538. ** New verbs are likely to be added in future releases of SQLite.
  1539. ** Additional arguments depend on the verb.
  1540. **
  1541. ** INVARIANTS:
  1542. **
  1543. ** {H14203} A call to [sqlite3_db_config(D,V,...)] shall return [SQLITE_OK]
  1544. ** if and only if the call is successful.
  1545. **
  1546. ** {H14206} If one or more slots of the [lookaside memory allocator] for
  1547. ** [database connection] D are in use, then a call to
  1548. ** [sqlite3_db_config](D,[SQLITE_DBCONFIG_LOOKASIDE],...) shall
  1549. ** fail with an [SQLITE_BUSY] return code.
  1550. **
  1551. ** {H14209} A successful call to
  1552. ** [sqlite3_db_config](D,[SQLITE_DBCONFIG_LOOKASIDE],B,Z,N) where
  1553. ** D is an open [database connection] and Z and N are positive
  1554. ** integers and B is an aligned buffer at least Z*N bytes in size
  1555. ** shall cause the [lookaside memory allocator] for D to use buffer B
  1556. ** with N slots of Z bytes each.
  1557. **
  1558. ** {H14212} A successful call to
  1559. ** [sqlite3_db_config](D,[SQLITE_DBCONFIG_LOOKASIDE],B,Z,N) where
  1560. ** D is an open [database connection] and Z and N are positive
  1561. ** integers and B is NULL pointer shall cause the
  1562. ** [lookaside memory allocator] for D to a obtain Z*N byte buffer
  1563. ** from the primary memory allocator and use that buffer
  1564. ** with N lookaside slots of Z bytes each.
  1565. **
  1566. ** {H14215} A successful call to
  1567. ** [sqlite3_db_config](D,[SQLITE_DBCONFIG_LOOKASIDE],B,Z,N) where
  1568. ** D is an open [database connection] and Z and N are zero shall
  1569. ** disable the [lookaside memory allocator] for D.
  1570. **
  1571. **
  1572. */
  1573. SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_config(sqlite3*, int op, ...);
  1574. /*
  1575. ** CAPI3REF: Memory Allocation Routines {H10155} <S20120>
  1576. ** EXPERIMENTAL
  1577. **
  1578. ** An instance of this object defines the interface between SQLite
  1579. ** and low-level memory allocation routines.
  1580. **
  1581. ** This object is used in only one place in the SQLite interface.
  1582. ** A pointer to an instance of this object is the argument to
  1583. ** [sqlite3_config()] when the configuration option is
  1584. ** [SQLITE_CONFIG_MALLOC]. By creating an instance of this object
  1585. ** and passing it to [sqlite3_config()] during configuration, an
  1586. ** application can specify an alternative memory allocation subsystem
  1587. ** for SQLite to use for all of its dynamic memory needs.
  1588. **
  1589. ** Note that SQLite comes with a built-in memory allocator that is
  1590. ** perfectly adequate for the overwhelming majority of applications
  1591. ** and that this object is only useful to a tiny minority of applications
  1592. ** with specialized memory allocation requirements. This object is
  1593. ** also used during testing of SQLite in order to specify an alternative
  1594. ** memory allocator that simulates memory out-of-memory conditions in
  1595. ** order to verify that SQLite recovers gracefully from such
  1596. ** conditions.
  1597. **
  1598. ** The xMalloc, xFree, and xRealloc methods must work like the
  1599. ** malloc(), free(), and realloc() functions from the standard library.
  1600. **
  1601. ** xSize should return the allocated size of a memory allocation
  1602. ** previously obtained from xMalloc or xRealloc. The allocated size
  1603. ** is always at least as big as the requested size but may be larger.
  1604. **
  1605. ** The xRoundup method returns what would be the allocated size of
  1606. ** a memory allocation given a particular requested size. Most memory
  1607. ** allocators round up memory allocations at least to the next multiple
  1608. ** of 8. Some allocators round up to a larger multiple or to a power of 2.
  1609. **
  1610. ** The xInit method initializes the memory allocator. (For example,
  1611. ** it might allocate any require mutexes or initialize internal data
  1612. ** structures. The xShutdown method is invoked (indirectly) by
  1613. ** [sqlite3_shutdown()] and should deallocate any resources acquired
  1614. ** by xInit. The pAppData pointer is used as the only parameter to
  1615. ** xInit and xShutdown.
  1616. */
  1617. typedef struct sqlite3_mem_methods sqlite3_mem_methods;
  1618. struct sqlite3_mem_methods {
  1619. void *(*xMalloc)(int); /* Memory allocation function */
  1620. void (*xFree)(void*); /* Free a prior allocation */
  1621. void *(*xRealloc)(void*,int); /* Resize an allocation */
  1622. int (*xSize)(void*); /* Return the size of an allocation */
  1623. int (*xRoundup)(int); /* Round up request size to allocation size */
  1624. int (*xInit)(void*); /* Initialize the memory allocator */
  1625. void (*xShutdown)(void*); /* Deinitialize the memory allocator */
  1626. void *pAppData; /* Argument to xInit() and xShutdown() */
  1627. };
  1628. /*
  1629. ** CAPI3REF: Configuration Options {H10160} <S20000>
  1630. ** EXPERIMENTAL
  1631. **
  1632. ** These constants are the available integer configuration options that
  1633. ** can be passed as the first argument to the [sqlite3_config()] interface.
  1634. **
  1635. ** New configuration options may be added in future releases of SQLite.
  1636. ** Existing configuration options might be discontinued. Applications
  1637. ** should check the return code from [sqlite3_config()] to make sure that
  1638. ** the call worked. The [sqlite3_config()] interface will return a
  1639. ** non-zero [error code] if a discontinued or unsupported configuration option
  1640. ** is invoked.
  1641. **
  1642. ** <dl>
  1643. ** <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
  1644. ** <dd>There are no arguments to this option. This option disables
  1645. ** all mutexing and puts SQLite into a mode where it can only be used
  1646. ** by a single thread.</dd>
  1647. **
  1648. ** <dt>SQLITE_CONFIG_MULTITHREAD</dt>
  1649. ** <dd>There are no arguments to this option. This option disables
  1650. ** mutexing on [database connection] and [prepared statement] objects.
  1651. ** The application is responsible for serializing access to
  1652. ** [database connections] and [prepared statements]. But other mutexes
  1653. ** are enabled so that SQLite will be safe to use in a multi-threaded
  1654. ** environment as long as no two threads attempt to use the same
  1655. ** [database connection] at the same time. See the [threading mode]
  1656. ** documentation for additional information.</dd>
  1657. **
  1658. ** <dt>SQLITE_CONFIG_SERIALIZED</dt>
  1659. ** <dd>There are no arguments to this option. This option enables
  1660. ** all mutexes including the recursive
  1661. ** mutexes on [database connection] and [prepared statement] objects.
  1662. ** In this mode (which is the default when SQLite is compiled with
  1663. ** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access
  1664. ** to [database connections] and [prepared statements] so that the
  1665. ** application is free to use the same [database connection] or the
  1666. ** same [prepared statement] in different threads at the same time.
  1667. ** See the [threading mode] documentation for additional information.</dd>
  1668. **
  1669. ** <dt>SQLITE_CONFIG_MALLOC</dt>
  1670. ** <dd>This option takes a single argument which is a pointer to an
  1671. ** instance of the [sqlite3_mem_methods] structure. The argument specifies
  1672. ** alternative low-level memory allocation routines to be used in place of
  1673. ** the memory allocation routines built into SQLite.</dd>
  1674. **
  1675. ** <dt>SQLITE_CONFIG_GETMALLOC</dt>
  1676. ** <dd>This option takes a single argument which is a pointer to an
  1677. ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods]
  1678. ** structure is filled with the currently defined memory allocation routines.
  1679. ** This option can be used to overload the default memory allocation
  1680. ** routines with a wrapper that simulations memory allocation failure or
  1681. ** tracks memory usage, for example.</dd>
  1682. **
  1683. ** <dt>SQLITE_CONFIG_MEMSTATUS</dt>
  1684. ** <dd>This option takes single argument of type int, interpreted as a
  1685. ** boolean, which enables or disables the collection of memory allocation
  1686. ** statistics. When disabled, the following SQLite interfaces become
  1687. ** non-operational:
  1688. ** <ul>
  1689. ** <li> [sqlite3_memory_used()]
  1690. ** <li> [sqlite3_memory_highwater()]
  1691. ** <li> [sqlite3_soft_heap_limit()]
  1692. ** <li> [sqlite3_status()]
  1693. ** </ul>
  1694. ** </dd>
  1695. **
  1696. ** <dt>SQLITE_CONFIG_SCRATCH</dt>
  1697. ** <dd>This option specifies a static memory buffer that SQLite can use for
  1698. ** scratch memory. There are three arguments: A pointer to the memory, the
  1699. ** size of each scratch buffer (sz), and the number of buffers (N). The sz
  1700. ** argument must be a multiple of 16. The sz parameter should be a few bytes
  1701. ** larger than the actual scratch space required due internal overhead.
  1702. ** The first
  1703. ** argument should point to an allocation of at least sz*N bytes of memory.
  1704. ** SQLite will use no more than one scratch buffer at once per thread, so
  1705. ** N should be set to the expected maximum number of threads. The sz
  1706. ** parameter should be 6 times the size of the largest database page size.
  1707. ** Scratch buffers are used as part of the btree balance operation. If
  1708. ** The btree balancer needs additional memory beyond what is provided by
  1709. ** scratch buffers or if no scratch buffer space is specified, then SQLite
  1710. ** goes to [sqlite3_malloc()] to obtain the memory it needs.</dd>
  1711. **
  1712. ** <dt>SQLITE_CONFIG_PAGECACHE</dt>
  1713. ** <dd>This option specifies a static memory buffer that SQLite can use for
  1714. ** the database page cache with the default page cache implemenation.
  1715. ** This configuration should not be used if an application-define page
  1716. ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option.
  1717. ** There are three arguments to this option: A pointer to the
  1718. ** memory, the size of each page buffer (sz), and the number of pages (N).
  1719. ** The sz argument must be a power of two between 512 and 32768. The first
  1720. ** argument should point to an allocation of at least sz*N bytes of memory.
  1721. ** SQLite will use the memory provided by the first argument to satisfy its
  1722. ** memory needs for the first N pages that it adds to cache. If additional
  1723. ** page cache memory is needed beyond what is provided by this option, then
  1724. ** SQLite goes to [sqlite3_malloc()] for the additional storage space.
  1725. ** The implementation might use one or more of the N buffers to hold
  1726. ** memory accounting information. </dd>
  1727. **
  1728. ** <dt>SQLITE_CONFIG_HEAP</dt>
  1729. ** <dd>This option specifies a static memory buffer that SQLite will use
  1730. ** for all of its dynamic memory allocation needs beyond those provided
  1731. ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
  1732. ** There are three arguments: A pointer to the memory, the number of
  1733. ** bytes in the memory buffer, and the minimum allocation size. If
  1734. ** the first pointer (the memory pointer) is NULL, then SQLite reverts
  1735. ** to using its default memory allocator (the system malloc() implementation),
  1736. ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. If the
  1737. ** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
  1738. ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
  1739. ** allocator is engaged to handle all of SQLites memory allocation needs.</dd>
  1740. **
  1741. ** <dt>SQLITE_CONFIG_MUTEX</dt>
  1742. ** <dd>This option takes a single argument which is a pointer to an
  1743. ** instance of the [sqlite3_mutex_methods] structure. The argument specifies
  1744. ** alternative low-level mutex routines to be used in place
  1745. ** the mutex routines built into SQLite.</dd>
  1746. **
  1747. ** <dt>SQLITE_CONFIG_GETMUTEX</dt>
  1748. ** <dd>This option takes a single argument which is a pointer to an
  1749. ** instance of the [sqlite3_mutex_methods] structure. The
  1750. ** [sqlite3_mutex_methods]
  1751. ** structure is filled with the currently defined mutex routines.
  1752. ** This option can be used to overload the default mutex allocation
  1753. ** routines with a wrapper used to track mutex usage for performance
  1754. ** profiling or testing, for example.</dd>
  1755. **
  1756. ** <dt>SQLITE_CONFIG_LOOKASIDE</dt>
  1757. ** <dd>This option takes two arguments that determine the default
  1758. ** memory allcation lookaside optimization. The first argument is the
  1759. ** size of each lookaside buffer slot and the second is the number of
  1760. ** slots allocated to each database connection.</dd>
  1761. **
  1762. ** <dt>SQLITE_CONFIG_PCACHE</dt>
  1763. ** <dd>This option takes a single argument which is a pointer to
  1764. ** an [sqlite3_pcache_methods] object. This object specifies the interface
  1765. ** to a custom page cache implementation. SQLite makes a copy of the
  1766. ** object and uses it for page cache memory allocations.</dd>
  1767. **
  1768. ** <dt>SQLITE_CONFIG_GETPCACHE</dt>
  1769. ** <dd>This option takes a single argument which is a pointer to an
  1770. ** [sqlite3_pcache_methods] object. SQLite copies of the current
  1771. ** page cache implementation into that object.</dd>
  1772. **
  1773. ** </dl>
  1774. */
  1775. #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
  1776. #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
  1777. #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
  1778. #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
  1779. #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */
  1780. #define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */
  1781. #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */
  1782. #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */
  1783. #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */
  1784. #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */
  1785. #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */
  1786. /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
  1787. #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */
  1788. #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
  1789. #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
  1790. /*
  1791. ** CAPI3REF: Configuration Options {H10170} <S20000>
  1792. ** EXPERIMENTAL
  1793. **
  1794. ** These constants are the available integer configuration options that
  1795. ** can be passed as the second argument to the [sqlite3_db_config()] interface.
  1796. **
  1797. ** New configuration options may be added in future releases of SQLite.
  1798. ** Existing configuration options might be discontinued. Applications
  1799. ** should check the return code from [sqlite3_db_config()] to make sure that
  1800. ** the call worked. The [sqlite3_db_config()] interface will return a
  1801. ** non-zero [error code] if a discontinued or unsupported configuration option
  1802. ** is invoked.
  1803. **
  1804. ** <dl>
  1805. ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
  1806. ** <dd>This option takes three additional arguments that determine the
  1807. ** [lookaside memory allocator] configuration for the [database connection].
  1808. ** The first argument (the third parameter to [sqlite3_db_config()] is a
  1809. ** pointer to a memory buffer to use for lookaside memory. The first
  1810. ** argument may be NULL in which case SQLite will allocate the lookaside
  1811. ** buffer itself using [sqlite3_malloc()]. The second argument is the
  1812. ** size of each lookaside buffer slot and the third argument is the number of
  1813. ** slots. The size of the buffer in the first argument must be greater than
  1814. ** or equal to the product of the second and third arguments.</dd>
  1815. **
  1816. ** </dl>
  1817. */
  1818. #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
  1819. /*
  1820. ** CAPI3REF: Enable Or Disable Extended Result Codes {H12200} <S10700>
  1821. **
  1822. ** The sqlite3_extended_result_codes() routine enables or disables the
  1823. ** [extended result codes] feature of SQLite. The extended result
  1824. ** codes are disabled by default for historical compatibility considerations.
  1825. **
  1826. ** INVARIANTS:
  1827. **
  1828. ** {H12201} Each new [database connection] shall have the
  1829. ** [extended result codes] feature disabled by default.
  1830. **
  1831. ** {H12202} The [sqlite3_extended_result_codes(D,F)] interface shall enable
  1832. ** [extended result codes] for the [database connection] D
  1833. ** if the F parameter is true, or disable them if F is false.
  1834. */
  1835. SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
  1836. /*
  1837. ** CAPI3REF: Last Insert Rowid {H12220} <S10700>
  1838. **
  1839. ** Each entry in an SQLite table has a unique 64-bit signed
  1840. ** integer key called the [ROWID | "rowid"]. The rowid is always available
  1841. ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
  1842. ** names are not also used by explicitly declared columns. If
  1843. ** the table has a column of type [INTEGER PRIMARY KEY] then that column
  1844. ** is another alias for the rowid.
  1845. **
  1846. ** This routine returns the [rowid] of the most recent
  1847. ** successful [INSERT] into the database from the [database connection]
  1848. ** in the first argument. If no successful [INSERT]s
  1849. ** have ever occurred on that database connection, zero is returned.
  1850. **
  1851. ** If an [INSERT] occurs within a trigger, then the [rowid] of the inserted
  1852. ** row is returned by this routine as long as the trigger is running.
  1853. ** But once the trigger terminates, the value returned by this routine
  1854. ** reverts to the last value inserted before the trigger fired.
  1855. **
  1856. ** An [INSERT] that fails due to a constraint violation is not a
  1857. ** successful [INSERT] and does not change the value returned by this
  1858. ** routine. Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
  1859. ** and INSERT OR ABORT make no changes to the return value of this
  1860. ** routine when their insertion fails. When INSERT OR REPLACE
  1861. ** encounters a constraint violation, it does not fail. The
  1862. ** INSERT continues to completion after deleting rows that caused
  1863. ** the constraint problem so INSERT OR REPLACE will always change
  1864. ** the return value of this interface.
  1865. **
  1866. ** For the purposes of this routine, an [INSERT] is considered to
  1867. ** be successful even if it is subsequently rolled back.
  1868. **
  1869. ** INVARIANTS:
  1870. **
  1871. ** {H12221} The [sqlite3_last_insert_rowid()] function shall return
  1872. ** the [rowid]
  1873. ** of the most recent successful [INSERT] performed on the same
  1874. ** [database connection] and within the same or higher level
  1875. ** trigger context, or zero if there have been no qualifying
  1876. ** [INSERT] statements.
  1877. **
  1878. ** {H12223} The [sqlite3_last_insert_rowid()] function shall return the
  1879. ** same value when called from the same trigger context
  1880. ** immediately before and after a [ROLLBACK].
  1881. **
  1882. ** ASSUMPTIONS:
  1883. **
  1884. ** {A12232} If a separate thread performs a new [INSERT] on the same
  1885. ** database connection while the [sqlite3_last_insert_rowid()]
  1886. ** function is running and thus changes the last insert [rowid],
  1887. ** then the value returned by [sqlite3_last_insert_rowid()] is
  1888. ** unpredictable and might not equal either the old or the new
  1889. ** last insert [rowid].
  1890. */
  1891. SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
  1892. /*
  1893. ** CAPI3REF: Count The Number Of Rows Modified {H12240} <S10600>
  1894. **
  1895. ** This function returns the number of database rows that were changed
  1896. ** or inserted or deleted by the most recently completed SQL statement
  1897. ** on the [database connection] specified by the first parameter.
  1898. ** Only changes that are directly specified by the [INSERT], [UPDATE],
  1899. ** or [DELETE] statement are counted. Auxiliary changes caused by
  1900. ** triggers are not counted. Use the [sqlite3_total_changes()] function
  1901. ** to find the total number of changes including changes caused by triggers.
  1902. **
  1903. ** A "row change" is a change to a single row of a single table
  1904. ** caused by an INSERT, DELETE, or UPDATE statement. Rows that
  1905. ** are changed as side effects of REPLACE constraint resolution,
  1906. ** rollback, ABORT processing, DROP TABLE, or by any other
  1907. ** mechanisms do not count as direct row changes.
  1908. **
  1909. ** A "trigger context" is a scope of execution that begins and
  1910. ** ends with the script of a trigger. Most SQL statements are
  1911. ** evaluated outside of any trigger. This is the "top level"
  1912. ** trigger context. If a trigger fires from the top level, a
  1913. ** new trigger context is entered for the duration of that one
  1914. ** trigger. Subtriggers create subcontexts for their duration.
  1915. **
  1916. ** Calling [sqlite3_exec()] or [sqlite3_step()] recursively does
  1917. ** not create a new trigger context.
  1918. **
  1919. ** This function returns the number of direct row changes in the
  1920. ** most recent INSERT, UPDATE, or DELETE statement within the same
  1921. ** trigger context.
  1922. **
  1923. ** Thus, when called from the top level, this function returns the
  1924. ** number of changes in the most recent INSERT, UPDATE, or DELETE
  1925. ** that also occurred at the top level. Within the body of a trigger,
  1926. ** the sqlite3_changes() interface can be called to find the number of
  1927. ** changes in the most recently completed INSERT, UPDATE, or DELETE
  1928. ** statement within the body of the same trigger.
  1929. ** However, the number returned does not include changes
  1930. ** caused by subtriggers since those have their own context.
  1931. **
  1932. ** SQLite implements the command "DELETE FROM table" without a WHERE clause
  1933. ** by dropping and recreating the table. Doing so is much faster than going
  1934. ** through and deleting individual elements from the table. Because of this
  1935. ** optimization, the deletions in "DELETE FROM table" are not row changes and
  1936. ** will not be counted by the sqlite3_changes() or [sqlite3_total_changes()]
  1937. ** functions, regardless of the number of elements that were originally
  1938. ** in the table. To get an accurate count of the number of rows deleted, use
  1939. ** "DELETE FROM table WHERE 1" instead. Or recompile using the
  1940. ** [SQLITE_OMIT_TRUNCATE_OPTIMIZATION] compile-time option to disable the
  1941. ** optimization on all queries.
  1942. **
  1943. ** INVARIANTS:
  1944. **
  1945. ** {H12241} The [sqlite3_changes()] function shall return the number of
  1946. ** row changes caused by the most recent INSERT, UPDATE,
  1947. ** or DELETE statement on the same database connection and
  1948. ** within the same or higher trigger context, or zero if there have
  1949. ** not been any qualifying row changes.
  1950. **
  1951. ** {H12243} Statements of the form "DELETE FROM tablename" with no
  1952. ** WHERE clause shall cause subsequent calls to
  1953. ** [sqlite3_changes()] to return zero, regardless of the
  1954. ** number of rows originally in the table.
  1955. **
  1956. ** ASSUMPTIONS:
  1957. **
  1958. ** {A12252} If a separate thread makes changes on the same database connection
  1959. ** while [sqlite3_changes()] is running then the value returned
  1960. ** is unpredictable and not meaningful.
  1961. */
  1962. SQLITE_API int sqlite3_changes(sqlite3*);
  1963. /*
  1964. ** CAPI3REF: Total Number Of Rows Modified {H12260} <S10600>
  1965. **
  1966. ** This function returns the number of row changes caused by INSERT,
  1967. ** UPDATE or DELETE statements since the [database connection] was opened.
  1968. ** The count includes all changes from all trigger contexts. However,
  1969. ** the count does not include changes used to implement REPLACE constraints,
  1970. ** do rollbacks or ABORT processing, or DROP table processing.
  1971. ** The changes are counted as soon as the statement that makes them is
  1972. ** completed (when the statement handle is passed to [sqlite3_reset()] or
  1973. ** [sqlite3_finalize()]).
  1974. **
  1975. ** SQLite implements the command "DELETE FROM table" without a WHERE clause
  1976. ** by dropping and recreating the table. (This is much faster than going
  1977. ** through and deleting individual elements from the table.) Because of this
  1978. ** optimization, the deletions in "DELETE FROM table" are not row changes and
  1979. ** will not be counted by the sqlite3_changes() or [sqlite3_total_changes()]
  1980. ** functions, regardless of the number of elements that were originally
  1981. ** in the table. To get an accurate count of the number of rows deleted, use
  1982. ** "DELETE FROM table WHERE 1" instead. Or recompile using the
  1983. ** [SQLITE_OMIT_TRUNCATE_OPTIMIZATION] compile-time option to disable the
  1984. ** optimization on all queries.
  1985. **
  1986. ** See also the [sqlite3_changes()] interface.
  1987. **
  1988. ** INVARIANTS:
  1989. **
  1990. ** {H12261} The [sqlite3_total_changes()] returns the total number
  1991. ** of row changes caused by INSERT, UPDATE, and/or DELETE
  1992. ** statements on the same [database connection], in any
  1993. ** trigger context, since the database connection was created.
  1994. **
  1995. ** {H12263} Statements of the form "DELETE FROM tablename" with no
  1996. ** WHERE clause shall not change the value returned
  1997. ** by [sqlite3_total_changes()].
  1998. **
  1999. ** ASSUMPTIONS:
  2000. **
  2001. ** {A12264} If a separate thread makes changes on the same database connection
  2002. ** while [sqlite3_total_changes()] is running then the value
  2003. ** returned is unpredictable and not meaningful.
  2004. */
  2005. SQLITE_API int sqlite3_total_changes(sqlite3*);
  2006. /*
  2007. ** CAPI3REF: Interrupt A Long-Running Query {H12270} <S30500>
  2008. **
  2009. ** This function causes any pending database operation to abort and
  2010. ** return at its earliest opportunity. This routine is typically
  2011. ** called in response to a user action such as pressing "Cancel"
  2012. ** or Ctrl-C where the user wants a long query operation to halt
  2013. ** immediately.
  2014. **
  2015. ** It is safe to call this routine from a thread different from the
  2016. ** thread that is currently running the database operation. But it
  2017. ** is not safe to call this routine with a [database connection] that
  2018. ** is closed or might close before sqlite3_interrupt() returns.
  2019. **
  2020. ** If an SQL operation is very nearly finished at the time when
  2021. ** sqlite3_interrupt() is called, then it might not have an opportunity
  2022. ** to be interrupted and might continue to completion.
  2023. **
  2024. ** An SQL operation that is interrupted will return [SQLITE_INTERRUPT].
  2025. ** If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
  2026. ** that is inside an explicit transaction, then the entire transaction
  2027. ** will be rolled back automatically.
  2028. **
  2029. ** A call to sqlite3_interrupt() has no effect on SQL statements
  2030. ** that are started after sqlite3_interrupt() returns.
  2031. **
  2032. ** INVARIANTS:
  2033. **
  2034. ** {H12271} The [sqlite3_interrupt()] interface will force all running
  2035. ** SQL statements associated with the same database connection
  2036. ** to halt after processing at most one additional row of data.
  2037. **
  2038. ** {H12272} Any SQL statement that is interrupted by [sqlite3_interrupt()]
  2039. ** will return [SQLITE_INTERRUPT].
  2040. **
  2041. ** ASSUMPTIONS:
  2042. **
  2043. ** {A12279} If the database connection closes while [sqlite3_interrupt()]
  2044. ** is running then bad things will likely happen.
  2045. */
  2046. SQLITE_API void sqlite3_interrupt(sqlite3*);
  2047. /*
  2048. ** CAPI3REF: Determine If An SQL Statement Is Complete {H10510} <S70200>
  2049. **
  2050. ** These routines are useful for command-line input to determine if the
  2051. ** currently entered text seems to form complete a SQL statement or
  2052. ** if additional input is needed before sending the text into
  2053. ** SQLite for parsing. These routines return true if the input string
  2054. ** appears to be a complete SQL statement. A statement is judged to be
  2055. ** complete if it ends with a semicolon token and is not a fragment of a
  2056. ** CREATE TRIGGER statement. Semicolons that are embedded within
  2057. ** string literals or quoted identifier names or comments are not
  2058. ** independent tokens (they are part of the token in which they are
  2059. ** embedded) and thus do not count as a statement terminator.
  2060. **
  2061. ** These routines do not parse the SQL statements thus
  2062. ** will not detect syntactically incorrect SQL.
  2063. **
  2064. ** INVARIANTS:
  2065. **
  2066. ** {H10511} A successful evaluation of [sqlite3_complete()] or
  2067. ** [sqlite3_complete16()] functions shall
  2068. ** return a numeric 1 if and only if the last non-whitespace
  2069. ** token in their input is a semicolon that is not in between
  2070. ** the BEGIN and END of a CREATE TRIGGER statement.
  2071. **
  2072. ** {H10512} If a memory allocation error occurs during an invocation
  2073. ** of [sqlite3_complete()] or [sqlite3_complete16()] then the
  2074. ** routine shall return [SQLITE_NOMEM].
  2075. **
  2076. ** ASSUMPTIONS:
  2077. **
  2078. ** {A10512} The input to [sqlite3_complete()] must be a zero-terminated
  2079. ** UTF-8 string.
  2080. **
  2081. ** {A10513} The input to [sqlite3_complete16()] must be a zero-terminated
  2082. ** UTF-16 string in native byte order.
  2083. */
  2084. SQLITE_API int sqlite3_complete(const char *sql);
  2085. SQLITE_API int sqlite3_complete16(const void *sql);
  2086. /*
  2087. ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors {H12310} <S40400>
  2088. **
  2089. ** This routine sets a callback function that might be invoked whenever
  2090. ** an attempt is made to open a database table that another thread
  2091. ** or process has locked.
  2092. **
  2093. ** If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]
  2094. ** is returned immediately upon encountering the lock. If the busy callback
  2095. ** is not NULL, then the callback will be invoked with two arguments.
  2096. **
  2097. ** The first argument to the handler is a copy of the void* pointer which
  2098. ** is the third argument to sqlite3_busy_handler(). The second argument to
  2099. ** the handler callback is the number of times that the busy handler has
  2100. ** been invoked for this locking event. If the
  2101. ** busy callback returns 0, then no additional attempts are made to
  2102. ** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned.
  2103. ** If the callback returns non-zero, then another attempt
  2104. ** is made to open the database for reading and the cycle repeats.
  2105. **
  2106. ** The presence of a busy handler does not guarantee that it will be invoked
  2107. ** when there is lock contention. If SQLite determines that invoking the busy
  2108. ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
  2109. ** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler.
  2110. ** Consider a scenario where one process is holding a read lock that
  2111. ** it is trying to promote to a reserved lock and
  2112. ** a second process is holding a reserved lock that it is trying
  2113. ** to promote to an exclusive lock. The first process cannot proceed
  2114. ** because it is blocked by the second and the second process cannot
  2115. ** proceed because it is blocked by the first. If both processes
  2116. ** invoke the busy handlers, neither will make any progress. Therefore,
  2117. ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
  2118. ** will induce the first process to release its read lock and allow
  2119. ** the second process to proceed.
  2120. **
  2121. ** The default busy callback is NULL.
  2122. **
  2123. ** The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED]
  2124. ** when SQLite is in the middle of a large transaction where all the
  2125. ** changes will not fit into the in-memory cache. SQLite will
  2126. ** already hold a RESERVED lock on the database file, but it needs
  2127. ** to promote this lock to EXCLUSIVE so that it can spill cache
  2128. ** pages into the database file without harm to concurrent
  2129. ** readers. If it is unable to promote the lock, then the in-memory
  2130. ** cache will be left in an inconsistent state and so the error
  2131. ** code is promoted from the relatively benign [SQLITE_BUSY] to
  2132. ** the more severe [SQLITE_IOERR_BLOCKED]. This error code promotion
  2133. ** forces an automatic rollback of the changes. See the
  2134. ** <a href="/cvstrac/wiki?p=CorruptionFollowingBusyError">
  2135. ** CorruptionFollowingBusyError</a> wiki page for a discussion of why
  2136. ** this is important.
  2137. **
  2138. ** There can only be a single busy handler defined for each
  2139. ** [database connection]. Setting a new busy handler clears any
  2140. ** previously set handler. Note that calling [sqlite3_busy_timeout()]
  2141. ** will also set or clear the busy handler.
  2142. **
  2143. ** The busy callback should not take any actions which modify the
  2144. ** database connection that invoked the busy handler. Any such actions
  2145. ** result in undefined behavior.
  2146. **
  2147. ** INVARIANTS:
  2148. **
  2149. ** {H12311} The [sqlite3_busy_handler(D,C,A)] function shall replace
  2150. ** busy callback in the [database connection] D with a new
  2151. ** a new busy handler C and application data pointer A.
  2152. **
  2153. ** {H12312} Newly created [database connections] shall have a busy
  2154. ** handler of NULL.
  2155. **
  2156. ** {H12314} When two or more [database connections] share a
  2157. ** [sqlite3_enable_shared_cache | common cache],
  2158. ** the busy handler for the database connection currently using
  2159. ** the cache shall be invoked when the cache encounters a lock.
  2160. **
  2161. ** {H12316} If a busy handler callback returns zero, then the SQLite interface
  2162. ** that provoked the locking event shall return [SQLITE_BUSY].
  2163. **
  2164. ** {H12318} SQLite shall invokes the busy handler with two arguments which
  2165. ** are a copy of the pointer supplied by the 3rd parameter to
  2166. ** [sqlite3_busy_handler()] and a count of the number of prior
  2167. ** invocations of the busy handler for the same locking event.
  2168. **
  2169. ** ASSUMPTIONS:
  2170. **
  2171. ** {A12319} A busy handler must not close the database connection
  2172. ** or [prepared statement] that invoked the busy handler.
  2173. */
  2174. SQLITE_API int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
  2175. /*
  2176. ** CAPI3REF: Set A Busy Timeout {H12340} <S40410>
  2177. **
  2178. ** This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
  2179. ** for a specified amount of time when a table is locked. The handler
  2180. ** will sleep multiple times until at least "ms" milliseconds of sleeping
  2181. ** have accumulated. {H12343} After "ms" milliseconds of sleeping,
  2182. ** the handler returns 0 which causes [sqlite3_step()] to return
  2183. ** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED].
  2184. **
  2185. ** Calling this routine with an argument less than or equal to zero
  2186. ** turns off all busy handlers.
  2187. **
  2188. ** There can only be a single busy handler for a particular
  2189. ** [database connection] any any given moment. If another busy handler
  2190. ** was defined (using [sqlite3_busy_handler()]) prior to calling
  2191. ** this routine, that other busy handler is cleared.
  2192. **
  2193. ** INVARIANTS:
  2194. **
  2195. ** {H12341} The [sqlite3_busy_timeout()] function shall override any prior
  2196. ** [sqlite3_busy_timeout()] or [sqlite3_busy_handler()] setting
  2197. ** on the same [database connection].
  2198. **
  2199. ** {H12343} If the 2nd parameter to [sqlite3_busy_timeout()] is less than
  2200. ** or equal to zero, then the busy handler shall be cleared so that
  2201. ** all subsequent locking events immediately return [SQLITE_BUSY].
  2202. **
  2203. ** {H12344} If the 2nd parameter to [sqlite3_busy_timeout()] is a positive
  2204. ** number N, then a busy handler shall be set that repeatedly calls
  2205. ** the xSleep() method in the [sqlite3_vfs | VFS interface] until
  2206. ** either the lock clears or until the cumulative sleep time
  2207. ** reported back by xSleep() exceeds N milliseconds.
  2208. */
  2209. SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
  2210. /*
  2211. ** CAPI3REF: Convenience Routines For Running Queries {H12370} <S10000>
  2212. **
  2213. ** Definition: A <b>result table</b> is memory data structure created by the
  2214. ** [sqlite3_get_table()] interface. A result table records the
  2215. ** complete query results from one or more queries.
  2216. **
  2217. ** The table conceptually has a number of rows and columns. But
  2218. ** these numbers are not part of the result table itself. These
  2219. ** numbers are obtained separately. Let N be the number of rows
  2220. ** and M be the number of columns.
  2221. **
  2222. ** A result table is an array of pointers to zero-terminated UTF-8 strings.
  2223. ** There are (N+1)*M elements in the array. The first M pointers point
  2224. ** to zero-terminated strings that contain the names of the columns.
  2225. ** The remaining entries all point to query results. NULL values result
  2226. ** in NULL pointers. All other values are in their UTF-8 zero-terminated
  2227. ** string representation as returned by [sqlite3_column_text()].
  2228. **
  2229. ** A result table might consist of one or more memory allocations.
  2230. ** It is not safe to pass a result table directly to [sqlite3_free()].
  2231. ** A result table should be deallocated using [sqlite3_free_table()].
  2232. **
  2233. ** As an example of the result table format, suppose a query result
  2234. ** is as follows:
  2235. **
  2236. ** <blockquote><pre>
  2237. ** Name | Age
  2238. ** -----------------------
  2239. ** Alice | 43
  2240. ** Bob | 28
  2241. ** Cindy | 21
  2242. ** </pre></blockquote>
  2243. **
  2244. ** There are two column (M==2) and three rows (N==3). Thus the
  2245. ** result table has 8 entries. Suppose the result table is stored
  2246. ** in an array names azResult. Then azResult holds this content:
  2247. **
  2248. ** <blockquote><pre>
  2249. ** azResult&#91;0] = "Name";
  2250. ** azResult&#91;1] = "Age";
  2251. ** azResult&#91;2] = "Alice";
  2252. ** azResult&#91;3] = "43";
  2253. ** azResult&#91;4] = "Bob";
  2254. ** azResult&#91;5] = "28";
  2255. ** azResult&#91;6] = "Cindy";
  2256. ** azResult&#91;7] = "21";
  2257. ** </pre></blockquote>
  2258. **
  2259. ** The sqlite3_get_table() function evaluates one or more
  2260. ** semicolon-separated SQL statements in the zero-terminated UTF-8
  2261. ** string of its 2nd parameter. It returns a result table to the
  2262. ** pointer given in its 3rd parameter.
  2263. **
  2264. ** After the calling function has finished using the result, it should
  2265. ** pass the pointer to the result table to sqlite3_free_table() in order to
  2266. ** release the memory that was malloced. Because of the way the
  2267. ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
  2268. ** function must not try to call [sqlite3_free()] directly. Only
  2269. ** [sqlite3_free_table()] is able to release the memory properly and safely.
  2270. **
  2271. ** The sqlite3_get_table() interface is implemented as a wrapper around
  2272. ** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access
  2273. ** to any internal data structures of SQLite. It uses only the public
  2274. ** interface defined here. As a consequence, errors that occur in the
  2275. ** wrapper layer outside of the internal [sqlite3_exec()] call are not
  2276. ** reflected in subsequent calls to [sqlite3_errcode()] or [sqlite3_errmsg()].
  2277. **
  2278. ** INVARIANTS:
  2279. **
  2280. ** {H12371} If a [sqlite3_get_table()] fails a memory allocation, then
  2281. ** it shall free the result table under construction, abort the
  2282. ** query in process, skip any subsequent queries, set the
  2283. ** *pazResult output pointer to NULL and return [SQLITE_NOMEM].
  2284. **
  2285. ** {H12373} If the pnColumn parameter to [sqlite3_get_table()] is not NULL
  2286. ** then a successful invocation of [sqlite3_get_table()] shall
  2287. ** write the number of columns in the
  2288. ** result set of the query into *pnColumn.
  2289. **
  2290. ** {H12374} If the pnRow parameter to [sqlite3_get_table()] is not NULL
  2291. ** then a successful invocation of [sqlite3_get_table()] shall
  2292. ** writes the number of rows in the
  2293. ** result set of the query into *pnRow.
  2294. **
  2295. ** {H12376} A successful invocation of [sqlite3_get_table()] that computes
  2296. ** N rows of result with C columns per row shall make *pazResult
  2297. ** point to an array of pointers to (N+1)*C strings where the first
  2298. ** C strings are column names as obtained from
  2299. ** [sqlite3_column_name()] and the rest are column result values
  2300. ** obtained from [sqlite3_column_text()].
  2301. **
  2302. ** {H12379} The values in the pazResult array returned by [sqlite3_get_table()]
  2303. ** shall remain valid until cleared by [sqlite3_free_table()].
  2304. **
  2305. ** {H12382} When an error occurs during evaluation of [sqlite3_get_table()]
  2306. ** the function shall set *pazResult to NULL, write an error message
  2307. ** into memory obtained from [sqlite3_malloc()], make
  2308. ** **pzErrmsg point to that error message, and return a
  2309. ** appropriate [error code].
  2310. */
  2311. SQLITE_API int sqlite3_get_table(
  2312. sqlite3 *db, /* An open database */
  2313. const char *zSql, /* SQL to be evaluated */
  2314. char ***pazResult, /* Results of the query */
  2315. int *pnRow, /* Number of result rows written here */
  2316. int *pnColumn, /* Number of result columns written here */
  2317. char **pzErrmsg /* Error msg written here */
  2318. );
  2319. SQLITE_API void sqlite3_free_table(char **result);
  2320. /*
  2321. ** CAPI3REF: Formatted String Printing Functions {H17400} <S70000><S20000>
  2322. **
  2323. ** These routines are workalikes of the "printf()" family of functions
  2324. ** from the standard C library.
  2325. **
  2326. ** The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
  2327. ** results into memory obtained from [sqlite3_malloc()].
  2328. ** The strings returned by these two routines should be
  2329. ** released by [sqlite3_free()]. Both routines return a
  2330. ** NULL pointer if [sqlite3_malloc()] is unable to allocate enough
  2331. ** memory to hold the resulting string.
  2332. **
  2333. ** In sqlite3_snprintf() routine is similar to "snprintf()" from
  2334. ** the standard C library. The result is written into the
  2335. ** buffer supplied as the second parameter whose size is given by
  2336. ** the first parameter. Note that the order of the
  2337. ** first two parameters is reversed from snprintf(). This is an
  2338. ** historical accident that cannot be fixed without breaking
  2339. ** backwards compatibility. Note also that sqlite3_snprintf()
  2340. ** returns a pointer to its buffer instead of the number of
  2341. ** characters actually written into the buffer. We admit that
  2342. ** the number of characters written would be a more useful return
  2343. ** value but we cannot change the implementation of sqlite3_snprintf()
  2344. ** now without breaking compatibility.
  2345. **
  2346. ** As long as the buffer size is greater than zero, sqlite3_snprintf()
  2347. ** guarantees that the buffer is always zero-terminated. The first
  2348. ** parameter "n" is the total size of the buffer, including space for
  2349. ** the zero terminator. So the longest string that can be completely
  2350. ** written will be n-1 characters.
  2351. **
  2352. ** These routines all implement some additional formatting
  2353. ** options that are useful for constructing SQL statements.
  2354. ** All of the usual printf() formatting options apply. In addition, there
  2355. ** is are "%q", "%Q", and "%z" options.
  2356. **
  2357. ** The %q option works like %s in that it substitutes a null-terminated
  2358. ** string from the argument list. But %q also doubles every '\'' character.
  2359. ** %q is designed for use inside a string literal. By doubling each '\''
  2360. ** character it escapes that character and allows it to be inserted into
  2361. ** the string.
  2362. **
  2363. ** For example, assume the string variable zText contains text as follows:
  2364. **
  2365. ** <blockquote><pre>
  2366. ** char *zText = "It's a happy day!";
  2367. ** </pre></blockquote>
  2368. **
  2369. ** One can use this text in an SQL statement as follows:
  2370. **
  2371. ** <blockquote><pre>
  2372. ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);
  2373. ** sqlite3_exec(db, zSQL, 0, 0, 0);
  2374. ** sqlite3_free(zSQL);
  2375. ** </pre></blockquote>
  2376. **
  2377. ** Because the %q format string is used, the '\'' character in zText
  2378. ** is escaped and the SQL generated is as follows:
  2379. **
  2380. ** <blockquote><pre>
  2381. ** INSERT INTO table1 VALUES('It''s a happy day!')
  2382. ** </pre></blockquote>
  2383. **
  2384. ** This is correct. Had we used %s instead of %q, the generated SQL
  2385. ** would have looked like this:
  2386. **
  2387. ** <blockquote><pre>
  2388. ** INSERT INTO table1 VALUES('It's a happy day!');
  2389. ** </pre></blockquote>
  2390. **
  2391. ** This second example is an SQL syntax error. As a general rule you should
  2392. ** always use %q instead of %s when inserting text into a string literal.
  2393. **
  2394. ** The %Q option works like %q except it also adds single quotes around
  2395. ** the outside of the total string. Additionally, if the parameter in the
  2396. ** argument list is a NULL pointer, %Q substitutes the text "NULL" (without
  2397. ** single quotes) in place of the %Q option. So, for example, one could say:
  2398. **
  2399. ** <blockquote><pre>
  2400. ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
  2401. ** sqlite3_exec(db, zSQL, 0, 0, 0);
  2402. ** sqlite3_free(zSQL);
  2403. ** </pre></blockquote>
  2404. **
  2405. ** The code above will render a correct SQL statement in the zSQL
  2406. ** variable even if the zText variable is a NULL pointer.
  2407. **
  2408. ** The "%z" formatting option works exactly like "%s" with the
  2409. ** addition that after the string has been read and copied into
  2410. ** the result, [sqlite3_free()] is called on the input string. {END}
  2411. **
  2412. ** INVARIANTS:
  2413. **
  2414. ** {H17403} The [sqlite3_mprintf()] and [sqlite3_vmprintf()] interfaces
  2415. ** return either pointers to zero-terminated UTF-8 strings held in
  2416. ** memory obtained from [sqlite3_malloc()] or NULL pointers if
  2417. ** a call to [sqlite3_malloc()] fails.
  2418. **
  2419. ** {H17406} The [sqlite3_snprintf()] interface writes a zero-terminated
  2420. ** UTF-8 string into the buffer pointed to by the second parameter
  2421. ** provided that the first parameter is greater than zero.
  2422. **
  2423. ** {H17407} The [sqlite3_snprintf()] interface does not write slots of
  2424. ** its output buffer (the second parameter) outside the range
  2425. ** of 0 through N-1 (where N is the first parameter)
  2426. ** regardless of the length of the string
  2427. ** requested by the format specification.
  2428. */
  2429. SQLITE_API char *sqlite3_mprintf(const char*,...);
  2430. SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
  2431. SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
  2432. /*
  2433. ** CAPI3REF: Memory Allocation Subsystem {H17300} <S20000>
  2434. **
  2435. ** The SQLite core uses these three routines for all of its own
  2436. ** internal memory allocation needs. "Core" in the previous sentence
  2437. ** does not include operating-system specific VFS implementation. The
  2438. ** Windows VFS uses native malloc() and free() for some operations.
  2439. **
  2440. ** The sqlite3_malloc() routine returns a pointer to a block
  2441. ** of memory at least N bytes in length, where N is the parameter.
  2442. ** If sqlite3_malloc() is unable to obtain sufficient free
  2443. ** memory, it returns a NULL pointer. If the parameter N to
  2444. ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
  2445. ** a NULL pointer.
  2446. **
  2447. ** Calling sqlite3_free() with a pointer previously returned
  2448. ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
  2449. ** that it might be reused. The sqlite3_free() routine is
  2450. ** a no-op if is called with a NULL pointer. Passing a NULL pointer
  2451. ** to sqlite3_free() is harmless. After being freed, memory
  2452. ** should neither be read nor written. Even reading previously freed
  2453. ** memory might result in a segmentation fault or other severe error.
  2454. ** Memory corruption, a segmentation fault, or other severe error
  2455. ** might result if sqlite3_free() is called with a non-NULL pointer that
  2456. ** was not obtained from sqlite3_malloc() or sqlite3_realloc().
  2457. **
  2458. ** The sqlite3_realloc() interface attempts to resize a
  2459. ** prior memory allocation to be at least N bytes, where N is the
  2460. ** second parameter. The memory allocation to be resized is the first
  2461. ** parameter. If the first parameter to sqlite3_realloc()
  2462. ** is a NULL pointer then its behavior is identical to calling
  2463. ** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc().
  2464. ** If the second parameter to sqlite3_realloc() is zero or
  2465. ** negative then the behavior is exactly the same as calling
  2466. ** sqlite3_free(P) where P is the first parameter to sqlite3_realloc().
  2467. ** sqlite3_realloc() returns a pointer to a memory allocation
  2468. ** of at least N bytes in size or NULL if sufficient memory is unavailable.
  2469. ** If M is the size of the prior allocation, then min(N,M) bytes
  2470. ** of the prior allocation are copied into the beginning of buffer returned
  2471. ** by sqlite3_realloc() and the prior allocation is freed.
  2472. ** If sqlite3_realloc() returns NULL, then the prior allocation
  2473. ** is not freed.
  2474. **
  2475. ** The memory returned by sqlite3_malloc() and sqlite3_realloc()
  2476. ** is always aligned to at least an 8 byte boundary. {END}
  2477. **
  2478. ** The default implementation of the memory allocation subsystem uses
  2479. ** the malloc(), realloc() and free() provided by the standard C library.
  2480. ** {H17382} However, if SQLite is compiled with the
  2481. ** SQLITE_MEMORY_SIZE=<i>NNN</i> C preprocessor macro (where <i>NNN</i>
  2482. ** is an integer), then SQLite create a static array of at least
  2483. ** <i>NNN</i> bytes in size and uses that array for all of its dynamic
  2484. ** memory allocation needs. {END} Additional memory allocator options
  2485. ** may be added in future releases.
  2486. **
  2487. ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
  2488. ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
  2489. ** implementation of these routines to be omitted. That capability
  2490. ** is no longer provided. Only built-in memory allocators can be used.
  2491. **
  2492. ** The Windows OS interface layer calls
  2493. ** the system malloc() and free() directly when converting
  2494. ** filenames between the UTF-8 encoding used by SQLite
  2495. ** and whatever filename encoding is used by the particular Windows
  2496. ** installation. Memory allocation errors are detected, but
  2497. ** they are reported back as [SQLITE_CANTOPEN] or
  2498. ** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
  2499. **
  2500. ** INVARIANTS:
  2501. **
  2502. ** {H17303} The [sqlite3_malloc(N)] interface returns either a pointer to
  2503. ** a newly checked-out block of at least N bytes of memory
  2504. ** that is 8-byte aligned, or it returns NULL if it is unable
  2505. ** to fulfill the request.
  2506. **
  2507. ** {H17304} The [sqlite3_malloc(N)] interface returns a NULL pointer if
  2508. ** N is less than or equal to zero.
  2509. **
  2510. ** {H17305} The [sqlite3_free(P)] interface releases memory previously
  2511. ** returned from [sqlite3_malloc()] or [sqlite3_realloc()],
  2512. ** making it available for reuse.
  2513. **
  2514. ** {H17306} A call to [sqlite3_free(NULL)] is a harmless no-op.
  2515. **
  2516. ** {H17310} A call to [sqlite3_realloc(0,N)] is equivalent to a call
  2517. ** to [sqlite3_malloc(N)].
  2518. **
  2519. ** {H17312} A call to [sqlite3_realloc(P,0)] is equivalent to a call
  2520. ** to [sqlite3_free(P)].
  2521. **
  2522. ** {H17315} The SQLite core uses [sqlite3_malloc()], [sqlite3_realloc()],
  2523. ** and [sqlite3_free()] for all of its memory allocation and
  2524. ** deallocation needs.
  2525. **
  2526. ** {H17318} The [sqlite3_realloc(P,N)] interface returns either a pointer
  2527. ** to a block of checked-out memory of at least N bytes in size
  2528. ** that is 8-byte aligned, or a NULL pointer.
  2529. **
  2530. ** {H17321} When [sqlite3_realloc(P,N)] returns a non-NULL pointer, it first
  2531. ** copies the first K bytes of content from P into the newly
  2532. ** allocated block, where K is the lesser of N and the size of
  2533. ** the buffer P.
  2534. **
  2535. ** {H17322} When [sqlite3_realloc(P,N)] returns a non-NULL pointer, it first
  2536. ** releases the buffer P.
  2537. **
  2538. ** {H17323} When [sqlite3_realloc(P,N)] returns NULL, the buffer P is
  2539. ** not modified or released.
  2540. **
  2541. ** ASSUMPTIONS:
  2542. **
  2543. ** {A17350} The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
  2544. ** must be either NULL or else pointers obtained from a prior
  2545. ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
  2546. ** not yet been released.
  2547. **
  2548. ** {A17351} The application must not read or write any part of
  2549. ** a block of memory after it has been released using
  2550. ** [sqlite3_free()] or [sqlite3_realloc()].
  2551. */
  2552. SQLITE_API void *sqlite3_malloc(int);
  2553. SQLITE_API void *sqlite3_realloc(void*, int);
  2554. SQLITE_API void sqlite3_free(void*);
  2555. /*
  2556. ** CAPI3REF: Memory Allocator Statistics {H17370} <S30210>
  2557. **
  2558. ** SQLite provides these two interfaces for reporting on the status
  2559. ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
  2560. ** routines, which form the built-in memory allocation subsystem.
  2561. **
  2562. ** INVARIANTS:
  2563. **
  2564. ** {H17371} The [sqlite3_memory_used()] routine returns the number of bytes
  2565. ** of memory currently outstanding (malloced but not freed).
  2566. **
  2567. ** {H17373} The [sqlite3_memory_highwater()] routine returns the maximum
  2568. ** value of [sqlite3_memory_used()] since the high-water mark
  2569. ** was last reset.
  2570. **
  2571. ** {H17374} The values returned by [sqlite3_memory_used()] and
  2572. ** [sqlite3_memory_highwater()] include any overhead
  2573. ** added by SQLite in its implementation of [sqlite3_malloc()],
  2574. ** but not overhead added by the any underlying system library
  2575. ** routines that [sqlite3_malloc()] may call.
  2576. **
  2577. ** {H17375} The memory high-water mark is reset to the current value of
  2578. ** [sqlite3_memory_used()] if and only if the parameter to
  2579. ** [sqlite3_memory_highwater()] is true. The value returned
  2580. ** by [sqlite3_memory_highwater(1)] is the high-water mark
  2581. ** prior to the reset.
  2582. */
  2583. SQLITE_API sqlite3_int64 sqlite3_memory_used(void);
  2584. SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
  2585. /*
  2586. ** CAPI3REF: Pseudo-Random Number Generator {H17390} <S20000>
  2587. **
  2588. ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
  2589. ** select random [ROWID | ROWIDs] when inserting new records into a table that
  2590. ** already uses the largest possible [ROWID]. The PRNG is also used for
  2591. ** the build-in random() and randomblob() SQL functions. This interface allows
  2592. ** applications to access the same PRNG for other purposes.
  2593. **
  2594. ** A call to this routine stores N bytes of randomness into buffer P.
  2595. **
  2596. ** The first time this routine is invoked (either internally or by
  2597. ** the application) the PRNG is seeded using randomness obtained
  2598. ** from the xRandomness method of the default [sqlite3_vfs] object.
  2599. ** On all subsequent invocations, the pseudo-randomness is generated
  2600. ** internally and without recourse to the [sqlite3_vfs] xRandomness
  2601. ** method.
  2602. **
  2603. ** INVARIANTS:
  2604. **
  2605. ** {H17392} The [sqlite3_randomness(N,P)] interface writes N bytes of
  2606. ** high-quality pseudo-randomness into buffer P.
  2607. */
  2608. SQLITE_API void sqlite3_randomness(int N, void *P);
  2609. /*
  2610. ** CAPI3REF: Compile-Time Authorization Callbacks {H12500} <S70100>
  2611. **
  2612. ** This routine registers a authorizer callback with a particular
  2613. ** [database connection], supplied in the first argument.
  2614. ** The authorizer callback is invoked as SQL statements are being compiled
  2615. ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
  2616. ** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()]. At various
  2617. ** points during the compilation process, as logic is being created
  2618. ** to perform various actions, the authorizer callback is invoked to
  2619. ** see if those actions are allowed. The authorizer callback should
  2620. ** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the
  2621. ** specific action but allow the SQL statement to continue to be
  2622. ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
  2623. ** rejected with an error. If the authorizer callback returns
  2624. ** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]
  2625. ** then the [sqlite3_prepare_v2()] or equivalent call that triggered
  2626. ** the authorizer will fail with an error message.
  2627. **
  2628. ** When the callback returns [SQLITE_OK], that means the operation
  2629. ** requested is ok. When the callback returns [SQLITE_DENY], the
  2630. ** [sqlite3_prepare_v2()] or equivalent call that triggered the
  2631. ** authorizer will fail with an error message explaining that
  2632. ** access is denied. If the authorizer code is [SQLITE_READ]
  2633. ** and the callback returns [SQLITE_IGNORE] then the
  2634. ** [prepared statement] statement is constructed to substitute
  2635. ** a NULL value in place of the table column that would have
  2636. ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE]
  2637. ** return can be used to deny an untrusted user access to individual
  2638. ** columns of a table.
  2639. **
  2640. ** The first parameter to the authorizer callback is a copy of the third
  2641. ** parameter to the sqlite3_set_authorizer() interface. The second parameter
  2642. ** to the callback is an integer [SQLITE_COPY | action code] that specifies
  2643. ** the particular action to be authorized. The third through sixth parameters
  2644. ** to the callback are zero-terminated strings that contain additional
  2645. ** details about the action to be authorized.
  2646. **
  2647. ** An authorizer is used when [sqlite3_prepare | preparing]
  2648. ** SQL statements from an untrusted source, to ensure that the SQL statements
  2649. ** do not try to access data they are not allowed to see, or that they do not
  2650. ** try to execute malicious statements that damage the database. For
  2651. ** example, an application may allow a user to enter arbitrary
  2652. ** SQL queries for evaluation by a database. But the application does
  2653. ** not want the user to be able to make arbitrary changes to the
  2654. ** database. An authorizer could then be put in place while the
  2655. ** user-entered SQL is being [sqlite3_prepare | prepared] that
  2656. ** disallows everything except [SELECT] statements.
  2657. **
  2658. ** Applications that need to process SQL from untrusted sources
  2659. ** might also consider lowering resource limits using [sqlite3_limit()]
  2660. ** and limiting database size using the [max_page_count] [PRAGMA]
  2661. ** in addition to using an authorizer.
  2662. **
  2663. ** Only a single authorizer can be in place on a database connection
  2664. ** at a time. Each call to sqlite3_set_authorizer overrides the
  2665. ** previous call. Disable the authorizer by installing a NULL callback.
  2666. ** The authorizer is disabled by default.
  2667. **
  2668. ** The authorizer callback must not do anything that will modify
  2669. ** the database connection that invoked the authorizer callback.
  2670. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  2671. ** database connections for the meaning of "modify" in this paragraph.
  2672. **
  2673. ** When [sqlite3_prepare_v2()] is used to prepare a statement, the
  2674. ** statement might be reprepared during [sqlite3_step()] due to a
  2675. ** schema change. Hence, the application should ensure that the
  2676. ** correct authorizer callback remains in place during the [sqlite3_step()].
  2677. **
  2678. ** Note that the authorizer callback is invoked only during
  2679. ** [sqlite3_prepare()] or its variants. Authorization is not
  2680. ** performed during statement evaluation in [sqlite3_step()].
  2681. **
  2682. ** INVARIANTS:
  2683. **
  2684. ** {H12501} The [sqlite3_set_authorizer(D,...)] interface registers a
  2685. ** authorizer callback with database connection D.
  2686. **
  2687. ** {H12502} The authorizer callback is invoked as SQL statements are
  2688. ** being parseed and compiled.
  2689. **
  2690. ** {H12503} If the authorizer callback returns any value other than
  2691. ** [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY], then
  2692. ** the application interface call that caused
  2693. ** the authorizer callback to run shall fail with an
  2694. ** [SQLITE_ERROR] error code and an appropriate error message.
  2695. **
  2696. ** {H12504} When the authorizer callback returns [SQLITE_OK], the operation
  2697. ** described is processed normally.
  2698. **
  2699. ** {H12505} When the authorizer callback returns [SQLITE_DENY], the
  2700. ** application interface call that caused the
  2701. ** authorizer callback to run shall fail
  2702. ** with an [SQLITE_ERROR] error code and an error message
  2703. ** explaining that access is denied.
  2704. **
  2705. ** {H12506} If the authorizer code (the 2nd parameter to the authorizer
  2706. ** callback) is [SQLITE_READ] and the authorizer callback returns
  2707. ** [SQLITE_IGNORE], then the prepared statement is constructed to
  2708. ** insert a NULL value in place of the table column that would have
  2709. ** been read if [SQLITE_OK] had been returned.
  2710. **
  2711. ** {H12507} If the authorizer code (the 2nd parameter to the authorizer
  2712. ** callback) is anything other than [SQLITE_READ], then
  2713. ** a return of [SQLITE_IGNORE] has the same effect as [SQLITE_DENY].
  2714. **
  2715. ** {H12510} The first parameter to the authorizer callback is a copy of
  2716. ** the third parameter to the [sqlite3_set_authorizer()] interface.
  2717. **
  2718. ** {H12511} The second parameter to the callback is an integer
  2719. ** [SQLITE_COPY | action code] that specifies the particular action
  2720. ** to be authorized.
  2721. **
  2722. ** {H12512} The third through sixth parameters to the callback are
  2723. ** zero-terminated strings that contain
  2724. ** additional details about the action to be authorized.
  2725. **
  2726. ** {H12520} Each call to [sqlite3_set_authorizer()] overrides
  2727. ** any previously installed authorizer.
  2728. **
  2729. ** {H12521} A NULL authorizer means that no authorization
  2730. ** callback is invoked.
  2731. **
  2732. ** {H12522} The default authorizer is NULL.
  2733. */
  2734. SQLITE_API int sqlite3_set_authorizer(
  2735. sqlite3*,
  2736. int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
  2737. void *pUserData
  2738. );
  2739. /*
  2740. ** CAPI3REF: Authorizer Return Codes {H12590} <H12500>
  2741. **
  2742. ** The [sqlite3_set_authorizer | authorizer callback function] must
  2743. ** return either [SQLITE_OK] or one of these two constants in order
  2744. ** to signal SQLite whether or not the action is permitted. See the
  2745. ** [sqlite3_set_authorizer | authorizer documentation] for additional
  2746. ** information.
  2747. */
  2748. #define SQLITE_DENY 1 /* Abort the SQL statement with an error */
  2749. #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
  2750. /*
  2751. ** CAPI3REF: Authorizer Action Codes {H12550} <H12500>
  2752. **
  2753. ** The [sqlite3_set_authorizer()] interface registers a callback function
  2754. ** that is invoked to authorize certain SQL statement actions. The
  2755. ** second parameter to the callback is an integer code that specifies
  2756. ** what action is being authorized. These are the integer action codes that
  2757. ** the authorizer callback may be passed.
  2758. **
  2759. ** These action code values signify what kind of operation is to be
  2760. ** authorized. The 3rd and 4th parameters to the authorization
  2761. ** callback function will be parameters or NULL depending on which of these
  2762. ** codes is used as the second parameter. The 5th parameter to the
  2763. ** authorizer callback is the name of the database ("main", "temp",
  2764. ** etc.) if applicable. The 6th parameter to the authorizer callback
  2765. ** is the name of the inner-most trigger or view that is responsible for
  2766. ** the access attempt or NULL if this access attempt is directly from
  2767. ** top-level SQL code.
  2768. **
  2769. ** INVARIANTS:
  2770. **
  2771. ** {H12551} The second parameter to an
  2772. ** [sqlite3_set_authorizer | authorizer callback] shall be an integer
  2773. ** [SQLITE_COPY | authorizer code] that specifies what action
  2774. ** is being authorized.
  2775. **
  2776. ** {H12552} The 3rd and 4th parameters to the
  2777. ** [sqlite3_set_authorizer | authorization callback]
  2778. ** shall be parameters or NULL depending on which
  2779. ** [SQLITE_COPY | authorizer code] is used as the second parameter.
  2780. **
  2781. ** {H12553} The 5th parameter to the
  2782. ** [sqlite3_set_authorizer | authorizer callback] shall be the name
  2783. ** of the database (example: "main", "temp", etc.) if applicable.
  2784. **
  2785. ** {H12554} The 6th parameter to the
  2786. ** [sqlite3_set_authorizer | authorizer callback] shall be the name
  2787. ** of the inner-most trigger or view that is responsible for
  2788. ** the access attempt or NULL if this access attempt is directly from
  2789. ** top-level SQL code.
  2790. */
  2791. /******************************************* 3rd ************ 4th ***********/
  2792. #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
  2793. #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
  2794. #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
  2795. #define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */
  2796. #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */
  2797. #define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */
  2798. #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */
  2799. #define SQLITE_CREATE_VIEW 8 /* View Name NULL */
  2800. #define SQLITE_DELETE 9 /* Table Name NULL */
  2801. #define SQLITE_DROP_INDEX 10 /* Index Name Table Name */
  2802. #define SQLITE_DROP_TABLE 11 /* Table Name NULL */
  2803. #define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */
  2804. #define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */
  2805. #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */
  2806. #define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */
  2807. #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */
  2808. #define SQLITE_DROP_VIEW 17 /* View Name NULL */
  2809. #define SQLITE_INSERT 18 /* Table Name NULL */
  2810. #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */
  2811. #define SQLITE_READ 20 /* Table Name Column Name */
  2812. #define SQLITE_SELECT 21 /* NULL NULL */
  2813. #define SQLITE_TRANSACTION 22 /* Operation NULL */
  2814. #define SQLITE_UPDATE 23 /* Table Name Column Name */
  2815. #define SQLITE_ATTACH 24 /* Filename NULL */
  2816. #define SQLITE_DETACH 25 /* Database Name NULL */
  2817. #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
  2818. #define SQLITE_REINDEX 27 /* Index Name NULL */
  2819. #define SQLITE_ANALYZE 28 /* Table Name NULL */
  2820. #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
  2821. #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
  2822. #define SQLITE_FUNCTION 31 /* NULL Function Name */
  2823. #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
  2824. #define SQLITE_COPY 0 /* No longer used */
  2825. /*
  2826. ** CAPI3REF: Tracing And Profiling Functions {H12280} <S60400>
  2827. ** EXPERIMENTAL
  2828. **
  2829. ** These routines register callback functions that can be used for
  2830. ** tracing and profiling the execution of SQL statements.
  2831. **
  2832. ** The callback function registered by sqlite3_trace() is invoked at
  2833. ** various times when an SQL statement is being run by [sqlite3_step()].
  2834. ** The callback returns a UTF-8 rendering of the SQL statement text
  2835. ** as the statement first begins executing. Additional callbacks occur
  2836. ** as each triggered subprogram is entered. The callbacks for triggers
  2837. ** contain a UTF-8 SQL comment that identifies the trigger.
  2838. **
  2839. ** The callback function registered by sqlite3_profile() is invoked
  2840. ** as each SQL statement finishes. The profile callback contains
  2841. ** the original statement text and an estimate of wall-clock time
  2842. ** of how long that statement took to run.
  2843. **
  2844. ** INVARIANTS:
  2845. **
  2846. ** {H12281} The callback function registered by [sqlite3_trace()]
  2847. ** shall be invoked
  2848. ** whenever an SQL statement first begins to execute and
  2849. ** whenever a trigger subprogram first begins to run.
  2850. **
  2851. ** {H12282} Each call to [sqlite3_trace()] shall override the previously
  2852. ** registered trace callback.
  2853. **
  2854. ** {H12283} A NULL trace callback shall disable tracing.
  2855. **
  2856. ** {H12284} The first argument to the trace callback shall be a copy of
  2857. ** the pointer which was the 3rd argument to [sqlite3_trace()].
  2858. **
  2859. ** {H12285} The second argument to the trace callback is a
  2860. ** zero-terminated UTF-8 string containing the original text
  2861. ** of the SQL statement as it was passed into [sqlite3_prepare_v2()]
  2862. ** or the equivalent, or an SQL comment indicating the beginning
  2863. ** of a trigger subprogram.
  2864. **
  2865. ** {H12287} The callback function registered by [sqlite3_profile()] is invoked
  2866. ** as each SQL statement finishes.
  2867. **
  2868. ** {H12288} The first parameter to the profile callback is a copy of
  2869. ** the 3rd parameter to [sqlite3_profile()].
  2870. **
  2871. ** {H12289} The second parameter to the profile callback is a
  2872. ** zero-terminated UTF-8 string that contains the complete text of
  2873. ** the SQL statement as it was processed by [sqlite3_prepare_v2()]
  2874. ** or the equivalent.
  2875. **
  2876. ** {H12290} The third parameter to the profile callback is an estimate
  2877. ** of the number of nanoseconds of wall-clock time required to
  2878. ** run the SQL statement from start to finish.
  2879. */
  2880. SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
  2881. SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
  2882. void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
  2883. /*
  2884. ** CAPI3REF: Query Progress Callbacks {H12910} <S60400>
  2885. **
  2886. ** This routine configures a callback function - the
  2887. ** progress callback - that is invoked periodically during long
  2888. ** running calls to [sqlite3_exec()], [sqlite3_step()] and
  2889. ** [sqlite3_get_table()]. An example use for this
  2890. ** interface is to keep a GUI updated during a large query.
  2891. **
  2892. ** If the progress callback returns non-zero, the operation is
  2893. ** interrupted. This feature can be used to implement a
  2894. ** "Cancel" button on a GUI progress dialog box.
  2895. **
  2896. ** The progress handler must not do anything that will modify
  2897. ** the database connection that invoked the progress handler.
  2898. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  2899. ** database connections for the meaning of "modify" in this paragraph.
  2900. **
  2901. ** INVARIANTS:
  2902. **
  2903. ** {H12911} The callback function registered by sqlite3_progress_handler()
  2904. ** is invoked periodically during long running calls to
  2905. ** [sqlite3_step()].
  2906. **
  2907. ** {H12912} The progress callback is invoked once for every N virtual
  2908. ** machine opcodes, where N is the second argument to
  2909. ** the [sqlite3_progress_handler()] call that registered
  2910. ** the callback. If N is less than 1, sqlite3_progress_handler()
  2911. ** acts as if a NULL progress handler had been specified.
  2912. **
  2913. ** {H12913} The progress callback itself is identified by the third
  2914. ** argument to sqlite3_progress_handler().
  2915. **
  2916. ** {H12914} The fourth argument to sqlite3_progress_handler() is a
  2917. ** void pointer passed to the progress callback
  2918. ** function each time it is invoked.
  2919. **
  2920. ** {H12915} If a call to [sqlite3_step()] results in fewer than N opcodes
  2921. ** being executed, then the progress callback is never invoked.
  2922. **
  2923. ** {H12916} Every call to [sqlite3_progress_handler()]
  2924. ** overwrites any previously registered progress handler.
  2925. **
  2926. ** {H12917} If the progress handler callback is NULL then no progress
  2927. ** handler is invoked.
  2928. **
  2929. ** {H12918} If the progress callback returns a result other than 0, then
  2930. ** the behavior is a if [sqlite3_interrupt()] had been called.
  2931. ** <S30500>
  2932. */
  2933. SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
  2934. /*
  2935. ** CAPI3REF: Opening A New Database Connection {H12700} <S40200>
  2936. **
  2937. ** These routines open an SQLite database file whose name is given by the
  2938. ** filename argument. The filename argument is interpreted as UTF-8 for
  2939. ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
  2940. ** order for sqlite3_open16(). A [database connection] handle is usually
  2941. ** returned in *ppDb, even if an error occurs. The only exception is that
  2942. ** if SQLite is unable to allocate memory to hold the [sqlite3] object,
  2943. ** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]
  2944. ** object. If the database is opened (and/or created) successfully, then
  2945. ** [SQLITE_OK] is returned. Otherwise an [error code] is returned. The
  2946. ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
  2947. ** an English language description of the error.
  2948. **
  2949. ** The default encoding for the database will be UTF-8 if
  2950. ** sqlite3_open() or sqlite3_open_v2() is called and
  2951. ** UTF-16 in the native byte order if sqlite3_open16() is used.
  2952. **
  2953. ** Whether or not an error occurs when it is opened, resources
  2954. ** associated with the [database connection] handle should be released by
  2955. ** passing it to [sqlite3_close()] when it is no longer required.
  2956. **
  2957. ** The sqlite3_open_v2() interface works like sqlite3_open()
  2958. ** except that it accepts two additional parameters for additional control
  2959. ** over the new database connection. The flags parameter can take one of
  2960. ** the following three values, optionally combined with the
  2961. ** [SQLITE_OPEN_NOMUTEX] or [SQLITE_OPEN_FULLMUTEX] flags:
  2962. **
  2963. ** <dl>
  2964. ** <dt>[SQLITE_OPEN_READONLY]</dt>
  2965. ** <dd>The database is opened in read-only mode. If the database does not
  2966. ** already exist, an error is returned.</dd>
  2967. **
  2968. ** <dt>[SQLITE_OPEN_READWRITE]</dt>
  2969. ** <dd>The database is opened for reading and writing if possible, or reading
  2970. ** only if the file is write protected by the operating system. In either
  2971. ** case the database must already exist, otherwise an error is returned.</dd>
  2972. **
  2973. ** <dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
  2974. ** <dd>The database is opened for reading and writing, and is creates it if
  2975. ** it does not already exist. This is the behavior that is always used for
  2976. ** sqlite3_open() and sqlite3_open16().</dd>
  2977. ** </dl>
  2978. **
  2979. ** If the 3rd parameter to sqlite3_open_v2() is not one of the
  2980. ** combinations shown above or one of the combinations shown above combined
  2981. ** with the [SQLITE_OPEN_NOMUTEX] or [SQLITE_OPEN_FULLMUTEX] flags,
  2982. ** then the behavior is undefined.
  2983. **
  2984. ** If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
  2985. ** opens in the multi-thread [threading mode] as long as the single-thread
  2986. ** mode has not been set at compile-time or start-time. If the
  2987. ** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens
  2988. ** in the serialized [threading mode] unless single-thread was
  2989. ** previously selected at compile-time or start-time.
  2990. **
  2991. ** If the filename is ":memory:", then a private, temporary in-memory database
  2992. ** is created for the connection. This in-memory database will vanish when
  2993. ** the database connection is closed. Future versions of SQLite might
  2994. ** make use of additional special filenames that begin with the ":" character.
  2995. ** It is recommended that when a database filename actually does begin with
  2996. ** a ":" character you should prefix the filename with a pathname such as
  2997. ** "./" to avoid ambiguity.
  2998. **
  2999. ** If the filename is an empty string, then a private, temporary
  3000. ** on-disk database will be created. This private database will be
  3001. ** automatically deleted as soon as the database connection is closed.
  3002. **
  3003. ** The fourth parameter to sqlite3_open_v2() is the name of the
  3004. ** [sqlite3_vfs] object that defines the operating system interface that
  3005. ** the new database connection should use. If the fourth parameter is
  3006. ** a NULL pointer then the default [sqlite3_vfs] object is used.
  3007. **
  3008. ** <b>Note to Windows users:</b> The encoding used for the filename argument
  3009. ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
  3010. ** codepage is currently defined. Filenames containing international
  3011. ** characters must be converted to UTF-8 prior to passing them into
  3012. ** sqlite3_open() or sqlite3_open_v2().
  3013. **
  3014. ** INVARIANTS:
  3015. **
  3016. ** {H12701} The [sqlite3_open()], [sqlite3_open16()], and
  3017. ** [sqlite3_open_v2()] interfaces create a new
  3018. ** [database connection] associated with
  3019. ** the database file given in their first parameter.
  3020. **
  3021. ** {H12702} The filename argument is interpreted as UTF-8
  3022. ** for [sqlite3_open()] and [sqlite3_open_v2()] and as UTF-16
  3023. ** in the native byte order for [sqlite3_open16()].
  3024. **
  3025. ** {H12703} A successful invocation of [sqlite3_open()], [sqlite3_open16()],
  3026. ** or [sqlite3_open_v2()] writes a pointer to a new
  3027. ** [database connection] into *ppDb.
  3028. **
  3029. ** {H12704} The [sqlite3_open()], [sqlite3_open16()], and
  3030. ** [sqlite3_open_v2()] interfaces return [SQLITE_OK] upon success,
  3031. ** or an appropriate [error code] on failure.
  3032. **
  3033. ** {H12706} The default text encoding for a new database created using
  3034. ** [sqlite3_open()] or [sqlite3_open_v2()] will be UTF-8.
  3035. **
  3036. ** {H12707} The default text encoding for a new database created using
  3037. ** [sqlite3_open16()] will be UTF-16.
  3038. **
  3039. ** {H12709} The [sqlite3_open(F,D)] interface is equivalent to
  3040. ** [sqlite3_open_v2(F,D,G,0)] where the G parameter is
  3041. ** [SQLITE_OPEN_READWRITE]|[SQLITE_OPEN_CREATE].
  3042. **
  3043. ** {H12711} If the G parameter to [sqlite3_open_v2(F,D,G,V)] contains the
  3044. ** bit value [SQLITE_OPEN_READONLY] then the database is opened
  3045. ** for reading only.
  3046. **
  3047. ** {H12712} If the G parameter to [sqlite3_open_v2(F,D,G,V)] contains the
  3048. ** bit value [SQLITE_OPEN_READWRITE] then the database is opened
  3049. ** reading and writing if possible, or for reading only if the
  3050. ** file is write protected by the operating system.
  3051. **
  3052. ** {H12713} If the G parameter to [sqlite3_open_v2(F,D,G,V)] omits the
  3053. ** bit value [SQLITE_OPEN_CREATE] and the database does not
  3054. ** previously exist, an error is returned.
  3055. **
  3056. ** {H12714} If the G parameter to [sqlite3_open_v2(F,D,G,V)] contains the
  3057. ** bit value [SQLITE_OPEN_CREATE] and the database does not
  3058. ** previously exist, then an attempt is made to create and
  3059. ** initialize the database.
  3060. **
  3061. ** {H12717} If the filename argument to [sqlite3_open()], [sqlite3_open16()],
  3062. ** or [sqlite3_open_v2()] is ":memory:", then an private,
  3063. ** ephemeral, in-memory database is created for the connection.
  3064. ** <todo>Is SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE required
  3065. ** in sqlite3_open_v2()?</todo>
  3066. **
  3067. ** {H12719} If the filename is NULL or an empty string, then a private,
  3068. ** ephemeral on-disk database will be created.
  3069. ** <todo>Is SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE required
  3070. ** in sqlite3_open_v2()?</todo>
  3071. **
  3072. ** {H12721} The [database connection] created by [sqlite3_open_v2(F,D,G,V)]
  3073. ** will use the [sqlite3_vfs] object identified by the V parameter,
  3074. ** or the default [sqlite3_vfs] object if V is a NULL pointer.
  3075. **
  3076. ** {H12723} Two [database connections] will share a common cache if both were
  3077. ** opened with the same VFS while [shared cache mode] was enabled and
  3078. ** if both filenames compare equal using memcmp() after having been
  3079. ** processed by the [sqlite3_vfs | xFullPathname] method of the VFS.
  3080. */
  3081. SQLITE_API int sqlite3_open(
  3082. const char *filename, /* Database filename (UTF-8) */
  3083. sqlite3 **ppDb /* OUT: SQLite db handle */
  3084. );
  3085. SQLITE_API int sqlite3_open16(
  3086. const void *filename, /* Database filename (UTF-16) */
  3087. sqlite3 **ppDb /* OUT: SQLite db handle */
  3088. );
  3089. SQLITE_API int sqlite3_open_v2(
  3090. const char *filename, /* Database filename (UTF-8) */
  3091. sqlite3 **ppDb, /* OUT: SQLite db handle */
  3092. int flags, /* Flags */
  3093. const char *zVfs /* Name of VFS module to use */
  3094. );
  3095. /*
  3096. ** CAPI3REF: Error Codes And Messages {H12800} <S60200>
  3097. **
  3098. ** The sqlite3_errcode() interface returns the numeric [result code] or
  3099. ** [extended result code] for the most recent failed sqlite3_* API call
  3100. ** associated with a [database connection]. If a prior API call failed
  3101. ** but the most recent API call succeeded, the return value from
  3102. ** sqlite3_errcode() is undefined. The sqlite3_extended_errcode()
  3103. ** interface is the same except that it always returns the
  3104. ** [extended result code] even when extended result codes are
  3105. ** disabled.
  3106. **
  3107. ** The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
  3108. ** text that describes the error, as either UTF-8 or UTF-16 respectively.
  3109. ** Memory to hold the error message string is managed internally.
  3110. ** The application does not need to worry about freeing the result.
  3111. ** However, the error string might be overwritten or deallocated by
  3112. ** subsequent calls to other SQLite interface functions.
  3113. **
  3114. ** When the serialized [threading mode] is in use, it might be the
  3115. ** case that a second error occurs on a separate thread in between
  3116. ** the time of the first error and the call to these interfaces.
  3117. ** When that happens, the second error will be reported since these
  3118. ** interfaces always report the most recent result. To avoid
  3119. ** this, each thread can obtain exclusive use of the [database connection] D
  3120. ** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning
  3121. ** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after
  3122. ** all calls to the interfaces listed here are completed.
  3123. **
  3124. ** If an interface fails with SQLITE_MISUSE, that means the interface
  3125. ** was invoked incorrectly by the application. In that case, the
  3126. ** error code and message may or may not be set.
  3127. **
  3128. ** INVARIANTS:
  3129. **
  3130. ** {H12801} The [sqlite3_errcode(D)] interface returns the numeric
  3131. ** [result code] or [extended result code] for the most recently
  3132. ** failed interface call associated with the [database connection] D.
  3133. **
  3134. ** {H12802} The [sqlite3_extended_errcode(D)] interface returns the numeric
  3135. ** [extended result code] for the most recently
  3136. ** failed interface call associated with the [database connection] D.
  3137. **
  3138. ** {H12803} The [sqlite3_errmsg(D)] and [sqlite3_errmsg16(D)]
  3139. ** interfaces return English-language text that describes
  3140. ** the error in the mostly recently failed interface call,
  3141. ** encoded as either UTF-8 or UTF-16 respectively.
  3142. **
  3143. ** {H12807} The strings returned by [sqlite3_errmsg()] and [sqlite3_errmsg16()]
  3144. ** are valid until the next SQLite interface call.
  3145. **
  3146. ** {H12808} Calls to API routines that do not return an error code
  3147. ** (example: [sqlite3_data_count()]) do not
  3148. ** change the error code or message returned by
  3149. ** [sqlite3_errcode()], [sqlite3_extended_errcode()],
  3150. ** [sqlite3_errmsg()], or [sqlite3_errmsg16()].
  3151. **
  3152. ** {H12809} Interfaces that are not associated with a specific
  3153. ** [database connection] (examples:
  3154. ** [sqlite3_mprintf()] or [sqlite3_enable_shared_cache()]
  3155. ** do not change the values returned by
  3156. ** [sqlite3_errcode()], [sqlite3_extended_errcode()],
  3157. ** [sqlite3_errmsg()], or [sqlite3_errmsg16()].
  3158. */
  3159. SQLITE_API int sqlite3_errcode(sqlite3 *db);
  3160. SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
  3161. SQLITE_API const char *sqlite3_errmsg(sqlite3*);
  3162. SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
  3163. /*
  3164. ** CAPI3REF: SQL Statement Object {H13000} <H13010>
  3165. ** KEYWORDS: {prepared statement} {prepared statements}
  3166. **
  3167. ** An instance of this object represents a single SQL statement.
  3168. ** This object is variously known as a "prepared statement" or a
  3169. ** "compiled SQL statement" or simply as a "statement".
  3170. **
  3171. ** The life of a statement object goes something like this:
  3172. **
  3173. ** <ol>
  3174. ** <li> Create the object using [sqlite3_prepare_v2()] or a related
  3175. ** function.
  3176. ** <li> Bind values to [host parameters] using the sqlite3_bind_*()
  3177. ** interfaces.
  3178. ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
  3179. ** <li> Reset the statement using [sqlite3_reset()] then go back
  3180. ** to step 2. Do this zero or more times.
  3181. ** <li> Destroy the object using [sqlite3_finalize()].
  3182. ** </ol>
  3183. **
  3184. ** Refer to documentation on individual methods above for additional
  3185. ** information.
  3186. */
  3187. typedef struct sqlite3_stmt sqlite3_stmt;
  3188. /*
  3189. ** CAPI3REF: Run-time Limits {H12760} <S20600>
  3190. **
  3191. ** This interface allows the size of various constructs to be limited
  3192. ** on a connection by connection basis. The first parameter is the
  3193. ** [database connection] whose limit is to be set or queried. The
  3194. ** second parameter is one of the [limit categories] that define a
  3195. ** class of constructs to be size limited. The third parameter is the
  3196. ** new limit for that construct. The function returns the old limit.
  3197. **
  3198. ** If the new limit is a negative number, the limit is unchanged.
  3199. ** For the limit category of SQLITE_LIMIT_XYZ there is a hard upper
  3200. ** bound set by a compile-time C preprocessor macro named SQLITE_MAX_XYZ.
  3201. ** (The "_LIMIT_" in the name is changed to "_MAX_".)
  3202. ** Attempts to increase a limit above its hard upper bound are
  3203. ** silently truncated to the hard upper limit.
  3204. **
  3205. ** Run time limits are intended for use in applications that manage
  3206. ** both their own internal database and also databases that are controlled
  3207. ** by untrusted external sources. An example application might be a
  3208. ** webbrowser that has its own databases for storing history and
  3209. ** separate databases controlled by JavaScript applications downloaded
  3210. ** off the Internet. The internal databases can be given the
  3211. ** large, default limits. Databases managed by external sources can
  3212. ** be given much smaller limits designed to prevent a denial of service
  3213. ** attack. Developers might also want to use the [sqlite3_set_authorizer()]
  3214. ** interface to further control untrusted SQL. The size of the database
  3215. ** created by an untrusted script can be contained using the
  3216. ** [max_page_count] [PRAGMA].
  3217. **
  3218. ** New run-time limit categories may be added in future releases.
  3219. **
  3220. ** INVARIANTS:
  3221. **
  3222. ** {H12762} A successful call to [sqlite3_limit(D,C,V)] where V is
  3223. ** positive changes the limit on the size of construct C in the
  3224. ** [database connection] D to the lesser of V and the hard upper
  3225. ** bound on the size of C that is set at compile-time.
  3226. **
  3227. ** {H12766} A successful call to [sqlite3_limit(D,C,V)] where V is negative
  3228. ** leaves the state of the [database connection] D unchanged.
  3229. **
  3230. ** {H12769} A successful call to [sqlite3_limit(D,C,V)] returns the
  3231. ** value of the limit on the size of construct C in the
  3232. ** [database connection] D as it was prior to the call.
  3233. */
  3234. SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
  3235. /*
  3236. ** CAPI3REF: Run-Time Limit Categories {H12790} <H12760>
  3237. ** KEYWORDS: {limit category} {limit categories}
  3238. **
  3239. ** These constants define various aspects of a [database connection]
  3240. ** that can be limited in size by calls to [sqlite3_limit()].
  3241. ** The meanings of the various limits are as follows:
  3242. **
  3243. ** <dl>
  3244. ** <dt>SQLITE_LIMIT_LENGTH</dt>
  3245. ** <dd>The maximum size of any string or BLOB or table row.<dd>
  3246. **
  3247. ** <dt>SQLITE_LIMIT_SQL_LENGTH</dt>
  3248. ** <dd>The maximum length of an SQL statement.</dd>
  3249. **
  3250. ** <dt>SQLITE_LIMIT_COLUMN</dt>
  3251. ** <dd>The maximum number of columns in a table definition or in the
  3252. ** result set of a SELECT or the maximum number of columns in an index
  3253. ** or in an ORDER BY or GROUP BY clause.</dd>
  3254. **
  3255. ** <dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
  3256. ** <dd>The maximum depth of the parse tree on any expression.</dd>
  3257. **
  3258. ** <dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
  3259. ** <dd>The maximum number of terms in a compound SELECT statement.</dd>
  3260. **
  3261. ** <dt>SQLITE_LIMIT_VDBE_OP</dt>
  3262. ** <dd>The maximum number of instructions in a virtual machine program
  3263. ** used to implement an SQL statement.</dd>
  3264. **
  3265. ** <dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
  3266. ** <dd>The maximum number of arguments on a function.</dd>
  3267. **
  3268. ** <dt>SQLITE_LIMIT_ATTACHED</dt>
  3269. ** <dd>The maximum number of attached databases.</dd>
  3270. **
  3271. ** <dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
  3272. ** <dd>The maximum length of the pattern argument to the LIKE or
  3273. ** GLOB operators.</dd>
  3274. **
  3275. ** <dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
  3276. ** <dd>The maximum number of variables in an SQL statement that can
  3277. ** be bound.</dd>
  3278. ** </dl>
  3279. */
  3280. #define SQLITE_LIMIT_LENGTH 0
  3281. #define SQLITE_LIMIT_SQL_LENGTH 1
  3282. #define SQLITE_LIMIT_COLUMN 2
  3283. #define SQLITE_LIMIT_EXPR_DEPTH 3
  3284. #define SQLITE_LIMIT_COMPOUND_SELECT 4
  3285. #define SQLITE_LIMIT_VDBE_OP 5
  3286. #define SQLITE_LIMIT_FUNCTION_ARG 6
  3287. #define SQLITE_LIMIT_ATTACHED 7
  3288. #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
  3289. #define SQLITE_LIMIT_VARIABLE_NUMBER 9
  3290. /*
  3291. ** CAPI3REF: Compiling An SQL Statement {H13010} <S10000>
  3292. ** KEYWORDS: {SQL statement compiler}
  3293. **
  3294. ** To execute an SQL query, it must first be compiled into a byte-code
  3295. ** program using one of these routines.
  3296. **
  3297. ** The first argument, "db", is a [database connection] obtained from a
  3298. ** prior call to [sqlite3_open()], [sqlite3_open_v2()] or [sqlite3_open16()].
  3299. **
  3300. ** The second argument, "zSql", is the statement to be compiled, encoded
  3301. ** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2()
  3302. ** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2()
  3303. ** use UTF-16.
  3304. **
  3305. ** If the nByte argument is less than zero, then zSql is read up to the
  3306. ** first zero terminator. If nByte is non-negative, then it is the maximum
  3307. ** number of bytes read from zSql. When nByte is non-negative, the
  3308. ** zSql string ends at either the first '\000' or '\u0000' character or
  3309. ** the nByte-th byte, whichever comes first. If the caller knows
  3310. ** that the supplied string is nul-terminated, then there is a small
  3311. ** performance advantage to be gained by passing an nByte parameter that
  3312. ** is equal to the number of bytes in the input string <i>including</i>
  3313. ** the nul-terminator bytes.
  3314. **
  3315. ** *pzTail is made to point to the first byte past the end of the
  3316. ** first SQL statement in zSql. These routines only compile the first
  3317. ** statement in zSql, so *pzTail is left pointing to what remains
  3318. ** uncompiled.
  3319. **
  3320. ** *ppStmt is left pointing to a compiled [prepared statement] that can be
  3321. ** executed using [sqlite3_step()]. If there is an error, *ppStmt is set
  3322. ** to NULL. If the input text contains no SQL (if the input is an empty
  3323. ** string or a comment) then *ppStmt is set to NULL.
  3324. ** {A13018} The calling procedure is responsible for deleting the compiled
  3325. ** SQL statement using [sqlite3_finalize()] after it has finished with it.
  3326. **
  3327. ** On success, [SQLITE_OK] is returned, otherwise an [error code] is returned.
  3328. **
  3329. ** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are
  3330. ** recommended for all new programs. The two older interfaces are retained
  3331. ** for backwards compatibility, but their use is discouraged.
  3332. ** In the "v2" interfaces, the prepared statement
  3333. ** that is returned (the [sqlite3_stmt] object) contains a copy of the
  3334. ** original SQL text. This causes the [sqlite3_step()] interface to
  3335. ** behave a differently in two ways:
  3336. **
  3337. ** <ol>
  3338. ** <li>
  3339. ** If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
  3340. ** always used to do, [sqlite3_step()] will automatically recompile the SQL
  3341. ** statement and try to run it again. If the schema has changed in
  3342. ** a way that makes the statement no longer valid, [sqlite3_step()] will still
  3343. ** return [SQLITE_SCHEMA]. But unlike the legacy behavior, [SQLITE_SCHEMA] is
  3344. ** now a fatal error. Calling [sqlite3_prepare_v2()] again will not make the
  3345. ** error go away. Note: use [sqlite3_errmsg()] to find the text
  3346. ** of the parsing error that results in an [SQLITE_SCHEMA] return.
  3347. ** </li>
  3348. **
  3349. ** <li>
  3350. ** When an error occurs, [sqlite3_step()] will return one of the detailed
  3351. ** [error codes] or [extended error codes]. The legacy behavior was that
  3352. ** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code
  3353. ** and you would have to make a second call to [sqlite3_reset()] in order
  3354. ** to find the underlying cause of the problem. With the "v2" prepare
  3355. ** interfaces, the underlying reason for the error is returned immediately.
  3356. ** </li>
  3357. ** </ol>
  3358. **
  3359. ** INVARIANTS:
  3360. **
  3361. ** {H13011} The [sqlite3_prepare(db,zSql,...)] and
  3362. ** [sqlite3_prepare_v2(db,zSql,...)] interfaces interpret the
  3363. ** text in their zSql parameter as UTF-8.
  3364. **
  3365. ** {H13012} The [sqlite3_prepare16(db,zSql,...)] and
  3366. ** [sqlite3_prepare16_v2(db,zSql,...)] interfaces interpret the
  3367. ** text in their zSql parameter as UTF-16 in the native byte order.
  3368. **
  3369. ** {H13013} If the nByte argument to [sqlite3_prepare_v2(db,zSql,nByte,...)]
  3370. ** and its variants is less than zero, the SQL text is
  3371. ** read from zSql is read up to the first zero terminator.
  3372. **
  3373. ** {H13014} If the nByte argument to [sqlite3_prepare_v2(db,zSql,nByte,...)]
  3374. ** and its variants is non-negative, then at most nBytes bytes of
  3375. ** SQL text is read from zSql.
  3376. **
  3377. ** {H13015} In [sqlite3_prepare_v2(db,zSql,N,P,pzTail)] and its variants
  3378. ** if the zSql input text contains more than one SQL statement
  3379. ** and pzTail is not NULL, then *pzTail is made to point to the
  3380. ** first byte past the end of the first SQL statement in zSql.
  3381. ** <todo>What does *pzTail point to if there is one statement?</todo>
  3382. **
  3383. ** {H13016} A successful call to [sqlite3_prepare_v2(db,zSql,N,ppStmt,...)]
  3384. ** or one of its variants writes into *ppStmt a pointer to a new
  3385. ** [prepared statement] or a pointer to NULL if zSql contains
  3386. ** nothing other than whitespace or comments.
  3387. **
  3388. ** {H13019} The [sqlite3_prepare_v2()] interface and its variants return
  3389. ** [SQLITE_OK] or an appropriate [error code] upon failure.
  3390. **
  3391. ** {H13021} Before [sqlite3_prepare(db,zSql,nByte,ppStmt,pzTail)] or its
  3392. ** variants returns an error (any value other than [SQLITE_OK]),
  3393. ** they first set *ppStmt to NULL.
  3394. */
  3395. SQLITE_API int sqlite3_prepare(
  3396. sqlite3 *db, /* Database handle */
  3397. const char *zSql, /* SQL statement, UTF-8 encoded */
  3398. int nByte, /* Maximum length of zSql in bytes. */
  3399. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  3400. const char **pzTail /* OUT: Pointer to unused portion of zSql */
  3401. );
  3402. SQLITE_API int sqlite3_prepare_v2(
  3403. sqlite3 *db, /* Database handle */
  3404. const char *zSql, /* SQL statement, UTF-8 encoded */
  3405. int nByte, /* Maximum length of zSql in bytes. */
  3406. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  3407. const char **pzTail /* OUT: Pointer to unused portion of zSql */
  3408. );
  3409. SQLITE_API int sqlite3_prepare16(
  3410. sqlite3 *db, /* Database handle */
  3411. const void *zSql, /* SQL statement, UTF-16 encoded */
  3412. int nByte, /* Maximum length of zSql in bytes. */
  3413. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  3414. const void **pzTail /* OUT: Pointer to unused portion of zSql */
  3415. );
  3416. SQLITE_API int sqlite3_prepare16_v2(
  3417. sqlite3 *db, /* Database handle */
  3418. const void *zSql, /* SQL statement, UTF-16 encoded */
  3419. int nByte, /* Maximum length of zSql in bytes. */
  3420. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  3421. const void **pzTail /* OUT: Pointer to unused portion of zSql */
  3422. );
  3423. /*
  3424. ** CAPI3REF: Retrieving Statement SQL {H13100} <H13000>
  3425. **
  3426. ** This interface can be used to retrieve a saved copy of the original
  3427. ** SQL text used to create a [prepared statement] if that statement was
  3428. ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
  3429. **
  3430. ** INVARIANTS:
  3431. **
  3432. ** {H13101} If the [prepared statement] passed as the argument to
  3433. ** [sqlite3_sql()] was compiled using either [sqlite3_prepare_v2()] or
  3434. ** [sqlite3_prepare16_v2()], then [sqlite3_sql()] returns
  3435. ** a pointer to a zero-terminated string containing a UTF-8 rendering
  3436. ** of the original SQL statement.
  3437. **
  3438. ** {H13102} If the [prepared statement] passed as the argument to
  3439. ** [sqlite3_sql()] was compiled using either [sqlite3_prepare()] or
  3440. ** [sqlite3_prepare16()], then [sqlite3_sql()] returns a NULL pointer.
  3441. **
  3442. ** {H13103} The string returned by [sqlite3_sql(S)] is valid until the
  3443. ** [prepared statement] S is deleted using [sqlite3_finalize(S)].
  3444. */
  3445. SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
  3446. /*
  3447. ** CAPI3REF: Dynamically Typed Value Object {H15000} <S20200>
  3448. ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
  3449. **
  3450. ** SQLite uses the sqlite3_value object to represent all values
  3451. ** that can be stored in a database table. SQLite uses dynamic typing
  3452. ** for the values it stores. Values stored in sqlite3_value objects
  3453. ** can be integers, floating point values, strings, BLOBs, or NULL.
  3454. **
  3455. ** An sqlite3_value object may be either "protected" or "unprotected".
  3456. ** Some interfaces require a protected sqlite3_value. Other interfaces
  3457. ** will accept either a protected or an unprotected sqlite3_value.
  3458. ** Every interface that accepts sqlite3_value arguments specifies
  3459. ** whether or not it requires a protected sqlite3_value.
  3460. **
  3461. ** The terms "protected" and "unprotected" refer to whether or not
  3462. ** a mutex is held. A internal mutex is held for a protected
  3463. ** sqlite3_value object but no mutex is held for an unprotected
  3464. ** sqlite3_value object. If SQLite is compiled to be single-threaded
  3465. ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
  3466. ** or if SQLite is run in one of reduced mutex modes
  3467. ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
  3468. ** then there is no distinction between protected and unprotected
  3469. ** sqlite3_value objects and they can be used interchangeably. However,
  3470. ** for maximum code portability it is recommended that applications
  3471. ** still make the distinction between between protected and unprotected
  3472. ** sqlite3_value objects even when not strictly required.
  3473. **
  3474. ** The sqlite3_value objects that are passed as parameters into the
  3475. ** implementation of [application-defined SQL functions] are protected.
  3476. ** The sqlite3_value object returned by
  3477. ** [sqlite3_column_value()] is unprotected.
  3478. ** Unprotected sqlite3_value objects may only be used with
  3479. ** [sqlite3_result_value()] and [sqlite3_bind_value()].
  3480. ** The [sqlite3_value_blob | sqlite3_value_type()] family of
  3481. ** interfaces require protected sqlite3_value objects.
  3482. */
  3483. typedef struct Mem sqlite3_value;
  3484. /*
  3485. ** CAPI3REF: SQL Function Context Object {H16001} <S20200>
  3486. **
  3487. ** The context in which an SQL function executes is stored in an
  3488. ** sqlite3_context object. A pointer to an sqlite3_context object
  3489. ** is always first parameter to [application-defined SQL functions].
  3490. ** The application-defined SQL function implementation will pass this
  3491. ** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
  3492. ** [sqlite3_aggregate_context()], [sqlite3_user_data()],
  3493. ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
  3494. ** and/or [sqlite3_set_auxdata()].
  3495. */
  3496. typedef struct sqlite3_context sqlite3_context;
  3497. /*
  3498. ** CAPI3REF: Binding Values To Prepared Statements {H13500} <S70300>
  3499. ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
  3500. ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
  3501. **
  3502. ** In the SQL strings input to [sqlite3_prepare_v2()] and its variants,
  3503. ** literals may be replaced by a parameter in one of these forms:
  3504. **
  3505. ** <ul>
  3506. ** <li> ?
  3507. ** <li> ?NNN
  3508. ** <li> :VVV
  3509. ** <li> @VVV
  3510. ** <li> $VVV
  3511. ** </ul>
  3512. **
  3513. ** In the parameter forms shown above NNN is an integer literal,
  3514. ** and VVV is an alpha-numeric parameter name. The values of these
  3515. ** parameters (also called "host parameter names" or "SQL parameters")
  3516. ** can be set using the sqlite3_bind_*() routines defined here.
  3517. **
  3518. ** The first argument to the sqlite3_bind_*() routines is always
  3519. ** a pointer to the [sqlite3_stmt] object returned from
  3520. ** [sqlite3_prepare_v2()] or its variants.
  3521. **
  3522. ** The second argument is the index of the SQL parameter to be set.
  3523. ** The leftmost SQL parameter has an index of 1. When the same named
  3524. ** SQL parameter is used more than once, second and subsequent
  3525. ** occurrences have the same index as the first occurrence.
  3526. ** The index for named parameters can be looked up using the
  3527. ** [sqlite3_bind_parameter_index()] API if desired. The index
  3528. ** for "?NNN" parameters is the value of NNN.
  3529. ** The NNN value must be between 1 and the [sqlite3_limit()]
  3530. ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
  3531. **
  3532. ** The third argument is the value to bind to the parameter.
  3533. **
  3534. ** In those routines that have a fourth argument, its value is the
  3535. ** number of bytes in the parameter. To be clear: the value is the
  3536. ** number of <u>bytes</u> in the value, not the number of characters.
  3537. ** If the fourth parameter is negative, the length of the string is
  3538. ** the number of bytes up to the first zero terminator.
  3539. **
  3540. ** The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
  3541. ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
  3542. ** string after SQLite has finished with it. If the fifth argument is
  3543. ** the special value [SQLITE_STATIC], then SQLite assumes that the
  3544. ** information is in static, unmanaged space and does not need to be freed.
  3545. ** If the fifth argument has the value [SQLITE_TRANSIENT], then
  3546. ** SQLite makes its own private copy of the data immediately, before
  3547. ** the sqlite3_bind_*() routine returns.
  3548. **
  3549. ** The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
  3550. ** is filled with zeroes. A zeroblob uses a fixed amount of memory
  3551. ** (just an integer to hold its size) while it is being processed.
  3552. ** Zeroblobs are intended to serve as placeholders for BLOBs whose
  3553. ** content is later written using
  3554. ** [sqlite3_blob_open | incremental BLOB I/O] routines.
  3555. ** A negative value for the zeroblob results in a zero-length BLOB.
  3556. **
  3557. ** The sqlite3_bind_*() routines must be called after
  3558. ** [sqlite3_prepare_v2()] (and its variants) or [sqlite3_reset()] and
  3559. ** before [sqlite3_step()].
  3560. ** Bindings are not cleared by the [sqlite3_reset()] routine.
  3561. ** Unbound parameters are interpreted as NULL.
  3562. **
  3563. ** These routines return [SQLITE_OK] on success or an error code if
  3564. ** anything goes wrong. [SQLITE_RANGE] is returned if the parameter
  3565. ** index is out of range. [SQLITE_NOMEM] is returned if malloc() fails.
  3566. ** [SQLITE_MISUSE] might be returned if these routines are called on a
  3567. ** virtual machine that is the wrong state or which has already been finalized.
  3568. ** Detection of misuse is unreliable. Applications should not depend
  3569. ** on SQLITE_MISUSE returns. SQLITE_MISUSE is intended to indicate a
  3570. ** a logic error in the application. Future versions of SQLite might
  3571. ** panic rather than return SQLITE_MISUSE.
  3572. **
  3573. ** See also: [sqlite3_bind_parameter_count()],
  3574. ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
  3575. **
  3576. ** INVARIANTS:
  3577. **
  3578. ** {H13506} The [SQL statement compiler] recognizes tokens of the forms
  3579. ** "?", "?NNN", "$VVV", ":VVV", and "@VVV" as SQL parameters,
  3580. ** where NNN is any sequence of one or more digits
  3581. ** and where VVV is any sequence of one or more alphanumeric
  3582. ** characters or "::" optionally followed by a string containing
  3583. ** no spaces and contained within parentheses.
  3584. **
  3585. ** {H13509} The initial value of an SQL parameter is NULL.
  3586. **
  3587. ** {H13512} The index of an "?" SQL parameter is one larger than the
  3588. ** largest index of SQL parameter to the left, or 1 if
  3589. ** the "?" is the leftmost SQL parameter.
  3590. **
  3591. ** {H13515} The index of an "?NNN" SQL parameter is the integer NNN.
  3592. **
  3593. ** {H13518} The index of an ":VVV", "$VVV", or "@VVV" SQL parameter is
  3594. ** the same as the index of leftmost occurrences of the same
  3595. ** parameter, or one more than the largest index over all
  3596. ** parameters to the left if this is the first occurrence
  3597. ** of this parameter, or 1 if this is the leftmost parameter.
  3598. **
  3599. ** {H13521} The [SQL statement compiler] fails with an [SQLITE_RANGE]
  3600. ** error if the index of an SQL parameter is less than 1
  3601. ** or greater than the compile-time SQLITE_MAX_VARIABLE_NUMBER
  3602. ** parameter.
  3603. **
  3604. ** {H13524} Calls to [sqlite3_bind_text | sqlite3_bind(S,N,V,...)]
  3605. ** associate the value V with all SQL parameters having an
  3606. ** index of N in the [prepared statement] S.
  3607. **
  3608. ** {H13527} Calls to [sqlite3_bind_text | sqlite3_bind(S,N,...)]
  3609. ** override prior calls with the same values of S and N.
  3610. **
  3611. ** {H13530} Bindings established by [sqlite3_bind_text | sqlite3_bind(S,...)]
  3612. ** persist across calls to [sqlite3_reset(S)].
  3613. **
  3614. ** {H13533} In calls to [sqlite3_bind_blob(S,N,V,L,D)],
  3615. ** [sqlite3_bind_text(S,N,V,L,D)], or
  3616. ** [sqlite3_bind_text16(S,N,V,L,D)] SQLite binds the first L
  3617. ** bytes of the BLOB or string pointed to by V, when L
  3618. ** is non-negative.
  3619. **
  3620. ** {H13536} In calls to [sqlite3_bind_text(S,N,V,L,D)] or
  3621. ** [sqlite3_bind_text16(S,N,V,L,D)] SQLite binds characters
  3622. ** from V through the first zero character when L is negative.
  3623. **
  3624. ** {H13539} In calls to [sqlite3_bind_blob(S,N,V,L,D)],
  3625. ** [sqlite3_bind_text(S,N,V,L,D)], or
  3626. ** [sqlite3_bind_text16(S,N,V,L,D)] when D is the special
  3627. ** constant [SQLITE_STATIC], SQLite assumes that the value V
  3628. ** is held in static unmanaged space that will not change
  3629. ** during the lifetime of the binding.
  3630. **
  3631. ** {H13542} In calls to [sqlite3_bind_blob(S,N,V,L,D)],
  3632. ** [sqlite3_bind_text(S,N,V,L,D)], or
  3633. ** [sqlite3_bind_text16(S,N,V,L,D)] when D is the special
  3634. ** constant [SQLITE_TRANSIENT], the routine makes a
  3635. ** private copy of the value V before it returns.
  3636. **
  3637. ** {H13545} In calls to [sqlite3_bind_blob(S,N,V,L,D)],
  3638. ** [sqlite3_bind_text(S,N,V,L,D)], or
  3639. ** [sqlite3_bind_text16(S,N,V,L,D)] when D is a pointer to
  3640. ** a function, SQLite invokes that function to destroy the
  3641. ** value V after it has finished using the value V.
  3642. **
  3643. ** {H13548} In calls to [sqlite3_bind_zeroblob(S,N,V,L)] the value bound
  3644. ** is a BLOB of L bytes, or a zero-length BLOB if L is negative.
  3645. **
  3646. ** {H13551} In calls to [sqlite3_bind_value(S,N,V)] the V argument may
  3647. ** be either a [protected sqlite3_value] object or an
  3648. ** [unprotected sqlite3_value] object.
  3649. */
  3650. SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
  3651. SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
  3652. SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
  3653. SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
  3654. SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
  3655. SQLITE_API int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));
  3656. SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
  3657. SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
  3658. SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
  3659. /*
  3660. ** CAPI3REF: Number Of SQL Parameters {H13600} <S70300>
  3661. **
  3662. ** This routine can be used to find the number of [SQL parameters]
  3663. ** in a [prepared statement]. SQL parameters are tokens of the
  3664. ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
  3665. ** placeholders for values that are [sqlite3_bind_blob | bound]
  3666. ** to the parameters at a later time.
  3667. **
  3668. ** This routine actually returns the index of the largest (rightmost)
  3669. ** parameter. For all forms except ?NNN, this will correspond to the
  3670. ** number of unique parameters. If parameters of the ?NNN are used,
  3671. ** there may be gaps in the list.
  3672. **
  3673. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  3674. ** [sqlite3_bind_parameter_name()], and
  3675. ** [sqlite3_bind_parameter_index()].
  3676. **
  3677. ** INVARIANTS:
  3678. **
  3679. ** {H13601} The [sqlite3_bind_parameter_count(S)] interface returns
  3680. ** the largest index of all SQL parameters in the
  3681. ** [prepared statement] S, or 0 if S contains no SQL parameters.
  3682. */
  3683. SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*);
  3684. /*
  3685. ** CAPI3REF: Name Of A Host Parameter {H13620} <S70300>
  3686. **
  3687. ** This routine returns a pointer to the name of the n-th
  3688. ** [SQL parameter] in a [prepared statement].
  3689. ** SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
  3690. ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
  3691. ** respectively.
  3692. ** In other words, the initial ":" or "$" or "@" or "?"
  3693. ** is included as part of the name.
  3694. ** Parameters of the form "?" without a following integer have no name
  3695. ** and are also referred to as "anonymous parameters".
  3696. **
  3697. ** The first host parameter has an index of 1, not 0.
  3698. **
  3699. ** If the value n is out of range or if the n-th parameter is
  3700. ** nameless, then NULL is returned. The returned string is
  3701. ** always in UTF-8 encoding even if the named parameter was
  3702. ** originally specified as UTF-16 in [sqlite3_prepare16()] or
  3703. ** [sqlite3_prepare16_v2()].
  3704. **
  3705. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  3706. ** [sqlite3_bind_parameter_count()], and
  3707. ** [sqlite3_bind_parameter_index()].
  3708. **
  3709. ** INVARIANTS:
  3710. **
  3711. ** {H13621} The [sqlite3_bind_parameter_name(S,N)] interface returns
  3712. ** a UTF-8 rendering of the name of the SQL parameter in
  3713. ** the [prepared statement] S having index N, or
  3714. ** NULL if there is no SQL parameter with index N or if the
  3715. ** parameter with index N is an anonymous parameter "?".
  3716. */
  3717. SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
  3718. /*
  3719. ** CAPI3REF: Index Of A Parameter With A Given Name {H13640} <S70300>
  3720. **
  3721. ** Return the index of an SQL parameter given its name. The
  3722. ** index value returned is suitable for use as the second
  3723. ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. A zero
  3724. ** is returned if no matching parameter is found. The parameter
  3725. ** name must be given in UTF-8 even if the original statement
  3726. ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()].
  3727. **
  3728. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  3729. ** [sqlite3_bind_parameter_count()], and
  3730. ** [sqlite3_bind_parameter_index()].
  3731. **
  3732. ** INVARIANTS:
  3733. **
  3734. ** {H13641} The [sqlite3_bind_parameter_index(S,N)] interface returns
  3735. ** the index of SQL parameter in the [prepared statement]
  3736. ** S whose name matches the UTF-8 string N, or 0 if there is
  3737. ** no match.
  3738. */
  3739. SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
  3740. /*
  3741. ** CAPI3REF: Reset All Bindings On A Prepared Statement {H13660} <S70300>
  3742. **
  3743. ** Contrary to the intuition of many, [sqlite3_reset()] does not reset
  3744. ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
  3745. ** Use this routine to reset all host parameters to NULL.
  3746. **
  3747. ** INVARIANTS:
  3748. **
  3749. ** {H13661} The [sqlite3_clear_bindings(S)] interface resets all SQL
  3750. ** parameter bindings in the [prepared statement] S back to NULL.
  3751. */
  3752. SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*);
  3753. /*
  3754. ** CAPI3REF: Number Of Columns In A Result Set {H13710} <S10700>
  3755. **
  3756. ** Return the number of columns in the result set returned by the
  3757. ** [prepared statement]. This routine returns 0 if pStmt is an SQL
  3758. ** statement that does not return data (for example an [UPDATE]).
  3759. **
  3760. ** INVARIANTS:
  3761. **
  3762. ** {H13711} The [sqlite3_column_count(S)] interface returns the number of
  3763. ** columns in the result set generated by the [prepared statement] S,
  3764. ** or 0 if S does not generate a result set.
  3765. */
  3766. SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
  3767. /*
  3768. ** CAPI3REF: Column Names In A Result Set {H13720} <S10700>
  3769. **
  3770. ** These routines return the name assigned to a particular column
  3771. ** in the result set of a [SELECT] statement. The sqlite3_column_name()
  3772. ** interface returns a pointer to a zero-terminated UTF-8 string
  3773. ** and sqlite3_column_name16() returns a pointer to a zero-terminated
  3774. ** UTF-16 string. The first parameter is the [prepared statement]
  3775. ** that implements the [SELECT] statement. The second parameter is the
  3776. ** column number. The leftmost column is number 0.
  3777. **
  3778. ** The returned string pointer is valid until either the [prepared statement]
  3779. ** is destroyed by [sqlite3_finalize()] or until the next call to
  3780. ** sqlite3_column_name() or sqlite3_column_name16() on the same column.
  3781. **
  3782. ** If sqlite3_malloc() fails during the processing of either routine
  3783. ** (for example during a conversion from UTF-8 to UTF-16) then a
  3784. ** NULL pointer is returned.
  3785. **
  3786. ** The name of a result column is the value of the "AS" clause for
  3787. ** that column, if there is an AS clause. If there is no AS clause
  3788. ** then the name of the column is unspecified and may change from
  3789. ** one release of SQLite to the next.
  3790. **
  3791. ** INVARIANTS:
  3792. **
  3793. ** {H13721} A successful invocation of the [sqlite3_column_name(S,N)]
  3794. ** interface returns the name of the Nth column (where 0 is
  3795. ** the leftmost column) for the result set of the
  3796. ** [prepared statement] S as a zero-terminated UTF-8 string.
  3797. **
  3798. ** {H13723} A successful invocation of the [sqlite3_column_name16(S,N)]
  3799. ** interface returns the name of the Nth column (where 0 is
  3800. ** the leftmost column) for the result set of the
  3801. ** [prepared statement] S as a zero-terminated UTF-16 string
  3802. ** in the native byte order.
  3803. **
  3804. ** {H13724} The [sqlite3_column_name()] and [sqlite3_column_name16()]
  3805. ** interfaces return a NULL pointer if they are unable to
  3806. ** allocate memory to hold their normal return strings.
  3807. **
  3808. ** {H13725} If the N parameter to [sqlite3_column_name(S,N)] or
  3809. ** [sqlite3_column_name16(S,N)] is out of range, then the
  3810. ** interfaces return a NULL pointer.
  3811. **
  3812. ** {H13726} The strings returned by [sqlite3_column_name(S,N)] and
  3813. ** [sqlite3_column_name16(S,N)] are valid until the next
  3814. ** call to either routine with the same S and N parameters
  3815. ** or until [sqlite3_finalize(S)] is called.
  3816. **
  3817. ** {H13727} When a result column of a [SELECT] statement contains
  3818. ** an AS clause, the name of that column is the identifier
  3819. ** to the right of the AS keyword.
  3820. */
  3821. SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N);
  3822. SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N);
  3823. /*
  3824. ** CAPI3REF: Source Of Data In A Query Result {H13740} <S10700>
  3825. **
  3826. ** These routines provide a means to determine what column of what
  3827. ** table in which database a result of a [SELECT] statement comes from.
  3828. ** The name of the database or table or column can be returned as
  3829. ** either a UTF-8 or UTF-16 string. The _database_ routines return
  3830. ** the database name, the _table_ routines return the table name, and
  3831. ** the origin_ routines return the column name.
  3832. ** The returned string is valid until the [prepared statement] is destroyed
  3833. ** using [sqlite3_finalize()] or until the same information is requested
  3834. ** again in a different encoding.
  3835. **
  3836. ** The names returned are the original un-aliased names of the
  3837. ** database, table, and column.
  3838. **
  3839. ** The first argument to the following calls is a [prepared statement].
  3840. ** These functions return information about the Nth column returned by
  3841. ** the statement, where N is the second function argument.
  3842. **
  3843. ** If the Nth column returned by the statement is an expression or
  3844. ** subquery and is not a column value, then all of these functions return
  3845. ** NULL. These routine might also return NULL if a memory allocation error
  3846. ** occurs. Otherwise, they return the name of the attached database, table
  3847. ** and column that query result column was extracted from.
  3848. **
  3849. ** As with all other SQLite APIs, those postfixed with "16" return
  3850. ** UTF-16 encoded strings, the other functions return UTF-8. {END}
  3851. **
  3852. ** These APIs are only available if the library was compiled with the
  3853. ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
  3854. **
  3855. ** {A13751}
  3856. ** If two or more threads call one or more of these routines against the same
  3857. ** prepared statement and column at the same time then the results are
  3858. ** undefined.
  3859. **
  3860. ** INVARIANTS:
  3861. **
  3862. ** {H13741} The [sqlite3_column_database_name(S,N)] interface returns either
  3863. ** the UTF-8 zero-terminated name of the database from which the
  3864. ** Nth result column of the [prepared statement] S is extracted,
  3865. ** or NULL if the Nth column of S is a general expression
  3866. ** or if unable to allocate memory to store the name.
  3867. **
  3868. ** {H13742} The [sqlite3_column_database_name16(S,N)] interface returns either
  3869. ** the UTF-16 native byte order zero-terminated name of the database
  3870. ** from which the Nth result column of the [prepared statement] S is
  3871. ** extracted, or NULL if the Nth column of S is a general expression
  3872. ** or if unable to allocate memory to store the name.
  3873. **
  3874. ** {H13743} The [sqlite3_column_table_name(S,N)] interface returns either
  3875. ** the UTF-8 zero-terminated name of the table from which the
  3876. ** Nth result column of the [prepared statement] S is extracted,
  3877. ** or NULL if the Nth column of S is a general expression
  3878. ** or if unable to allocate memory to store the name.
  3879. **
  3880. ** {H13744} The [sqlite3_column_table_name16(S,N)] interface returns either
  3881. ** the UTF-16 native byte order zero-terminated name of the table
  3882. ** from which the Nth result column of the [prepared statement] S is
  3883. ** extracted, or NULL if the Nth column of S is a general expression
  3884. ** or if unable to allocate memory to store the name.
  3885. **
  3886. ** {H13745} The [sqlite3_column_origin_name(S,N)] interface returns either
  3887. ** the UTF-8 zero-terminated name of the table column from which the
  3888. ** Nth result column of the [prepared statement] S is extracted,
  3889. ** or NULL if the Nth column of S is a general expression
  3890. ** or if unable to allocate memory to store the name.
  3891. **
  3892. ** {H13746} The [sqlite3_column_origin_name16(S,N)] interface returns either
  3893. ** the UTF-16 native byte order zero-terminated name of the table
  3894. ** column from which the Nth result column of the
  3895. ** [prepared statement] S is extracted, or NULL if the Nth column
  3896. ** of S is a general expression or if unable to allocate memory
  3897. ** to store the name.
  3898. **
  3899. ** {H13748} The return values from
  3900. ** [sqlite3_column_database_name | column metadata interfaces]
  3901. ** are valid for the lifetime of the [prepared statement]
  3902. ** or until the encoding is changed by another metadata
  3903. ** interface call for the same prepared statement and column.
  3904. **
  3905. ** ASSUMPTIONS:
  3906. **
  3907. ** {A13751} If two or more threads call one or more
  3908. ** [sqlite3_column_database_name | column metadata interfaces]
  3909. ** for the same [prepared statement] and result column
  3910. ** at the same time then the results are undefined.
  3911. */
  3912. SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int);
  3913. SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
  3914. SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int);
  3915. SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
  3916. SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
  3917. SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
  3918. /*
  3919. ** CAPI3REF: Declared Datatype Of A Query Result {H13760} <S10700>
  3920. **
  3921. ** The first parameter is a [prepared statement].
  3922. ** If this statement is a [SELECT] statement and the Nth column of the
  3923. ** returned result set of that [SELECT] is a table column (not an
  3924. ** expression or subquery) then the declared type of the table
  3925. ** column is returned. If the Nth column of the result set is an
  3926. ** expression or subquery, then a NULL pointer is returned.
  3927. ** The returned string is always UTF-8 encoded. {END}
  3928. **
  3929. ** For example, given the database schema:
  3930. **
  3931. ** CREATE TABLE t1(c1 VARIANT);
  3932. **
  3933. ** and the following statement to be compiled:
  3934. **
  3935. ** SELECT c1 + 1, c1 FROM t1;
  3936. **
  3937. ** this routine would return the string "VARIANT" for the second result
  3938. ** column (i==1), and a NULL pointer for the first result column (i==0).
  3939. **
  3940. ** SQLite uses dynamic run-time typing. So just because a column
  3941. ** is declared to contain a particular type does not mean that the
  3942. ** data stored in that column is of the declared type. SQLite is
  3943. ** strongly typed, but the typing is dynamic not static. Type
  3944. ** is associated with individual values, not with the containers
  3945. ** used to hold those values.
  3946. **
  3947. ** INVARIANTS:
  3948. **
  3949. ** {H13761} A successful call to [sqlite3_column_decltype(S,N)] returns a
  3950. ** zero-terminated UTF-8 string containing the declared datatype
  3951. ** of the table column that appears as the Nth column (numbered
  3952. ** from 0) of the result set to the [prepared statement] S.
  3953. **
  3954. ** {H13762} A successful call to [sqlite3_column_decltype16(S,N)]
  3955. ** returns a zero-terminated UTF-16 native byte order string
  3956. ** containing the declared datatype of the table column that appears
  3957. ** as the Nth column (numbered from 0) of the result set to the
  3958. ** [prepared statement] S.
  3959. **
  3960. ** {H13763} If N is less than 0 or N is greater than or equal to
  3961. ** the number of columns in the [prepared statement] S,
  3962. ** or if the Nth column of S is an expression or subquery rather
  3963. ** than a table column, or if a memory allocation failure
  3964. ** occurs during encoding conversions, then
  3965. ** calls to [sqlite3_column_decltype(S,N)] or
  3966. ** [sqlite3_column_decltype16(S,N)] return NULL.
  3967. */
  3968. SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int);
  3969. SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
  3970. /*
  3971. ** CAPI3REF: Evaluate An SQL Statement {H13200} <S10000>
  3972. **
  3973. ** After a [prepared statement] has been prepared using either
  3974. ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
  3975. ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
  3976. ** must be called one or more times to evaluate the statement.
  3977. **
  3978. ** The details of the behavior of the sqlite3_step() interface depend
  3979. ** on whether the statement was prepared using the newer "v2" interface
  3980. ** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy
  3981. ** interface [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the
  3982. ** new "v2" interface is recommended for new applications but the legacy
  3983. ** interface will continue to be supported.
  3984. **
  3985. ** In the legacy interface, the return value will be either [SQLITE_BUSY],
  3986. ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
  3987. ** With the "v2" interface, any of the other [result codes] or
  3988. ** [extended result codes] might be returned as well.
  3989. **
  3990. ** [SQLITE_BUSY] means that the database engine was unable to acquire the
  3991. ** database locks it needs to do its job. If the statement is a [COMMIT]
  3992. ** or occurs outside of an explicit transaction, then you can retry the
  3993. ** statement. If the statement is not a [COMMIT] and occurs within a
  3994. ** explicit transaction then you should rollback the transaction before
  3995. ** continuing.
  3996. **
  3997. ** [SQLITE_DONE] means that the statement has finished executing
  3998. ** successfully. sqlite3_step() should not be called again on this virtual
  3999. ** machine without first calling [sqlite3_reset()] to reset the virtual
  4000. ** machine back to its initial state.
  4001. **
  4002. ** If the SQL statement being executed returns any data, then [SQLITE_ROW]
  4003. ** is returned each time a new row of data is ready for processing by the
  4004. ** caller. The values may be accessed using the [column access functions].
  4005. ** sqlite3_step() is called again to retrieve the next row of data.
  4006. **
  4007. ** [SQLITE_ERROR] means that a run-time error (such as a constraint
  4008. ** violation) has occurred. sqlite3_step() should not be called again on
  4009. ** the VM. More information may be found by calling [sqlite3_errmsg()].
  4010. ** With the legacy interface, a more specific error code (for example,
  4011. ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
  4012. ** can be obtained by calling [sqlite3_reset()] on the
  4013. ** [prepared statement]. In the "v2" interface,
  4014. ** the more specific error code is returned directly by sqlite3_step().
  4015. **
  4016. ** [SQLITE_MISUSE] means that the this routine was called inappropriately.
  4017. ** Perhaps it was called on a [prepared statement] that has
  4018. ** already been [sqlite3_finalize | finalized] or on one that had
  4019. ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could
  4020. ** be the case that the same database connection is being used by two or
  4021. ** more threads at the same moment in time.
  4022. **
  4023. ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
  4024. ** API always returns a generic error code, [SQLITE_ERROR], following any
  4025. ** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call
  4026. ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the
  4027. ** specific [error codes] that better describes the error.
  4028. ** We admit that this is a goofy design. The problem has been fixed
  4029. ** with the "v2" interface. If you prepare all of your SQL statements
  4030. ** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead
  4031. ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,
  4032. ** then the more specific [error codes] are returned directly
  4033. ** by sqlite3_step(). The use of the "v2" interface is recommended.
  4034. **
  4035. ** INVARIANTS:
  4036. **
  4037. ** {H13202} If the [prepared statement] S is ready to be run, then
  4038. ** [sqlite3_step(S)] advances that prepared statement until
  4039. ** completion or until it is ready to return another row of the
  4040. ** result set, or until an [sqlite3_interrupt | interrupt]
  4041. ** or a run-time error occurs.
  4042. **
  4043. ** {H15304} When a call to [sqlite3_step(S)] causes the [prepared statement]
  4044. ** S to run to completion, the function returns [SQLITE_DONE].
  4045. **
  4046. ** {H15306} When a call to [sqlite3_step(S)] stops because it is ready to
  4047. ** return another row of the result set, it returns [SQLITE_ROW].
  4048. **
  4049. ** {H15308} If a call to [sqlite3_step(S)] encounters an
  4050. ** [sqlite3_interrupt | interrupt] or a run-time error,
  4051. ** it returns an appropriate error code that is not one of
  4052. ** [SQLITE_OK], [SQLITE_ROW], or [SQLITE_DONE].
  4053. **
  4054. ** {H15310} If an [sqlite3_interrupt | interrupt] or a run-time error
  4055. ** occurs during a call to [sqlite3_step(S)]
  4056. ** for a [prepared statement] S created using
  4057. ** legacy interfaces [sqlite3_prepare()] or
  4058. ** [sqlite3_prepare16()], then the function returns either
  4059. ** [SQLITE_ERROR], [SQLITE_BUSY], or [SQLITE_MISUSE].
  4060. */
  4061. SQLITE_API int sqlite3_step(sqlite3_stmt*);
  4062. /*
  4063. ** CAPI3REF: Number of columns in a result set {H13770} <S10700>
  4064. **
  4065. ** Returns the number of values in the current row of the result set.
  4066. **
  4067. ** INVARIANTS:
  4068. **
  4069. ** {H13771} After a call to [sqlite3_step(S)] that returns [SQLITE_ROW],
  4070. ** the [sqlite3_data_count(S)] routine will return the same value
  4071. ** as the [sqlite3_column_count(S)] function.
  4072. **
  4073. ** {H13772} After [sqlite3_step(S)] has returned any value other than
  4074. ** [SQLITE_ROW] or before [sqlite3_step(S)] has been called on the
  4075. ** [prepared statement] for the first time since it was
  4076. ** [sqlite3_prepare | prepared] or [sqlite3_reset | reset],
  4077. ** the [sqlite3_data_count(S)] routine returns zero.
  4078. */
  4079. SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
  4080. /*
  4081. ** CAPI3REF: Fundamental Datatypes {H10265} <S10110><S10120>
  4082. ** KEYWORDS: SQLITE_TEXT
  4083. **
  4084. ** {H10266} Every value in SQLite has one of five fundamental datatypes:
  4085. **
  4086. ** <ul>
  4087. ** <li> 64-bit signed integer
  4088. ** <li> 64-bit IEEE floating point number
  4089. ** <li> string
  4090. ** <li> BLOB
  4091. ** <li> NULL
  4092. ** </ul> {END}
  4093. **
  4094. ** These constants are codes for each of those types.
  4095. **
  4096. ** Note that the SQLITE_TEXT constant was also used in SQLite version 2
  4097. ** for a completely different meaning. Software that links against both
  4098. ** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not
  4099. ** SQLITE_TEXT.
  4100. */
  4101. #define SQLITE_INTEGER 1
  4102. #define SQLITE_FLOAT 2
  4103. #define SQLITE_BLOB 4
  4104. #define SQLITE_NULL 5
  4105. #ifdef SQLITE_TEXT
  4106. # undef SQLITE_TEXT
  4107. #else
  4108. # define SQLITE_TEXT 3
  4109. #endif
  4110. #define SQLITE3_TEXT 3
  4111. /*
  4112. ** CAPI3REF: Result Values From A Query {H13800} <S10700>
  4113. ** KEYWORDS: {column access functions}
  4114. **
  4115. ** These routines form the "result set query" interface.
  4116. **
  4117. ** These routines return information about a single column of the current
  4118. ** result row of a query. In every case the first argument is a pointer
  4119. ** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]
  4120. ** that was returned from [sqlite3_prepare_v2()] or one of its variants)
  4121. ** and the second argument is the index of the column for which information
  4122. ** should be returned. The leftmost column of the result set has the index 0.
  4123. **
  4124. ** If the SQL statement does not currently point to a valid row, or if the
  4125. ** column index is out of range, the result is undefined.
  4126. ** These routines may only be called when the most recent call to
  4127. ** [sqlite3_step()] has returned [SQLITE_ROW] and neither
  4128. ** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently.
  4129. ** If any of these routines are called after [sqlite3_reset()] or
  4130. ** [sqlite3_finalize()] or after [sqlite3_step()] has returned
  4131. ** something other than [SQLITE_ROW], the results are undefined.
  4132. ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()]
  4133. ** are called from a different thread while any of these routines
  4134. ** are pending, then the results are undefined.
  4135. **
  4136. ** The sqlite3_column_type() routine returns the
  4137. ** [SQLITE_INTEGER | datatype code] for the initial data type
  4138. ** of the result column. The returned value is one of [SQLITE_INTEGER],
  4139. ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. The value
  4140. ** returned by sqlite3_column_type() is only meaningful if no type
  4141. ** conversions have occurred as described below. After a type conversion,
  4142. ** the value returned by sqlite3_column_type() is undefined. Future
  4143. ** versions of SQLite may change the behavior of sqlite3_column_type()
  4144. ** following a type conversion.
  4145. **
  4146. ** If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
  4147. ** routine returns the number of bytes in that BLOB or string.
  4148. ** If the result is a UTF-16 string, then sqlite3_column_bytes() converts
  4149. ** the string to UTF-8 and then returns the number of bytes.
  4150. ** If the result is a numeric value then sqlite3_column_bytes() uses
  4151. ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
  4152. ** the number of bytes in that string.
  4153. ** The value returned does not include the zero terminator at the end
  4154. ** of the string. For clarity: the value returned is the number of
  4155. ** bytes in the string, not the number of characters.
  4156. **
  4157. ** Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
  4158. ** even empty strings, are always zero terminated. The return
  4159. ** value from sqlite3_column_blob() for a zero-length BLOB is an arbitrary
  4160. ** pointer, possibly even a NULL pointer.
  4161. **
  4162. ** The sqlite3_column_bytes16() routine is similar to sqlite3_column_bytes()
  4163. ** but leaves the result in UTF-16 in native byte order instead of UTF-8.
  4164. ** The zero terminator is not included in this count.
  4165. **
  4166. ** The object returned by [sqlite3_column_value()] is an
  4167. ** [unprotected sqlite3_value] object. An unprotected sqlite3_value object
  4168. ** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()].
  4169. ** If the [unprotected sqlite3_value] object returned by
  4170. ** [sqlite3_column_value()] is used in any other way, including calls
  4171. ** to routines like [sqlite3_value_int()], [sqlite3_value_text()],
  4172. ** or [sqlite3_value_bytes()], then the behavior is undefined.
  4173. **
  4174. ** These routines attempt to convert the value where appropriate. For
  4175. ** example, if the internal representation is FLOAT and a text result
  4176. ** is requested, [sqlite3_snprintf()] is used internally to perform the
  4177. ** conversion automatically. The following table details the conversions
  4178. ** that are applied:
  4179. **
  4180. ** <blockquote>
  4181. ** <table border="1">
  4182. ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion
  4183. **
  4184. ** <tr><td> NULL <td> INTEGER <td> Result is 0
  4185. ** <tr><td> NULL <td> FLOAT <td> Result is 0.0
  4186. ** <tr><td> NULL <td> TEXT <td> Result is NULL pointer
  4187. ** <tr><td> NULL <td> BLOB <td> Result is NULL pointer
  4188. ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
  4189. ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
  4190. ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT
  4191. ** <tr><td> FLOAT <td> INTEGER <td> Convert from float to integer
  4192. ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
  4193. ** <tr><td> FLOAT <td> BLOB <td> Same as FLOAT->TEXT
  4194. ** <tr><td> TEXT <td> INTEGER <td> Use atoi()
  4195. ** <tr><td> TEXT <td> FLOAT <td> Use atof()
  4196. ** <tr><td> TEXT <td> BLOB <td> No change
  4197. ** <tr><td> BLOB <td> INTEGER <td> Convert to TEXT then use atoi()
  4198. ** <tr><td> BLOB <td> FLOAT <td> Convert to TEXT then use atof()
  4199. ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed
  4200. ** </table>
  4201. ** </blockquote>
  4202. **
  4203. ** The table above makes reference to standard C library functions atoi()
  4204. ** and atof(). SQLite does not really use these functions. It has its
  4205. ** own equivalent internal routines. The atoi() and atof() names are
  4206. ** used in the table for brevity and because they are familiar to most
  4207. ** C programmers.
  4208. **
  4209. ** Note that when type conversions occur, pointers returned by prior
  4210. ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
  4211. ** sqlite3_column_text16() may be invalidated.
  4212. ** Type conversions and pointer invalidations might occur
  4213. ** in the following cases:
  4214. **
  4215. ** <ul>
  4216. ** <li> The initial content is a BLOB and sqlite3_column_text() or
  4217. ** sqlite3_column_text16() is called. A zero-terminator might
  4218. ** need to be added to the string.</li>
  4219. ** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or
  4220. ** sqlite3_column_text16() is called. The content must be converted
  4221. ** to UTF-16.</li>
  4222. ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
  4223. ** sqlite3_column_text() is called. The content must be converted
  4224. ** to UTF-8.</li>
  4225. ** </ul>
  4226. **
  4227. ** Conversions between UTF-16be and UTF-16le are always done in place and do
  4228. ** not invalidate a prior pointer, though of course the content of the buffer
  4229. ** that the prior pointer points to will have been modified. Other kinds
  4230. ** of conversion are done in place when it is possible, but sometimes they
  4231. ** are not possible and in those cases prior pointers are invalidated.
  4232. **
  4233. ** The safest and easiest to remember policy is to invoke these routines
  4234. ** in one of the following ways:
  4235. **
  4236. ** <ul>
  4237. ** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
  4238. ** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
  4239. ** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
  4240. ** </ul>
  4241. **
  4242. ** In other words, you should call sqlite3_column_text(),
  4243. ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
  4244. ** into the desired format, then invoke sqlite3_column_bytes() or
  4245. ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls
  4246. ** to sqlite3_column_text() or sqlite3_column_blob() with calls to
  4247. ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()
  4248. ** with calls to sqlite3_column_bytes().
  4249. **
  4250. ** The pointers returned are valid until a type conversion occurs as
  4251. ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
  4252. ** [sqlite3_finalize()] is called. The memory space used to hold strings
  4253. ** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned
  4254. ** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
  4255. ** [sqlite3_free()].
  4256. **
  4257. ** If a memory allocation error occurs during the evaluation of any
  4258. ** of these routines, a default value is returned. The default value
  4259. ** is either the integer 0, the floating point number 0.0, or a NULL
  4260. ** pointer. Subsequent calls to [sqlite3_errcode()] will return
  4261. ** [SQLITE_NOMEM].
  4262. **
  4263. ** INVARIANTS:
  4264. **
  4265. ** {H13803} The [sqlite3_column_blob(S,N)] interface converts the
  4266. ** Nth column in the current row of the result set for
  4267. ** the [prepared statement] S into a BLOB and then returns a
  4268. ** pointer to the converted value.
  4269. **
  4270. ** {H13806} The [sqlite3_column_bytes(S,N)] interface returns the
  4271. ** number of bytes in the BLOB or string (exclusive of the
  4272. ** zero terminator on the string) that was returned by the
  4273. ** most recent call to [sqlite3_column_blob(S,N)] or
  4274. ** [sqlite3_column_text(S,N)].
  4275. **
  4276. ** {H13809} The [sqlite3_column_bytes16(S,N)] interface returns the
  4277. ** number of bytes in the string (exclusive of the
  4278. ** zero terminator on the string) that was returned by the
  4279. ** most recent call to [sqlite3_column_text16(S,N)].
  4280. **
  4281. ** {H13812} The [sqlite3_column_double(S,N)] interface converts the
  4282. ** Nth column in the current row of the result set for the
  4283. ** [prepared statement] S into a floating point value and
  4284. ** returns a copy of that value.
  4285. **
  4286. ** {H13815} The [sqlite3_column_int(S,N)] interface converts the
  4287. ** Nth column in the current row of the result set for the
  4288. ** [prepared statement] S into a 64-bit signed integer and
  4289. ** returns the lower 32 bits of that integer.
  4290. **
  4291. ** {H13818} The [sqlite3_column_int64(S,N)] interface converts the
  4292. ** Nth column in the current row of the result set for the
  4293. ** [prepared statement] S into a 64-bit signed integer and
  4294. ** returns a copy of that integer.
  4295. **
  4296. ** {H13821} The [sqlite3_column_text(S,N)] interface converts the
  4297. ** Nth column in the current row of the result set for
  4298. ** the [prepared statement] S into a zero-terminated UTF-8
  4299. ** string and returns a pointer to that string.
  4300. **
  4301. ** {H13824} The [sqlite3_column_text16(S,N)] interface converts the
  4302. ** Nth column in the current row of the result set for the
  4303. ** [prepared statement] S into a zero-terminated 2-byte
  4304. ** aligned UTF-16 native byte order string and returns
  4305. ** a pointer to that string.
  4306. **
  4307. ** {H13827} The [sqlite3_column_type(S,N)] interface returns
  4308. ** one of [SQLITE_NULL], [SQLITE_INTEGER], [SQLITE_FLOAT],
  4309. ** [SQLITE_TEXT], or [SQLITE_BLOB] as appropriate for
  4310. ** the Nth column in the current row of the result set for
  4311. ** the [prepared statement] S.
  4312. **
  4313. ** {H13830} The [sqlite3_column_value(S,N)] interface returns a
  4314. ** pointer to an [unprotected sqlite3_value] object for the
  4315. ** Nth column in the current row of the result set for
  4316. ** the [prepared statement] S.
  4317. */
  4318. SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
  4319. SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
  4320. SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
  4321. SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol);
  4322. SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol);
  4323. SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
  4324. SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
  4325. SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
  4326. SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol);
  4327. SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
  4328. /*
  4329. ** CAPI3REF: Destroy A Prepared Statement Object {H13300} <S70300><S30100>
  4330. **
  4331. ** The sqlite3_finalize() function is called to delete a [prepared statement].
  4332. ** If the statement was executed successfully or not executed at all, then
  4333. ** SQLITE_OK is returned. If execution of the statement failed then an
  4334. ** [error code] or [extended error code] is returned.
  4335. **
  4336. ** This routine can be called at any point during the execution of the
  4337. ** [prepared statement]. If the virtual machine has not
  4338. ** completed execution when this routine is called, that is like
  4339. ** encountering an error or an [sqlite3_interrupt | interrupt].
  4340. ** Incomplete updates may be rolled back and transactions canceled,
  4341. ** depending on the circumstances, and the
  4342. ** [error code] returned will be [SQLITE_ABORT].
  4343. **
  4344. ** INVARIANTS:
  4345. **
  4346. ** {H11302} The [sqlite3_finalize(S)] interface destroys the
  4347. ** [prepared statement] S and releases all
  4348. ** memory and file resources held by that object.
  4349. **
  4350. ** {H11304} If the most recent call to [sqlite3_step(S)] for the
  4351. ** [prepared statement] S returned an error,
  4352. ** then [sqlite3_finalize(S)] returns that same error.
  4353. */
  4354. SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
  4355. /*
  4356. ** CAPI3REF: Reset A Prepared Statement Object {H13330} <S70300>
  4357. **
  4358. ** The sqlite3_reset() function is called to reset a [prepared statement]
  4359. ** object back to its initial state, ready to be re-executed.
  4360. ** Any SQL statement variables that had values bound to them using
  4361. ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
  4362. ** Use [sqlite3_clear_bindings()] to reset the bindings.
  4363. **
  4364. ** {H11332} The [sqlite3_reset(S)] interface resets the [prepared statement] S
  4365. ** back to the beginning of its program.
  4366. **
  4367. ** {H11334} If the most recent call to [sqlite3_step(S)] for the
  4368. ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE],
  4369. ** or if [sqlite3_step(S)] has never before been called on S,
  4370. ** then [sqlite3_reset(S)] returns [SQLITE_OK].
  4371. **
  4372. ** {H11336} If the most recent call to [sqlite3_step(S)] for the
  4373. ** [prepared statement] S indicated an error, then
  4374. ** [sqlite3_reset(S)] returns an appropriate [error code].
  4375. **
  4376. ** {H11338} The [sqlite3_reset(S)] interface does not change the values
  4377. ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
  4378. */
  4379. SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
  4380. /*
  4381. ** CAPI3REF: Create Or Redefine SQL Functions {H16100} <S20200>
  4382. ** KEYWORDS: {function creation routines}
  4383. ** KEYWORDS: {application-defined SQL function}
  4384. ** KEYWORDS: {application-defined SQL functions}
  4385. **
  4386. ** These two functions (collectively known as "function creation routines")
  4387. ** are used to add SQL functions or aggregates or to redefine the behavior
  4388. ** of existing SQL functions or aggregates. The only difference between the
  4389. ** two is that the second parameter, the name of the (scalar) function or
  4390. ** aggregate, is encoded in UTF-8 for sqlite3_create_function() and UTF-16
  4391. ** for sqlite3_create_function16().
  4392. **
  4393. ** The first parameter is the [database connection] to which the SQL
  4394. ** function is to be added. If a single program uses more than one database
  4395. ** connection internally, then SQL functions must be added individually to
  4396. ** each database connection.
  4397. **
  4398. ** The second parameter is the name of the SQL function to be created or
  4399. ** redefined. The length of the name is limited to 255 bytes, exclusive of
  4400. ** the zero-terminator. Note that the name length limit is in bytes, not
  4401. ** characters. Any attempt to create a function with a longer name
  4402. ** will result in [SQLITE_ERROR] being returned.
  4403. **
  4404. ** The third parameter (nArg)
  4405. ** is the number of arguments that the SQL function or
  4406. ** aggregate takes. If this parameter is negative, then the SQL function or
  4407. ** aggregate may take any number of arguments.
  4408. **
  4409. ** The fourth parameter, eTextRep, specifies what
  4410. ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
  4411. ** its parameters. Any SQL function implementation should be able to work
  4412. ** work with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
  4413. ** more efficient with one encoding than another. It is allowed to
  4414. ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
  4415. ** times with the same function but with different values of eTextRep.
  4416. ** When multiple implementations of the same function are available, SQLite
  4417. ** will pick the one that involves the least amount of data conversion.
  4418. ** If there is only a single implementation which does not care what text
  4419. ** encoding is used, then the fourth argument should be [SQLITE_ANY].
  4420. **
  4421. ** The fifth parameter is an arbitrary pointer. The implementation of the
  4422. ** function can gain access to this pointer using [sqlite3_user_data()].
  4423. **
  4424. ** The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
  4425. ** pointers to C-language functions that implement the SQL function or
  4426. ** aggregate. A scalar SQL function requires an implementation of the xFunc
  4427. ** callback only, NULL pointers should be passed as the xStep and xFinal
  4428. ** parameters. An aggregate SQL function requires an implementation of xStep
  4429. ** and xFinal and NULL should be passed for xFunc. To delete an existing
  4430. ** SQL function or aggregate, pass NULL for all three function callbacks.
  4431. **
  4432. ** It is permitted to register multiple implementations of the same
  4433. ** functions with the same name but with either differing numbers of
  4434. ** arguments or differing preferred text encodings. SQLite will use
  4435. ** the implementation most closely matches the way in which the
  4436. ** SQL function is used. A function implementation with a non-negative
  4437. ** nArg parameter is a better match than a function implementation with
  4438. ** a negative nArg. A function where the preferred text encoding
  4439. ** matches the database encoding is a better
  4440. ** match than a function where the encoding is different.
  4441. ** A function where the encoding difference is between UTF16le and UTF16be
  4442. ** is a closer match than a function where the encoding difference is
  4443. ** between UTF8 and UTF16.
  4444. **
  4445. ** Built-in functions may be overloaded by new application-defined functions.
  4446. ** The first application-defined function with a given name overrides all
  4447. ** built-in functions in the same [database connection] with the same name.
  4448. ** Subsequent application-defined functions of the same name only override
  4449. ** prior application-defined functions that are an exact match for the
  4450. ** number of parameters and preferred encoding.
  4451. **
  4452. ** An application-defined function is permitted to call other
  4453. ** SQLite interfaces. However, such calls must not
  4454. ** close the database connection nor finalize or reset the prepared
  4455. ** statement in which the function is running.
  4456. **
  4457. ** INVARIANTS:
  4458. **
  4459. ** {H16103} The [sqlite3_create_function16(D,X,...)] interface shall behave
  4460. ** as [sqlite3_create_function(D,X,...)] in every way except that it
  4461. ** interprets the X argument as zero-terminated UTF-16
  4462. ** native byte order instead of as zero-terminated UTF-8.
  4463. **
  4464. ** {H16106} A successful invocation of the
  4465. ** [sqlite3_create_function(D,X,N,E,...)] interface shall register
  4466. ** or replaces callback functions in the [database connection] D
  4467. ** used to implement the SQL function named X with N parameters
  4468. ** and having a preferred text encoding of E.
  4469. **
  4470. ** {H16109} A successful call to [sqlite3_create_function(D,X,N,E,P,F,S,L)]
  4471. ** shall replace the P, F, S, and L values from any prior calls with
  4472. ** the same D, X, N, and E values.
  4473. **
  4474. ** {H16112} The [sqlite3_create_function(D,X,...)] interface shall fail
  4475. ** if the SQL function name X is
  4476. ** longer than 255 bytes exclusive of the zero terminator.
  4477. **
  4478. ** {H16118} The [sqlite3_create_function(D,X,N,E,P,F,S,L)] interface
  4479. ** shall fail unless either F is NULL and S and L are non-NULL or
  4480. *** F is non-NULL and S and L are NULL.
  4481. **
  4482. ** {H16121} The [sqlite3_create_function(D,...)] interface shall fails with an
  4483. ** error code of [SQLITE_BUSY] if there exist [prepared statements]
  4484. ** associated with the [database connection] D.
  4485. **
  4486. ** {H16124} The [sqlite3_create_function(D,X,N,...)] interface shall fail with
  4487. ** an error code of [SQLITE_ERROR] if parameter N is less
  4488. ** than -1 or greater than 127.
  4489. **
  4490. ** {H16127} When N is non-negative, the [sqlite3_create_function(D,X,N,...)]
  4491. ** interface shall register callbacks to be invoked for the
  4492. ** SQL function
  4493. ** named X when the number of arguments to the SQL function is
  4494. ** exactly N.
  4495. **
  4496. ** {H16130} When N is -1, the [sqlite3_create_function(D,X,N,...)]
  4497. ** interface shall register callbacks to be invoked for the SQL
  4498. ** function named X with any number of arguments.
  4499. **
  4500. ** {H16133} When calls to [sqlite3_create_function(D,X,N,...)]
  4501. ** specify multiple implementations of the same function X
  4502. ** and when one implementation has N>=0 and the other has N=(-1)
  4503. ** the implementation with a non-zero N shall be preferred.
  4504. **
  4505. ** {H16136} When calls to [sqlite3_create_function(D,X,N,E,...)]
  4506. ** specify multiple implementations of the same function X with
  4507. ** the same number of arguments N but with different
  4508. ** encodings E, then the implementation where E matches the
  4509. ** database encoding shall preferred.
  4510. **
  4511. ** {H16139} For an aggregate SQL function created using
  4512. ** [sqlite3_create_function(D,X,N,E,P,0,S,L)] the finalizer
  4513. ** function L shall always be invoked exactly once if the
  4514. ** step function S is called one or more times.
  4515. **
  4516. ** {H16142} When SQLite invokes either the xFunc or xStep function of
  4517. ** an application-defined SQL function or aggregate created
  4518. ** by [sqlite3_create_function()] or [sqlite3_create_function16()],
  4519. ** then the array of [sqlite3_value] objects passed as the
  4520. ** third parameter shall be [protected sqlite3_value] objects.
  4521. */
  4522. SQLITE_API int sqlite3_create_function(
  4523. sqlite3 *db,
  4524. const char *zFunctionName,
  4525. int nArg,
  4526. int eTextRep,
  4527. void *pApp,
  4528. void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  4529. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  4530. void (*xFinal)(sqlite3_context*)
  4531. );
  4532. SQLITE_API int sqlite3_create_function16(
  4533. sqlite3 *db,
  4534. const void *zFunctionName,
  4535. int nArg,
  4536. int eTextRep,
  4537. void *pApp,
  4538. void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  4539. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  4540. void (*xFinal)(sqlite3_context*)
  4541. );
  4542. /*
  4543. ** CAPI3REF: Text Encodings {H10267} <S50200> <H16100>
  4544. **
  4545. ** These constant define integer codes that represent the various
  4546. ** text encodings supported by SQLite.
  4547. */
  4548. #define SQLITE_UTF8 1
  4549. #define SQLITE_UTF16LE 2
  4550. #define SQLITE_UTF16BE 3
  4551. #define SQLITE_UTF16 4 /* Use native byte order */
  4552. #define SQLITE_ANY 5 /* sqlite3_create_function only */
  4553. #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
  4554. /*
  4555. ** CAPI3REF: Deprecated Functions
  4556. ** DEPRECATED
  4557. **
  4558. ** These functions are [deprecated]. In order to maintain
  4559. ** backwards compatibility with older code, these functions continue
  4560. ** to be supported. However, new applications should avoid
  4561. ** the use of these functions. To help encourage people to avoid
  4562. ** using these functions, we are not going to tell you what they do.
  4563. */
  4564. #ifndef SQLITE_OMIT_DEPRECATED
  4565. SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
  4566. SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
  4567. SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
  4568. SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);
  4569. SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
  4570. SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64);
  4571. #endif
  4572. /*
  4573. ** CAPI3REF: Obtaining SQL Function Parameter Values {H15100} <S20200>
  4574. **
  4575. ** The C-language implementation of SQL functions and aggregates uses
  4576. ** this set of interface routines to access the parameter values on
  4577. ** the function or aggregate.
  4578. **
  4579. ** The xFunc (for scalar functions) or xStep (for aggregates) parameters
  4580. ** to [sqlite3_create_function()] and [sqlite3_create_function16()]
  4581. ** define callbacks that implement the SQL functions and aggregates.
  4582. ** The 4th parameter to these callbacks is an array of pointers to
  4583. ** [protected sqlite3_value] objects. There is one [sqlite3_value] object for
  4584. ** each parameter to the SQL function. These routines are used to
  4585. ** extract values from the [sqlite3_value] objects.
  4586. **
  4587. ** These routines work only with [protected sqlite3_value] objects.
  4588. ** Any attempt to use these routines on an [unprotected sqlite3_value]
  4589. ** object results in undefined behavior.
  4590. **
  4591. ** These routines work just like the corresponding [column access functions]
  4592. ** except that these routines take a single [protected sqlite3_value] object
  4593. ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
  4594. **
  4595. ** The sqlite3_value_text16() interface extracts a UTF-16 string
  4596. ** in the native byte-order of the host machine. The
  4597. ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
  4598. ** extract UTF-16 strings as big-endian and little-endian respectively.
  4599. **
  4600. ** The sqlite3_value_numeric_type() interface attempts to apply
  4601. ** numeric affinity to the value. This means that an attempt is
  4602. ** made to convert the value to an integer or floating point. If
  4603. ** such a conversion is possible without loss of information (in other
  4604. ** words, if the value is a string that looks like a number)
  4605. ** then the conversion is performed. Otherwise no conversion occurs.
  4606. ** The [SQLITE_INTEGER | datatype] after conversion is returned.
  4607. **
  4608. ** Please pay particular attention to the fact that the pointer returned
  4609. ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
  4610. ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
  4611. ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
  4612. ** or [sqlite3_value_text16()].
  4613. **
  4614. ** These routines must be called from the same thread as
  4615. ** the SQL function that supplied the [sqlite3_value*] parameters.
  4616. **
  4617. ** INVARIANTS:
  4618. **
  4619. ** {H15103} The [sqlite3_value_blob(V)] interface converts the
  4620. ** [protected sqlite3_value] object V into a BLOB and then
  4621. ** returns a pointer to the converted value.
  4622. **
  4623. ** {H15106} The [sqlite3_value_bytes(V)] interface returns the
  4624. ** number of bytes in the BLOB or string (exclusive of the
  4625. ** zero terminator on the string) that was returned by the
  4626. ** most recent call to [sqlite3_value_blob(V)] or
  4627. ** [sqlite3_value_text(V)].
  4628. **
  4629. ** {H15109} The [sqlite3_value_bytes16(V)] interface returns the
  4630. ** number of bytes in the string (exclusive of the
  4631. ** zero terminator on the string) that was returned by the
  4632. ** most recent call to [sqlite3_value_text16(V)],
  4633. ** [sqlite3_value_text16be(V)], or [sqlite3_value_text16le(V)].
  4634. **
  4635. ** {H15112} The [sqlite3_value_double(V)] interface converts the
  4636. ** [protected sqlite3_value] object V into a floating point value and
  4637. ** returns a copy of that value.
  4638. **
  4639. ** {H15115} The [sqlite3_value_int(V)] interface converts the
  4640. ** [protected sqlite3_value] object V into a 64-bit signed integer and
  4641. ** returns the lower 32 bits of that integer.
  4642. **
  4643. ** {H15118} The [sqlite3_value_int64(V)] interface converts the
  4644. ** [protected sqlite3_value] object V into a 64-bit signed integer and
  4645. ** returns a copy of that integer.
  4646. **
  4647. ** {H15121} The [sqlite3_value_text(V)] interface converts the
  4648. ** [protected sqlite3_value] object V into a zero-terminated UTF-8
  4649. ** string and returns a pointer to that string.
  4650. **
  4651. ** {H15124} The [sqlite3_value_text16(V)] interface converts the
  4652. ** [protected sqlite3_value] object V into a zero-terminated 2-byte
  4653. ** aligned UTF-16 native byte order
  4654. ** string and returns a pointer to that string.
  4655. **
  4656. ** {H15127} The [sqlite3_value_text16be(V)] interface converts the
  4657. ** [protected sqlite3_value] object V into a zero-terminated 2-byte
  4658. ** aligned UTF-16 big-endian
  4659. ** string and returns a pointer to that string.
  4660. **
  4661. ** {H15130} The [sqlite3_value_text16le(V)] interface converts the
  4662. ** [protected sqlite3_value] object V into a zero-terminated 2-byte
  4663. ** aligned UTF-16 little-endian
  4664. ** string and returns a pointer to that string.
  4665. **
  4666. ** {H15133} The [sqlite3_value_type(V)] interface returns
  4667. ** one of [SQLITE_NULL], [SQLITE_INTEGER], [SQLITE_FLOAT],
  4668. ** [SQLITE_TEXT], or [SQLITE_BLOB] as appropriate for
  4669. ** the [sqlite3_value] object V.
  4670. **
  4671. ** {H15136} The [sqlite3_value_numeric_type(V)] interface converts
  4672. ** the [protected sqlite3_value] object V into either an integer or
  4673. ** a floating point value if it can do so without loss of
  4674. ** information, and returns one of [SQLITE_NULL],
  4675. ** [SQLITE_INTEGER], [SQLITE_FLOAT], [SQLITE_TEXT], or
  4676. ** [SQLITE_BLOB] as appropriate for the
  4677. ** [protected sqlite3_value] object V after the conversion attempt.
  4678. */
  4679. SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);
  4680. SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
  4681. SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
  4682. SQLITE_API double sqlite3_value_double(sqlite3_value*);
  4683. SQLITE_API int sqlite3_value_int(sqlite3_value*);
  4684. SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
  4685. SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);
  4686. SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);
  4687. SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);
  4688. SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
  4689. SQLITE_API int sqlite3_value_type(sqlite3_value*);
  4690. SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
  4691. /*
  4692. ** CAPI3REF: Obtain Aggregate Function Context {H16210} <S20200>
  4693. **
  4694. ** The implementation of aggregate SQL functions use this routine to allocate
  4695. ** a structure for storing their state.
  4696. **
  4697. ** The first time the sqlite3_aggregate_context() routine is called for a
  4698. ** particular aggregate, SQLite allocates nBytes of memory, zeroes out that
  4699. ** memory, and returns a pointer to it. On second and subsequent calls to
  4700. ** sqlite3_aggregate_context() for the same aggregate function index,
  4701. ** the same buffer is returned. The implementation of the aggregate can use
  4702. ** the returned buffer to accumulate data.
  4703. **
  4704. ** SQLite automatically frees the allocated buffer when the aggregate
  4705. ** query concludes.
  4706. **
  4707. ** The first parameter should be a copy of the
  4708. ** [sqlite3_context | SQL function context] that is the first parameter
  4709. ** to the callback routine that implements the aggregate function.
  4710. **
  4711. ** This routine must be called from the same thread in which
  4712. ** the aggregate SQL function is running.
  4713. **
  4714. ** INVARIANTS:
  4715. **
  4716. ** {H16211} The first invocation of [sqlite3_aggregate_context(C,N)] for
  4717. ** a particular instance of an aggregate function (for a particular
  4718. ** context C) causes SQLite to allocate N bytes of memory,
  4719. ** zero that memory, and return a pointer to the allocated memory.
  4720. **
  4721. ** {H16213} If a memory allocation error occurs during
  4722. ** [sqlite3_aggregate_context(C,N)] then the function returns 0.
  4723. **
  4724. ** {H16215} Second and subsequent invocations of
  4725. ** [sqlite3_aggregate_context(C,N)] for the same context pointer C
  4726. ** ignore the N parameter and return a pointer to the same
  4727. ** block of memory returned by the first invocation.
  4728. **
  4729. ** {H16217} The memory allocated by [sqlite3_aggregate_context(C,N)] is
  4730. ** automatically freed on the next call to [sqlite3_reset()]
  4731. ** or [sqlite3_finalize()] for the [prepared statement] containing
  4732. ** the aggregate function associated with context C.
  4733. */
  4734. SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
  4735. /*
  4736. ** CAPI3REF: User Data For Functions {H16240} <S20200>
  4737. **
  4738. ** The sqlite3_user_data() interface returns a copy of
  4739. ** the pointer that was the pUserData parameter (the 5th parameter)
  4740. ** of the [sqlite3_create_function()]
  4741. ** and [sqlite3_create_function16()] routines that originally
  4742. ** registered the application defined function. {END}
  4743. **
  4744. ** This routine must be called from the same thread in which
  4745. ** the application-defined function is running.
  4746. **
  4747. ** INVARIANTS:
  4748. **
  4749. ** {H16243} The [sqlite3_user_data(C)] interface returns a copy of the
  4750. ** P pointer from the [sqlite3_create_function(D,X,N,E,P,F,S,L)]
  4751. ** or [sqlite3_create_function16(D,X,N,E,P,F,S,L)] call that
  4752. ** registered the SQL function associated with [sqlite3_context] C.
  4753. */
  4754. SQLITE_API void *sqlite3_user_data(sqlite3_context*);
  4755. /*
  4756. ** CAPI3REF: Database Connection For Functions {H16250} <S60600><S20200>
  4757. **
  4758. ** The sqlite3_context_db_handle() interface returns a copy of
  4759. ** the pointer to the [database connection] (the 1st parameter)
  4760. ** of the [sqlite3_create_function()]
  4761. ** and [sqlite3_create_function16()] routines that originally
  4762. ** registered the application defined function.
  4763. **
  4764. ** INVARIANTS:
  4765. **
  4766. ** {H16253} The [sqlite3_context_db_handle(C)] interface returns a copy of the
  4767. ** D pointer from the [sqlite3_create_function(D,X,N,E,P,F,S,L)]
  4768. ** or [sqlite3_create_function16(D,X,N,E,P,F,S,L)] call that
  4769. ** registered the SQL function associated with [sqlite3_context] C.
  4770. */
  4771. SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
  4772. /*
  4773. ** CAPI3REF: Function Auxiliary Data {H16270} <S20200>
  4774. **
  4775. ** The following two functions may be used by scalar SQL functions to
  4776. ** associate metadata with argument values. If the same value is passed to
  4777. ** multiple invocations of the same SQL function during query execution, under
  4778. ** some circumstances the associated metadata may be preserved. This may
  4779. ** be used, for example, to add a regular-expression matching scalar
  4780. ** function. The compiled version of the regular expression is stored as
  4781. ** metadata associated with the SQL value passed as the regular expression
  4782. ** pattern. The compiled regular expression can be reused on multiple
  4783. ** invocations of the same function so that the original pattern string
  4784. ** does not need to be recompiled on each invocation.
  4785. **
  4786. ** The sqlite3_get_auxdata() interface returns a pointer to the metadata
  4787. ** associated by the sqlite3_set_auxdata() function with the Nth argument
  4788. ** value to the application-defined function. If no metadata has been ever
  4789. ** been set for the Nth argument of the function, or if the corresponding
  4790. ** function parameter has changed since the meta-data was set,
  4791. ** then sqlite3_get_auxdata() returns a NULL pointer.
  4792. **
  4793. ** The sqlite3_set_auxdata() interface saves the metadata
  4794. ** pointed to by its 3rd parameter as the metadata for the N-th
  4795. ** argument of the application-defined function. Subsequent
  4796. ** calls to sqlite3_get_auxdata() might return this data, if it has
  4797. ** not been destroyed.
  4798. ** If it is not NULL, SQLite will invoke the destructor
  4799. ** function given by the 4th parameter to sqlite3_set_auxdata() on
  4800. ** the metadata when the corresponding function parameter changes
  4801. ** or when the SQL statement completes, whichever comes first.
  4802. **
  4803. ** SQLite is free to call the destructor and drop metadata on any
  4804. ** parameter of any function at any time. The only guarantee is that
  4805. ** the destructor will be called before the metadata is dropped.
  4806. **
  4807. ** In practice, metadata is preserved between function calls for
  4808. ** expressions that are constant at compile time. This includes literal
  4809. ** values and SQL variables.
  4810. **
  4811. ** These routines must be called from the same thread in which
  4812. ** the SQL function is running.
  4813. **
  4814. ** INVARIANTS:
  4815. **
  4816. ** {H16272} The [sqlite3_get_auxdata(C,N)] interface returns a pointer
  4817. ** to metadata associated with the Nth parameter of the SQL function
  4818. ** whose context is C, or NULL if there is no metadata associated
  4819. ** with that parameter.
  4820. **
  4821. ** {H16274} The [sqlite3_set_auxdata(C,N,P,D)] interface assigns a metadata
  4822. ** pointer P to the Nth parameter of the SQL function with context C.
  4823. **
  4824. ** {H16276} SQLite will invoke the destructor D with a single argument
  4825. ** which is the metadata pointer P following a call to
  4826. ** [sqlite3_set_auxdata(C,N,P,D)] when SQLite ceases to hold
  4827. ** the metadata.
  4828. **
  4829. ** {H16277} SQLite ceases to hold metadata for an SQL function parameter
  4830. ** when the value of that parameter changes.
  4831. **
  4832. ** {H16278} When [sqlite3_set_auxdata(C,N,P,D)] is invoked, the destructor
  4833. ** is called for any prior metadata associated with the same function
  4834. ** context C and parameter N.
  4835. **
  4836. ** {H16279} SQLite will call destructors for any metadata it is holding
  4837. ** in a particular [prepared statement] S when either
  4838. ** [sqlite3_reset(S)] or [sqlite3_finalize(S)] is called.
  4839. */
  4840. SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
  4841. SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
  4842. /*
  4843. ** CAPI3REF: Constants Defining Special Destructor Behavior {H10280} <S30100>
  4844. **
  4845. ** These are special values for the destructor that is passed in as the
  4846. ** final argument to routines like [sqlite3_result_blob()]. If the destructor
  4847. ** argument is SQLITE_STATIC, it means that the content pointer is constant
  4848. ** and will never change. It does not need to be destroyed. The
  4849. ** SQLITE_TRANSIENT value means that the content will likely change in
  4850. ** the near future and that SQLite should make its own private copy of
  4851. ** the content before returning.
  4852. **
  4853. ** The typedef is necessary to work around problems in certain
  4854. ** C++ compilers. See ticket #2191.
  4855. */
  4856. typedef void (*sqlite3_destructor_type)(void*);
  4857. #define SQLITE_STATIC ((sqlite3_destructor_type)0)
  4858. #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
  4859. /*
  4860. ** CAPI3REF: Setting The Result Of An SQL Function {H16400} <S20200>
  4861. **
  4862. ** These routines are used by the xFunc or xFinal callbacks that
  4863. ** implement SQL functions and aggregates. See
  4864. ** [sqlite3_create_function()] and [sqlite3_create_function16()]
  4865. ** for additional information.
  4866. **
  4867. ** These functions work very much like the [parameter binding] family of
  4868. ** functions used to bind values to host parameters in prepared statements.
  4869. ** Refer to the [SQL parameter] documentation for additional information.
  4870. **
  4871. ** The sqlite3_result_blob() interface sets the result from
  4872. ** an application-defined function to be the BLOB whose content is pointed
  4873. ** to by the second parameter and which is N bytes long where N is the
  4874. ** third parameter.
  4875. **
  4876. ** The sqlite3_result_zeroblob() interfaces set the result of
  4877. ** the application-defined function to be a BLOB containing all zero
  4878. ** bytes and N bytes in size, where N is the value of the 2nd parameter.
  4879. **
  4880. ** The sqlite3_result_double() interface sets the result from
  4881. ** an application-defined function to be a floating point value specified
  4882. ** by its 2nd argument.
  4883. **
  4884. ** The sqlite3_result_error() and sqlite3_result_error16() functions
  4885. ** cause the implemented SQL function to throw an exception.
  4886. ** SQLite uses the string pointed to by the
  4887. ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
  4888. ** as the text of an error message. SQLite interprets the error
  4889. ** message string from sqlite3_result_error() as UTF-8. SQLite
  4890. ** interprets the string from sqlite3_result_error16() as UTF-16 in native
  4891. ** byte order. If the third parameter to sqlite3_result_error()
  4892. ** or sqlite3_result_error16() is negative then SQLite takes as the error
  4893. ** message all text up through the first zero character.
  4894. ** If the third parameter to sqlite3_result_error() or
  4895. ** sqlite3_result_error16() is non-negative then SQLite takes that many
  4896. ** bytes (not characters) from the 2nd parameter as the error message.
  4897. ** The sqlite3_result_error() and sqlite3_result_error16()
  4898. ** routines make a private copy of the error message text before
  4899. ** they return. Hence, the calling function can deallocate or
  4900. ** modify the text after they return without harm.
  4901. ** The sqlite3_result_error_code() function changes the error code
  4902. ** returned by SQLite as a result of an error in a function. By default,
  4903. ** the error code is SQLITE_ERROR. A subsequent call to sqlite3_result_error()
  4904. ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
  4905. **
  4906. ** The sqlite3_result_toobig() interface causes SQLite to throw an error
  4907. ** indicating that a string or BLOB is to long to represent.
  4908. **
  4909. ** The sqlite3_result_nomem() interface causes SQLite to throw an error
  4910. ** indicating that a memory allocation failed.
  4911. **
  4912. ** The sqlite3_result_int() interface sets the return value
  4913. ** of the application-defined function to be the 32-bit signed integer
  4914. ** value given in the 2nd argument.
  4915. ** The sqlite3_result_int64() interface sets the return value
  4916. ** of the application-defined function to be the 64-bit signed integer
  4917. ** value given in the 2nd argument.
  4918. **
  4919. ** The sqlite3_result_null() interface sets the return value
  4920. ** of the application-defined function to be NULL.
  4921. **
  4922. ** The sqlite3_result_text(), sqlite3_result_text16(),
  4923. ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
  4924. ** set the return value of the application-defined function to be
  4925. ** a text string which is represented as UTF-8, UTF-16 native byte order,
  4926. ** UTF-16 little endian, or UTF-16 big endian, respectively.
  4927. ** SQLite takes the text result from the application from
  4928. ** the 2nd parameter of the sqlite3_result_text* interfaces.
  4929. ** If the 3rd parameter to the sqlite3_result_text* interfaces
  4930. ** is negative, then SQLite takes result text from the 2nd parameter
  4931. ** through the first zero character.
  4932. ** If the 3rd parameter to the sqlite3_result_text* interfaces
  4933. ** is non-negative, then as many bytes (not characters) of the text
  4934. ** pointed to by the 2nd parameter are taken as the application-defined
  4935. ** function result.
  4936. ** If the 4th parameter to the sqlite3_result_text* interfaces
  4937. ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
  4938. ** function as the destructor on the text or BLOB result when it has
  4939. ** finished using that result.
  4940. ** If the 4th parameter to the sqlite3_result_text* interfaces or
  4941. ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite
  4942. ** assumes that the text or BLOB result is in constant space and does not
  4943. ** copy the it or call a destructor when it has finished using that result.
  4944. ** If the 4th parameter to the sqlite3_result_text* interfaces
  4945. ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
  4946. ** then SQLite makes a copy of the result into space obtained from
  4947. ** from [sqlite3_malloc()] before it returns.
  4948. **
  4949. ** The sqlite3_result_value() interface sets the result of
  4950. ** the application-defined function to be a copy the
  4951. ** [unprotected sqlite3_value] object specified by the 2nd parameter. The
  4952. ** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
  4953. ** so that the [sqlite3_value] specified in the parameter may change or
  4954. ** be deallocated after sqlite3_result_value() returns without harm.
  4955. ** A [protected sqlite3_value] object may always be used where an
  4956. ** [unprotected sqlite3_value] object is required, so either
  4957. ** kind of [sqlite3_value] object can be used with this interface.
  4958. **
  4959. ** If these routines are called from within the different thread
  4960. ** than the one containing the application-defined function that received
  4961. ** the [sqlite3_context] pointer, the results are undefined.
  4962. **
  4963. ** INVARIANTS:
  4964. **
  4965. ** {H16403} The default return value from any SQL function is NULL.
  4966. **
  4967. ** {H16406} The [sqlite3_result_blob(C,V,N,D)] interface changes the
  4968. ** return value of function C to be a BLOB that is N bytes
  4969. ** in length and with content pointed to by V.
  4970. **
  4971. ** {H16409} The [sqlite3_result_double(C,V)] interface changes the
  4972. ** return value of function C to be the floating point value V.
  4973. **
  4974. ** {H16412} The [sqlite3_result_error(C,V,N)] interface changes the return
  4975. ** value of function C to be an exception with error code
  4976. ** [SQLITE_ERROR] and a UTF-8 error message copied from V up to the
  4977. ** first zero byte or until N bytes are read if N is positive.
  4978. **
  4979. ** {H16415} The [sqlite3_result_error16(C,V,N)] interface changes the return
  4980. ** value of function C to be an exception with error code
  4981. ** [SQLITE_ERROR] and a UTF-16 native byte order error message
  4982. ** copied from V up to the first zero terminator or until N bytes
  4983. ** are read if N is positive.
  4984. **
  4985. ** {H16418} The [sqlite3_result_error_toobig(C)] interface changes the return
  4986. ** value of the function C to be an exception with error code
  4987. ** [SQLITE_TOOBIG] and an appropriate error message.
  4988. **
  4989. ** {H16421} The [sqlite3_result_error_nomem(C)] interface changes the return
  4990. ** value of the function C to be an exception with error code
  4991. ** [SQLITE_NOMEM] and an appropriate error message.
  4992. **
  4993. ** {H16424} The [sqlite3_result_error_code(C,E)] interface changes the return
  4994. ** value of the function C to be an exception with error code E.
  4995. ** The error message text is unchanged.
  4996. **
  4997. ** {H16427} The [sqlite3_result_int(C,V)] interface changes the
  4998. ** return value of function C to be the 32-bit integer value V.
  4999. **
  5000. ** {H16430} The [sqlite3_result_int64(C,V)] interface changes the
  5001. ** return value of function C to be the 64-bit integer value V.
  5002. **
  5003. ** {H16433} The [sqlite3_result_null(C)] interface changes the
  5004. ** return value of function C to be NULL.
  5005. **
  5006. ** {H16436} The [sqlite3_result_text(C,V,N,D)] interface changes the
  5007. ** return value of function C to be the UTF-8 string
  5008. ** V up to the first zero if N is negative
  5009. ** or the first N bytes of V if N is non-negative.
  5010. **
  5011. ** {H16439} The [sqlite3_result_text16(C,V,N,D)] interface changes the
  5012. ** return value of function C to be the UTF-16 native byte order
  5013. ** string V up to the first zero if N is negative
  5014. ** or the first N bytes of V if N is non-negative.
  5015. **
  5016. ** {H16442} The [sqlite3_result_text16be(C,V,N,D)] interface changes the
  5017. ** return value of function C to be the UTF-16 big-endian
  5018. ** string V up to the first zero if N is negative
  5019. ** or the first N bytes or V if N is non-negative.
  5020. **
  5021. ** {H16445} The [sqlite3_result_text16le(C,V,N,D)] interface changes the
  5022. ** return value of function C to be the UTF-16 little-endian
  5023. ** string V up to the first zero if N is negative
  5024. ** or the first N bytes of V if N is non-negative.
  5025. **
  5026. ** {H16448} The [sqlite3_result_value(C,V)] interface changes the
  5027. ** return value of function C to be the [unprotected sqlite3_value]
  5028. ** object V.
  5029. **
  5030. ** {H16451} The [sqlite3_result_zeroblob(C,N)] interface changes the
  5031. ** return value of function C to be an N-byte BLOB of all zeros.
  5032. **
  5033. ** {H16454} The [sqlite3_result_error()] and [sqlite3_result_error16()]
  5034. ** interfaces make a copy of their error message strings before
  5035. ** returning.
  5036. **
  5037. ** {H16457} If the D destructor parameter to [sqlite3_result_blob(C,V,N,D)],
  5038. ** [sqlite3_result_text(C,V,N,D)], [sqlite3_result_text16(C,V,N,D)],
  5039. ** [sqlite3_result_text16be(C,V,N,D)], or
  5040. ** [sqlite3_result_text16le(C,V,N,D)] is the constant [SQLITE_STATIC]
  5041. ** then no destructor is ever called on the pointer V and SQLite
  5042. ** assumes that V is immutable.
  5043. **
  5044. ** {H16460} If the D destructor parameter to [sqlite3_result_blob(C,V,N,D)],
  5045. ** [sqlite3_result_text(C,V,N,D)], [sqlite3_result_text16(C,V,N,D)],
  5046. ** [sqlite3_result_text16be(C,V,N,D)], or
  5047. ** [sqlite3_result_text16le(C,V,N,D)] is the constant
  5048. ** [SQLITE_TRANSIENT] then the interfaces makes a copy of the
  5049. ** content of V and retains the copy.
  5050. **
  5051. ** {H16463} If the D destructor parameter to [sqlite3_result_blob(C,V,N,D)],
  5052. ** [sqlite3_result_text(C,V,N,D)], [sqlite3_result_text16(C,V,N,D)],
  5053. ** [sqlite3_result_text16be(C,V,N,D)], or
  5054. ** [sqlite3_result_text16le(C,V,N,D)] is some value other than
  5055. ** the constants [SQLITE_STATIC] and [SQLITE_TRANSIENT] then
  5056. ** SQLite will invoke the destructor D with V as its only argument
  5057. ** when it has finished with the V value.
  5058. */
  5059. SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
  5060. SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
  5061. SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
  5062. SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
  5063. SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
  5064. SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
  5065. SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int);
  5066. SQLITE_API void sqlite3_result_int(sqlite3_context*, int);
  5067. SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
  5068. SQLITE_API void sqlite3_result_null(sqlite3_context*);
  5069. SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
  5070. SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
  5071. SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
  5072. SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
  5073. SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
  5074. SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
  5075. /*
  5076. ** CAPI3REF: Define New Collating Sequences {H16600} <S20300>
  5077. **
  5078. ** These functions are used to add new collation sequences to the
  5079. ** [database connection] specified as the first argument.
  5080. **
  5081. ** The name of the new collation sequence is specified as a UTF-8 string
  5082. ** for sqlite3_create_collation() and sqlite3_create_collation_v2()
  5083. ** and a UTF-16 string for sqlite3_create_collation16(). In all cases
  5084. ** the name is passed as the second function argument.
  5085. **
  5086. ** The third argument may be one of the constants [SQLITE_UTF8],
  5087. ** [SQLITE_UTF16LE] or [SQLITE_UTF16BE], indicating that the user-supplied
  5088. ** routine expects to be passed pointers to strings encoded using UTF-8,
  5089. ** UTF-16 little-endian, or UTF-16 big-endian, respectively. The
  5090. ** third argument might also be [SQLITE_UTF16_ALIGNED] to indicate that
  5091. ** the routine expects pointers to 16-bit word aligned strings
  5092. ** of UTF-16 in the native byte order of the host computer.
  5093. **
  5094. ** A pointer to the user supplied routine must be passed as the fifth
  5095. ** argument. If it is NULL, this is the same as deleting the collation
  5096. ** sequence (so that SQLite cannot call it anymore).
  5097. ** Each time the application supplied function is invoked, it is passed
  5098. ** as its first parameter a copy of the void* passed as the fourth argument
  5099. ** to sqlite3_create_collation() or sqlite3_create_collation16().
  5100. **
  5101. ** The remaining arguments to the application-supplied routine are two strings,
  5102. ** each represented by a (length, data) pair and encoded in the encoding
  5103. ** that was passed as the third argument when the collation sequence was
  5104. ** registered. {END} The application defined collation routine should
  5105. ** return negative, zero or positive if the first string is less than,
  5106. ** equal to, or greater than the second string. i.e. (STRING1 - STRING2).
  5107. **
  5108. ** The sqlite3_create_collation_v2() works like sqlite3_create_collation()
  5109. ** except that it takes an extra argument which is a destructor for
  5110. ** the collation. The destructor is called when the collation is
  5111. ** destroyed and is passed a copy of the fourth parameter void* pointer
  5112. ** of the sqlite3_create_collation_v2().
  5113. ** Collations are destroyed when they are overridden by later calls to the
  5114. ** collation creation functions or when the [database connection] is closed
  5115. ** using [sqlite3_close()].
  5116. **
  5117. ** INVARIANTS:
  5118. **
  5119. ** {H16603} A successful call to the
  5120. ** [sqlite3_create_collation_v2(B,X,E,P,F,D)] interface
  5121. ** registers function F as the comparison function used to
  5122. ** implement collation X on the [database connection] B for
  5123. ** databases having encoding E.
  5124. **
  5125. ** {H16604} SQLite understands the X parameter to
  5126. ** [sqlite3_create_collation_v2(B,X,E,P,F,D)] as a zero-terminated
  5127. ** UTF-8 string in which case is ignored for ASCII characters and
  5128. ** is significant for non-ASCII characters.
  5129. **
  5130. ** {H16606} Successive calls to [sqlite3_create_collation_v2(B,X,E,P,F,D)]
  5131. ** with the same values for B, X, and E, override prior values
  5132. ** of P, F, and D.
  5133. **
  5134. ** {H16609} If the destructor D in [sqlite3_create_collation_v2(B,X,E,P,F,D)]
  5135. ** is not NULL then it is called with argument P when the
  5136. ** collating function is dropped by SQLite.
  5137. **
  5138. ** {H16612} A collating function is dropped when it is overloaded.
  5139. **
  5140. ** {H16615} A collating function is dropped when the database connection
  5141. ** is closed using [sqlite3_close()].
  5142. **
  5143. ** {H16618} The pointer P in [sqlite3_create_collation_v2(B,X,E,P,F,D)]
  5144. ** is passed through as the first parameter to the comparison
  5145. ** function F for all subsequent invocations of F.
  5146. **
  5147. ** {H16621} A call to [sqlite3_create_collation(B,X,E,P,F)] is exactly
  5148. ** the same as a call to [sqlite3_create_collation_v2()] with
  5149. ** the same parameters and a NULL destructor.
  5150. **
  5151. ** {H16624} Following a [sqlite3_create_collation_v2(B,X,E,P,F,D)],
  5152. ** SQLite uses the comparison function F for all text comparison
  5153. ** operations on the [database connection] B on text values that
  5154. ** use the collating sequence named X.
  5155. **
  5156. ** {H16627} The [sqlite3_create_collation16(B,X,E,P,F)] works the same
  5157. ** as [sqlite3_create_collation(B,X,E,P,F)] except that the
  5158. ** collation name X is understood as UTF-16 in native byte order
  5159. ** instead of UTF-8.
  5160. **
  5161. ** {H16630} When multiple comparison functions are available for the same
  5162. ** collating sequence, SQLite chooses the one whose text encoding
  5163. ** requires the least amount of conversion from the default
  5164. ** text encoding of the database.
  5165. */
  5166. SQLITE_API int sqlite3_create_collation(
  5167. sqlite3*,
  5168. const char *zName,
  5169. int eTextRep,
  5170. void*,
  5171. int(*xCompare)(void*,int,const void*,int,const void*)
  5172. );
  5173. SQLITE_API int sqlite3_create_collation_v2(
  5174. sqlite3*,
  5175. const char *zName,
  5176. int eTextRep,
  5177. void*,
  5178. int(*xCompare)(void*,int,const void*,int,const void*),
  5179. void(*xDestroy)(void*)
  5180. );
  5181. SQLITE_API int sqlite3_create_collation16(
  5182. sqlite3*,
  5183. const void *zName,
  5184. int eTextRep,
  5185. void*,
  5186. int(*xCompare)(void*,int,const void*,int,const void*)
  5187. );
  5188. /*
  5189. ** CAPI3REF: Collation Needed Callbacks {H16700} <S20300>
  5190. **
  5191. ** To avoid having to register all collation sequences before a database
  5192. ** can be used, a single callback function may be registered with the
  5193. ** [database connection] to be called whenever an undefined collation
  5194. ** sequence is required.
  5195. **
  5196. ** If the function is registered using the sqlite3_collation_needed() API,
  5197. ** then it is passed the names of undefined collation sequences as strings
  5198. ** encoded in UTF-8. {H16703} If sqlite3_collation_needed16() is used,
  5199. ** the names are passed as UTF-16 in machine native byte order.
  5200. ** A call to either function replaces any existing callback.
  5201. **
  5202. ** When the callback is invoked, the first argument passed is a copy
  5203. ** of the second argument to sqlite3_collation_needed() or
  5204. ** sqlite3_collation_needed16(). The second argument is the database
  5205. ** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE],
  5206. ** or [SQLITE_UTF16LE], indicating the most desirable form of the collation
  5207. ** sequence function required. The fourth parameter is the name of the
  5208. ** required collation sequence.
  5209. **
  5210. ** The callback function should register the desired collation using
  5211. ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
  5212. ** [sqlite3_create_collation_v2()].
  5213. **
  5214. ** INVARIANTS:
  5215. **
  5216. ** {H16702} A successful call to [sqlite3_collation_needed(D,P,F)]
  5217. ** or [sqlite3_collation_needed16(D,P,F)] causes
  5218. ** the [database connection] D to invoke callback F with first
  5219. ** parameter P whenever it needs a comparison function for a
  5220. ** collating sequence that it does not know about.
  5221. **
  5222. ** {H16704} Each successful call to [sqlite3_collation_needed()] or
  5223. ** [sqlite3_collation_needed16()] overrides the callback registered
  5224. ** on the same [database connection] by prior calls to either
  5225. ** interface.
  5226. **
  5227. ** {H16706} The name of the requested collating function passed in the
  5228. ** 4th parameter to the callback is in UTF-8 if the callback
  5229. ** was registered using [sqlite3_collation_needed()] and
  5230. ** is in UTF-16 native byte order if the callback was
  5231. ** registered using [sqlite3_collation_needed16()].
  5232. */
  5233. SQLITE_API int sqlite3_collation_needed(
  5234. sqlite3*,
  5235. void*,
  5236. void(*)(void*,sqlite3*,int eTextRep,const char*)
  5237. );
  5238. SQLITE_API int sqlite3_collation_needed16(
  5239. sqlite3*,
  5240. void*,
  5241. void(*)(void*,sqlite3*,int eTextRep,const void*)
  5242. );
  5243. /*
  5244. ** Specify the key for an encrypted database. This routine should be
  5245. ** called right after sqlite3_open().
  5246. **
  5247. ** The code to implement this API is not available in the public release
  5248. ** of SQLite.
  5249. */
  5250. SQLITE_API int sqlite3_key(
  5251. sqlite3 *db, /* Database to be rekeyed */
  5252. const void *pKey, int nKey /* The key */
  5253. );
  5254. /*
  5255. ** Change the key on an open database. If the current database is not
  5256. ** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the
  5257. ** database is decrypted.
  5258. **
  5259. ** The code to implement this API is not available in the public release
  5260. ** of SQLite.
  5261. */
  5262. SQLITE_API int sqlite3_rekey(
  5263. sqlite3 *db, /* Database to be rekeyed */
  5264. const void *pKey, int nKey /* The new key */
  5265. );
  5266. /*
  5267. ** CAPI3REF: Suspend Execution For A Short Time {H10530} <S40410>
  5268. **
  5269. ** The sqlite3_sleep() function causes the current thread to suspend execution
  5270. ** for at least a number of milliseconds specified in its parameter.
  5271. **
  5272. ** If the operating system does not support sleep requests with
  5273. ** millisecond time resolution, then the time will be rounded up to
  5274. ** the nearest second. The number of milliseconds of sleep actually
  5275. ** requested from the operating system is returned.
  5276. **
  5277. ** SQLite implements this interface by calling the xSleep()
  5278. ** method of the default [sqlite3_vfs] object.
  5279. **
  5280. ** INVARIANTS:
  5281. **
  5282. ** {H10533} The [sqlite3_sleep(M)] interface invokes the xSleep
  5283. ** method of the default [sqlite3_vfs|VFS] in order to
  5284. ** suspend execution of the current thread for at least
  5285. ** M milliseconds.
  5286. **
  5287. ** {H10536} The [sqlite3_sleep(M)] interface returns the number of
  5288. ** milliseconds of sleep actually requested of the operating
  5289. ** system, which might be larger than the parameter M.
  5290. */
  5291. SQLITE_API int sqlite3_sleep(int);
  5292. /*
  5293. ** CAPI3REF: Name Of The Folder Holding Temporary Files {H10310} <S20000>
  5294. **
  5295. ** If this global variable is made to point to a string which is
  5296. ** the name of a folder (a.k.a. directory), then all temporary files
  5297. ** created by SQLite will be placed in that directory. If this variable
  5298. ** is a NULL pointer, then SQLite performs a search for an appropriate
  5299. ** temporary file directory.
  5300. **
  5301. ** It is not safe to modify this variable once a [database connection]
  5302. ** has been opened. It is intended that this variable be set once
  5303. ** as part of process initialization and before any SQLite interface
  5304. ** routines have been call and remain unchanged thereafter.
  5305. */
  5306. SQLITE_API char *sqlite3_temp_directory;
  5307. /*
  5308. ** CAPI3REF: Test For Auto-Commit Mode {H12930} <S60200>
  5309. ** KEYWORDS: {autocommit mode}
  5310. **
  5311. ** The sqlite3_get_autocommit() interface returns non-zero or
  5312. ** zero if the given database connection is or is not in autocommit mode,
  5313. ** respectively. Autocommit mode is on by default.
  5314. ** Autocommit mode is disabled by a [BEGIN] statement.
  5315. ** Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].
  5316. **
  5317. ** If certain kinds of errors occur on a statement within a multi-statement
  5318. ** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR],
  5319. ** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the
  5320. ** transaction might be rolled back automatically. The only way to
  5321. ** find out whether SQLite automatically rolled back the transaction after
  5322. ** an error is to use this function.
  5323. **
  5324. ** INVARIANTS:
  5325. **
  5326. ** {H12931} The [sqlite3_get_autocommit(D)] interface returns non-zero or
  5327. ** zero if the [database connection] D is or is not in autocommit
  5328. ** mode, respectively.
  5329. **
  5330. ** {H12932} Autocommit mode is on by default.
  5331. **
  5332. ** {H12933} Autocommit mode is disabled by a successful [BEGIN] statement.
  5333. **
  5334. ** {H12934} Autocommit mode is enabled by a successful [COMMIT] or [ROLLBACK]
  5335. ** statement.
  5336. **
  5337. ** ASSUMPTIONS:
  5338. **
  5339. ** {A12936} If another thread changes the autocommit status of the database
  5340. ** connection while this routine is running, then the return value
  5341. ** is undefined.
  5342. */
  5343. SQLITE_API int sqlite3_get_autocommit(sqlite3*);
  5344. /*
  5345. ** CAPI3REF: Find The Database Handle Of A Prepared Statement {H13120} <S60600>
  5346. **
  5347. ** The sqlite3_db_handle interface returns the [database connection] handle
  5348. ** to which a [prepared statement] belongs. The database handle returned by
  5349. ** sqlite3_db_handle is the same database handle that was the first argument
  5350. ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
  5351. ** create the statement in the first place.
  5352. **
  5353. ** INVARIANTS:
  5354. **
  5355. ** {H13123} The [sqlite3_db_handle(S)] interface returns a pointer
  5356. ** to the [database connection] associated with the
  5357. ** [prepared statement] S.
  5358. */
  5359. SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
  5360. /*
  5361. ** CAPI3REF: Find the next prepared statement {H13140} <S60600>
  5362. **
  5363. ** This interface returns a pointer to the next [prepared statement] after
  5364. ** pStmt associated with the [database connection] pDb. If pStmt is NULL
  5365. ** then this interface returns a pointer to the first prepared statement
  5366. ** associated with the database connection pDb. If no prepared statement
  5367. ** satisfies the conditions of this routine, it returns NULL.
  5368. **
  5369. ** INVARIANTS:
  5370. **
  5371. ** {H13143} If D is a [database connection] that holds one or more
  5372. ** unfinalized [prepared statements] and S is a NULL pointer,
  5373. ** then [sqlite3_next_stmt(D, S)] routine shall return a pointer
  5374. ** to one of the prepared statements associated with D.
  5375. **
  5376. ** {H13146} If D is a [database connection] that holds no unfinalized
  5377. ** [prepared statements] and S is a NULL pointer, then
  5378. ** [sqlite3_next_stmt(D, S)] routine shall return a NULL pointer.
  5379. **
  5380. ** {H13149} If S is a [prepared statement] in the [database connection] D
  5381. ** and S is not the last prepared statement in D, then
  5382. ** [sqlite3_next_stmt(D, S)] routine shall return a pointer
  5383. ** to the next prepared statement in D after S.
  5384. **
  5385. ** {H13152} If S is the last [prepared statement] in the
  5386. ** [database connection] D then the [sqlite3_next_stmt(D, S)]
  5387. ** routine shall return a NULL pointer.
  5388. **
  5389. ** ASSUMPTIONS:
  5390. **
  5391. ** {A13154} The [database connection] pointer D in a call to
  5392. ** [sqlite3_next_stmt(D,S)] must refer to an open database
  5393. ** connection and in particular must not be a NULL pointer.
  5394. */
  5395. SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
  5396. /*
  5397. ** CAPI3REF: Commit And Rollback Notification Callbacks {H12950} <S60400>
  5398. **
  5399. ** The sqlite3_commit_hook() interface registers a callback
  5400. ** function to be invoked whenever a transaction is committed.
  5401. ** Any callback set by a previous call to sqlite3_commit_hook()
  5402. ** for the same database connection is overridden.
  5403. ** The sqlite3_rollback_hook() interface registers a callback
  5404. ** function to be invoked whenever a transaction is committed.
  5405. ** Any callback set by a previous call to sqlite3_commit_hook()
  5406. ** for the same database connection is overridden.
  5407. ** The pArg argument is passed through to the callback.
  5408. ** If the callback on a commit hook function returns non-zero,
  5409. ** then the commit is converted into a rollback.
  5410. **
  5411. ** If another function was previously registered, its
  5412. ** pArg value is returned. Otherwise NULL is returned.
  5413. **
  5414. ** The callback implementation must not do anything that will modify
  5415. ** the database connection that invoked the callback. Any actions
  5416. ** to modify the database connection must be deferred until after the
  5417. ** completion of the [sqlite3_step()] call that triggered the commit
  5418. ** or rollback hook in the first place.
  5419. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  5420. ** database connections for the meaning of "modify" in this paragraph.
  5421. **
  5422. ** Registering a NULL function disables the callback.
  5423. **
  5424. ** For the purposes of this API, a transaction is said to have been
  5425. ** rolled back if an explicit "ROLLBACK" statement is executed, or
  5426. ** an error or constraint causes an implicit rollback to occur.
  5427. ** The rollback callback is not invoked if a transaction is
  5428. ** automatically rolled back because the database connection is closed.
  5429. ** The rollback callback is not invoked if a transaction is
  5430. ** rolled back because a commit callback returned non-zero.
  5431. ** <todo> Check on this </todo>
  5432. **
  5433. ** INVARIANTS:
  5434. **
  5435. ** {H12951} The [sqlite3_commit_hook(D,F,P)] interface registers the
  5436. ** callback function F to be invoked with argument P whenever
  5437. ** a transaction commits on the [database connection] D.
  5438. **
  5439. ** {H12952} The [sqlite3_commit_hook(D,F,P)] interface returns the P argument
  5440. ** from the previous call with the same [database connection] D,
  5441. ** or NULL on the first call for a particular database connection D.
  5442. **
  5443. ** {H12953} Each call to [sqlite3_commit_hook()] overwrites the callback
  5444. ** registered by prior calls.
  5445. **
  5446. ** {H12954} If the F argument to [sqlite3_commit_hook(D,F,P)] is NULL
  5447. ** then the commit hook callback is canceled and no callback
  5448. ** is invoked when a transaction commits.
  5449. **
  5450. ** {H12955} If the commit callback returns non-zero then the commit is
  5451. ** converted into a rollback.
  5452. **
  5453. ** {H12961} The [sqlite3_rollback_hook(D,F,P)] interface registers the
  5454. ** callback function F to be invoked with argument P whenever
  5455. ** a transaction rolls back on the [database connection] D.
  5456. **
  5457. ** {H12962} The [sqlite3_rollback_hook(D,F,P)] interface returns the P
  5458. ** argument from the previous call with the same
  5459. ** [database connection] D, or NULL on the first call
  5460. ** for a particular database connection D.
  5461. **
  5462. ** {H12963} Each call to [sqlite3_rollback_hook()] overwrites the callback
  5463. ** registered by prior calls.
  5464. **
  5465. ** {H12964} If the F argument to [sqlite3_rollback_hook(D,F,P)] is NULL
  5466. ** then the rollback hook callback is canceled and no callback
  5467. ** is invoked when a transaction rolls back.
  5468. */
  5469. SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
  5470. SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
  5471. /*
  5472. ** CAPI3REF: Data Change Notification Callbacks {H12970} <S60400>
  5473. **
  5474. ** The sqlite3_update_hook() interface registers a callback function
  5475. ** with the [database connection] identified by the first argument
  5476. ** to be invoked whenever a row is updated, inserted or deleted.
  5477. ** Any callback set by a previous call to this function
  5478. ** for the same database connection is overridden.
  5479. **
  5480. ** The second argument is a pointer to the function to invoke when a
  5481. ** row is updated, inserted or deleted.
  5482. ** The first argument to the callback is a copy of the third argument
  5483. ** to sqlite3_update_hook().
  5484. ** The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
  5485. ** or [SQLITE_UPDATE], depending on the operation that caused the callback
  5486. ** to be invoked.
  5487. ** The third and fourth arguments to the callback contain pointers to the
  5488. ** database and table name containing the affected row.
  5489. ** The final callback parameter is the [rowid] of the row.
  5490. ** In the case of an update, this is the [rowid] after the update takes place.
  5491. **
  5492. ** The update hook is not invoked when internal system tables are
  5493. ** modified (i.e. sqlite_master and sqlite_sequence).
  5494. **
  5495. ** The update hook implementation must not do anything that will modify
  5496. ** the database connection that invoked the update hook. Any actions
  5497. ** to modify the database connection must be deferred until after the
  5498. ** completion of the [sqlite3_step()] call that triggered the update hook.
  5499. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  5500. ** database connections for the meaning of "modify" in this paragraph.
  5501. **
  5502. ** If another function was previously registered, its pArg value
  5503. ** is returned. Otherwise NULL is returned.
  5504. **
  5505. ** INVARIANTS:
  5506. **
  5507. ** {H12971} The [sqlite3_update_hook(D,F,P)] interface causes the callback
  5508. ** function F to be invoked with first parameter P whenever
  5509. ** a table row is modified, inserted, or deleted on
  5510. ** the [database connection] D.
  5511. **
  5512. ** {H12973} The [sqlite3_update_hook(D,F,P)] interface returns the value
  5513. ** of P for the previous call on the same [database connection] D,
  5514. ** or NULL for the first call.
  5515. **
  5516. ** {H12975} If the update hook callback F in [sqlite3_update_hook(D,F,P)]
  5517. ** is NULL then the no update callbacks are made.
  5518. **
  5519. ** {H12977} Each call to [sqlite3_update_hook(D,F,P)] overrides prior calls
  5520. ** to the same interface on the same [database connection] D.
  5521. **
  5522. ** {H12979} The update hook callback is not invoked when internal system
  5523. ** tables such as sqlite_master and sqlite_sequence are modified.
  5524. **
  5525. ** {H12981} The second parameter to the update callback
  5526. ** is one of [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE],
  5527. ** depending on the operation that caused the callback to be invoked.
  5528. **
  5529. ** {H12983} The third and fourth arguments to the callback contain pointers
  5530. ** to zero-terminated UTF-8 strings which are the names of the
  5531. ** database and table that is being updated.
  5532. ** {H12985} The final callback parameter is the [rowid] of the row after
  5533. ** the change occurs.
  5534. */
  5535. SQLITE_API void *sqlite3_update_hook(
  5536. sqlite3*,
  5537. void(*)(void *,int ,char const *,char const *,sqlite3_int64),
  5538. void*
  5539. );
  5540. /*
  5541. ** CAPI3REF: Enable Or Disable Shared Pager Cache {H10330} <S30900>
  5542. ** KEYWORDS: {shared cache} {shared cache mode}
  5543. **
  5544. ** This routine enables or disables the sharing of the database cache
  5545. ** and schema data structures between [database connection | connections]
  5546. ** to the same database. Sharing is enabled if the argument is true
  5547. ** and disabled if the argument is false.
  5548. **
  5549. ** Cache sharing is enabled and disabled for an entire process. {END}
  5550. ** This is a change as of SQLite version 3.5.0. In prior versions of SQLite,
  5551. ** sharing was enabled or disabled for each thread separately.
  5552. **
  5553. ** The cache sharing mode set by this interface effects all subsequent
  5554. ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
  5555. ** Existing database connections continue use the sharing mode
  5556. ** that was in effect at the time they were opened.
  5557. **
  5558. ** Virtual tables cannot be used with a shared cache. When shared
  5559. ** cache is enabled, the [sqlite3_create_module()] API used to register
  5560. ** virtual tables will always return an error.
  5561. **
  5562. ** This routine returns [SQLITE_OK] if shared cache was enabled or disabled
  5563. ** successfully. An [error code] is returned otherwise.
  5564. **
  5565. ** Shared cache is disabled by default. But this might change in
  5566. ** future releases of SQLite. Applications that care about shared
  5567. ** cache setting should set it explicitly.
  5568. **
  5569. ** INVARIANTS:
  5570. **
  5571. ** {H10331} A successful invocation of [sqlite3_enable_shared_cache(B)]
  5572. ** will enable or disable shared cache mode for any subsequently
  5573. ** created [database connection] in the same process.
  5574. **
  5575. ** {H10336} When shared cache is enabled, the [sqlite3_create_module()]
  5576. ** interface will always return an error.
  5577. **
  5578. ** {H10337} The [sqlite3_enable_shared_cache(B)] interface returns
  5579. ** [SQLITE_OK] if shared cache was enabled or disabled successfully.
  5580. **
  5581. ** {H10339} Shared cache is disabled by default.
  5582. */
  5583. SQLITE_API int sqlite3_enable_shared_cache(int);
  5584. /*
  5585. ** CAPI3REF: Attempt To Free Heap Memory {H17340} <S30220>
  5586. **
  5587. ** The sqlite3_release_memory() interface attempts to free N bytes
  5588. ** of heap memory by deallocating non-essential memory allocations
  5589. ** held by the database library. {END} Memory used to cache database
  5590. ** pages to improve performance is an example of non-essential memory.
  5591. ** sqlite3_release_memory() returns the number of bytes actually freed,
  5592. ** which might be more or less than the amount requested.
  5593. **
  5594. ** INVARIANTS:
  5595. **
  5596. ** {H17341} The [sqlite3_release_memory(N)] interface attempts to
  5597. ** free N bytes of heap memory by deallocating non-essential
  5598. ** memory allocations held by the database library.
  5599. **
  5600. ** {H16342} The [sqlite3_release_memory(N)] returns the number
  5601. ** of bytes actually freed, which might be more or less
  5602. ** than the amount requested.
  5603. */
  5604. SQLITE_API int sqlite3_release_memory(int);
  5605. /*
  5606. ** CAPI3REF: Impose A Limit On Heap Size {H17350} <S30220>
  5607. **
  5608. ** The sqlite3_soft_heap_limit() interface places a "soft" limit
  5609. ** on the amount of heap memory that may be allocated by SQLite.
  5610. ** If an internal allocation is requested that would exceed the
  5611. ** soft heap limit, [sqlite3_release_memory()] is invoked one or
  5612. ** more times to free up some space before the allocation is performed.
  5613. **
  5614. ** The limit is called "soft", because if [sqlite3_release_memory()]
  5615. ** cannot free sufficient memory to prevent the limit from being exceeded,
  5616. ** the memory is allocated anyway and the current operation proceeds.
  5617. **
  5618. ** A negative or zero value for N means that there is no soft heap limit and
  5619. ** [sqlite3_release_memory()] will only be called when memory is exhausted.
  5620. ** The default value for the soft heap limit is zero.
  5621. **
  5622. ** SQLite makes a best effort to honor the soft heap limit.
  5623. ** But if the soft heap limit cannot be honored, execution will
  5624. ** continue without error or notification. This is why the limit is
  5625. ** called a "soft" limit. It is advisory only.
  5626. **
  5627. ** Prior to SQLite version 3.5.0, this routine only constrained the memory
  5628. ** allocated by a single thread - the same thread in which this routine
  5629. ** runs. Beginning with SQLite version 3.5.0, the soft heap limit is
  5630. ** applied to all threads. The value specified for the soft heap limit
  5631. ** is an upper bound on the total memory allocation for all threads. In
  5632. ** version 3.5.0 there is no mechanism for limiting the heap usage for
  5633. ** individual threads.
  5634. **
  5635. ** INVARIANTS:
  5636. **
  5637. ** {H16351} The [sqlite3_soft_heap_limit(N)] interface places a soft limit
  5638. ** of N bytes on the amount of heap memory that may be allocated
  5639. ** using [sqlite3_malloc()] or [sqlite3_realloc()] at any point
  5640. ** in time.
  5641. **
  5642. ** {H16352} If a call to [sqlite3_malloc()] or [sqlite3_realloc()] would
  5643. ** cause the total amount of allocated memory to exceed the
  5644. ** soft heap limit, then [sqlite3_release_memory()] is invoked
  5645. ** in an attempt to reduce the memory usage prior to proceeding
  5646. ** with the memory allocation attempt.
  5647. **
  5648. ** {H16353} Calls to [sqlite3_malloc()] or [sqlite3_realloc()] that trigger
  5649. ** attempts to reduce memory usage through the soft heap limit
  5650. ** mechanism continue even if the attempt to reduce memory
  5651. ** usage is unsuccessful.
  5652. **
  5653. ** {H16354} A negative or zero value for N in a call to
  5654. ** [sqlite3_soft_heap_limit(N)] means that there is no soft
  5655. ** heap limit and [sqlite3_release_memory()] will only be
  5656. ** called when memory is completely exhausted.
  5657. **
  5658. ** {H16355} The default value for the soft heap limit is zero.
  5659. **
  5660. ** {H16358} Each call to [sqlite3_soft_heap_limit(N)] overrides the
  5661. ** values set by all prior calls.
  5662. */
  5663. SQLITE_API void sqlite3_soft_heap_limit(int);
  5664. /*
  5665. ** CAPI3REF: Extract Metadata About A Column Of A Table {H12850} <S60300>
  5666. **
  5667. ** This routine returns metadata about a specific column of a specific
  5668. ** database table accessible using the [database connection] handle
  5669. ** passed as the first function argument.
  5670. **
  5671. ** The column is identified by the second, third and fourth parameters to
  5672. ** this function. The second parameter is either the name of the database
  5673. ** (i.e. "main", "temp" or an attached database) containing the specified
  5674. ** table or NULL. If it is NULL, then all attached databases are searched
  5675. ** for the table using the same algorithm used by the database engine to
  5676. ** resolve unqualified table references.
  5677. **
  5678. ** The third and fourth parameters to this function are the table and column
  5679. ** name of the desired column, respectively. Neither of these parameters
  5680. ** may be NULL.
  5681. **
  5682. ** Metadata is returned by writing to the memory locations passed as the 5th
  5683. ** and subsequent parameters to this function. Any of these arguments may be
  5684. ** NULL, in which case the corresponding element of metadata is omitted.
  5685. **
  5686. ** <blockquote>
  5687. ** <table border="1">
  5688. ** <tr><th> Parameter <th> Output<br>Type <th> Description
  5689. **
  5690. ** <tr><td> 5th <td> const char* <td> Data type
  5691. ** <tr><td> 6th <td> const char* <td> Name of default collation sequence
  5692. ** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint
  5693. ** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY
  5694. ** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT]
  5695. ** </table>
  5696. ** </blockquote>
  5697. **
  5698. ** The memory pointed to by the character pointers returned for the
  5699. ** declaration type and collation sequence is valid only until the next
  5700. ** call to any SQLite API function.
  5701. **
  5702. ** If the specified table is actually a view, an [error code] is returned.
  5703. **
  5704. ** If the specified column is "rowid", "oid" or "_rowid_" and an
  5705. ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
  5706. ** parameters are set for the explicitly declared column. If there is no
  5707. ** explicitly declared [INTEGER PRIMARY KEY] column, then the output
  5708. ** parameters are set as follows:
  5709. **
  5710. ** <pre>
  5711. ** data type: "INTEGER"
  5712. ** collation sequence: "BINARY"
  5713. ** not null: 0
  5714. ** primary key: 1
  5715. ** auto increment: 0
  5716. ** </pre>
  5717. **
  5718. ** This function may load one or more schemas from database files. If an
  5719. ** error occurs during this process, or if the requested table or column
  5720. ** cannot be found, an [error code] is returned and an error message left
  5721. ** in the [database connection] (to be retrieved using sqlite3_errmsg()).
  5722. **
  5723. ** This API is only available if the library was compiled with the
  5724. ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
  5725. */
  5726. SQLITE_API int sqlite3_table_column_metadata(
  5727. sqlite3 *db, /* Connection handle */
  5728. const char *zDbName, /* Database name or NULL */
  5729. const char *zTableName, /* Table name */
  5730. const char *zColumnName, /* Column name */
  5731. char const **pzDataType, /* OUTPUT: Declared data type */
  5732. char const **pzCollSeq, /* OUTPUT: Collation sequence name */
  5733. int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */
  5734. int *pPrimaryKey, /* OUTPUT: True if column part of PK */
  5735. int *pAutoinc /* OUTPUT: True if column is auto-increment */
  5736. );
  5737. /*
  5738. ** CAPI3REF: Load An Extension {H12600} <S20500>
  5739. **
  5740. ** This interface loads an SQLite extension library from the named file.
  5741. **
  5742. ** {H12601} The sqlite3_load_extension() interface attempts to load an
  5743. ** SQLite extension library contained in the file zFile.
  5744. **
  5745. ** {H12602} The entry point is zProc.
  5746. **
  5747. ** {H12603} zProc may be 0, in which case the name of the entry point
  5748. ** defaults to "sqlite3_extension_init".
  5749. **
  5750. ** {H12604} The sqlite3_load_extension() interface shall return
  5751. ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
  5752. **
  5753. ** {H12605} If an error occurs and pzErrMsg is not 0, then the
  5754. ** [sqlite3_load_extension()] interface shall attempt to
  5755. ** fill *pzErrMsg with error message text stored in memory
  5756. ** obtained from [sqlite3_malloc()]. {END} The calling function
  5757. ** should free this memory by calling [sqlite3_free()].
  5758. **
  5759. ** {H12606} Extension loading must be enabled using
  5760. ** [sqlite3_enable_load_extension()] prior to calling this API,
  5761. ** otherwise an error will be returned.
  5762. */
  5763. SQLITE_API int sqlite3_load_extension(
  5764. sqlite3 *db, /* Load the extension into this database connection */
  5765. const char *zFile, /* Name of the shared library containing extension */
  5766. const char *zProc, /* Entry point. Derived from zFile if 0 */
  5767. char **pzErrMsg /* Put error message here if not 0 */
  5768. );
  5769. /*
  5770. ** CAPI3REF: Enable Or Disable Extension Loading {H12620} <S20500>
  5771. **
  5772. ** So as not to open security holes in older applications that are
  5773. ** unprepared to deal with extension loading, and as a means of disabling
  5774. ** extension loading while evaluating user-entered SQL, the following API
  5775. ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
  5776. **
  5777. ** Extension loading is off by default. See ticket #1863.
  5778. **
  5779. ** {H12621} Call the sqlite3_enable_load_extension() routine with onoff==1
  5780. ** to turn extension loading on and call it with onoff==0 to turn
  5781. ** it back off again.
  5782. **
  5783. ** {H12622} Extension loading is off by default.
  5784. */
  5785. SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
  5786. /*
  5787. ** CAPI3REF: Automatically Load An Extensions {H12640} <S20500>
  5788. **
  5789. ** This API can be invoked at program startup in order to register
  5790. ** one or more statically linked extensions that will be available
  5791. ** to all new [database connections]. {END}
  5792. **
  5793. ** This routine stores a pointer to the extension in an array that is
  5794. ** obtained from [sqlite3_malloc()]. If you run a memory leak checker
  5795. ** on your program and it reports a leak because of this array, invoke
  5796. ** [sqlite3_reset_auto_extension()] prior to shutdown to free the memory.
  5797. **
  5798. ** {H12641} This function registers an extension entry point that is
  5799. ** automatically invoked whenever a new [database connection]
  5800. ** is opened using [sqlite3_open()], [sqlite3_open16()],
  5801. ** or [sqlite3_open_v2()].
  5802. **
  5803. ** {H12642} Duplicate extensions are detected so calling this routine
  5804. ** multiple times with the same extension is harmless.
  5805. **
  5806. ** {H12643} This routine stores a pointer to the extension in an array
  5807. ** that is obtained from [sqlite3_malloc()].
  5808. **
  5809. ** {H12644} Automatic extensions apply across all threads.
  5810. */
  5811. SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void));
  5812. /*
  5813. ** CAPI3REF: Reset Automatic Extension Loading {H12660} <S20500>
  5814. **
  5815. ** This function disables all previously registered automatic
  5816. ** extensions. {END} It undoes the effect of all prior
  5817. ** [sqlite3_auto_extension()] calls.
  5818. **
  5819. ** {H12661} This function disables all previously registered
  5820. ** automatic extensions.
  5821. **
  5822. ** {H12662} This function disables automatic extensions in all threads.
  5823. */
  5824. SQLITE_API void sqlite3_reset_auto_extension(void);
  5825. /*
  5826. ****** EXPERIMENTAL - subject to change without notice **************
  5827. **
  5828. ** The interface to the virtual-table mechanism is currently considered
  5829. ** to be experimental. The interface might change in incompatible ways.
  5830. ** If this is a problem for you, do not use the interface at this time.
  5831. **
  5832. ** When the virtual-table mechanism stabilizes, we will declare the
  5833. ** interface fixed, support it indefinitely, and remove this comment.
  5834. */
  5835. /*
  5836. ** Structures used by the virtual table interface
  5837. */
  5838. typedef struct sqlite3_vtab sqlite3_vtab;
  5839. typedef struct sqlite3_index_info sqlite3_index_info;
  5840. typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;
  5841. typedef struct sqlite3_module sqlite3_module;
  5842. /*
  5843. ** CAPI3REF: Virtual Table Object {H18000} <S20400>
  5844. ** KEYWORDS: sqlite3_module
  5845. ** EXPERIMENTAL
  5846. **
  5847. ** A module is a class of virtual tables. Each module is defined
  5848. ** by an instance of the following structure. This structure consists
  5849. ** mostly of methods for the module.
  5850. **
  5851. ** This interface is experimental and is subject to change or
  5852. ** removal in future releases of SQLite.
  5853. */
  5854. struct sqlite3_module {
  5855. int iVersion;
  5856. int (*xCreate)(sqlite3*, void *pAux,
  5857. int argc, const char *const*argv,
  5858. sqlite3_vtab **ppVTab, char**);
  5859. int (*xConnect)(sqlite3*, void *pAux,
  5860. int argc, const char *const*argv,
  5861. sqlite3_vtab **ppVTab, char**);
  5862. int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
  5863. int (*xDisconnect)(sqlite3_vtab *pVTab);
  5864. int (*xDestroy)(sqlite3_vtab *pVTab);
  5865. int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);
  5866. int (*xClose)(sqlite3_vtab_cursor*);
  5867. int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
  5868. int argc, sqlite3_value **argv);
  5869. int (*xNext)(sqlite3_vtab_cursor*);
  5870. int (*xEof)(sqlite3_vtab_cursor*);
  5871. int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int);
  5872. int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid);
  5873. int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *);
  5874. int (*xBegin)(sqlite3_vtab *pVTab);
  5875. int (*xSync)(sqlite3_vtab *pVTab);
  5876. int (*xCommit)(sqlite3_vtab *pVTab);
  5877. int (*xRollback)(sqlite3_vtab *pVTab);
  5878. int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
  5879. void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
  5880. void **ppArg);
  5881. int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
  5882. };
  5883. /*
  5884. ** CAPI3REF: Virtual Table Indexing Information {H18100} <S20400>
  5885. ** KEYWORDS: sqlite3_index_info
  5886. ** EXPERIMENTAL
  5887. **
  5888. ** The sqlite3_index_info structure and its substructures is used to
  5889. ** pass information into and receive the reply from the xBestIndex
  5890. ** method of an sqlite3_module. The fields under **Inputs** are the
  5891. ** inputs to xBestIndex and are read-only. xBestIndex inserts its
  5892. ** results into the **Outputs** fields.
  5893. **
  5894. ** The aConstraint[] array records WHERE clause constraints of the form:
  5895. **
  5896. ** <pre>column OP expr</pre>
  5897. **
  5898. ** where OP is =, &lt;, &lt;=, &gt;, or &gt;=. The particular operator is
  5899. ** stored in aConstraint[].op. The index of the column is stored in
  5900. ** aConstraint[].iColumn. aConstraint[].usable is TRUE if the
  5901. ** expr on the right-hand side can be evaluated (and thus the constraint
  5902. ** is usable) and false if it cannot.
  5903. **
  5904. ** The optimizer automatically inverts terms of the form "expr OP column"
  5905. ** and makes other simplifications to the WHERE clause in an attempt to
  5906. ** get as many WHERE clause terms into the form shown above as possible.
  5907. ** The aConstraint[] array only reports WHERE clause terms in the correct
  5908. ** form that refer to the particular virtual table being queried.
  5909. **
  5910. ** Information about the ORDER BY clause is stored in aOrderBy[].
  5911. ** Each term of aOrderBy records a column of the ORDER BY clause.
  5912. **
  5913. ** The xBestIndex method must fill aConstraintUsage[] with information
  5914. ** about what parameters to pass to xFilter. If argvIndex>0 then
  5915. ** the right-hand side of the corresponding aConstraint[] is evaluated
  5916. ** and becomes the argvIndex-th entry in argv. If aConstraintUsage[].omit
  5917. ** is true, then the constraint is assumed to be fully handled by the
  5918. ** virtual table and is not checked again by SQLite.
  5919. **
  5920. ** The idxNum and idxPtr values are recorded and passed into xFilter.
  5921. ** sqlite3_free() is used to free idxPtr if needToFreeIdxPtr is true.
  5922. **
  5923. ** The orderByConsumed means that output from xFilter will occur in
  5924. ** the correct order to satisfy the ORDER BY clause so that no separate
  5925. ** sorting step is required.
  5926. **
  5927. ** The estimatedCost value is an estimate of the cost of doing the
  5928. ** particular lookup. A full scan of a table with N entries should have
  5929. ** a cost of N. A binary search of a table of N entries should have a
  5930. ** cost of approximately log(N).
  5931. **
  5932. ** This interface is experimental and is subject to change or
  5933. ** removal in future releases of SQLite.
  5934. */
  5935. struct sqlite3_index_info {
  5936. /* Inputs */
  5937. int nConstraint; /* Number of entries in aConstraint */
  5938. struct sqlite3_index_constraint {
  5939. int iColumn; /* Column on left-hand side of constraint */
  5940. unsigned char op; /* Constraint operator */
  5941. unsigned char usable; /* True if this constraint is usable */
  5942. int iTermOffset; /* Used internally - xBestIndex should ignore */
  5943. } *aConstraint; /* Table of WHERE clause constraints */
  5944. int nOrderBy; /* Number of terms in the ORDER BY clause */
  5945. struct sqlite3_index_orderby {
  5946. int iColumn; /* Column number */
  5947. unsigned char desc; /* True for DESC. False for ASC. */
  5948. } *aOrderBy; /* The ORDER BY clause */
  5949. /* Outputs */
  5950. struct sqlite3_index_constraint_usage {
  5951. int argvIndex; /* if >0, constraint is part of argv to xFilter */
  5952. unsigned char omit; /* Do not code a test for this constraint */
  5953. } *aConstraintUsage;
  5954. int idxNum; /* Number used to identify the index */
  5955. char *idxStr; /* String, possibly obtained from sqlite3_malloc */
  5956. int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
  5957. int orderByConsumed; /* True if output is already ordered */
  5958. double estimatedCost; /* Estimated cost of using this index */
  5959. };
  5960. #define SQLITE_INDEX_CONSTRAINT_EQ 2
  5961. #define SQLITE_INDEX_CONSTRAINT_GT 4
  5962. #define SQLITE_INDEX_CONSTRAINT_LE 8
  5963. #define SQLITE_INDEX_CONSTRAINT_LT 16
  5964. #define SQLITE_INDEX_CONSTRAINT_GE 32
  5965. #define SQLITE_INDEX_CONSTRAINT_MATCH 64
  5966. /*
  5967. ** CAPI3REF: Register A Virtual Table Implementation {H18200} <S20400>
  5968. ** EXPERIMENTAL
  5969. **
  5970. ** This routine is used to register a new module name with a
  5971. ** [database connection]. Module names must be registered before
  5972. ** creating new virtual tables on the module, or before using
  5973. ** preexisting virtual tables of the module.
  5974. **
  5975. ** This interface is experimental and is subject to change or
  5976. ** removal in future releases of SQLite.
  5977. */
  5978. SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module(
  5979. sqlite3 *db, /* SQLite connection to register module with */
  5980. const char *zName, /* Name of the module */
  5981. const sqlite3_module *, /* Methods for the module */
  5982. void * /* Client data for xCreate/xConnect */
  5983. );
  5984. /*
  5985. ** CAPI3REF: Register A Virtual Table Implementation {H18210} <S20400>
  5986. ** EXPERIMENTAL
  5987. **
  5988. ** This routine is identical to the [sqlite3_create_module()] method above,
  5989. ** except that it allows a destructor function to be specified. It is
  5990. ** even more experimental than the rest of the virtual tables API.
  5991. */
  5992. SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module_v2(
  5993. sqlite3 *db, /* SQLite connection to register module with */
  5994. const char *zName, /* Name of the module */
  5995. const sqlite3_module *, /* Methods for the module */
  5996. void *, /* Client data for xCreate/xConnect */
  5997. void(*xDestroy)(void*) /* Module destructor function */
  5998. );
  5999. /*
  6000. ** CAPI3REF: Virtual Table Instance Object {H18010} <S20400>
  6001. ** KEYWORDS: sqlite3_vtab
  6002. ** EXPERIMENTAL
  6003. **
  6004. ** Every module implementation uses a subclass of the following structure
  6005. ** to describe a particular instance of the module. Each subclass will
  6006. ** be tailored to the specific needs of the module implementation.
  6007. ** The purpose of this superclass is to define certain fields that are
  6008. ** common to all module implementations.
  6009. **
  6010. ** Virtual tables methods can set an error message by assigning a
  6011. ** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should
  6012. ** take care that any prior string is freed by a call to [sqlite3_free()]
  6013. ** prior to assigning a new string to zErrMsg. After the error message
  6014. ** is delivered up to the client application, the string will be automatically
  6015. ** freed by sqlite3_free() and the zErrMsg field will be zeroed. Note
  6016. ** that sqlite3_mprintf() and sqlite3_free() are used on the zErrMsg field
  6017. ** since virtual tables are commonly implemented in loadable extensions which
  6018. ** do not have access to sqlite3MPrintf() or sqlite3Free().
  6019. **
  6020. ** This interface is experimental and is subject to change or
  6021. ** removal in future releases of SQLite.
  6022. */
  6023. struct sqlite3_vtab {
  6024. const sqlite3_module *pModule; /* The module for this virtual table */
  6025. int nRef; /* Used internally */
  6026. char *zErrMsg; /* Error message from sqlite3_mprintf() */
  6027. /* Virtual table implementations will typically add additional fields */
  6028. };
  6029. /*
  6030. ** CAPI3REF: Virtual Table Cursor Object {H18020} <S20400>
  6031. ** KEYWORDS: sqlite3_vtab_cursor
  6032. ** EXPERIMENTAL
  6033. **
  6034. ** Every module implementation uses a subclass of the following structure
  6035. ** to describe cursors that point into the virtual table and are used
  6036. ** to loop through the virtual table. Cursors are created using the
  6037. ** xOpen method of the module. Each module implementation will define
  6038. ** the content of a cursor structure to suit its own needs.
  6039. **
  6040. ** This superclass exists in order to define fields of the cursor that
  6041. ** are common to all implementations.
  6042. **
  6043. ** This interface is experimental and is subject to change or
  6044. ** removal in future releases of SQLite.
  6045. */
  6046. struct sqlite3_vtab_cursor {
  6047. sqlite3_vtab *pVtab; /* Virtual table of this cursor */
  6048. /* Virtual table implementations will typically add additional fields */
  6049. };
  6050. /*
  6051. ** CAPI3REF: Declare The Schema Of A Virtual Table {H18280} <S20400>
  6052. ** EXPERIMENTAL
  6053. **
  6054. ** The xCreate and xConnect methods of a module use the following API
  6055. ** to declare the format (the names and datatypes of the columns) of
  6056. ** the virtual tables they implement.
  6057. **
  6058. ** This interface is experimental and is subject to change or
  6059. ** removal in future releases of SQLite.
  6060. */
  6061. SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_declare_vtab(sqlite3*, const char *zCreateTable);
  6062. /*
  6063. ** CAPI3REF: Overload A Function For A Virtual Table {H18300} <S20400>
  6064. ** EXPERIMENTAL
  6065. **
  6066. ** Virtual tables can provide alternative implementations of functions
  6067. ** using the xFindFunction method. But global versions of those functions
  6068. ** must exist in order to be overloaded.
  6069. **
  6070. ** This API makes sure a global version of a function with a particular
  6071. ** name and number of parameters exists. If no such function exists
  6072. ** before this API is called, a new function is created. The implementation
  6073. ** of the new function always causes an exception to be thrown. So
  6074. ** the new function is not good for anything by itself. Its only
  6075. ** purpose is to be a placeholder function that can be overloaded
  6076. ** by virtual tables.
  6077. **
  6078. ** This API should be considered part of the virtual table interface,
  6079. ** which is experimental and subject to change.
  6080. */
  6081. SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
  6082. /*
  6083. ** The interface to the virtual-table mechanism defined above (back up
  6084. ** to a comment remarkably similar to this one) is currently considered
  6085. ** to be experimental. The interface might change in incompatible ways.
  6086. ** If this is a problem for you, do not use the interface at this time.
  6087. **
  6088. ** When the virtual-table mechanism stabilizes, we will declare the
  6089. ** interface fixed, support it indefinitely, and remove this comment.
  6090. **
  6091. ****** EXPERIMENTAL - subject to change without notice **************
  6092. */
  6093. /*
  6094. ** CAPI3REF: A Handle To An Open BLOB {H17800} <S30230>
  6095. ** KEYWORDS: {BLOB handle} {BLOB handles}
  6096. **
  6097. ** An instance of this object represents an open BLOB on which
  6098. ** [sqlite3_blob_open | incremental BLOB I/O] can be performed.
  6099. ** Objects of this type are created by [sqlite3_blob_open()]
  6100. ** and destroyed by [sqlite3_blob_close()].
  6101. ** The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces
  6102. ** can be used to read or write small subsections of the BLOB.
  6103. ** The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes.
  6104. */
  6105. typedef struct sqlite3_blob sqlite3_blob;
  6106. /*
  6107. ** CAPI3REF: Open A BLOB For Incremental I/O {H17810} <S30230>
  6108. **
  6109. ** This interfaces opens a [BLOB handle | handle] to the BLOB located
  6110. ** in row iRow, column zColumn, table zTable in database zDb;
  6111. ** in other words, the same BLOB that would be selected by:
  6112. **
  6113. ** <pre>
  6114. ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
  6115. ** </pre> {END}
  6116. **
  6117. ** If the flags parameter is non-zero, the the BLOB is opened for read
  6118. ** and write access. If it is zero, the BLOB is opened for read access.
  6119. **
  6120. ** Note that the database name is not the filename that contains
  6121. ** the database but rather the symbolic name of the database that
  6122. ** is assigned when the database is connected using [ATTACH].
  6123. ** For the main database file, the database name is "main".
  6124. ** For TEMP tables, the database name is "temp".
  6125. **
  6126. ** On success, [SQLITE_OK] is returned and the new [BLOB handle] is written
  6127. ** to *ppBlob. Otherwise an [error code] is returned and any value written
  6128. ** to *ppBlob should not be used by the caller.
  6129. ** This function sets the [database connection] error code and message
  6130. ** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()].
  6131. **
  6132. ** If the row that a BLOB handle points to is modified by an
  6133. ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
  6134. ** then the BLOB handle is marked as "expired".
  6135. ** This is true if any column of the row is changed, even a column
  6136. ** other than the one the BLOB handle is open on.
  6137. ** Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for
  6138. ** a expired BLOB handle fail with an return code of [SQLITE_ABORT].
  6139. ** Changes written into a BLOB prior to the BLOB expiring are not
  6140. ** rollback by the expiration of the BLOB. Such changes will eventually
  6141. ** commit if the transaction continues to completion.
  6142. **
  6143. ** INVARIANTS:
  6144. **
  6145. ** {H17813} A successful invocation of the [sqlite3_blob_open(D,B,T,C,R,F,P)]
  6146. ** interface shall open an [sqlite3_blob] object P on the BLOB
  6147. ** in column C of the table T in the database B on
  6148. ** the [database connection] D.
  6149. **
  6150. ** {H17814} A successful invocation of [sqlite3_blob_open(D,...)] shall start
  6151. ** a new transaction on the [database connection] D if that
  6152. ** connection is not already in a transaction.
  6153. **
  6154. ** {H17816} The [sqlite3_blob_open(D,B,T,C,R,F,P)] interface shall open
  6155. ** the BLOB for read and write access if and only if the F
  6156. ** parameter is non-zero.
  6157. **
  6158. ** {H17819} The [sqlite3_blob_open()] interface shall return [SQLITE_OK] on
  6159. ** success and an appropriate [error code] on failure.
  6160. **
  6161. ** {H17821} If an error occurs during evaluation of [sqlite3_blob_open(D,...)]
  6162. ** then subsequent calls to [sqlite3_errcode(D)],
  6163. ** [sqlite3_extended_errcode()],
  6164. ** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] shall return
  6165. ** information appropriate for that error.
  6166. **
  6167. ** {H17824} If any column in the row that a [sqlite3_blob] has open is
  6168. ** changed by a separate [UPDATE] or [DELETE] statement or by
  6169. ** an [ON CONFLICT] side effect, then the [sqlite3_blob] shall
  6170. ** be marked as invalid.
  6171. */
  6172. SQLITE_API int sqlite3_blob_open(
  6173. sqlite3*,
  6174. const char *zDb,
  6175. const char *zTable,
  6176. const char *zColumn,
  6177. sqlite3_int64 iRow,
  6178. int flags,
  6179. sqlite3_blob **ppBlob
  6180. );
  6181. /*
  6182. ** CAPI3REF: Close A BLOB Handle {H17830} <S30230>
  6183. **
  6184. ** Closes an open [BLOB handle].
  6185. **
  6186. ** Closing a BLOB shall cause the current transaction to commit
  6187. ** if there are no other BLOBs, no pending prepared statements, and the
  6188. ** database connection is in [autocommit mode].
  6189. ** If any writes were made to the BLOB, they might be held in cache
  6190. ** until the close operation if they will fit. {END}
  6191. **
  6192. ** Closing the BLOB often forces the changes
  6193. ** out to disk and so if any I/O errors occur, they will likely occur
  6194. ** at the time when the BLOB is closed. {H17833} Any errors that occur during
  6195. ** closing are reported as a non-zero return value.
  6196. **
  6197. ** The BLOB is closed unconditionally. Even if this routine returns
  6198. ** an error code, the BLOB is still closed.
  6199. **
  6200. ** INVARIANTS:
  6201. **
  6202. ** {H17833} The [sqlite3_blob_close(P)] interface closes an [sqlite3_blob]
  6203. ** object P previously opened using [sqlite3_blob_open()].
  6204. **
  6205. ** {H17836} Closing an [sqlite3_blob] object using
  6206. ** [sqlite3_blob_close()] shall cause the current transaction to
  6207. ** commit if there are no other open [sqlite3_blob] objects
  6208. ** or [prepared statements] on the same [database connection] and
  6209. ** the database connection is in [autocommit mode].
  6210. **
  6211. ** {H17839} The [sqlite3_blob_close(P)] interfaces shall close the
  6212. ** [sqlite3_blob] object P unconditionally, even if
  6213. ** [sqlite3_blob_close(P)] returns something other than [SQLITE_OK].
  6214. */
  6215. SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
  6216. /*
  6217. ** CAPI3REF: Return The Size Of An Open BLOB {H17840} <S30230>
  6218. **
  6219. ** Returns the size in bytes of the BLOB accessible via the open
  6220. ** []BLOB handle] in its only argument.
  6221. **
  6222. ** INVARIANTS:
  6223. **
  6224. ** {H17843} The [sqlite3_blob_bytes(P)] interface returns the size
  6225. ** in bytes of the BLOB that the [sqlite3_blob] object P
  6226. ** refers to.
  6227. */
  6228. SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *);
  6229. /*
  6230. ** CAPI3REF: Read Data From A BLOB Incrementally {H17850} <S30230>
  6231. **
  6232. ** This function is used to read data from an open [BLOB handle] into a
  6233. ** caller-supplied buffer. N bytes of data are copied into buffer Z
  6234. ** from the open BLOB, starting at offset iOffset.
  6235. **
  6236. ** If offset iOffset is less than N bytes from the end of the BLOB,
  6237. ** [SQLITE_ERROR] is returned and no data is read. If N or iOffset is
  6238. ** less than zero, [SQLITE_ERROR] is returned and no data is read.
  6239. **
  6240. ** An attempt to read from an expired [BLOB handle] fails with an
  6241. ** error code of [SQLITE_ABORT].
  6242. **
  6243. ** On success, SQLITE_OK is returned.
  6244. ** Otherwise, an [error code] or an [extended error code] is returned.
  6245. **
  6246. ** INVARIANTS:
  6247. **
  6248. ** {H17853} A successful invocation of [sqlite3_blob_read(P,Z,N,X)]
  6249. ** shall reads N bytes of data out of the BLOB referenced by
  6250. ** [BLOB handle] P beginning at offset X and store those bytes
  6251. ** into buffer Z.
  6252. **
  6253. ** {H17856} In [sqlite3_blob_read(P,Z,N,X)] if the size of the BLOB
  6254. ** is less than N+X bytes, then the function shall leave the
  6255. ** Z buffer unchanged and return [SQLITE_ERROR].
  6256. **
  6257. ** {H17859} In [sqlite3_blob_read(P,Z,N,X)] if X or N is less than zero
  6258. ** then the function shall leave the Z buffer unchanged
  6259. ** and return [SQLITE_ERROR].
  6260. **
  6261. ** {H17862} The [sqlite3_blob_read(P,Z,N,X)] interface shall return [SQLITE_OK]
  6262. ** if N bytes are successfully read into buffer Z.
  6263. **
  6264. ** {H17863} If the [BLOB handle] P is expired and X and N are within bounds
  6265. ** then [sqlite3_blob_read(P,Z,N,X)] shall leave the Z buffer
  6266. ** unchanged and return [SQLITE_ABORT].
  6267. **
  6268. ** {H17865} If the requested read could not be completed,
  6269. ** the [sqlite3_blob_read(P,Z,N,X)] interface shall return an
  6270. ** appropriate [error code] or [extended error code].
  6271. **
  6272. ** {H17868} If an error occurs during evaluation of [sqlite3_blob_read(P,...)]
  6273. ** then subsequent calls to [sqlite3_errcode(D)],
  6274. ** [sqlite3_extended_errcode()],
  6275. ** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] shall return
  6276. ** information appropriate for that error, where D is the
  6277. ** [database connection] that was used to open the [BLOB handle] P.
  6278. */
  6279. SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
  6280. /*
  6281. ** CAPI3REF: Write Data Into A BLOB Incrementally {H17870} <S30230>
  6282. **
  6283. ** This function is used to write data into an open [BLOB handle] from a
  6284. ** caller-supplied buffer. N bytes of data are copied from the buffer Z
  6285. ** into the open BLOB, starting at offset iOffset.
  6286. **
  6287. ** If the [BLOB handle] passed as the first argument was not opened for
  6288. ** writing (the flags parameter to [sqlite3_blob_open()] was zero),
  6289. ** this function returns [SQLITE_READONLY].
  6290. **
  6291. ** This function may only modify the contents of the BLOB; it is
  6292. ** not possible to increase the size of a BLOB using this API.
  6293. ** If offset iOffset is less than N bytes from the end of the BLOB,
  6294. ** [SQLITE_ERROR] is returned and no data is written. If N is
  6295. ** less than zero [SQLITE_ERROR] is returned and no data is written.
  6296. **
  6297. ** An attempt to write to an expired [BLOB handle] fails with an
  6298. ** error code of [SQLITE_ABORT]. Writes to the BLOB that occurred
  6299. ** before the [BLOB handle] expired are not rolled back by the
  6300. ** expiration of the handle, though of course those changes might
  6301. ** have been overwritten by the statement that expired the BLOB handle
  6302. ** or by other independent statements.
  6303. **
  6304. ** On success, SQLITE_OK is returned.
  6305. ** Otherwise, an [error code] or an [extended error code] is returned.
  6306. **
  6307. ** INVARIANTS:
  6308. **
  6309. ** {H17873} A successful invocation of [sqlite3_blob_write(P,Z,N,X)]
  6310. ** shall write N bytes of data from buffer Z into the BLOB
  6311. ** referenced by [BLOB handle] P beginning at offset X into
  6312. ** the BLOB.
  6313. **
  6314. ** {H17874} In the absence of other overridding changes, the changes
  6315. ** written to a BLOB by [sqlite3_blob_write()] shall
  6316. ** remain in effect after the associated [BLOB handle] expires.
  6317. **
  6318. ** {H17875} If the [BLOB handle] P was opened for reading only then
  6319. ** an invocation of [sqlite3_blob_write(P,Z,N,X)] shall leave
  6320. ** the referenced BLOB unchanged and return [SQLITE_READONLY].
  6321. **
  6322. ** {H17876} If the size of the BLOB referenced by [BLOB handle] P is
  6323. ** less than N+X bytes then [sqlite3_blob_write(P,Z,N,X)] shall
  6324. ** leave the BLOB unchanged and return [SQLITE_ERROR].
  6325. **
  6326. ** {H17877} If the [BLOB handle] P is expired and X and N are within bounds
  6327. ** then [sqlite3_blob_read(P,Z,N,X)] shall leave the BLOB
  6328. ** unchanged and return [SQLITE_ABORT].
  6329. **
  6330. ** {H17879} If X or N are less than zero then [sqlite3_blob_write(P,Z,N,X)]
  6331. ** shall leave the BLOB referenced by [BLOB handle] P unchanged
  6332. ** and return [SQLITE_ERROR].
  6333. **
  6334. ** {H17882} The [sqlite3_blob_write(P,Z,N,X)] interface shall return
  6335. ** [SQLITE_OK] if N bytes where successfully written into the BLOB.
  6336. **
  6337. ** {H17885} If the requested write could not be completed,
  6338. ** the [sqlite3_blob_write(P,Z,N,X)] interface shall return an
  6339. ** appropriate [error code] or [extended error code].
  6340. **
  6341. ** {H17888} If an error occurs during evaluation of [sqlite3_blob_write(D,...)]
  6342. ** then subsequent calls to [sqlite3_errcode(D)],
  6343. ** [sqlite3_extended_errcode()],
  6344. ** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] shall return
  6345. ** information appropriate for that error.
  6346. */
  6347. SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
  6348. /*
  6349. ** CAPI3REF: Virtual File System Objects {H11200} <S20100>
  6350. **
  6351. ** A virtual filesystem (VFS) is an [sqlite3_vfs] object
  6352. ** that SQLite uses to interact
  6353. ** with the underlying operating system. Most SQLite builds come with a
  6354. ** single default VFS that is appropriate for the host computer.
  6355. ** New VFSes can be registered and existing VFSes can be unregistered.
  6356. ** The following interfaces are provided.
  6357. **
  6358. ** The sqlite3_vfs_find() interface returns a pointer to a VFS given its name.
  6359. ** Names are case sensitive.
  6360. ** Names are zero-terminated UTF-8 strings.
  6361. ** If there is no match, a NULL pointer is returned.
  6362. ** If zVfsName is NULL then the default VFS is returned.
  6363. **
  6364. ** New VFSes are registered with sqlite3_vfs_register().
  6365. ** Each new VFS becomes the default VFS if the makeDflt flag is set.
  6366. ** The same VFS can be registered multiple times without injury.
  6367. ** To make an existing VFS into the default VFS, register it again
  6368. ** with the makeDflt flag set. If two different VFSes with the
  6369. ** same name are registered, the behavior is undefined. If a
  6370. ** VFS is registered with a name that is NULL or an empty string,
  6371. ** then the behavior is undefined.
  6372. **
  6373. ** Unregister a VFS with the sqlite3_vfs_unregister() interface.
  6374. ** If the default VFS is unregistered, another VFS is chosen as
  6375. ** the default. The choice for the new VFS is arbitrary.
  6376. **
  6377. ** INVARIANTS:
  6378. **
  6379. ** {H11203} The [sqlite3_vfs_find(N)] interface returns a pointer to the
  6380. ** registered [sqlite3_vfs] object whose name exactly matches
  6381. ** the zero-terminated UTF-8 string N, or it returns NULL if
  6382. ** there is no match.
  6383. **
  6384. ** {H11206} If the N parameter to [sqlite3_vfs_find(N)] is NULL then
  6385. ** the function returns a pointer to the default [sqlite3_vfs]
  6386. ** object if there is one, or NULL if there is no default
  6387. ** [sqlite3_vfs] object.
  6388. **
  6389. ** {H11209} The [sqlite3_vfs_register(P,F)] interface registers the
  6390. ** well-formed [sqlite3_vfs] object P using the name given
  6391. ** by the zName field of the object.
  6392. **
  6393. ** {H11212} Using the [sqlite3_vfs_register(P,F)] interface to register
  6394. ** the same [sqlite3_vfs] object multiple times is a harmless no-op.
  6395. **
  6396. ** {H11215} The [sqlite3_vfs_register(P,F)] interface makes the [sqlite3_vfs]
  6397. ** object P the default [sqlite3_vfs] object if F is non-zero.
  6398. **
  6399. ** {H11218} The [sqlite3_vfs_unregister(P)] interface unregisters the
  6400. ** [sqlite3_vfs] object P so that it is no longer returned by
  6401. ** subsequent calls to [sqlite3_vfs_find()].
  6402. */
  6403. SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName);
  6404. SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
  6405. SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*);
  6406. /*
  6407. ** CAPI3REF: Mutexes {H17000} <S20000>
  6408. **
  6409. ** The SQLite core uses these routines for thread
  6410. ** synchronization. Though they are intended for internal
  6411. ** use by SQLite, code that links against SQLite is
  6412. ** permitted to use any of these routines.
  6413. **
  6414. ** The SQLite source code contains multiple implementations
  6415. ** of these mutex routines. An appropriate implementation
  6416. ** is selected automatically at compile-time. The following
  6417. ** implementations are available in the SQLite core:
  6418. **
  6419. ** <ul>
  6420. ** <li> SQLITE_MUTEX_OS2
  6421. ** <li> SQLITE_MUTEX_PTHREAD
  6422. ** <li> SQLITE_MUTEX_W32
  6423. ** <li> SQLITE_MUTEX_NOOP
  6424. ** </ul>
  6425. **
  6426. ** The SQLITE_MUTEX_NOOP implementation is a set of routines
  6427. ** that does no real locking and is appropriate for use in
  6428. ** a single-threaded application. The SQLITE_MUTEX_OS2,
  6429. ** SQLITE_MUTEX_PTHREAD, and SQLITE_MUTEX_W32 implementations
  6430. ** are appropriate for use on OS/2, Unix, and Windows.
  6431. **
  6432. ** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
  6433. ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
  6434. ** implementation is included with the library. In this case the
  6435. ** application must supply a custom mutex implementation using the
  6436. ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
  6437. ** before calling sqlite3_initialize() or any other public sqlite3_
  6438. ** function that calls sqlite3_initialize().
  6439. **
  6440. ** {H17011} The sqlite3_mutex_alloc() routine allocates a new
  6441. ** mutex and returns a pointer to it. {H17012} If it returns NULL
  6442. ** that means that a mutex could not be allocated. {H17013} SQLite
  6443. ** will unwind its stack and return an error. {H17014} The argument
  6444. ** to sqlite3_mutex_alloc() is one of these integer constants:
  6445. **
  6446. ** <ul>
  6447. ** <li> SQLITE_MUTEX_FAST
  6448. ** <li> SQLITE_MUTEX_RECURSIVE
  6449. ** <li> SQLITE_MUTEX_STATIC_MASTER
  6450. ** <li> SQLITE_MUTEX_STATIC_MEM
  6451. ** <li> SQLITE_MUTEX_STATIC_MEM2
  6452. ** <li> SQLITE_MUTEX_STATIC_PRNG
  6453. ** <li> SQLITE_MUTEX_STATIC_LRU
  6454. ** <li> SQLITE_MUTEX_STATIC_LRU2
  6455. ** </ul>
  6456. **
  6457. ** {H17015} The first two constants cause sqlite3_mutex_alloc() to create
  6458. ** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
  6459. ** is used but not necessarily so when SQLITE_MUTEX_FAST is used. {END}
  6460. ** The mutex implementation does not need to make a distinction
  6461. ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
  6462. ** not want to. {H17016} But SQLite will only request a recursive mutex in
  6463. ** cases where it really needs one. {END} If a faster non-recursive mutex
  6464. ** implementation is available on the host platform, the mutex subsystem
  6465. ** might return such a mutex in response to SQLITE_MUTEX_FAST.
  6466. **
  6467. ** {H17017} The other allowed parameters to sqlite3_mutex_alloc() each return
  6468. ** a pointer to a static preexisting mutex. {END} Four static mutexes are
  6469. ** used by the current version of SQLite. Future versions of SQLite
  6470. ** may add additional static mutexes. Static mutexes are for internal
  6471. ** use by SQLite only. Applications that use SQLite mutexes should
  6472. ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
  6473. ** SQLITE_MUTEX_RECURSIVE.
  6474. **
  6475. ** {H17018} Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
  6476. ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
  6477. ** returns a different mutex on every call. {H17034} But for the static
  6478. ** mutex types, the same mutex is returned on every call that has
  6479. ** the same type number.
  6480. **
  6481. ** {H17019} The sqlite3_mutex_free() routine deallocates a previously
  6482. ** allocated dynamic mutex. {H17020} SQLite is careful to deallocate every
  6483. ** dynamic mutex that it allocates. {A17021} The dynamic mutexes must not be in
  6484. ** use when they are deallocated. {A17022} Attempting to deallocate a static
  6485. ** mutex results in undefined behavior. {H17023} SQLite never deallocates
  6486. ** a static mutex. {END}
  6487. **
  6488. ** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
  6489. ** to enter a mutex. {H17024} If another thread is already within the mutex,
  6490. ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
  6491. ** SQLITE_BUSY. {H17025} The sqlite3_mutex_try() interface returns [SQLITE_OK]
  6492. ** upon successful entry. {H17026} Mutexes created using
  6493. ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
  6494. ** {H17027} In such cases the,
  6495. ** mutex must be exited an equal number of times before another thread
  6496. ** can enter. {A17028} If the same thread tries to enter any other
  6497. ** kind of mutex more than once, the behavior is undefined.
  6498. ** {H17029} SQLite will never exhibit
  6499. ** such behavior in its own use of mutexes.
  6500. **
  6501. ** Some systems (for example, Windows 95) do not support the operation
  6502. ** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try()
  6503. ** will always return SQLITE_BUSY. {H17030} The SQLite core only ever uses
  6504. ** sqlite3_mutex_try() as an optimization so this is acceptable behavior.
  6505. **
  6506. ** {H17031} The sqlite3_mutex_leave() routine exits a mutex that was
  6507. ** previously entered by the same thread. {A17032} The behavior
  6508. ** is undefined if the mutex is not currently entered by the
  6509. ** calling thread or is not currently allocated. {H17033} SQLite will
  6510. ** never do either. {END}
  6511. **
  6512. ** If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
  6513. ** sqlite3_mutex_leave() is a NULL pointer, then all three routines
  6514. ** behave as no-ops.
  6515. **
  6516. ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].
  6517. */
  6518. SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int);
  6519. SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*);
  6520. SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*);
  6521. SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
  6522. SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
  6523. /*
  6524. ** CAPI3REF: Mutex Methods Object {H17120} <S20130>
  6525. ** EXPERIMENTAL
  6526. **
  6527. ** An instance of this structure defines the low-level routines
  6528. ** used to allocate and use mutexes.
  6529. **
  6530. ** Usually, the default mutex implementations provided by SQLite are
  6531. ** sufficient, however the user has the option of substituting a custom
  6532. ** implementation for specialized deployments or systems for which SQLite
  6533. ** does not provide a suitable implementation. In this case, the user
  6534. ** creates and populates an instance of this structure to pass
  6535. ** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
  6536. ** Additionally, an instance of this structure can be used as an
  6537. ** output variable when querying the system for the current mutex
  6538. ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
  6539. **
  6540. ** The xMutexInit method defined by this structure is invoked as
  6541. ** part of system initialization by the sqlite3_initialize() function.
  6542. ** {H17001} The xMutexInit routine shall be called by SQLite once for each
  6543. ** effective call to [sqlite3_initialize()].
  6544. **
  6545. ** The xMutexEnd method defined by this structure is invoked as
  6546. ** part of system shutdown by the sqlite3_shutdown() function. The
  6547. ** implementation of this method is expected to release all outstanding
  6548. ** resources obtained by the mutex methods implementation, especially
  6549. ** those obtained by the xMutexInit method. {H17003} The xMutexEnd()
  6550. ** interface shall be invoked once for each call to [sqlite3_shutdown()].
  6551. **
  6552. ** The remaining seven methods defined by this structure (xMutexAlloc,
  6553. ** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and
  6554. ** xMutexNotheld) implement the following interfaces (respectively):
  6555. **
  6556. ** <ul>
  6557. ** <li> [sqlite3_mutex_alloc()] </li>
  6558. ** <li> [sqlite3_mutex_free()] </li>
  6559. ** <li> [sqlite3_mutex_enter()] </li>
  6560. ** <li> [sqlite3_mutex_try()] </li>
  6561. ** <li> [sqlite3_mutex_leave()] </li>
  6562. ** <li> [sqlite3_mutex_held()] </li>
  6563. ** <li> [sqlite3_mutex_notheld()] </li>
  6564. ** </ul>
  6565. **
  6566. ** The only difference is that the public sqlite3_XXX functions enumerated
  6567. ** above silently ignore any invocations that pass a NULL pointer instead
  6568. ** of a valid mutex handle. The implementations of the methods defined
  6569. ** by this structure are not required to handle this case, the results
  6570. ** of passing a NULL pointer instead of a valid mutex handle are undefined
  6571. ** (i.e. it is acceptable to provide an implementation that segfaults if
  6572. ** it is passed a NULL pointer).
  6573. */
  6574. typedef struct sqlite3_mutex_methods sqlite3_mutex_methods;
  6575. struct sqlite3_mutex_methods {
  6576. int (*xMutexInit)(void);
  6577. int (*xMutexEnd)(void);
  6578. sqlite3_mutex *(*xMutexAlloc)(int);
  6579. void (*xMutexFree)(sqlite3_mutex *);
  6580. void (*xMutexEnter)(sqlite3_mutex *);
  6581. int (*xMutexTry)(sqlite3_mutex *);
  6582. void (*xMutexLeave)(sqlite3_mutex *);
  6583. int (*xMutexHeld)(sqlite3_mutex *);
  6584. int (*xMutexNotheld)(sqlite3_mutex *);
  6585. };
  6586. /*
  6587. ** CAPI3REF: Mutex Verification Routines {H17080} <S20130> <S30800>
  6588. **
  6589. ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
  6590. ** are intended for use inside assert() statements. {H17081} The SQLite core
  6591. ** never uses these routines except inside an assert() and applications
  6592. ** are advised to follow the lead of the core. {H17082} The core only
  6593. ** provides implementations for these routines when it is compiled
  6594. ** with the SQLITE_DEBUG flag. {A17087} External mutex implementations
  6595. ** are only required to provide these routines if SQLITE_DEBUG is
  6596. ** defined and if NDEBUG is not defined.
  6597. **
  6598. ** {H17083} These routines should return true if the mutex in their argument
  6599. ** is held or not held, respectively, by the calling thread.
  6600. **
  6601. ** {X17084} The implementation is not required to provided versions of these
  6602. ** routines that actually work. If the implementation does not provide working
  6603. ** versions of these routines, it should at least provide stubs that always
  6604. ** return true so that one does not get spurious assertion failures.
  6605. **
  6606. ** {H17085} If the argument to sqlite3_mutex_held() is a NULL pointer then
  6607. ** the routine should return 1. {END} This seems counter-intuitive since
  6608. ** clearly the mutex cannot be held if it does not exist. But the
  6609. ** the reason the mutex does not exist is because the build is not
  6610. ** using mutexes. And we do not want the assert() containing the
  6611. ** call to sqlite3_mutex_held() to fail, so a non-zero return is
  6612. ** the appropriate thing to do. {H17086} The sqlite3_mutex_notheld()
  6613. ** interface should also return 1 when given a NULL pointer.
  6614. */
  6615. SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);
  6616. SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
  6617. /*
  6618. ** CAPI3REF: Mutex Types {H17001} <H17000>
  6619. **
  6620. ** The [sqlite3_mutex_alloc()] interface takes a single argument
  6621. ** which is one of these integer constants.
  6622. **
  6623. ** The set of static mutexes may change from one SQLite release to the
  6624. ** next. Applications that override the built-in mutex logic must be
  6625. ** prepared to accommodate additional static mutexes.
  6626. */
  6627. #define SQLITE_MUTEX_FAST 0
  6628. #define SQLITE_MUTEX_RECURSIVE 1
  6629. #define SQLITE_MUTEX_STATIC_MASTER 2
  6630. #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */
  6631. #define SQLITE_MUTEX_STATIC_MEM2 4 /* sqlite3_release_memory() */
  6632. #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */
  6633. #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
  6634. #define SQLITE_MUTEX_STATIC_LRU2 7 /* lru page list */
  6635. /*
  6636. ** CAPI3REF: Retrieve the mutex for a database connection {H17002} <H17000>
  6637. **
  6638. ** This interface returns a pointer the [sqlite3_mutex] object that
  6639. ** serializes access to the [database connection] given in the argument
  6640. ** when the [threading mode] is Serialized.
  6641. ** If the [threading mode] is Single-thread or Multi-thread then this
  6642. ** routine returns a NULL pointer.
  6643. */
  6644. SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*);
  6645. /*
  6646. ** CAPI3REF: Low-Level Control Of Database Files {H11300} <S30800>
  6647. **
  6648. ** {H11301} The [sqlite3_file_control()] interface makes a direct call to the
  6649. ** xFileControl method for the [sqlite3_io_methods] object associated
  6650. ** with a particular database identified by the second argument. {H11302} The
  6651. ** name of the database is the name assigned to the database by the
  6652. ** <a href="lang_attach.html">ATTACH</a> SQL command that opened the
  6653. ** database. {H11303} To control the main database file, use the name "main"
  6654. ** or a NULL pointer. {H11304} The third and fourth parameters to this routine
  6655. ** are passed directly through to the second and third parameters of
  6656. ** the xFileControl method. {H11305} The return value of the xFileControl
  6657. ** method becomes the return value of this routine.
  6658. **
  6659. ** {H11306} If the second parameter (zDbName) does not match the name of any
  6660. ** open database file, then SQLITE_ERROR is returned. {H11307} This error
  6661. ** code is not remembered and will not be recalled by [sqlite3_errcode()]
  6662. ** or [sqlite3_errmsg()]. {A11308} The underlying xFileControl method might
  6663. ** also return SQLITE_ERROR. {A11309} There is no way to distinguish between
  6664. ** an incorrect zDbName and an SQLITE_ERROR return from the underlying
  6665. ** xFileControl method. {END}
  6666. **
  6667. ** See also: [SQLITE_FCNTL_LOCKSTATE]
  6668. */
  6669. SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
  6670. /*
  6671. ** CAPI3REF: Testing Interface {H11400} <S30800>
  6672. **
  6673. ** The sqlite3_test_control() interface is used to read out internal
  6674. ** state of SQLite and to inject faults into SQLite for testing
  6675. ** purposes. The first parameter is an operation code that determines
  6676. ** the number, meaning, and operation of all subsequent parameters.
  6677. **
  6678. ** This interface is not for use by applications. It exists solely
  6679. ** for verifying the correct operation of the SQLite library. Depending
  6680. ** on how the SQLite library is compiled, this interface might not exist.
  6681. **
  6682. ** The details of the operation codes, their meanings, the parameters
  6683. ** they take, and what they do are all subject to change without notice.
  6684. ** Unlike most of the SQLite API, this function is not guaranteed to
  6685. ** operate consistently from one release to the next.
  6686. */
  6687. SQLITE_API int sqlite3_test_control(int op, ...);
  6688. /*
  6689. ** CAPI3REF: Testing Interface Operation Codes {H11410} <H11400>
  6690. **
  6691. ** These constants are the valid operation code parameters used
  6692. ** as the first argument to [sqlite3_test_control()].
  6693. **
  6694. ** These parameters and their meanings are subject to change
  6695. ** without notice. These values are for testing purposes only.
  6696. ** Applications should not use any of these parameters or the
  6697. ** [sqlite3_test_control()] interface.
  6698. */
  6699. #define SQLITE_TESTCTRL_PRNG_SAVE 5
  6700. #define SQLITE_TESTCTRL_PRNG_RESTORE 6
  6701. #define SQLITE_TESTCTRL_PRNG_RESET 7
  6702. #define SQLITE_TESTCTRL_BITVEC_TEST 8
  6703. #define SQLITE_TESTCTRL_FAULT_INSTALL 9
  6704. #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10
  6705. /*
  6706. ** CAPI3REF: SQLite Runtime Status {H17200} <S60200>
  6707. ** EXPERIMENTAL
  6708. **
  6709. ** This interface is used to retrieve runtime status information
  6710. ** about the preformance of SQLite, and optionally to reset various
  6711. ** highwater marks. The first argument is an integer code for
  6712. ** the specific parameter to measure. Recognized integer codes
  6713. ** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...].
  6714. ** The current value of the parameter is returned into *pCurrent.
  6715. ** The highest recorded value is returned in *pHighwater. If the
  6716. ** resetFlag is true, then the highest record value is reset after
  6717. ** *pHighwater is written. Some parameters do not record the highest
  6718. ** value. For those parameters
  6719. ** nothing is written into *pHighwater and the resetFlag is ignored.
  6720. ** Other parameters record only the highwater mark and not the current
  6721. ** value. For these latter parameters nothing is written into *pCurrent.
  6722. **
  6723. ** This routine returns SQLITE_OK on success and a non-zero
  6724. ** [error code] on failure.
  6725. **
  6726. ** This routine is threadsafe but is not atomic. This routine can
  6727. ** called while other threads are running the same or different SQLite
  6728. ** interfaces. However the values returned in *pCurrent and
  6729. ** *pHighwater reflect the status of SQLite at different points in time
  6730. ** and it is possible that another thread might change the parameter
  6731. ** in between the times when *pCurrent and *pHighwater are written.
  6732. **
  6733. ** See also: [sqlite3_db_status()]
  6734. */
  6735. SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
  6736. /*
  6737. ** CAPI3REF: Status Parameters {H17250} <H17200>
  6738. ** EXPERIMENTAL
  6739. **
  6740. ** These integer constants designate various run-time status parameters
  6741. ** that can be returned by [sqlite3_status()].
  6742. **
  6743. ** <dl>
  6744. ** <dt>SQLITE_STATUS_MEMORY_USED</dt>
  6745. ** <dd>This parameter is the current amount of memory checked out
  6746. ** using [sqlite3_malloc()], either directly or indirectly. The
  6747. ** figure includes calls made to [sqlite3_malloc()] by the application
  6748. ** and internal memory usage by the SQLite library. Scratch memory
  6749. ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
  6750. ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
  6751. ** this parameter. The amount returned is the sum of the allocation
  6752. ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>
  6753. **
  6754. ** <dt>SQLITE_STATUS_MALLOC_SIZE</dt>
  6755. ** <dd>This parameter records the largest memory allocation request
  6756. ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
  6757. ** internal equivalents). Only the value returned in the
  6758. ** *pHighwater parameter to [sqlite3_status()] is of interest.
  6759. ** The value written into the *pCurrent parameter is undefined.</dd>
  6760. **
  6761. ** <dt>SQLITE_STATUS_PAGECACHE_USED</dt>
  6762. ** <dd>This parameter returns the number of pages used out of the
  6763. ** [pagecache memory allocator] that was configured using
  6764. ** [SQLITE_CONFIG_PAGECACHE]. The
  6765. ** value returned is in pages, not in bytes.</dd>
  6766. **
  6767. ** <dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
  6768. ** <dd>This parameter returns the number of bytes of page cache
  6769. ** allocation which could not be statisfied by the [SQLITE_CONFIG_PAGECACHE]
  6770. ** buffer and where forced to overflow to [sqlite3_malloc()]. The
  6771. ** returned value includes allocations that overflowed because they
  6772. ** where too large (they were larger than the "sz" parameter to
  6773. ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
  6774. ** no space was left in the page cache.</dd>
  6775. **
  6776. ** <dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
  6777. ** <dd>This parameter records the largest memory allocation request
  6778. ** handed to [pagecache memory allocator]. Only the value returned in the
  6779. ** *pHighwater parameter to [sqlite3_status()] is of interest.
  6780. ** The value written into the *pCurrent parameter is undefined.</dd>
  6781. **
  6782. ** <dt>SQLITE_STATUS_SCRATCH_USED</dt>
  6783. ** <dd>This parameter returns the number of allocations used out of the
  6784. ** [scratch memory allocator] configured using
  6785. ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
  6786. ** in bytes. Since a single thread may only have one scratch allocation
  6787. ** outstanding at time, this parameter also reports the number of threads
  6788. ** using scratch memory at the same time.</dd>
  6789. **
  6790. ** <dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
  6791. ** <dd>This parameter returns the number of bytes of scratch memory
  6792. ** allocation which could not be statisfied by the [SQLITE_CONFIG_SCRATCH]
  6793. ** buffer and where forced to overflow to [sqlite3_malloc()]. The values
  6794. ** returned include overflows because the requested allocation was too
  6795. ** larger (that is, because the requested allocation was larger than the
  6796. ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
  6797. ** slots were available.
  6798. ** </dd>
  6799. **
  6800. ** <dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
  6801. ** <dd>This parameter records the largest memory allocation request
  6802. ** handed to [scratch memory allocator]. Only the value returned in the
  6803. ** *pHighwater parameter to [sqlite3_status()] is of interest.
  6804. ** The value written into the *pCurrent parameter is undefined.</dd>
  6805. **
  6806. ** <dt>SQLITE_STATUS_PARSER_STACK</dt>
  6807. ** <dd>This parameter records the deepest parser stack. It is only
  6808. ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>
  6809. ** </dl>
  6810. **
  6811. ** New status parameters may be added from time to time.
  6812. */
  6813. #define SQLITE_STATUS_MEMORY_USED 0
  6814. #define SQLITE_STATUS_PAGECACHE_USED 1
  6815. #define SQLITE_STATUS_PAGECACHE_OVERFLOW 2
  6816. #define SQLITE_STATUS_SCRATCH_USED 3
  6817. #define SQLITE_STATUS_SCRATCH_OVERFLOW 4
  6818. #define SQLITE_STATUS_MALLOC_SIZE 5
  6819. #define SQLITE_STATUS_PARSER_STACK 6
  6820. #define SQLITE_STATUS_PAGECACHE_SIZE 7
  6821. #define SQLITE_STATUS_SCRATCH_SIZE 8
  6822. /*
  6823. ** CAPI3REF: Database Connection Status {H17500} <S60200>
  6824. ** EXPERIMENTAL
  6825. **
  6826. ** This interface is used to retrieve runtime status information
  6827. ** about a single [database connection]. The first argument is the
  6828. ** database connection object to be interrogated. The second argument
  6829. ** is the parameter to interrogate. Currently, the only allowed value
  6830. ** for the second parameter is [SQLITE_DBSTATUS_LOOKASIDE_USED].
  6831. ** Additional options will likely appear in future releases of SQLite.
  6832. **
  6833. ** The current value of the requested parameter is written into *pCur
  6834. ** and the highest instantaneous value is written into *pHiwtr. If
  6835. ** the resetFlg is true, then the highest instantaneous value is
  6836. ** reset back down to the current value.
  6837. **
  6838. ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
  6839. */
  6840. SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
  6841. /*
  6842. ** CAPI3REF: Status Parameters for database connections {H17520} <H17500>
  6843. ** EXPERIMENTAL
  6844. **
  6845. ** Status verbs for [sqlite3_db_status()].
  6846. **
  6847. ** <dl>
  6848. ** <dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
  6849. ** <dd>This parameter returns the number of lookaside memory slots currently
  6850. ** checked out.</dd>
  6851. ** </dl>
  6852. */
  6853. #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
  6854. /*
  6855. ** CAPI3REF: Prepared Statement Status {H17550} <S60200>
  6856. ** EXPERIMENTAL
  6857. **
  6858. ** Each prepared statement maintains various
  6859. ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
  6860. ** of times it has performed specific operations. These counters can
  6861. ** be used to monitor the performance characteristics of the prepared
  6862. ** statements. For example, if the number of table steps greatly exceeds
  6863. ** the number of table searches or result rows, that would tend to indicate
  6864. ** that the prepared statement is using a full table scan rather than
  6865. ** an index.
  6866. **
  6867. ** This interface is used to retrieve and reset counter values from
  6868. ** a [prepared statement]. The first argument is the prepared statement
  6869. ** object to be interrogated. The second argument
  6870. ** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter]
  6871. ** to be interrogated.
  6872. ** The current value of the requested counter is returned.
  6873. ** If the resetFlg is true, then the counter is reset to zero after this
  6874. ** interface call returns.
  6875. **
  6876. ** See also: [sqlite3_status()] and [sqlite3_db_status()].
  6877. */
  6878. SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
  6879. /*
  6880. ** CAPI3REF: Status Parameters for prepared statements {H17570} <H17550>
  6881. ** EXPERIMENTAL
  6882. **
  6883. ** These preprocessor macros define integer codes that name counter
  6884. ** values associated with the [sqlite3_stmt_status()] interface.
  6885. ** The meanings of the various counters are as follows:
  6886. **
  6887. ** <dl>
  6888. ** <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
  6889. ** <dd>This is the number of times that SQLite has stepped forward in
  6890. ** a table as part of a full table scan. Large numbers for this counter
  6891. ** may indicate opportunities for performance improvement through
  6892. ** careful use of indices.</dd>
  6893. **
  6894. ** <dt>SQLITE_STMTSTATUS_SORT</dt>
  6895. ** <dd>This is the number of sort operations that have occurred.
  6896. ** A non-zero value in this counter may indicate an opportunity to
  6897. ** improvement performance through careful use of indices.</dd>
  6898. **
  6899. ** </dl>
  6900. */
  6901. #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
  6902. #define SQLITE_STMTSTATUS_SORT 2
  6903. /*
  6904. ** CAPI3REF: Custom Page Cache Object
  6905. ** EXPERIMENTAL
  6906. **
  6907. ** The sqlite3_pcache type is opaque. It is implemented by
  6908. ** the pluggable module. The SQLite core has no knowledge of
  6909. ** its size or internal structure and never deals with the
  6910. ** sqlite3_pcache object except by holding and passing pointers
  6911. ** to the object.
  6912. **
  6913. ** See [sqlite3_pcache_methods] for additional information.
  6914. */
  6915. typedef struct sqlite3_pcache sqlite3_pcache;
  6916. /*
  6917. ** CAPI3REF: Application Defined Page Cache.
  6918. ** EXPERIMENTAL
  6919. **
  6920. ** The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
  6921. ** register an alternative page cache implementation by passing in an
  6922. ** instance of the sqlite3_pcache_methods structure. The majority of the
  6923. ** heap memory used by sqlite is used by the page cache to cache data read
  6924. ** from, or ready to be written to, the database file. By implementing a
  6925. ** custom page cache using this API, an application can control more
  6926. ** precisely the amount of memory consumed by sqlite, the way in which
  6927. ** said memory is allocated and released, and the policies used to
  6928. ** determine exactly which parts of a database file are cached and for
  6929. ** how long.
  6930. **
  6931. ** The contents of the structure are copied to an internal buffer by sqlite
  6932. ** within the call to [sqlite3_config].
  6933. **
  6934. ** The xInit() method is called once for each call to [sqlite3_initialize()]
  6935. ** (usually only once during the lifetime of the process). It is passed
  6936. ** a copy of the sqlite3_pcache_methods.pArg value. It can be used to set
  6937. ** up global structures and mutexes required by the custom page cache
  6938. ** implementation. The xShutdown() method is called from within
  6939. ** [sqlite3_shutdown()], if the application invokes this API. It can be used
  6940. ** to clean up any outstanding resources before process shutdown, if required.
  6941. **
  6942. ** The xCreate() method is used to construct a new cache instance. The
  6943. ** first parameter, szPage, is the size in bytes of the pages that must
  6944. ** be allocated by the cache. szPage will not be a power of two. The
  6945. ** second argument, bPurgeable, is true if the cache being created will
  6946. ** be used to cache database pages read from a file stored on disk, or
  6947. ** false if it is used for an in-memory database. The cache implementation
  6948. ** does not have to do anything special based on the value of bPurgeable,
  6949. ** it is purely advisory.
  6950. **
  6951. ** The xCachesize() method may be called at any time by SQLite to set the
  6952. ** suggested maximum cache-size (number of pages stored by) the cache
  6953. ** instance passed as the first argument. This is the value configured using
  6954. ** the SQLite "[PRAGMA cache_size]" command. As with the bPurgeable parameter,
  6955. ** the implementation is not required to do anything special with this
  6956. ** value, it is advisory only.
  6957. **
  6958. ** The xPagecount() method should return the number of pages currently
  6959. ** stored in the cache supplied as an argument.
  6960. **
  6961. ** The xFetch() method is used to fetch a page and return a pointer to it.
  6962. ** A 'page', in this context, is a buffer of szPage bytes aligned at an
  6963. ** 8-byte boundary. The page to be fetched is determined by the key. The
  6964. ** mimimum key value is 1. After it has been retrieved using xFetch, the page
  6965. ** is considered to be pinned.
  6966. **
  6967. ** If the requested page is already in the page cache, then a pointer to
  6968. ** the cached buffer should be returned with its contents intact. If the
  6969. ** page is not already in the cache, then the expected behaviour of the
  6970. ** cache is determined by the value of the createFlag parameter passed
  6971. ** to xFetch, according to the following table:
  6972. **
  6973. ** <table border=1 width=85% align=center>
  6974. ** <tr><th>createFlag<th>Expected Behaviour
  6975. ** <tr><td>0<td>NULL should be returned. No new cache entry is created.
  6976. ** <tr><td>1<td>If createFlag is set to 1, this indicates that
  6977. ** SQLite is holding pinned pages that can be unpinned
  6978. ** by writing their contents to the database file (a
  6979. ** relatively expensive operation). In this situation the
  6980. ** cache implementation has two choices: it can return NULL,
  6981. ** in which case SQLite will attempt to unpin one or more
  6982. ** pages before re-requesting the same page, or it can
  6983. ** allocate a new page and return a pointer to it. If a new
  6984. ** page is allocated, then it must be completely zeroed before
  6985. ** it is returned.
  6986. ** <tr><td>2<td>If createFlag is set to 2, then SQLite is not holding any
  6987. ** pinned pages associated with the specific cache passed
  6988. ** as the first argument to xFetch() that can be unpinned. The
  6989. ** cache implementation should attempt to allocate a new
  6990. ** cache entry and return a pointer to it. Again, the new
  6991. ** page should be zeroed before it is returned. If the xFetch()
  6992. ** method returns NULL when createFlag==2, SQLite assumes that
  6993. ** a memory allocation failed and returns SQLITE_NOMEM to the
  6994. ** user.
  6995. ** </table>
  6996. **
  6997. ** xUnpin() is called by SQLite with a pointer to a currently pinned page
  6998. ** as its second argument. If the third parameter, discard, is non-zero,
  6999. ** then the page should be evicted from the cache. In this case SQLite
  7000. ** assumes that the next time the page is retrieved from the cache using
  7001. ** the xFetch() method, it will be zeroed. If the discard parameter is
  7002. ** zero, then the page is considered to be unpinned. The cache implementation
  7003. ** may choose to reclaim (free or recycle) unpinned pages at any time.
  7004. ** SQLite assumes that next time the page is retrieved from the cache
  7005. ** it will either be zeroed, or contain the same data that it did when it
  7006. ** was unpinned.
  7007. **
  7008. ** The cache is not required to perform any reference counting. A single
  7009. ** call to xUnpin() unpins the page regardless of the number of prior calls
  7010. ** to xFetch().
  7011. **
  7012. ** The xRekey() method is used to change the key value associated with the
  7013. ** page passed as the second argument from oldKey to newKey. If the cache
  7014. ** previously contains an entry associated with newKey, it should be
  7015. ** discarded. Any prior cache entry associated with newKey is guaranteed not
  7016. ** to be pinned.
  7017. **
  7018. ** When SQLite calls the xTruncate() method, the cache must discard all
  7019. ** existing cache entries with page numbers (keys) greater than or equal
  7020. ** to the value of the iLimit parameter passed to xTruncate(). If any
  7021. ** of these pages are pinned, they are implicitly unpinned, meaning that
  7022. ** they can be safely discarded.
  7023. **
  7024. ** The xDestroy() method is used to delete a cache allocated by xCreate().
  7025. ** All resources associated with the specified cache should be freed. After
  7026. ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
  7027. ** handle invalid, and will not use it with any other sqlite3_pcache_methods
  7028. ** functions.
  7029. */
  7030. typedef struct sqlite3_pcache_methods sqlite3_pcache_methods;
  7031. struct sqlite3_pcache_methods {
  7032. void *pArg;
  7033. int (*xInit)(void*);
  7034. void (*xShutdown)(void*);
  7035. sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable);
  7036. void (*xCachesize)(sqlite3_pcache*, int nCachesize);
  7037. int (*xPagecount)(sqlite3_pcache*);
  7038. void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
  7039. void (*xUnpin)(sqlite3_pcache*, void*, int discard);
  7040. void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey);
  7041. void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
  7042. void (*xDestroy)(sqlite3_pcache*);
  7043. };
  7044. /*
  7045. ** Undo the hack that converts floating point types to integer for
  7046. ** builds on processors without floating point support.
  7047. */
  7048. #ifdef SQLITE_OMIT_FLOATING_POINT
  7049. # undef double
  7050. #endif
  7051. #if 0
  7052. } /* End of the 'extern "C"' block */
  7053. #endif
  7054. #endif
  7055. /************** End of sqlite3.h *********************************************/
  7056. /************** Continuing where we left off in sqliteInt.h ******************/
  7057. /************** Include hash.h in the middle of sqliteInt.h ******************/
  7058. /************** Begin file hash.h ********************************************/
  7059. /*
  7060. ** 2001 September 22
  7061. **
  7062. ** The author disclaims copyright to this source code. In place of
  7063. ** a legal notice, here is a blessing:
  7064. **
  7065. ** May you do good and not evil.
  7066. ** May you find forgiveness for yourself and forgive others.
  7067. ** May you share freely, never taking more than you give.
  7068. **
  7069. *************************************************************************
  7070. ** This is the header file for the generic hash-table implemenation
  7071. ** used in SQLite.
  7072. **
  7073. ** $Id: hash.h,v 1.12 2008/10/10 17:41:29 drh Exp $
  7074. */
  7075. #ifndef _SQLITE_HASH_H_
  7076. #define _SQLITE_HASH_H_
  7077. /* Forward declarations of structures. */
  7078. typedef struct Hash Hash;
  7079. typedef struct HashElem HashElem;
  7080. /* A complete hash table is an instance of the following structure.
  7081. ** The internals of this structure are intended to be opaque -- client
  7082. ** code should not attempt to access or modify the fields of this structure
  7083. ** directly. Change this structure only by using the routines below.
  7084. ** However, many of the "procedures" and "functions" for modifying and
  7085. ** accessing this structure are really macros, so we can't really make
  7086. ** this structure opaque.
  7087. */
  7088. struct Hash {
  7089. unsigned int copyKey: 1; /* True if copy of key made on insert */
  7090. unsigned int htsize : 31; /* Number of buckets in the hash table */
  7091. unsigned int count; /* Number of entries in this table */
  7092. HashElem *first; /* The first element of the array */
  7093. struct _ht { /* the hash table */
  7094. int count; /* Number of entries with this hash */
  7095. HashElem *chain; /* Pointer to first entry with this hash */
  7096. } *ht;
  7097. };
  7098. /* Each element in the hash table is an instance of the following
  7099. ** structure. All elements are stored on a single doubly-linked list.
  7100. **
  7101. ** Again, this structure is intended to be opaque, but it can't really
  7102. ** be opaque because it is used by macros.
  7103. */
  7104. struct HashElem {
  7105. HashElem *next, *prev; /* Next and previous elements in the table */
  7106. void *data; /* Data associated with this element */
  7107. void *pKey; int nKey; /* Key associated with this element */
  7108. };
  7109. /*
  7110. ** Access routines. To delete, insert a NULL pointer.
  7111. */
  7112. SQLITE_PRIVATE void sqlite3HashInit(Hash*, int copyKey);
  7113. SQLITE_PRIVATE void *sqlite3HashInsert(Hash*, const void *pKey, int nKey, void *pData);
  7114. SQLITE_PRIVATE void *sqlite3HashFind(const Hash*, const void *pKey, int nKey);
  7115. SQLITE_PRIVATE HashElem *sqlite3HashFindElem(const Hash*, const void *pKey, int nKey);
  7116. SQLITE_PRIVATE void sqlite3HashClear(Hash*);
  7117. /*
  7118. ** Macros for looping over all elements of a hash table. The idiom is
  7119. ** like this:
  7120. **
  7121. ** Hash h;
  7122. ** HashElem *p;
  7123. ** ...
  7124. ** for(p=sqliteHashFirst(&h); p; p=sqliteHashNext(p)){
  7125. ** SomeStructure *pData = sqliteHashData(p);
  7126. ** // do something with pData
  7127. ** }
  7128. */
  7129. #define sqliteHashFirst(H) ((H)->first)
  7130. #define sqliteHashNext(E) ((E)->next)
  7131. #define sqliteHashData(E) ((E)->data)
  7132. #define sqliteHashKey(E) ((E)->pKey)
  7133. #define sqliteHashKeysize(E) ((E)->nKey)
  7134. /*
  7135. ** Number of entries in a hash table
  7136. */
  7137. #define sqliteHashCount(H) ((H)->count)
  7138. #endif /* _SQLITE_HASH_H_ */
  7139. /************** End of hash.h ************************************************/
  7140. /************** Continuing where we left off in sqliteInt.h ******************/
  7141. /************** Include parse.h in the middle of sqliteInt.h *****************/
  7142. /************** Begin file parse.h *******************************************/
  7143. #define TK_SEMI 1
  7144. #define TK_EXPLAIN 2
  7145. #define TK_QUERY 3
  7146. #define TK_PLAN 4
  7147. #define TK_BEGIN 5
  7148. #define TK_TRANSACTION 6
  7149. #define TK_DEFERRED 7
  7150. #define TK_IMMEDIATE 8
  7151. #define TK_EXCLUSIVE 9
  7152. #define TK_COMMIT 10
  7153. #define TK_END 11
  7154. #define TK_ROLLBACK 12
  7155. #define TK_SAVEPOINT 13
  7156. #define TK_RELEASE 14
  7157. #define TK_TO 15
  7158. #define TK_CREATE 16
  7159. #define TK_TABLE 17
  7160. #define TK_IF 18
  7161. #define TK_NOT 19
  7162. #define TK_EXISTS 20
  7163. #define TK_TEMP 21
  7164. #define TK_LP 22
  7165. #define TK_RP 23
  7166. #define TK_AS 24
  7167. #define TK_COMMA 25
  7168. #define TK_ID 26
  7169. #define TK_ABORT 27
  7170. #define TK_AFTER 28
  7171. #define TK_ANALYZE 29
  7172. #define TK_ASC 30
  7173. #define TK_ATTACH 31
  7174. #define TK_BEFORE 32
  7175. #define TK_CASCADE 33
  7176. #define TK_CAST 34
  7177. #define TK_CONFLICT 35
  7178. #define TK_DATABASE 36
  7179. #define TK_DESC 37
  7180. #define TK_DETACH 38
  7181. #define TK_EACH 39
  7182. #define TK_FAIL 40
  7183. #define TK_FOR 41
  7184. #define TK_IGNORE 42
  7185. #define TK_INITIALLY 43
  7186. #define TK_INSTEAD 44
  7187. #define TK_LIKE_KW 45
  7188. #define TK_MATCH 46
  7189. #define TK_KEY 47
  7190. #define TK_OF 48
  7191. #define TK_OFFSET 49
  7192. #define TK_PRAGMA 50
  7193. #define TK_RAISE 51
  7194. #define TK_REPLACE 52
  7195. #define TK_RESTRICT 53
  7196. #define TK_ROW 54
  7197. #define TK_TRIGGER 55
  7198. #define TK_VACUUM 56
  7199. #define TK_VIEW 57
  7200. #define TK_VIRTUAL 58
  7201. #define TK_REINDEX 59
  7202. #define TK_RENAME 60
  7203. #define TK_CTIME_KW 61
  7204. #define TK_ANY 62
  7205. #define TK_OR 63
  7206. #define TK_AND 64
  7207. #define TK_IS 65
  7208. #define TK_BETWEEN 66
  7209. #define TK_IN 67
  7210. #define TK_ISNULL 68
  7211. #define TK_NOTNULL 69
  7212. #define TK_NE 70
  7213. #define TK_EQ 71
  7214. #define TK_GT 72
  7215. #define TK_LE 73
  7216. #define TK_LT 74
  7217. #define TK_GE 75
  7218. #define TK_ESCAPE 76
  7219. #define TK_BITAND 77
  7220. #define TK_BITOR 78
  7221. #define TK_LSHIFT 79
  7222. #define TK_RSHIFT 80
  7223. #define TK_PLUS 81
  7224. #define TK_MINUS 82
  7225. #define TK_STAR 83
  7226. #define TK_SLASH 84
  7227. #define TK_REM 85
  7228. #define TK_CONCAT 86
  7229. #define TK_COLLATE 87
  7230. #define TK_UMINUS 88
  7231. #define TK_UPLUS 89
  7232. #define TK_BITNOT 90
  7233. #define TK_STRING 91
  7234. #define TK_JOIN_KW 92
  7235. #define TK_CONSTRAINT 93
  7236. #define TK_DEFAULT 94
  7237. #define TK_NULL 95
  7238. #define TK_PRIMARY 96
  7239. #define TK_UNIQUE 97
  7240. #define TK_CHECK 98
  7241. #define TK_REFERENCES 99
  7242. #define TK_AUTOINCR 100
  7243. #define TK_ON 101
  7244. #define TK_DELETE 102
  7245. #define TK_UPDATE 103
  7246. #define TK_INSERT 104
  7247. #define TK_SET 105
  7248. #define TK_DEFERRABLE 106
  7249. #define TK_FOREIGN 107
  7250. #define TK_DROP 108
  7251. #define TK_UNION 109
  7252. #define TK_ALL 110
  7253. #define TK_EXCEPT 111
  7254. #define TK_INTERSECT 112
  7255. #define TK_SELECT 113
  7256. #define TK_DISTINCT 114
  7257. #define TK_DOT 115
  7258. #define TK_FROM 116
  7259. #define TK_JOIN 117
  7260. #define TK_INDEXED 118
  7261. #define TK_BY 119
  7262. #define TK_USING 120
  7263. #define TK_ORDER 121
  7264. #define TK_GROUP 122
  7265. #define TK_HAVING 123
  7266. #define TK_LIMIT 124
  7267. #define TK_WHERE 125
  7268. #define TK_INTO 126
  7269. #define TK_VALUES 127
  7270. #define TK_INTEGER 128
  7271. #define TK_FLOAT 129
  7272. #define TK_BLOB 130
  7273. #define TK_REGISTER 131
  7274. #define TK_VARIABLE 132
  7275. #define TK_CASE 133
  7276. #define TK_WHEN 134
  7277. #define TK_THEN 135
  7278. #define TK_ELSE 136
  7279. #define TK_INDEX 137
  7280. #define TK_ALTER 138
  7281. #define TK_ADD 139
  7282. #define TK_COLUMNKW 140
  7283. #define TK_TO_TEXT 141
  7284. #define TK_TO_BLOB 142
  7285. #define TK_TO_NUMERIC 143
  7286. #define TK_TO_INT 144
  7287. #define TK_TO_REAL 145
  7288. #define TK_END_OF_FILE 146
  7289. #define TK_ILLEGAL 147
  7290. #define TK_SPACE 148
  7291. #define TK_UNCLOSED_STRING 149
  7292. #define TK_FUNCTION 150
  7293. #define TK_COLUMN 151
  7294. #define TK_AGG_FUNCTION 152
  7295. #define TK_AGG_COLUMN 153
  7296. #define TK_CONST_FUNC 154
  7297. /************** End of parse.h ***********************************************/
  7298. /************** Continuing where we left off in sqliteInt.h ******************/
  7299. #include <stdio.h>
  7300. #include <stdlib.h>
  7301. #include <string.h>
  7302. #include <assert.h>
  7303. #include <stddef.h>
  7304. /*
  7305. ** If compiling for a processor that lacks floating point support,
  7306. ** substitute integer for floating-point
  7307. */
  7308. #ifdef SQLITE_OMIT_FLOATING_POINT
  7309. # define double sqlite_int64
  7310. # define LONGDOUBLE_TYPE sqlite_int64
  7311. # ifndef SQLITE_BIG_DBL
  7312. # define SQLITE_BIG_DBL (0x7fffffffffffffff)
  7313. # endif
  7314. # define SQLITE_OMIT_DATETIME_FUNCS 1
  7315. # define SQLITE_OMIT_TRACE 1
  7316. # undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
  7317. #endif
  7318. #ifndef SQLITE_BIG_DBL
  7319. # define SQLITE_BIG_DBL (1e99)
  7320. #endif
  7321. /*
  7322. ** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0
  7323. ** afterward. Having this macro allows us to cause the C compiler
  7324. ** to omit code used by TEMP tables without messy #ifndef statements.
  7325. */
  7326. #ifdef SQLITE_OMIT_TEMPDB
  7327. #define OMIT_TEMPDB 1
  7328. #else
  7329. #define OMIT_TEMPDB 0
  7330. #endif
  7331. /*
  7332. ** If the following macro is set to 1, then NULL values are considered
  7333. ** distinct when determining whether or not two entries are the same
  7334. ** in a UNIQUE index. This is the way PostgreSQL, Oracle, DB2, MySQL,
  7335. ** OCELOT, and Firebird all work. The SQL92 spec explicitly says this
  7336. ** is the way things are suppose to work.
  7337. **
  7338. ** If the following macro is set to 0, the NULLs are indistinct for
  7339. ** a UNIQUE index. In this mode, you can only have a single NULL entry
  7340. ** for a column declared UNIQUE. This is the way Informix and SQL Server
  7341. ** work.
  7342. */
  7343. #define NULL_DISTINCT_FOR_UNIQUE 1
  7344. /*
  7345. ** The "file format" number is an integer that is incremented whenever
  7346. ** the VDBE-level file format changes. The following macros define the
  7347. ** the default file format for new databases and the maximum file format
  7348. ** that the library can read.
  7349. */
  7350. #define SQLITE_MAX_FILE_FORMAT 4
  7351. #ifndef SQLITE_DEFAULT_FILE_FORMAT
  7352. # define SQLITE_DEFAULT_FILE_FORMAT 1
  7353. #endif
  7354. /*
  7355. ** Provide a default value for SQLITE_TEMP_STORE in case it is not specified
  7356. ** on the command-line
  7357. */
  7358. #ifndef SQLITE_TEMP_STORE
  7359. # define SQLITE_TEMP_STORE 1
  7360. #endif
  7361. /*
  7362. ** GCC does not define the offsetof() macro so we'll have to do it
  7363. ** ourselves.
  7364. */
  7365. #ifndef offsetof
  7366. #define offsetof(STRUCTURE,FIELD) ((int)((char*)&((STRUCTURE*)0)->FIELD))
  7367. #endif
  7368. /*
  7369. ** Check to see if this machine uses EBCDIC. (Yes, believe it or
  7370. ** not, there are still machines out there that use EBCDIC.)
  7371. */
  7372. #if 'A' == '\301'
  7373. # define SQLITE_EBCDIC 1
  7374. #else
  7375. # define SQLITE_ASCII 1
  7376. #endif
  7377. /*
  7378. ** Integers of known sizes. These typedefs might change for architectures
  7379. ** where the sizes very. Preprocessor macros are available so that the
  7380. ** types can be conveniently redefined at compile-type. Like this:
  7381. **
  7382. ** cc '-DUINTPTR_TYPE=long long int' ...
  7383. */
  7384. #ifndef UINT32_TYPE
  7385. # ifdef HAVE_UINT32_T
  7386. # define UINT32_TYPE uint32_t
  7387. # else
  7388. # define UINT32_TYPE unsigned int
  7389. # endif
  7390. #endif
  7391. #ifndef UINT16_TYPE
  7392. # ifdef HAVE_UINT16_T
  7393. # define UINT16_TYPE uint16_t
  7394. # else
  7395. # define UINT16_TYPE unsigned short int
  7396. # endif
  7397. #endif
  7398. #ifndef INT16_TYPE
  7399. # ifdef HAVE_INT16_T
  7400. # define INT16_TYPE int16_t
  7401. # else
  7402. # define INT16_TYPE short int
  7403. # endif
  7404. #endif
  7405. #ifndef UINT8_TYPE
  7406. # ifdef HAVE_UINT8_T
  7407. # define UINT8_TYPE uint8_t
  7408. # else
  7409. # define UINT8_TYPE unsigned char
  7410. # endif
  7411. #endif
  7412. #ifndef INT8_TYPE
  7413. # ifdef HAVE_INT8_T
  7414. # define INT8_TYPE int8_t
  7415. # else
  7416. # define INT8_TYPE signed char
  7417. # endif
  7418. #endif
  7419. #ifndef LONGDOUBLE_TYPE
  7420. # define LONGDOUBLE_TYPE long double
  7421. #endif
  7422. typedef sqlite_int64 i64; /* 8-byte signed integer */
  7423. typedef sqlite_uint64 u64; /* 8-byte unsigned integer */
  7424. typedef UINT32_TYPE u32; /* 4-byte unsigned integer */
  7425. typedef UINT16_TYPE u16; /* 2-byte unsigned integer */
  7426. typedef INT16_TYPE i16; /* 2-byte signed integer */
  7427. typedef UINT8_TYPE u8; /* 1-byte unsigned integer */
  7428. typedef INT8_TYPE i8; /* 1-byte signed integer */
  7429. /*
  7430. ** Macros to determine whether the machine is big or little endian,
  7431. ** evaluated at runtime.
  7432. */
  7433. #ifdef SQLITE_AMALGAMATION
  7434. SQLITE_PRIVATE const int sqlite3one = 1;
  7435. #else
  7436. SQLITE_PRIVATE const int sqlite3one;
  7437. #endif
  7438. #if defined(i386) || defined(__i386__) || defined(_M_IX86)\
  7439. || defined(__x86_64) || defined(__x86_64__)
  7440. # define SQLITE_BIGENDIAN 0
  7441. # define SQLITE_LITTLEENDIAN 1
  7442. # define SQLITE_UTF16NATIVE SQLITE_UTF16LE
  7443. #else
  7444. # define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0)
  7445. # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
  7446. # define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)
  7447. #endif
  7448. /*
  7449. ** Constants for the largest and smallest possible 64-bit signed integers.
  7450. ** These macros are designed to work correctly on both 32-bit and 64-bit
  7451. ** compilers.
  7452. */
  7453. #define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
  7454. #define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
  7455. /*
  7456. ** An instance of the following structure is used to store the busy-handler
  7457. ** callback for a given sqlite handle.
  7458. **
  7459. ** The sqlite.busyHandler member of the sqlite struct contains the busy
  7460. ** callback for the database handle. Each pager opened via the sqlite
  7461. ** handle is passed a pointer to sqlite.busyHandler. The busy-handler
  7462. ** callback is currently invoked only from within pager.c.
  7463. */
  7464. typedef struct BusyHandler BusyHandler;
  7465. struct BusyHandler {
  7466. int (*xFunc)(void *,int); /* The busy callback */
  7467. void *pArg; /* First arg to busy callback */
  7468. int nBusy; /* Incremented with each busy call */
  7469. };
  7470. /*
  7471. ** Name of the master database table. The master database table
  7472. ** is a special table that holds the names and attributes of all
  7473. ** user tables and indices.
  7474. */
  7475. #define MASTER_NAME "sqlite_master"
  7476. #define TEMP_MASTER_NAME "sqlite_temp_master"
  7477. /*
  7478. ** The root-page of the master database table.
  7479. */
  7480. #define MASTER_ROOT 1
  7481. /*
  7482. ** The name of the schema table.
  7483. */
  7484. #define SCHEMA_TABLE(x) ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME)
  7485. /*
  7486. ** A convenience macro that returns the number of elements in
  7487. ** an array.
  7488. */
  7489. #define ArraySize(X) ((int)(sizeof(X)/sizeof(X[0])))
  7490. /*
  7491. ** The following value as a destructor means to use sqlite3DbFree().
  7492. ** This is an internal extension to SQLITE_STATIC and SQLITE_TRANSIENT.
  7493. */
  7494. #define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3DbFree)
  7495. /*
  7496. ** When SQLITE_OMIT_WSD is defined, it means that the target platform does
  7497. ** not support Writable Static Data (WSD) such as global and static variables.
  7498. ** All variables must either be on the stack or dynamically allocated from
  7499. ** the heap. When WSD is unsupported, the variable declarations scattered
  7500. ** throughout the SQLite code must become constants instead. The SQLITE_WSD
  7501. ** macro is used for this purpose. And instead of referencing the variable
  7502. ** directly, we use its constant as a key to lookup the run-time allocated
  7503. ** buffer that holds real variable. The constant is also the initializer
  7504. ** for the run-time allocated buffer.
  7505. **
  7506. ** In the usual case where WSD is supported, the SQLITE_WSD and GLOBAL
  7507. ** macros become no-ops and have zero performance impact.
  7508. */
  7509. #ifdef SQLITE_OMIT_WSD
  7510. #define SQLITE_WSD const
  7511. #define GLOBAL(t,v) (*(t*)sqlite3_wsd_find((void*)&(v), sizeof(v)))
  7512. #define sqlite3GlobalConfig GLOBAL(struct Sqlite3Config, sqlite3Config)
  7513. SQLITE_API int sqlite3_wsd_init(int N, int J);
  7514. SQLITE_API void *sqlite3_wsd_find(void *K, int L);
  7515. #else
  7516. #define SQLITE_WSD
  7517. #define GLOBAL(t,v) v
  7518. #define sqlite3GlobalConfig sqlite3Config
  7519. #endif
  7520. /*
  7521. ** The following macros are used to suppress compiler warnings and to
  7522. ** make it clear to human readers when a function parameter is deliberately
  7523. ** left unused within the body of a function. This usually happens when
  7524. ** a function is called via a function pointer. For example the
  7525. ** implementation of an SQL aggregate step callback may not use the
  7526. ** parameter indicating the number of arguments passed to the aggregate,
  7527. ** if it knows that this is enforced elsewhere.
  7528. **
  7529. ** When a function parameter is not used at all within the body of a function,
  7530. ** it is generally named "NotUsed" or "NotUsed2" to make things even clearer.
  7531. ** However, these macros may also be used to suppress warnings related to
  7532. ** parameters that may or may not be used depending on compilation options.
  7533. ** For example those parameters only used in assert() statements. In these
  7534. ** cases the parameters are named as per the usual conventions.
  7535. */
  7536. #define UNUSED_PARAMETER(x) (void)(x)
  7537. #define UNUSED_PARAMETER2(x,y) UNUSED_PARAMETER(x),UNUSED_PARAMETER(y)
  7538. /*
  7539. ** Forward references to structures
  7540. */
  7541. typedef struct AggInfo AggInfo;
  7542. typedef struct AuthContext AuthContext;
  7543. typedef struct Bitvec Bitvec;
  7544. typedef struct RowSet RowSet;
  7545. typedef struct CollSeq CollSeq;
  7546. typedef struct Column Column;
  7547. typedef struct Db Db;
  7548. typedef struct Schema Schema;
  7549. typedef struct Expr Expr;
  7550. typedef struct ExprList ExprList;
  7551. typedef struct FKey FKey;
  7552. typedef struct FuncDef FuncDef;
  7553. typedef struct FuncDefHash FuncDefHash;
  7554. typedef struct IdList IdList;
  7555. typedef struct Index Index;
  7556. typedef struct KeyClass KeyClass;
  7557. typedef struct KeyInfo KeyInfo;
  7558. typedef struct Lookaside Lookaside;
  7559. typedef struct LookasideSlot LookasideSlot;
  7560. typedef struct Module Module;
  7561. typedef struct NameContext NameContext;
  7562. typedef struct Parse Parse;
  7563. typedef struct Savepoint Savepoint;
  7564. typedef struct Select Select;
  7565. typedef struct SrcList SrcList;
  7566. typedef struct StrAccum StrAccum;
  7567. typedef struct Table Table;
  7568. typedef struct TableLock TableLock;
  7569. typedef struct Token Token;
  7570. typedef struct TriggerStack TriggerStack;
  7571. typedef struct TriggerStep TriggerStep;
  7572. typedef struct Trigger Trigger;
  7573. typedef struct UnpackedRecord UnpackedRecord;
  7574. typedef struct Walker Walker;
  7575. typedef struct WherePlan WherePlan;
  7576. typedef struct WhereInfo WhereInfo;
  7577. typedef struct WhereLevel WhereLevel;
  7578. /*
  7579. ** Defer sourcing vdbe.h and btree.h until after the "u8" and
  7580. ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque
  7581. ** pointer types (i.e. FuncDef) defined above.
  7582. */
  7583. /************** Include btree.h in the middle of sqliteInt.h *****************/
  7584. /************** Begin file btree.h *******************************************/
  7585. /*
  7586. ** 2001 September 15
  7587. **
  7588. ** The author disclaims copyright to this source code. In place of
  7589. ** a legal notice, here is a blessing:
  7590. **
  7591. ** May you do good and not evil.
  7592. ** May you find forgiveness for yourself and forgive others.
  7593. ** May you share freely, never taking more than you give.
  7594. **
  7595. *************************************************************************
  7596. ** This header file defines the interface that the sqlite B-Tree file
  7597. ** subsystem. See comments in the source code for a detailed description
  7598. ** of what each interface routine does.
  7599. **
  7600. ** @(#) $Id: btree.h,v 1.106 2008/12/17 17:30:26 danielk1977 Exp $
  7601. */
  7602. #ifndef _BTREE_H_
  7603. #define _BTREE_H_
  7604. /* TODO: This definition is just included so other modules compile. It
  7605. ** needs to be revisited.
  7606. */
  7607. #define SQLITE_N_BTREE_META 10
  7608. /*
  7609. ** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
  7610. ** it must be turned on for each database using "PRAGMA auto_vacuum = 1".
  7611. */
  7612. #ifndef SQLITE_DEFAULT_AUTOVACUUM
  7613. #define SQLITE_DEFAULT_AUTOVACUUM 0
  7614. #endif
  7615. #define BTREE_AUTOVACUUM_NONE 0 /* Do not do auto-vacuum */
  7616. #define BTREE_AUTOVACUUM_FULL 1 /* Do full auto-vacuum */
  7617. #define BTREE_AUTOVACUUM_INCR 2 /* Incremental vacuum */
  7618. /*
  7619. ** Forward declarations of structure
  7620. */
  7621. typedef struct Btree Btree;
  7622. typedef struct BtCursor BtCursor;
  7623. typedef struct BtShared BtShared;
  7624. typedef struct BtreeMutexArray BtreeMutexArray;
  7625. /*
  7626. ** This structure records all of the Btrees that need to hold
  7627. ** a mutex before we enter sqlite3VdbeExec(). The Btrees are
  7628. ** are placed in aBtree[] in order of aBtree[]->pBt. That way,
  7629. ** we can always lock and unlock them all quickly.
  7630. */
  7631. struct BtreeMutexArray {
  7632. int nMutex;
  7633. Btree *aBtree[SQLITE_MAX_ATTACHED+1];
  7634. };
  7635. SQLITE_PRIVATE int sqlite3BtreeOpen(
  7636. const char *zFilename, /* Name of database file to open */
  7637. sqlite3 *db, /* Associated database connection */
  7638. Btree **, /* Return open Btree* here */
  7639. int flags, /* Flags */
  7640. int vfsFlags /* Flags passed through to VFS open */
  7641. );
  7642. /* The flags parameter to sqlite3BtreeOpen can be the bitwise or of the
  7643. ** following values.
  7644. **
  7645. ** NOTE: These values must match the corresponding PAGER_ values in
  7646. ** pager.h.
  7647. */
  7648. #define BTREE_OMIT_JOURNAL 1 /* Do not use journal. No argument */
  7649. #define BTREE_NO_READLOCK 2 /* Omit readlocks on readonly files */
  7650. #define BTREE_MEMORY 4 /* In-memory DB. No argument */
  7651. #define BTREE_READONLY 8 /* Open the database in read-only mode */
  7652. #define BTREE_READWRITE 16 /* Open for both reading and writing */
  7653. #define BTREE_CREATE 32 /* Create the database if it does not exist */
  7654. SQLITE_PRIVATE int sqlite3BtreeClose(Btree*);
  7655. SQLITE_PRIVATE int sqlite3BtreeSetCacheSize(Btree*,int);
  7656. SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel(Btree*,int,int);
  7657. SQLITE_PRIVATE int sqlite3BtreeSyncDisabled(Btree*);
  7658. SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree*,int,int);
  7659. SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*);
  7660. SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree*,int);
  7661. SQLITE_PRIVATE int sqlite3BtreeGetReserve(Btree*);
  7662. SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int);
  7663. SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
  7664. SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int);
  7665. SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);
  7666. SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*);
  7667. SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*);
  7668. SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*);
  7669. SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*);
  7670. SQLITE_PRIVATE int sqlite3BtreeCommitStmt(Btree*);
  7671. SQLITE_PRIVATE int sqlite3BtreeRollbackStmt(Btree*);
  7672. SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, int*, int flags);
  7673. SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree*);
  7674. SQLITE_PRIVATE int sqlite3BtreeIsInStmt(Btree*);
  7675. SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree*);
  7676. SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
  7677. SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *);
  7678. SQLITE_PRIVATE int sqlite3BtreeLockTable(Btree *, int, u8);
  7679. SQLITE_PRIVATE int sqlite3BtreeSavepoint(Btree *, int, int);
  7680. SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *);
  7681. SQLITE_PRIVATE const char *sqlite3BtreeGetDirname(Btree *);
  7682. SQLITE_PRIVATE const char *sqlite3BtreeGetJournalname(Btree *);
  7683. SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *, Btree *);
  7684. SQLITE_PRIVATE int sqlite3BtreeIncrVacuum(Btree *);
  7685. /* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR
  7686. ** of the following flags:
  7687. */
  7688. #define BTREE_INTKEY 1 /* Table has only 64-bit signed integer keys */
  7689. #define BTREE_ZERODATA 2 /* Table has keys only - no data */
  7690. #define BTREE_LEAFDATA 4 /* Data stored in leaves only. Implies INTKEY */
  7691. SQLITE_PRIVATE int sqlite3BtreeDropTable(Btree*, int, int*);
  7692. SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree*, int, int*);
  7693. SQLITE_PRIVATE int sqlite3BtreeGetMeta(Btree*, int idx, u32 *pValue);
  7694. SQLITE_PRIVATE int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
  7695. SQLITE_PRIVATE void sqlite3BtreeTripAllCursors(Btree*, int);
  7696. SQLITE_PRIVATE int sqlite3BtreeCursor(
  7697. Btree*, /* BTree containing table to open */
  7698. int iTable, /* Index of root page */
  7699. int wrFlag, /* 1 for writing. 0 for read-only */
  7700. struct KeyInfo*, /* First argument to compare function */
  7701. BtCursor *pCursor /* Space to write cursor structure */
  7702. );
  7703. SQLITE_PRIVATE int sqlite3BtreeCursorSize(void);
  7704. SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor*);
  7705. SQLITE_PRIVATE int sqlite3BtreeMoveto(
  7706. BtCursor*,
  7707. const void *pKey,
  7708. i64 nKey,
  7709. int bias,
  7710. int *pRes
  7711. );
  7712. SQLITE_PRIVATE int sqlite3BtreeMovetoUnpacked(
  7713. BtCursor*,
  7714. UnpackedRecord *pUnKey,
  7715. i64 intKey,
  7716. int bias,
  7717. int *pRes
  7718. );
  7719. SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor*, int*);
  7720. SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*);
  7721. SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey,
  7722. const void *pData, int nData,
  7723. int nZero, int bias);
  7724. SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes);
  7725. SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
  7726. SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
  7727. SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
  7728. SQLITE_PRIVATE int sqlite3BtreeFlags(BtCursor*);
  7729. SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
  7730. SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
  7731. SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
  7732. SQLITE_PRIVATE sqlite3 *sqlite3BtreeCursorDb(const BtCursor*);
  7733. SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, int *pAmt);
  7734. SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, int *pAmt);
  7735. SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
  7736. SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
  7737. SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
  7738. SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
  7739. SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
  7740. SQLITE_PRIVATE void sqlite3BtreeCacheOverflow(BtCursor *);
  7741. SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *);
  7742. #ifdef SQLITE_TEST
  7743. SQLITE_PRIVATE int sqlite3BtreeCursorInfo(BtCursor*, int*, int);
  7744. SQLITE_PRIVATE void sqlite3BtreeCursorList(Btree*);
  7745. #endif
  7746. /*
  7747. ** If we are not using shared cache, then there is no need to
  7748. ** use mutexes to access the BtShared structures. So make the
  7749. ** Enter and Leave procedures no-ops.
  7750. */
  7751. #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE
  7752. SQLITE_PRIVATE void sqlite3BtreeEnter(Btree*);
  7753. SQLITE_PRIVATE void sqlite3BtreeLeave(Btree*);
  7754. #ifndef NDEBUG
  7755. /* This routine is used inside assert() statements only. */
  7756. SQLITE_PRIVATE int sqlite3BtreeHoldsMutex(Btree*);
  7757. #endif
  7758. SQLITE_PRIVATE void sqlite3BtreeEnterCursor(BtCursor*);
  7759. SQLITE_PRIVATE void sqlite3BtreeLeaveCursor(BtCursor*);
  7760. SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3*);
  7761. SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3*);
  7762. #ifndef NDEBUG
  7763. /* This routine is used inside assert() statements only. */
  7764. SQLITE_PRIVATE int sqlite3BtreeHoldsAllMutexes(sqlite3*);
  7765. #endif
  7766. SQLITE_PRIVATE void sqlite3BtreeMutexArrayEnter(BtreeMutexArray*);
  7767. SQLITE_PRIVATE void sqlite3BtreeMutexArrayLeave(BtreeMutexArray*);
  7768. SQLITE_PRIVATE void sqlite3BtreeMutexArrayInsert(BtreeMutexArray*, Btree*);
  7769. #else
  7770. # define sqlite3BtreeEnter(X)
  7771. # define sqlite3BtreeLeave(X)
  7772. #ifndef NDEBUG
  7773. /* This routine is used inside assert() statements only. */
  7774. # define sqlite3BtreeHoldsMutex(X) 1
  7775. #endif
  7776. # define sqlite3BtreeEnterCursor(X)
  7777. # define sqlite3BtreeLeaveCursor(X)
  7778. # define sqlite3BtreeEnterAll(X)
  7779. # define sqlite3BtreeLeaveAll(X)
  7780. #ifndef NDEBUG
  7781. /* This routine is used inside assert() statements only. */
  7782. # define sqlite3BtreeHoldsAllMutexes(X) 1
  7783. #endif
  7784. # define sqlite3BtreeMutexArrayEnter(X)
  7785. # define sqlite3BtreeMutexArrayLeave(X)
  7786. # define sqlite3BtreeMutexArrayInsert(X,Y)
  7787. #endif
  7788. #endif /* _BTREE_H_ */
  7789. /************** End of btree.h ***********************************************/
  7790. /************** Continuing where we left off in sqliteInt.h ******************/
  7791. /************** Include vdbe.h in the middle of sqliteInt.h ******************/
  7792. /************** Begin file vdbe.h ********************************************/
  7793. /*
  7794. ** 2001 September 15
  7795. **
  7796. ** The author disclaims copyright to this source code. In place of
  7797. ** a legal notice, here is a blessing:
  7798. **
  7799. ** May you do good and not evil.
  7800. ** May you find forgiveness for yourself and forgive others.
  7801. ** May you share freely, never taking more than you give.
  7802. **
  7803. *************************************************************************
  7804. ** Header file for the Virtual DataBase Engine (VDBE)
  7805. **
  7806. ** This header defines the interface to the virtual database engine
  7807. ** or VDBE. The VDBE implements an abstract machine that runs a
  7808. ** simple program to access and modify the underlying database.
  7809. **
  7810. ** $Id: vdbe.h,v 1.139 2008/10/31 10:53:23 danielk1977 Exp $
  7811. */
  7812. #ifndef _SQLITE_VDBE_H_
  7813. #define _SQLITE_VDBE_H_
  7814. /*
  7815. ** A single VDBE is an opaque structure named "Vdbe". Only routines
  7816. ** in the source file sqliteVdbe.c are allowed to see the insides
  7817. ** of this structure.
  7818. */
  7819. typedef struct Vdbe Vdbe;
  7820. /*
  7821. ** The names of the following types declared in vdbeInt.h are required
  7822. ** for the VdbeOp definition.
  7823. */
  7824. typedef struct VdbeFunc VdbeFunc;
  7825. typedef struct Mem Mem;
  7826. /*
  7827. ** A single instruction of the virtual machine has an opcode
  7828. ** and as many as three operands. The instruction is recorded
  7829. ** as an instance of the following structure:
  7830. */
  7831. struct VdbeOp {
  7832. u8 opcode; /* What operation to perform */
  7833. signed char p4type; /* One of the P4_xxx constants for p4 */
  7834. u8 opflags; /* Not currently used */
  7835. u8 p5; /* Fifth parameter is an unsigned character */
  7836. int p1; /* First operand */
  7837. int p2; /* Second parameter (often the jump destination) */
  7838. int p3; /* The third parameter */
  7839. union { /* forth parameter */
  7840. int i; /* Integer value if p4type==P4_INT32 */
  7841. void *p; /* Generic pointer */
  7842. char *z; /* Pointer to data for string (char array) types */
  7843. i64 *pI64; /* Used when p4type is P4_INT64 */
  7844. double *pReal; /* Used when p4type is P4_REAL */
  7845. FuncDef *pFunc; /* Used when p4type is P4_FUNCDEF */
  7846. VdbeFunc *pVdbeFunc; /* Used when p4type is P4_VDBEFUNC */
  7847. CollSeq *pColl; /* Used when p4type is P4_COLLSEQ */
  7848. Mem *pMem; /* Used when p4type is P4_MEM */
  7849. sqlite3_vtab *pVtab; /* Used when p4type is P4_VTAB */
  7850. KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */
  7851. int *ai; /* Used when p4type is P4_INTARRAY */
  7852. } p4;
  7853. #ifdef SQLITE_DEBUG
  7854. char *zComment; /* Comment to improve readability */
  7855. #endif
  7856. #ifdef VDBE_PROFILE
  7857. int cnt; /* Number of times this instruction was executed */
  7858. u64 cycles; /* Total time spent executing this instruction */
  7859. #endif
  7860. };
  7861. typedef struct VdbeOp VdbeOp;
  7862. /*
  7863. ** A smaller version of VdbeOp used for the VdbeAddOpList() function because
  7864. ** it takes up less space.
  7865. */
  7866. struct VdbeOpList {
  7867. u8 opcode; /* What operation to perform */
  7868. signed char p1; /* First operand */
  7869. signed char p2; /* Second parameter (often the jump destination) */
  7870. signed char p3; /* Third parameter */
  7871. };
  7872. typedef struct VdbeOpList VdbeOpList;
  7873. /*
  7874. ** Allowed values of VdbeOp.p3type
  7875. */
  7876. #define P4_NOTUSED 0 /* The P4 parameter is not used */
  7877. #define P4_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */
  7878. #define P4_STATIC (-2) /* Pointer to a static string */
  7879. #define P4_COLLSEQ (-4) /* P4 is a pointer to a CollSeq structure */
  7880. #define P4_FUNCDEF (-5) /* P4 is a pointer to a FuncDef structure */
  7881. #define P4_KEYINFO (-6) /* P4 is a pointer to a KeyInfo structure */
  7882. #define P4_VDBEFUNC (-7) /* P4 is a pointer to a VdbeFunc structure */
  7883. #define P4_MEM (-8) /* P4 is a pointer to a Mem* structure */
  7884. #define P4_TRANSIENT (-9) /* P4 is a pointer to a transient string */
  7885. #define P4_VTAB (-10) /* P4 is a pointer to an sqlite3_vtab structure */
  7886. #define P4_MPRINTF (-11) /* P4 is a string obtained from sqlite3_mprintf() */
  7887. #define P4_REAL (-12) /* P4 is a 64-bit floating point value */
  7888. #define P4_INT64 (-13) /* P4 is a 64-bit signed integer */
  7889. #define P4_INT32 (-14) /* P4 is a 32-bit signed integer */
  7890. #define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */
  7891. /* When adding a P4 argument using P4_KEYINFO, a copy of the KeyInfo structure
  7892. ** is made. That copy is freed when the Vdbe is finalized. But if the
  7893. ** argument is P4_KEYINFO_HANDOFF, the passed in pointer is used. It still
  7894. ** gets freed when the Vdbe is finalized so it still should be obtained
  7895. ** from a single sqliteMalloc(). But no copy is made and the calling
  7896. ** function should *not* try to free the KeyInfo.
  7897. */
  7898. #define P4_KEYINFO_HANDOFF (-16)
  7899. #define P4_KEYINFO_STATIC (-17)
  7900. /*
  7901. ** The Vdbe.aColName array contains 5n Mem structures, where n is the
  7902. ** number of columns of data returned by the statement.
  7903. */
  7904. #define COLNAME_NAME 0
  7905. #define COLNAME_DECLTYPE 1
  7906. #define COLNAME_DATABASE 2
  7907. #define COLNAME_TABLE 3
  7908. #define COLNAME_COLUMN 4
  7909. #ifdef SQLITE_ENABLE_COLUMN_METADATA
  7910. # define COLNAME_N 5 /* Number of COLNAME_xxx symbols */
  7911. #else
  7912. # ifdef SQLITE_OMIT_DECLTYPE
  7913. # define COLNAME_N 1 /* Store only the name */
  7914. # else
  7915. # define COLNAME_N 2 /* Store the name and decltype */
  7916. # endif
  7917. #endif
  7918. /*
  7919. ** The following macro converts a relative address in the p2 field
  7920. ** of a VdbeOp structure into a negative number so that
  7921. ** sqlite3VdbeAddOpList() knows that the address is relative. Calling
  7922. ** the macro again restores the address.
  7923. */
  7924. #define ADDR(X) (-1-(X))
  7925. /*
  7926. ** The makefile scans the vdbe.c source file and creates the "opcodes.h"
  7927. ** header file that defines a number for each opcode used by the VDBE.
  7928. */
  7929. /************** Include opcodes.h in the middle of vdbe.h ********************/
  7930. /************** Begin file opcodes.h *****************************************/
  7931. /* Automatically generated. Do not edit */
  7932. /* See the mkopcodeh.awk script for details */
  7933. #define OP_VNext 1
  7934. #define OP_Affinity 2
  7935. #define OP_Column 3
  7936. #define OP_SetCookie 4
  7937. #define OP_Seek 5
  7938. #define OP_Real 129 /* same as TK_FLOAT */
  7939. #define OP_Sequence 6
  7940. #define OP_Savepoint 7
  7941. #define OP_Ge 75 /* same as TK_GE */
  7942. #define OP_RowKey 8
  7943. #define OP_SCopy 9
  7944. #define OP_Eq 71 /* same as TK_EQ */
  7945. #define OP_OpenWrite 10
  7946. #define OP_NotNull 69 /* same as TK_NOTNULL */
  7947. #define OP_If 11
  7948. #define OP_ToInt 144 /* same as TK_TO_INT */
  7949. #define OP_String8 91 /* same as TK_STRING */
  7950. #define OP_VRowid 12
  7951. #define OP_CollSeq 13
  7952. #define OP_OpenRead 14
  7953. #define OP_Expire 15
  7954. #define OP_AutoCommit 16
  7955. #define OP_Gt 72 /* same as TK_GT */
  7956. #define OP_Pagecount 17
  7957. #define OP_IntegrityCk 18
  7958. #define OP_Sort 20
  7959. #define OP_Copy 21
  7960. #define OP_Trace 22
  7961. #define OP_Function 23
  7962. #define OP_IfNeg 24
  7963. #define OP_And 64 /* same as TK_AND */
  7964. #define OP_Subtract 82 /* same as TK_MINUS */
  7965. #define OP_Noop 25
  7966. #define OP_Return 26
  7967. #define OP_Remainder 85 /* same as TK_REM */
  7968. #define OP_NewRowid 27
  7969. #define OP_Multiply 83 /* same as TK_STAR */
  7970. #define OP_Variable 28
  7971. #define OP_String 29
  7972. #define OP_RealAffinity 30
  7973. #define OP_VRename 31
  7974. #define OP_ParseSchema 32
  7975. #define OP_VOpen 33
  7976. #define OP_Close 34
  7977. #define OP_CreateIndex 35
  7978. #define OP_IsUnique 36
  7979. #define OP_NotFound 37
  7980. #define OP_Int64 38
  7981. #define OP_MustBeInt 39
  7982. #define OP_Halt 40
  7983. #define OP_Rowid 41
  7984. #define OP_IdxLT 42
  7985. #define OP_AddImm 43
  7986. #define OP_Statement 44
  7987. #define OP_RowData 45
  7988. #define OP_MemMax 46
  7989. #define OP_Or 63 /* same as TK_OR */
  7990. #define OP_NotExists 47
  7991. #define OP_Gosub 48
  7992. #define OP_Divide 84 /* same as TK_SLASH */
  7993. #define OP_Integer 49
  7994. #define OP_ToNumeric 143 /* same as TK_TO_NUMERIC*/
  7995. #define OP_Prev 50
  7996. #define OP_RowSetRead 51
  7997. #define OP_Concat 86 /* same as TK_CONCAT */
  7998. #define OP_RowSetAdd 52
  7999. #define OP_BitAnd 77 /* same as TK_BITAND */
  8000. #define OP_VColumn 53
  8001. #define OP_CreateTable 54
  8002. #define OP_Last 55
  8003. #define OP_SeekLe 56
  8004. #define OP_IsNull 68 /* same as TK_ISNULL */
  8005. #define OP_IncrVacuum 57
  8006. #define OP_IdxRowid 58
  8007. #define OP_ShiftRight 80 /* same as TK_RSHIFT */
  8008. #define OP_ResetCount 59
  8009. #define OP_ContextPush 60
  8010. #define OP_Yield 61
  8011. #define OP_DropTrigger 62
  8012. #define OP_DropIndex 65
  8013. #define OP_IdxGE 66
  8014. #define OP_IdxDelete 67
  8015. #define OP_Vacuum 76
  8016. #define OP_IfNot 87
  8017. #define OP_DropTable 88
  8018. #define OP_SeekLt 89
  8019. #define OP_MakeRecord 92
  8020. #define OP_ToBlob 142 /* same as TK_TO_BLOB */
  8021. #define OP_ResultRow 93
  8022. #define OP_Delete 94
  8023. #define OP_AggFinal 95
  8024. #define OP_Compare 96
  8025. #define OP_ShiftLeft 79 /* same as TK_LSHIFT */
  8026. #define OP_Goto 97
  8027. #define OP_TableLock 98
  8028. #define OP_Clear 99
  8029. #define OP_Le 73 /* same as TK_LE */
  8030. #define OP_VerifyCookie 100
  8031. #define OP_AggStep 101
  8032. #define OP_ToText 141 /* same as TK_TO_TEXT */
  8033. #define OP_Not 19 /* same as TK_NOT */
  8034. #define OP_ToReal 145 /* same as TK_TO_REAL */
  8035. #define OP_SetNumColumns 102
  8036. #define OP_Transaction 103
  8037. #define OP_VFilter 104
  8038. #define OP_Ne 70 /* same as TK_NE */
  8039. #define OP_VDestroy 105
  8040. #define OP_ContextPop 106
  8041. #define OP_BitOr 78 /* same as TK_BITOR */
  8042. #define OP_Next 107
  8043. #define OP_IdxInsert 108
  8044. #define OP_Lt 74 /* same as TK_LT */
  8045. #define OP_SeekGe 109
  8046. #define OP_Insert 110
  8047. #define OP_Destroy 111
  8048. #define OP_ReadCookie 112
  8049. #define OP_LoadAnalysis 113
  8050. #define OP_Explain 114
  8051. #define OP_OpenPseudo 115
  8052. #define OP_OpenEphemeral 116
  8053. #define OP_Null 117
  8054. #define OP_Move 118
  8055. #define OP_Blob 119
  8056. #define OP_Add 81 /* same as TK_PLUS */
  8057. #define OP_Rewind 120
  8058. #define OP_SeekGt 121
  8059. #define OP_VBegin 122
  8060. #define OP_VUpdate 123
  8061. #define OP_IfZero 124
  8062. #define OP_BitNot 90 /* same as TK_BITNOT */
  8063. #define OP_VCreate 125
  8064. #define OP_Found 126
  8065. #define OP_IfPos 127
  8066. #define OP_NullRow 128
  8067. #define OP_Jump 130
  8068. #define OP_Permutation 131
  8069. /* The following opcode values are never used */
  8070. #define OP_NotUsed_132 132
  8071. #define OP_NotUsed_133 133
  8072. #define OP_NotUsed_134 134
  8073. #define OP_NotUsed_135 135
  8074. #define OP_NotUsed_136 136
  8075. #define OP_NotUsed_137 137
  8076. #define OP_NotUsed_138 138
  8077. #define OP_NotUsed_139 139
  8078. #define OP_NotUsed_140 140
  8079. /* Properties such as "out2" or "jump" that are specified in
  8080. ** comments following the "case" for each opcode in the vdbe.c
  8081. ** are encoded into bitvectors as follows:
  8082. */
  8083. #define OPFLG_JUMP 0x0001 /* jump: P2 holds jmp target */
  8084. #define OPFLG_OUT2_PRERELEASE 0x0002 /* out2-prerelease: */
  8085. #define OPFLG_IN1 0x0004 /* in1: P1 is an input */
  8086. #define OPFLG_IN2 0x0008 /* in2: P2 is an input */
  8087. #define OPFLG_IN3 0x0010 /* in3: P3 is an input */
  8088. #define OPFLG_OUT3 0x0020 /* out3: P3 is an output */
  8089. #define OPFLG_INITIALIZER {\
  8090. /* 0 */ 0x00, 0x01, 0x00, 0x00, 0x10, 0x08, 0x02, 0x00,\
  8091. /* 8 */ 0x00, 0x04, 0x00, 0x05, 0x02, 0x00, 0x00, 0x00,\
  8092. /* 16 */ 0x00, 0x02, 0x00, 0x04, 0x01, 0x04, 0x00, 0x00,\
  8093. /* 24 */ 0x05, 0x00, 0x04, 0x02, 0x02, 0x02, 0x04, 0x00,\
  8094. /* 32 */ 0x00, 0x00, 0x00, 0x02, 0x11, 0x11, 0x02, 0x05,\
  8095. /* 40 */ 0x00, 0x02, 0x11, 0x04, 0x00, 0x00, 0x0c, 0x11,\
  8096. /* 48 */ 0x01, 0x02, 0x01, 0x21, 0x08, 0x00, 0x02, 0x01,\
  8097. /* 56 */ 0x11, 0x01, 0x02, 0x00, 0x00, 0x04, 0x00, 0x2c,\
  8098. /* 64 */ 0x2c, 0x00, 0x11, 0x00, 0x05, 0x05, 0x15, 0x15,\
  8099. /* 72 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x2c, 0x2c, 0x2c,\
  8100. /* 80 */ 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x05,\
  8101. /* 88 */ 0x00, 0x11, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00,\
  8102. /* 96 */ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
  8103. /* 104 */ 0x01, 0x00, 0x00, 0x01, 0x08, 0x11, 0x00, 0x02,\
  8104. /* 112 */ 0x02, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02,\
  8105. /* 120 */ 0x01, 0x11, 0x00, 0x00, 0x05, 0x00, 0x11, 0x05,\
  8106. /* 128 */ 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,\
  8107. /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04,\
  8108. /* 144 */ 0x04, 0x04,}
  8109. /************** End of opcodes.h *********************************************/
  8110. /************** Continuing where we left off in vdbe.h ***********************/
  8111. /*
  8112. ** Prototypes for the VDBE interface. See comments on the implementation
  8113. ** for a description of what each of these routines does.
  8114. */
  8115. SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(sqlite3*);
  8116. SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe*,int);
  8117. SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int);
  8118. SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
  8119. SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
  8120. SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
  8121. SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
  8122. SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
  8123. SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
  8124. SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, int addr, int P3);
  8125. SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
  8126. SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
  8127. SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr, int N);
  8128. SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
  8129. SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
  8130. SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
  8131. SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*);
  8132. SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe*);
  8133. SQLITE_PRIVATE void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int);
  8134. SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe*);
  8135. SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe*, int);
  8136. SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe*);
  8137. #ifdef SQLITE_DEBUG
  8138. SQLITE_PRIVATE void sqlite3VdbeTrace(Vdbe*,FILE*);
  8139. #endif
  8140. SQLITE_PRIVATE void sqlite3VdbeResetStepResult(Vdbe*);
  8141. SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe*);
  8142. SQLITE_PRIVATE void sqlite3VdbeSetNumCols(Vdbe*,int);
  8143. SQLITE_PRIVATE int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, void(*)(void*));
  8144. SQLITE_PRIVATE void sqlite3VdbeCountChanges(Vdbe*);
  8145. SQLITE_PRIVATE sqlite3 *sqlite3VdbeDb(Vdbe*);
  8146. SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe*, const char *z, int n);
  8147. SQLITE_PRIVATE void sqlite3VdbeSwap(Vdbe*,Vdbe*);
  8148. #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
  8149. SQLITE_PRIVATE int sqlite3VdbeReleaseMemory(int);
  8150. #endif
  8151. SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,
  8152. UnpackedRecord*,int);
  8153. SQLITE_PRIVATE void sqlite3VdbeDeleteUnpackedRecord(UnpackedRecord*);
  8154. SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
  8155. #ifndef NDEBUG
  8156. SQLITE_PRIVATE void sqlite3VdbeComment(Vdbe*, const char*, ...);
  8157. # define VdbeComment(X) sqlite3VdbeComment X
  8158. SQLITE_PRIVATE void sqlite3VdbeNoopComment(Vdbe*, const char*, ...);
  8159. # define VdbeNoopComment(X) sqlite3VdbeNoopComment X
  8160. #else
  8161. # define VdbeComment(X)
  8162. # define VdbeNoopComment(X)
  8163. #endif
  8164. #endif
  8165. /************** End of vdbe.h ************************************************/
  8166. /************** Continuing where we left off in sqliteInt.h ******************/
  8167. /************** Include pager.h in the middle of sqliteInt.h *****************/
  8168. /************** Begin file pager.h *******************************************/
  8169. /*
  8170. ** 2001 September 15
  8171. **
  8172. ** The author disclaims copyright to this source code. In place of
  8173. ** a legal notice, here is a blessing:
  8174. **
  8175. ** May you do good and not evil.
  8176. ** May you find forgiveness for yourself and forgive others.
  8177. ** May you share freely, never taking more than you give.
  8178. **
  8179. *************************************************************************
  8180. ** This header file defines the interface that the sqlite page cache
  8181. ** subsystem. The page cache subsystem reads and writes a file a page
  8182. ** at a time and provides a journal for rollback.
  8183. **
  8184. ** @(#) $Id: pager.h,v 1.93 2009/01/07 15:18:21 danielk1977 Exp $
  8185. */
  8186. #ifndef _PAGER_H_
  8187. #define _PAGER_H_
  8188. /*
  8189. ** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
  8190. ** it must be turned on for each database using "PRAGMA auto_vacuum = 1".
  8191. */
  8192. #ifndef SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT
  8193. #define SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT -1
  8194. #endif
  8195. /*
  8196. ** The type used to represent a page number. The first page in a file
  8197. ** is called page 1. 0 is used to represent "not a page".
  8198. */
  8199. typedef u32 Pgno;
  8200. /*
  8201. ** Each open file is managed by a separate instance of the "Pager" structure.
  8202. */
  8203. typedef struct Pager Pager;
  8204. /*
  8205. ** Handle type for pages.
  8206. */
  8207. typedef struct PgHdr DbPage;
  8208. /*
  8209. ** Allowed values for the flags parameter to sqlite3PagerOpen().
  8210. **
  8211. ** NOTE: This values must match the corresponding BTREE_ values in btree.h.
  8212. */
  8213. #define PAGER_OMIT_JOURNAL 0x0001 /* Do not use a rollback journal */
  8214. #define PAGER_NO_READLOCK 0x0002 /* Omit readlocks on readonly files */
  8215. /*
  8216. ** Valid values for the second argument to sqlite3PagerLockingMode().
  8217. */
  8218. #define PAGER_LOCKINGMODE_QUERY -1
  8219. #define PAGER_LOCKINGMODE_NORMAL 0
  8220. #define PAGER_LOCKINGMODE_EXCLUSIVE 1
  8221. /*
  8222. ** Valid values for the second argument to sqlite3PagerJournalMode().
  8223. */
  8224. #define PAGER_JOURNALMODE_QUERY -1
  8225. #define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */
  8226. #define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */
  8227. #define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */
  8228. #define PAGER_JOURNALMODE_TRUNCATE 3 /* Commit by truncating journal */
  8229. #define PAGER_JOURNALMODE_MEMORY 4 /* In-memory journal file */
  8230. /*
  8231. ** See source code comments for a detailed description of the following
  8232. ** routines:
  8233. */
  8234. SQLITE_PRIVATE int sqlite3PagerOpen(sqlite3_vfs *, Pager **ppPager, const char*, int,int,int);
  8235. SQLITE_PRIVATE void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *);
  8236. SQLITE_PRIVATE void sqlite3PagerSetReiniter(Pager*, void(*)(DbPage*));
  8237. SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u16*);
  8238. SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int);
  8239. SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
  8240. SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int);
  8241. SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager);
  8242. SQLITE_PRIVATE int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
  8243. #define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0)
  8244. SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
  8245. SQLITE_PRIVATE int sqlite3PagerPageRefcount(DbPage*);
  8246. SQLITE_PRIVATE int sqlite3PagerRef(DbPage*);
  8247. SQLITE_PRIVATE int sqlite3PagerUnref(DbPage*);
  8248. SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
  8249. SQLITE_PRIVATE int sqlite3PagerPagecount(Pager*, int*);
  8250. SQLITE_PRIVATE int sqlite3PagerBegin(DbPage*, int exFlag);
  8251. SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int);
  8252. SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
  8253. SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
  8254. SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
  8255. SQLITE_PRIVATE void sqlite3PagerDontRollback(DbPage*);
  8256. SQLITE_PRIVATE int sqlite3PagerDontWrite(DbPage*);
  8257. SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
  8258. SQLITE_PRIVATE void sqlite3PagerSetSafetyLevel(Pager*,int,int);
  8259. SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*);
  8260. SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*);
  8261. SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
  8262. SQLITE_PRIVATE const char *sqlite3PagerDirname(Pager*);
  8263. SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
  8264. SQLITE_PRIVATE int sqlite3PagerNosync(Pager*);
  8265. SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
  8266. SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *);
  8267. SQLITE_PRIVATE void *sqlite3PagerGetExtra(DbPage *);
  8268. SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int);
  8269. SQLITE_PRIVATE int sqlite3PagerJournalMode(Pager *, int);
  8270. SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *, i64);
  8271. SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
  8272. SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager);
  8273. SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
  8274. SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
  8275. #ifndef SQLITE_OMIT_AUTOVACUUM
  8276. SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
  8277. SQLITE_PRIVATE Pgno sqlite3PagerImageSize(Pager *);
  8278. #endif
  8279. #ifdef SQLITE_HAS_CODEC
  8280. SQLITE_PRIVATE void sqlite3PagerSetCodec(Pager*,void*(*)(void*,void*,Pgno,int),void*);
  8281. #endif
  8282. #if !defined(NDEBUG) || defined(SQLITE_TEST)
  8283. SQLITE_PRIVATE Pgno sqlite3PagerPagenumber(DbPage*);
  8284. SQLITE_PRIVATE int sqlite3PagerIswriteable(DbPage*);
  8285. #endif
  8286. #ifdef SQLITE_TEST
  8287. SQLITE_PRIVATE int *sqlite3PagerStats(Pager*);
  8288. SQLITE_PRIVATE void sqlite3PagerRefdump(Pager*);
  8289. SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*);
  8290. #endif
  8291. #ifdef SQLITE_TEST
  8292. void disable_simulated_io_errors(void);
  8293. void enable_simulated_io_errors(void);
  8294. #else
  8295. # define disable_simulated_io_errors()
  8296. # define enable_simulated_io_errors()
  8297. #endif
  8298. #endif /* _PAGER_H_ */
  8299. /************** End of pager.h ***********************************************/
  8300. /************** Continuing where we left off in sqliteInt.h ******************/
  8301. /************** Include pcache.h in the middle of sqliteInt.h ****************/
  8302. /************** Begin file pcache.h ******************************************/
  8303. /*
  8304. ** 2008 August 05
  8305. **
  8306. ** The author disclaims copyright to this source code. In place of
  8307. ** a legal notice, here is a blessing:
  8308. **
  8309. ** May you do good and not evil.
  8310. ** May you find forgiveness for yourself and forgive others.
  8311. ** May you share freely, never taking more than you give.
  8312. **
  8313. *************************************************************************
  8314. ** This header file defines the interface that the sqlite page cache
  8315. ** subsystem.
  8316. **
  8317. ** @(#) $Id: pcache.h,v 1.16 2008/11/19 16:52:44 danielk1977 Exp $
  8318. */
  8319. #ifndef _PCACHE_H_
  8320. typedef struct PgHdr PgHdr;
  8321. typedef struct PCache PCache;
  8322. /*
  8323. ** Every page in the cache is controlled by an instance of the following
  8324. ** structure.
  8325. */
  8326. struct PgHdr {
  8327. void *pData; /* Content of this page */
  8328. void *pExtra; /* Extra content */
  8329. PgHdr *pDirty; /* Transient list of dirty pages */
  8330. Pgno pgno; /* Page number for this page */
  8331. Pager *pPager; /* The pager this page is part of */
  8332. #ifdef SQLITE_CHECK_PAGES
  8333. u32 pageHash; /* Hash of page content */
  8334. #endif
  8335. u16 flags; /* PGHDR flags defined below */
  8336. /**********************************************************************
  8337. ** Elements above are public. All that follows is private to pcache.c
  8338. ** and should not be accessed by other modules.
  8339. */
  8340. i16 nRef; /* Number of users of this page */
  8341. PCache *pCache; /* Cache that owns this page */
  8342. PgHdr *pDirtyNext; /* Next element in list of dirty pages */
  8343. PgHdr *pDirtyPrev; /* Previous element in list of dirty pages */
  8344. };
  8345. /* Bit values for PgHdr.flags */
  8346. #define PGHDR_DIRTY 0x002 /* Page has changed */
  8347. #define PGHDR_NEED_SYNC 0x004 /* Fsync the rollback journal before
  8348. ** writing this page to the database */
  8349. #define PGHDR_NEED_READ 0x008 /* Content is unread */
  8350. #define PGHDR_REUSE_UNLIKELY 0x010 /* A hint that reuse is unlikely */
  8351. #define PGHDR_DONT_WRITE 0x020 /* Do not write content to disk */
  8352. /* Initialize and shutdown the page cache subsystem */
  8353. SQLITE_PRIVATE int sqlite3PcacheInitialize(void);
  8354. SQLITE_PRIVATE void sqlite3PcacheShutdown(void);
  8355. /* Page cache buffer management:
  8356. ** These routines implement SQLITE_CONFIG_PAGECACHE.
  8357. */
  8358. SQLITE_PRIVATE void sqlite3PCacheBufferSetup(void *, int sz, int n);
  8359. /* Create a new pager cache.
  8360. ** Under memory stress, invoke xStress to try to make pages clean.
  8361. ** Only clean and unpinned pages can be reclaimed.
  8362. */
  8363. SQLITE_PRIVATE void sqlite3PcacheOpen(
  8364. int szPage, /* Size of every page */
  8365. int szExtra, /* Extra space associated with each page */
  8366. int bPurgeable, /* True if pages are on backing store */
  8367. int (*xStress)(void*, PgHdr*), /* Call to try to make pages clean */
  8368. void *pStress, /* Argument to xStress */
  8369. PCache *pToInit /* Preallocated space for the PCache */
  8370. );
  8371. /* Modify the page-size after the cache has been created. */
  8372. SQLITE_PRIVATE void sqlite3PcacheSetPageSize(PCache *, int);
  8373. /* Return the size in bytes of a PCache object. Used to preallocate
  8374. ** storage space.
  8375. */
  8376. SQLITE_PRIVATE int sqlite3PcacheSize(void);
  8377. /* One release per successful fetch. Page is pinned until released.
  8378. ** Reference counted.
  8379. */
  8380. SQLITE_PRIVATE int sqlite3PcacheFetch(PCache*, Pgno, int createFlag, PgHdr**);
  8381. SQLITE_PRIVATE void sqlite3PcacheRelease(PgHdr*);
  8382. SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr*); /* Remove page from cache */
  8383. SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr*); /* Make sure page is marked dirty */
  8384. SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr*); /* Mark a single page as clean */
  8385. SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache*); /* Mark all dirty list pages as clean */
  8386. /* Change a page number. Used by incr-vacuum. */
  8387. SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr*, Pgno);
  8388. /* Remove all pages with pgno>x. Reset the cache if x==0 */
  8389. SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache*, Pgno x);
  8390. /* Get a list of all dirty pages in the cache, sorted by page number */
  8391. SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache*);
  8392. /* Reset and close the cache object */
  8393. SQLITE_PRIVATE void sqlite3PcacheClose(PCache*);
  8394. /* Clear flags from pages of the page cache */
  8395. SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *);
  8396. /* Discard the contents of the cache */
  8397. SQLITE_PRIVATE int sqlite3PcacheClear(PCache*);
  8398. /* Return the total number of outstanding page references */
  8399. SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache*);
  8400. /* Increment the reference count of an existing page */
  8401. SQLITE_PRIVATE void sqlite3PcacheRef(PgHdr*);
  8402. SQLITE_PRIVATE int sqlite3PcachePageRefcount(PgHdr*);
  8403. /* Return the total number of pages stored in the cache */
  8404. SQLITE_PRIVATE int sqlite3PcachePagecount(PCache*);
  8405. #ifdef SQLITE_CHECK_PAGES
  8406. /* Iterate through all dirty pages currently stored in the cache. This
  8407. ** interface is only available if SQLITE_CHECK_PAGES is defined when the
  8408. ** library is built.
  8409. */
  8410. SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
  8411. #endif
  8412. /* Set and get the suggested cache-size for the specified pager-cache.
  8413. **
  8414. ** If no global maximum is configured, then the system attempts to limit
  8415. ** the total number of pages cached by purgeable pager-caches to the sum
  8416. ** of the suggested cache-sizes.
  8417. */
  8418. SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *, int);
  8419. #ifdef SQLITE_TEST
  8420. SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *);
  8421. #endif
  8422. #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
  8423. /* Try to return memory used by the pcache module to the main memory heap */
  8424. SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int);
  8425. #endif
  8426. #ifdef SQLITE_TEST
  8427. SQLITE_PRIVATE void sqlite3PcacheStats(int*,int*,int*,int*);
  8428. #endif
  8429. SQLITE_PRIVATE void sqlite3PCacheSetDefault(void);
  8430. #endif /* _PCACHE_H_ */
  8431. /************** End of pcache.h **********************************************/
  8432. /************** Continuing where we left off in sqliteInt.h ******************/
  8433. /************** Include os.h in the middle of sqliteInt.h ********************/
  8434. /************** Begin file os.h **********************************************/
  8435. /*
  8436. ** 2001 September 16
  8437. **
  8438. ** The author disclaims copyright to this source code. In place of
  8439. ** a legal notice, here is a blessing:
  8440. **
  8441. ** May you do good and not evil.
  8442. ** May you find forgiveness for yourself and forgive others.
  8443. ** May you share freely, never taking more than you give.
  8444. **
  8445. ******************************************************************************
  8446. **
  8447. ** This header file (together with is companion C source-code file
  8448. ** "os.c") attempt to abstract the underlying operating system so that
  8449. ** the SQLite library will work on both POSIX and windows systems.
  8450. **
  8451. ** This header file is #include-ed by sqliteInt.h and thus ends up
  8452. ** being included by every source file.
  8453. **
  8454. ** $Id: os.h,v 1.107 2009/01/14 23:03:41 drh Exp $
  8455. */
  8456. #ifndef _SQLITE_OS_H_
  8457. #define _SQLITE_OS_H_
  8458. /*
  8459. ** Figure out if we are dealing with Unix, Windows, or some other
  8460. ** operating system. After the following block of preprocess macros,
  8461. ** all of SQLITE_OS_UNIX, SQLITE_OS_WIN, SQLITE_OS_OS2, and SQLITE_OS_OTHER
  8462. ** will defined to either 1 or 0. One of the four will be 1. The other
  8463. ** three will be 0.
  8464. */
  8465. #if defined(SQLITE_OS_OTHER)
  8466. # if SQLITE_OS_OTHER==1
  8467. # undef SQLITE_OS_UNIX
  8468. # define SQLITE_OS_UNIX 0
  8469. # undef SQLITE_OS_WIN
  8470. # define SQLITE_OS_WIN 0
  8471. # undef SQLITE_OS_OS2
  8472. # define SQLITE_OS_OS2 0
  8473. # else
  8474. # undef SQLITE_OS_OTHER
  8475. # endif
  8476. #endif
  8477. #if !defined(SQLITE_OS_UNIX) && !defined(SQLITE_OS_OTHER)
  8478. # define SQLITE_OS_OTHER 0
  8479. # ifndef SQLITE_OS_WIN
  8480. # if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
  8481. # define SQLITE_OS_WIN 1
  8482. # define SQLITE_OS_UNIX 0
  8483. # define SQLITE_OS_OS2 0
  8484. # elif defined(__EMX__) || defined(_OS2) || defined(OS2) || defined(_OS2_) || defined(__OS2__)
  8485. # define SQLITE_OS_WIN 0
  8486. # define SQLITE_OS_UNIX 0
  8487. # define SQLITE_OS_OS2 1
  8488. # else
  8489. # define SQLITE_OS_WIN 0
  8490. # define SQLITE_OS_UNIX 1
  8491. # define SQLITE_OS_OS2 0
  8492. # endif
  8493. # else
  8494. # define SQLITE_OS_UNIX 0
  8495. # define SQLITE_OS_OS2 0
  8496. # endif
  8497. #else
  8498. # ifndef SQLITE_OS_WIN
  8499. # define SQLITE_OS_WIN 0
  8500. # endif
  8501. #endif
  8502. /*
  8503. ** Determine if we are dealing with WindowsCE - which has a much
  8504. ** reduced API.
  8505. */
  8506. #if defined(_WIN32_WCE)
  8507. # define SQLITE_OS_WINCE 1
  8508. #else
  8509. # define SQLITE_OS_WINCE 0
  8510. #endif
  8511. /*
  8512. ** Define the maximum size of a temporary filename
  8513. */
  8514. #if SQLITE_OS_WIN
  8515. # include <windows.h>
  8516. # define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
  8517. #elif SQLITE_OS_OS2
  8518. # if (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3) && defined(OS2_HIGH_MEMORY)
  8519. # include <os2safe.h> /* has to be included before os2.h for linking to work */
  8520. # endif
  8521. # define INCL_DOSDATETIME
  8522. # define INCL_DOSFILEMGR
  8523. # define INCL_DOSERRORS
  8524. # define INCL_DOSMISC
  8525. # define INCL_DOSPROCESS
  8526. # define INCL_DOSMODULEMGR
  8527. # define INCL_DOSSEMAPHORES
  8528. # include <os2.h>
  8529. # include <uconv.h>
  8530. # define SQLITE_TEMPNAME_SIZE (CCHMAXPATHCOMP)
  8531. #else
  8532. # define SQLITE_TEMPNAME_SIZE 200
  8533. #endif
  8534. /* If the SET_FULLSYNC macro is not defined above, then make it
  8535. ** a no-op
  8536. */
  8537. #ifndef SET_FULLSYNC
  8538. # define SET_FULLSYNC(x,y)
  8539. #endif
  8540. /*
  8541. ** The default size of a disk sector
  8542. */
  8543. #ifndef SQLITE_DEFAULT_SECTOR_SIZE
  8544. # define SQLITE_DEFAULT_SECTOR_SIZE 512
  8545. #endif
  8546. /*
  8547. ** Temporary files are named starting with this prefix followed by 16 random
  8548. ** alphanumeric characters, and no file extension. They are stored in the
  8549. ** OS's standard temporary file directory, and are deleted prior to exit.
  8550. ** If sqlite is being embedded in another program, you may wish to change the
  8551. ** prefix to reflect your program's name, so that if your program exits
  8552. ** prematurely, old temporary files can be easily identified. This can be done
  8553. ** using -DSQLITE_TEMP_FILE_PREFIX=myprefix_ on the compiler command line.
  8554. **
  8555. ** 2006-10-31: The default prefix used to be "sqlite_". But then
  8556. ** Mcafee started using SQLite in their anti-virus product and it
  8557. ** started putting files with the "sqlite" name in the c:/temp folder.
  8558. ** This annoyed many windows users. Those users would then do a
  8559. ** Google search for "sqlite", find the telephone numbers of the
  8560. ** developers and call to wake them up at night and complain.
  8561. ** For this reason, the default name prefix is changed to be "sqlite"
  8562. ** spelled backwards. So the temp files are still identified, but
  8563. ** anybody smart enough to figure out the code is also likely smart
  8564. ** enough to know that calling the developer will not help get rid
  8565. ** of the file.
  8566. */
  8567. #ifndef SQLITE_TEMP_FILE_PREFIX
  8568. # define SQLITE_TEMP_FILE_PREFIX "etilqs_"
  8569. #endif
  8570. /*
  8571. ** The following values may be passed as the second argument to
  8572. ** sqlite3OsLock(). The various locks exhibit the following semantics:
  8573. **
  8574. ** SHARED: Any number of processes may hold a SHARED lock simultaneously.
  8575. ** RESERVED: A single process may hold a RESERVED lock on a file at
  8576. ** any time. Other processes may hold and obtain new SHARED locks.
  8577. ** PENDING: A single process may hold a PENDING lock on a file at
  8578. ** any one time. Existing SHARED locks may persist, but no new
  8579. ** SHARED locks may be obtained by other processes.
  8580. ** EXCLUSIVE: An EXCLUSIVE lock precludes all other locks.
  8581. **
  8582. ** PENDING_LOCK may not be passed directly to sqlite3OsLock(). Instead, a
  8583. ** process that requests an EXCLUSIVE lock may actually obtain a PENDING
  8584. ** lock. This can be upgraded to an EXCLUSIVE lock by a subsequent call to
  8585. ** sqlite3OsLock().
  8586. */
  8587. #define NO_LOCK 0
  8588. #define SHARED_LOCK 1
  8589. #define RESERVED_LOCK 2
  8590. #define PENDING_LOCK 3
  8591. #define EXCLUSIVE_LOCK 4
  8592. /*
  8593. ** File Locking Notes: (Mostly about windows but also some info for Unix)
  8594. **
  8595. ** We cannot use LockFileEx() or UnlockFileEx() on Win95/98/ME because
  8596. ** those functions are not available. So we use only LockFile() and
  8597. ** UnlockFile().
  8598. **
  8599. ** LockFile() prevents not just writing but also reading by other processes.
  8600. ** A SHARED_LOCK is obtained by locking a single randomly-chosen
  8601. ** byte out of a specific range of bytes. The lock byte is obtained at
  8602. ** random so two separate readers can probably access the file at the
  8603. ** same time, unless they are unlucky and choose the same lock byte.
  8604. ** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range.
  8605. ** There can only be one writer. A RESERVED_LOCK is obtained by locking
  8606. ** a single byte of the file that is designated as the reserved lock byte.
  8607. ** A PENDING_LOCK is obtained by locking a designated byte different from
  8608. ** the RESERVED_LOCK byte.
  8609. **
  8610. ** On WinNT/2K/XP systems, LockFileEx() and UnlockFileEx() are available,
  8611. ** which means we can use reader/writer locks. When reader/writer locks
  8612. ** are used, the lock is placed on the same range of bytes that is used
  8613. ** for probabilistic locking in Win95/98/ME. Hence, the locking scheme
  8614. ** will support two or more Win95 readers or two or more WinNT readers.
  8615. ** But a single Win95 reader will lock out all WinNT readers and a single
  8616. ** WinNT reader will lock out all other Win95 readers.
  8617. **
  8618. ** The following #defines specify the range of bytes used for locking.
  8619. ** SHARED_SIZE is the number of bytes available in the pool from which
  8620. ** a random byte is selected for a shared lock. The pool of bytes for
  8621. ** shared locks begins at SHARED_FIRST.
  8622. **
  8623. ** These #defines are available in sqlite_aux.h so that adaptors for
  8624. ** connecting SQLite to other operating systems can use the same byte
  8625. ** ranges for locking. In particular, the same locking strategy and
  8626. ** byte ranges are used for Unix. This leaves open the possiblity of having
  8627. ** clients on win95, winNT, and unix all talking to the same shared file
  8628. ** and all locking correctly. To do so would require that samba (or whatever
  8629. ** tool is being used for file sharing) implements locks correctly between
  8630. ** windows and unix. I'm guessing that isn't likely to happen, but by
  8631. ** using the same locking range we are at least open to the possibility.
  8632. **
  8633. ** Locking in windows is manditory. For this reason, we cannot store
  8634. ** actual data in the bytes used for locking. The pager never allocates
  8635. ** the pages involved in locking therefore. SHARED_SIZE is selected so
  8636. ** that all locks will fit on a single page even at the minimum page size.
  8637. ** PENDING_BYTE defines the beginning of the locks. By default PENDING_BYTE
  8638. ** is set high so that we don't have to allocate an unused page except
  8639. ** for very large databases. But one should test the page skipping logic
  8640. ** by setting PENDING_BYTE low and running the entire regression suite.
  8641. **
  8642. ** Changing the value of PENDING_BYTE results in a subtly incompatible
  8643. ** file format. Depending on how it is changed, you might not notice
  8644. ** the incompatibility right away, even running a full regression test.
  8645. ** The default location of PENDING_BYTE is the first byte past the
  8646. ** 1GB boundary.
  8647. **
  8648. */
  8649. #ifndef SQLITE_TEST
  8650. #define PENDING_BYTE 0x40000000 /* First byte past the 1GB boundary */
  8651. #else
  8652. SQLITE_API extern unsigned int sqlite3_pending_byte;
  8653. #define PENDING_BYTE sqlite3_pending_byte
  8654. #endif
  8655. #define RESERVED_BYTE (PENDING_BYTE+1)
  8656. #define SHARED_FIRST (PENDING_BYTE+2)
  8657. #define SHARED_SIZE 510
  8658. /*
  8659. ** Functions for accessing sqlite3_file methods
  8660. */
  8661. SQLITE_PRIVATE int sqlite3OsClose(sqlite3_file*);
  8662. SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file*, void*, int amt, i64 offset);
  8663. SQLITE_PRIVATE int sqlite3OsWrite(sqlite3_file*, const void*, int amt, i64 offset);
  8664. SQLITE_PRIVATE int sqlite3OsTruncate(sqlite3_file*, i64 size);
  8665. SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file*, int);
  8666. SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file*, i64 *pSize);
  8667. SQLITE_PRIVATE int sqlite3OsLock(sqlite3_file*, int);
  8668. SQLITE_PRIVATE int sqlite3OsUnlock(sqlite3_file*, int);
  8669. SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut);
  8670. SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file*,int,void*);
  8671. #define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0
  8672. SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id);
  8673. SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id);
  8674. /*
  8675. ** Functions for accessing sqlite3_vfs methods
  8676. */
  8677. SQLITE_PRIVATE int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int, int *);
  8678. SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *, const char *, int);
  8679. SQLITE_PRIVATE int sqlite3OsAccess(sqlite3_vfs *, const char *, int, int *pResOut);
  8680. SQLITE_PRIVATE int sqlite3OsFullPathname(sqlite3_vfs *, const char *, int, char *);
  8681. #ifndef SQLITE_OMIT_LOAD_EXTENSION
  8682. SQLITE_PRIVATE void *sqlite3OsDlOpen(sqlite3_vfs *, const char *);
  8683. SQLITE_PRIVATE void sqlite3OsDlError(sqlite3_vfs *, int, char *);
  8684. void (*sqlite3OsDlSym(sqlite3_vfs *, void *, const char *))(void);
  8685. SQLITE_PRIVATE void sqlite3OsDlClose(sqlite3_vfs *, void *);
  8686. #endif /* SQLITE_OMIT_LOAD_EXTENSION */
  8687. SQLITE_PRIVATE int sqlite3OsRandomness(sqlite3_vfs *, int, char *);
  8688. SQLITE_PRIVATE int sqlite3OsSleep(sqlite3_vfs *, int);
  8689. SQLITE_PRIVATE int sqlite3OsCurrentTime(sqlite3_vfs *, double*);
  8690. /*
  8691. ** Convenience functions for opening and closing files using
  8692. ** sqlite3_malloc() to obtain space for the file-handle structure.
  8693. */
  8694. SQLITE_PRIVATE int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int,int*);
  8695. SQLITE_PRIVATE int sqlite3OsCloseFree(sqlite3_file *);
  8696. #endif /* _SQLITE_OS_H_ */
  8697. /************** End of os.h **************************************************/
  8698. /************** Continuing where we left off in sqliteInt.h ******************/
  8699. /************** Include mutex.h in the middle of sqliteInt.h *****************/
  8700. /************** Begin file mutex.h *******************************************/
  8701. /*
  8702. ** 2007 August 28
  8703. **
  8704. ** The author disclaims copyright to this source code. In place of
  8705. ** a legal notice, here is a blessing:
  8706. **
  8707. ** May you do good and not evil.
  8708. ** May you find forgiveness for yourself and forgive others.
  8709. ** May you share freely, never taking more than you give.
  8710. **
  8711. *************************************************************************
  8712. **
  8713. ** This file contains the common header for all mutex implementations.
  8714. ** The sqliteInt.h header #includes this file so that it is available
  8715. ** to all source files. We break it out in an effort to keep the code
  8716. ** better organized.
  8717. **
  8718. ** NOTE: source files should *not* #include this header file directly.
  8719. ** Source files should #include the sqliteInt.h file and let that file
  8720. ** include this one indirectly.
  8721. **
  8722. ** $Id: mutex.h,v 1.9 2008/10/07 15:25:48 drh Exp $
  8723. */
  8724. /*
  8725. ** Figure out what version of the code to use. The choices are
  8726. **
  8727. ** SQLITE_MUTEX_OMIT No mutex logic. Not even stubs. The
  8728. ** mutexes implemention cannot be overridden
  8729. ** at start-time.
  8730. **
  8731. ** SQLITE_MUTEX_NOOP For single-threaded applications. No
  8732. ** mutual exclusion is provided. But this
  8733. ** implementation can be overridden at
  8734. ** start-time.
  8735. **
  8736. ** SQLITE_MUTEX_PTHREADS For multi-threaded applications on Unix.
  8737. **
  8738. ** SQLITE_MUTEX_W32 For multi-threaded applications on Win32.
  8739. **
  8740. ** SQLITE_MUTEX_OS2 For multi-threaded applications on OS/2.
  8741. */
  8742. #if !SQLITE_THREADSAFE
  8743. # define SQLITE_MUTEX_OMIT
  8744. #endif
  8745. #if SQLITE_THREADSAFE && !defined(SQLITE_MUTEX_NOOP)
  8746. # if SQLITE_OS_UNIX
  8747. # define SQLITE_MUTEX_PTHREADS
  8748. # elif SQLITE_OS_WIN
  8749. # define SQLITE_MUTEX_W32
  8750. # elif SQLITE_OS_OS2
  8751. # define SQLITE_MUTEX_OS2
  8752. # else
  8753. # define SQLITE_MUTEX_NOOP
  8754. # endif
  8755. #endif
  8756. #ifdef SQLITE_MUTEX_OMIT
  8757. /*
  8758. ** If this is a no-op implementation, implement everything as macros.
  8759. */
  8760. #define sqlite3_mutex_alloc(X) ((sqlite3_mutex*)8)
  8761. #define sqlite3_mutex_free(X)
  8762. #define sqlite3_mutex_enter(X)
  8763. #define sqlite3_mutex_try(X) SQLITE_OK
  8764. #define sqlite3_mutex_leave(X)
  8765. #define sqlite3_mutex_held(X) 1
  8766. #define sqlite3_mutex_notheld(X) 1
  8767. #define sqlite3MutexAlloc(X) ((sqlite3_mutex*)8)
  8768. #define sqlite3MutexInit() SQLITE_OK
  8769. #define sqlite3MutexEnd()
  8770. #endif /* defined(SQLITE_OMIT_MUTEX) */
  8771. /************** End of mutex.h ***********************************************/
  8772. /************** Continuing where we left off in sqliteInt.h ******************/
  8773. /*
  8774. ** Each database file to be accessed by the system is an instance
  8775. ** of the following structure. There are normally two of these structures
  8776. ** in the sqlite.aDb[] array. aDb[0] is the main database file and
  8777. ** aDb[1] is the database file used to hold temporary tables. Additional
  8778. ** databases may be attached.
  8779. */
  8780. struct Db {
  8781. char *zName; /* Name of this database */
  8782. Btree *pBt; /* The B*Tree structure for this database file */
  8783. u8 inTrans; /* 0: not writable. 1: Transaction. 2: Checkpoint */
  8784. u8 safety_level; /* How aggressive at syncing data to disk */
  8785. void *pAux; /* Auxiliary data. Usually NULL */
  8786. void (*xFreeAux)(void*); /* Routine to free pAux */
  8787. Schema *pSchema; /* Pointer to database schema (possibly shared) */
  8788. };
  8789. /*
  8790. ** An instance of the following structure stores a database schema.
  8791. **
  8792. ** If there are no virtual tables configured in this schema, the
  8793. ** Schema.db variable is set to NULL. After the first virtual table
  8794. ** has been added, it is set to point to the database connection
  8795. ** used to create the connection. Once a virtual table has been
  8796. ** added to the Schema structure and the Schema.db variable populated,
  8797. ** only that database connection may use the Schema to prepare
  8798. ** statements.
  8799. */
  8800. struct Schema {
  8801. int schema_cookie; /* Database schema version number for this file */
  8802. Hash tblHash; /* All tables indexed by name */
  8803. Hash idxHash; /* All (named) indices indexed by name */
  8804. Hash trigHash; /* All triggers indexed by name */
  8805. Hash aFKey; /* Foreign keys indexed by to-table */
  8806. Table *pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */
  8807. u8 file_format; /* Schema format version for this file */
  8808. u8 enc; /* Text encoding used by this database */
  8809. u16 flags; /* Flags associated with this schema */
  8810. int cache_size; /* Number of pages to use in the cache */
  8811. #ifndef SQLITE_OMIT_VIRTUALTABLE
  8812. sqlite3 *db; /* "Owner" connection. See comment above */
  8813. #endif
  8814. };
  8815. /*
  8816. ** These macros can be used to test, set, or clear bits in the
  8817. ** Db.flags field.
  8818. */
  8819. #define DbHasProperty(D,I,P) (((D)->aDb[I].pSchema->flags&(P))==(P))
  8820. #define DbHasAnyProperty(D,I,P) (((D)->aDb[I].pSchema->flags&(P))!=0)
  8821. #define DbSetProperty(D,I,P) (D)->aDb[I].pSchema->flags|=(P)
  8822. #define DbClearProperty(D,I,P) (D)->aDb[I].pSchema->flags&=~(P)
  8823. /*
  8824. ** Allowed values for the DB.flags field.
  8825. **
  8826. ** The DB_SchemaLoaded flag is set after the database schema has been
  8827. ** read into internal hash tables.
  8828. **
  8829. ** DB_UnresetViews means that one or more views have column names that
  8830. ** have been filled out. If the schema changes, these column names might
  8831. ** changes and so the view will need to be reset.
  8832. */
  8833. #define DB_SchemaLoaded 0x0001 /* The schema has been loaded */
  8834. #define DB_UnresetViews 0x0002 /* Some views have defined column names */
  8835. #define DB_Empty 0x0004 /* The file is empty (length 0 bytes) */
  8836. /*
  8837. ** The number of different kinds of things that can be limited
  8838. ** using the sqlite3_limit() interface.
  8839. */
  8840. #define SQLITE_N_LIMIT (SQLITE_LIMIT_VARIABLE_NUMBER+1)
  8841. /*
  8842. ** Lookaside malloc is a set of fixed-size buffers that can be used
  8843. ** to satisfy small transient memory allocation requests for objects
  8844. ** associated with a particular database connection. The use of
  8845. ** lookaside malloc provides a significant performance enhancement
  8846. ** (approx 10%) by avoiding numerous malloc/free requests while parsing
  8847. ** SQL statements.
  8848. **
  8849. ** The Lookaside structure holds configuration information about the
  8850. ** lookaside malloc subsystem. Each available memory allocation in
  8851. ** the lookaside subsystem is stored on a linked list of LookasideSlot
  8852. ** objects.
  8853. */
  8854. struct Lookaside {
  8855. u16 sz; /* Size of each buffer in bytes */
  8856. u8 bEnabled; /* True if use lookaside. False to ignore it */
  8857. u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */
  8858. int nOut; /* Number of buffers currently checked out */
  8859. int mxOut; /* Highwater mark for nOut */
  8860. LookasideSlot *pFree; /* List of available buffers */
  8861. void *pStart; /* First byte of available memory space */
  8862. void *pEnd; /* First byte past end of available space */
  8863. };
  8864. struct LookasideSlot {
  8865. LookasideSlot *pNext; /* Next buffer in the list of free buffers */
  8866. };
  8867. /*
  8868. ** A hash table for function definitions.
  8869. **
  8870. ** Hash each FuncDef structure into one of the FuncDefHash.a[] slots.
  8871. ** Collisions are on the FuncDef.pHash chain.
  8872. */
  8873. struct FuncDefHash {
  8874. FuncDef *a[23]; /* Hash table for functions */
  8875. };
  8876. /*
  8877. ** Each database is an instance of the following structure.
  8878. **
  8879. ** The sqlite.lastRowid records the last insert rowid generated by an
  8880. ** insert statement. Inserts on views do not affect its value. Each
  8881. ** trigger has its own context, so that lastRowid can be updated inside
  8882. ** triggers as usual. The previous value will be restored once the trigger
  8883. ** exits. Upon entering a before or instead of trigger, lastRowid is no
  8884. ** longer (since after version 2.8.12) reset to -1.
  8885. **
  8886. ** The sqlite.nChange does not count changes within triggers and keeps no
  8887. ** context. It is reset at start of sqlite3_exec.
  8888. ** The sqlite.lsChange represents the number of changes made by the last
  8889. ** insert, update, or delete statement. It remains constant throughout the
  8890. ** length of a statement and is then updated by OP_SetCounts. It keeps a
  8891. ** context stack just like lastRowid so that the count of changes
  8892. ** within a trigger is not seen outside the trigger. Changes to views do not
  8893. ** affect the value of lsChange.
  8894. ** The sqlite.csChange keeps track of the number of current changes (since
  8895. ** the last statement) and is used to update sqlite_lsChange.
  8896. **
  8897. ** The member variables sqlite.errCode, sqlite.zErrMsg and sqlite.zErrMsg16
  8898. ** store the most recent error code and, if applicable, string. The
  8899. ** internal function sqlite3Error() is used to set these variables
  8900. ** consistently.
  8901. */
  8902. struct sqlite3 {
  8903. sqlite3_vfs *pVfs; /* OS Interface */
  8904. int nDb; /* Number of backends currently in use */
  8905. Db *aDb; /* All backends */
  8906. int flags; /* Miscellaneous flags. See below */
  8907. int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
  8908. int errCode; /* Most recent error code (SQLITE_*) */
  8909. int errMask; /* & result codes with this before returning */
  8910. u8 autoCommit; /* The auto-commit flag. */
  8911. u8 temp_store; /* 1: file 2: memory 0: default */
  8912. u8 mallocFailed; /* True if we have seen a malloc failure */
  8913. u8 dfltLockMode; /* Default locking-mode for attached dbs */
  8914. u8 dfltJournalMode; /* Default journal mode for attached dbs */
  8915. signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
  8916. int nextPagesize; /* Pagesize after VACUUM if >0 */
  8917. int nTable; /* Number of tables in the database */
  8918. CollSeq *pDfltColl; /* The default collating sequence (BINARY) */
  8919. i64 lastRowid; /* ROWID of most recent insert (see above) */
  8920. i64 priorNewRowid; /* Last randomly generated ROWID */
  8921. u32 magic; /* Magic number for detect library misuse */
  8922. int nChange; /* Value returned by sqlite3_changes() */
  8923. int nTotalChange; /* Value returned by sqlite3_total_changes() */
  8924. sqlite3_mutex *mutex; /* Connection mutex */
  8925. int aLimit[SQLITE_N_LIMIT]; /* Limits */
  8926. struct sqlite3InitInfo { /* Information used during initialization */
  8927. int iDb; /* When back is being initialized */
  8928. int newTnum; /* Rootpage of table being initialized */
  8929. u8 busy; /* TRUE if currently initializing */
  8930. } init;
  8931. int nExtension; /* Number of loaded extensions */
  8932. void **aExtension; /* Array of shared library handles */
  8933. struct Vdbe *pVdbe; /* List of active virtual machines */
  8934. int activeVdbeCnt; /* Number of VDBEs currently executing */
  8935. int writeVdbeCnt; /* Number of active VDBEs that are writing */
  8936. void (*xTrace)(void*,const char*); /* Trace function */
  8937. void *pTraceArg; /* Argument to the trace function */
  8938. void (*xProfile)(void*,const char*,u64); /* Profiling function */
  8939. void *pProfileArg; /* Argument to profile function */
  8940. void *pCommitArg; /* Argument to xCommitCallback() */
  8941. int (*xCommitCallback)(void*); /* Invoked at every commit. */
  8942. void *pRollbackArg; /* Argument to xRollbackCallback() */
  8943. void (*xRollbackCallback)(void*); /* Invoked at every commit. */
  8944. void *pUpdateArg;
  8945. void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64);
  8946. void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
  8947. void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
  8948. void *pCollNeededArg;
  8949. sqlite3_value *pErr; /* Most recent error message */
  8950. char *zErrMsg; /* Most recent error message (UTF-8 encoded) */
  8951. char *zErrMsg16; /* Most recent error message (UTF-16 encoded) */
  8952. union {
  8953. volatile int isInterrupted; /* True if sqlite3_interrupt has been called */
  8954. double notUsed1; /* Spacer */
  8955. } u1;
  8956. Lookaside lookaside; /* Lookaside malloc configuration */
  8957. #ifndef SQLITE_OMIT_AUTHORIZATION
  8958. int (*xAuth)(void*,int,const char*,const char*,const char*,const char*);
  8959. /* Access authorization function */
  8960. void *pAuthArg; /* 1st argument to the access auth function */
  8961. #endif
  8962. #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
  8963. int (*xProgress)(void *); /* The progress callback */
  8964. void *pProgressArg; /* Argument to the progress callback */
  8965. int nProgressOps; /* Number of opcodes for progress callback */
  8966. #endif
  8967. #ifndef SQLITE_OMIT_VIRTUALTABLE
  8968. Hash aModule; /* populated by sqlite3_create_module() */
  8969. Table *pVTab; /* vtab with active Connect/Create method */
  8970. sqlite3_vtab **aVTrans; /* Virtual tables with open transactions */
  8971. int nVTrans; /* Allocated size of aVTrans */
  8972. #endif
  8973. FuncDefHash aFunc; /* Hash table of connection functions */
  8974. Hash aCollSeq; /* All collating sequences */
  8975. BusyHandler busyHandler; /* Busy callback */
  8976. int busyTimeout; /* Busy handler timeout, in msec */
  8977. Db aDbStatic[2]; /* Static space for the 2 default backends */
  8978. #ifdef SQLITE_SSE
  8979. sqlite3_stmt *pFetch; /* Used by SSE to fetch stored statements */
  8980. #endif
  8981. Savepoint *pSavepoint; /* List of active savepoints */
  8982. int nSavepoint; /* Number of non-transaction savepoints */
  8983. u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */
  8984. };
  8985. /*
  8986. ** A macro to discover the encoding of a database.
  8987. */
  8988. #define ENC(db) ((db)->aDb[0].pSchema->enc)
  8989. /*
  8990. ** Possible values for the sqlite.flags and or Db.flags fields.
  8991. **
  8992. ** On sqlite.flags, the SQLITE_InTrans value means that we have
  8993. ** executed a BEGIN. On Db.flags, SQLITE_InTrans means a statement
  8994. ** transaction is active on that particular database file.
  8995. */
  8996. #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
  8997. #define SQLITE_InTrans 0x00000008 /* True if in a transaction */
  8998. #define SQLITE_InternChanges 0x00000010 /* Uncommitted Hash table changes */
  8999. #define SQLITE_FullColNames 0x00000020 /* Show full column names on SELECT */
  9000. #define SQLITE_ShortColNames 0x00000040 /* Show short columns names */
  9001. #define SQLITE_CountRows 0x00000080 /* Count rows changed by INSERT, */
  9002. /* DELETE, or UPDATE and return */
  9003. /* the count using a callback. */
  9004. #define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */
  9005. /* result set is empty */
  9006. #define SQLITE_SqlTrace 0x00000200 /* Debug print SQL as it executes */
  9007. #define SQLITE_VdbeListing 0x00000400 /* Debug listings of VDBE programs */
  9008. #define SQLITE_WriteSchema 0x00000800 /* OK to update SQLITE_MASTER */
  9009. #define SQLITE_NoReadlock 0x00001000 /* Readlocks are omitted when
  9010. ** accessing read-only databases */
  9011. #define SQLITE_IgnoreChecks 0x00002000 /* Do not enforce check constraints */
  9012. #define SQLITE_ReadUncommitted 0x00004000 /* For shared-cache mode */
  9013. #define SQLITE_LegacyFileFmt 0x00008000 /* Create new databases in format 1 */
  9014. #define SQLITE_FullFSync 0x00010000 /* Use full fsync on the backend */
  9015. #define SQLITE_LoadExtension 0x00020000 /* Enable load_extension */
  9016. #define SQLITE_RecoveryMode 0x00040000 /* Ignore schema errors */
  9017. #define SQLITE_SharedCache 0x00080000 /* Cache sharing is enabled */
  9018. #define SQLITE_Vtab 0x00100000 /* There exists a virtual table */
  9019. #define SQLITE_CommitBusy 0x00200000 /* In the process of committing */
  9020. /*
  9021. ** Possible values for the sqlite.magic field.
  9022. ** The numbers are obtained at random and have no special meaning, other
  9023. ** than being distinct from one another.
  9024. */
  9025. #define SQLITE_MAGIC_OPEN 0xa029a697 /* Database is open */
  9026. #define SQLITE_MAGIC_CLOSED 0x9f3c2d33 /* Database is closed */
  9027. #define SQLITE_MAGIC_SICK 0x4b771290 /* Error and awaiting close */
  9028. #define SQLITE_MAGIC_BUSY 0xf03b7906 /* Database currently in use */
  9029. #define SQLITE_MAGIC_ERROR 0xb5357930 /* An SQLITE_MISUSE error occurred */
  9030. /*
  9031. ** Each SQL function is defined by an instance of the following
  9032. ** structure. A pointer to this structure is stored in the sqlite.aFunc
  9033. ** hash table. When multiple functions have the same name, the hash table
  9034. ** points to a linked list of these structures.
  9035. */
  9036. struct FuncDef {
  9037. i16 nArg; /* Number of arguments. -1 means unlimited */
  9038. u8 iPrefEnc; /* Preferred text encoding (SQLITE_UTF8, 16LE, 16BE) */
  9039. u8 flags; /* Some combination of SQLITE_FUNC_* */
  9040. void *pUserData; /* User data parameter */
  9041. FuncDef *pNext; /* Next function with same name */
  9042. void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */
  9043. void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */
  9044. void (*xFinalize)(sqlite3_context*); /* Aggregate finalizer */
  9045. char *zName; /* SQL name of the function. */
  9046. FuncDef *pHash; /* Next with a different name but the same hash */
  9047. };
  9048. /*
  9049. ** Possible values for FuncDef.flags
  9050. */
  9051. #define SQLITE_FUNC_LIKE 0x01 /* Candidate for the LIKE optimization */
  9052. #define SQLITE_FUNC_CASE 0x02 /* Case-sensitive LIKE-type function */
  9053. #define SQLITE_FUNC_EPHEM 0x04 /* Ephemeral. Delete with VDBE */
  9054. #define SQLITE_FUNC_NEEDCOLL 0x08 /* sqlite3GetFuncCollSeq() might be called */
  9055. #define SQLITE_FUNC_PRIVATE 0x10 /* Allowed for internal use only */
  9056. /*
  9057. ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
  9058. ** used to create the initializers for the FuncDef structures.
  9059. **
  9060. ** FUNCTION(zName, nArg, iArg, bNC, xFunc)
  9061. ** Used to create a scalar function definition of a function zName
  9062. ** implemented by C function xFunc that accepts nArg arguments. The
  9063. ** value passed as iArg is cast to a (void*) and made available
  9064. ** as the user-data (sqlite3_user_data()) for the function. If
  9065. ** argument bNC is true, then the FuncDef.needCollate flag is set.
  9066. **
  9067. ** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
  9068. ** Used to create an aggregate function definition implemented by
  9069. ** the C functions xStep and xFinal. The first four parameters
  9070. ** are interpreted in the same way as the first 4 parameters to
  9071. ** FUNCTION().
  9072. **
  9073. ** LIKEFUNC(zName, nArg, pArg, flags)
  9074. ** Used to create a scalar function definition of a function zName
  9075. ** that accepts nArg arguments and is implemented by a call to C
  9076. ** function likeFunc. Argument pArg is cast to a (void *) and made
  9077. ** available as the function user-data (sqlite3_user_data()). The
  9078. ** FuncDef.flags variable is set to the value passed as the flags
  9079. ** parameter.
  9080. */
  9081. #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
  9082. {nArg, SQLITE_UTF8, bNC*8, SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0}
  9083. #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
  9084. {nArg, SQLITE_UTF8, bNC*8, pArg, 0, xFunc, 0, 0, #zName, 0}
  9085. #define LIKEFUNC(zName, nArg, arg, flags) \
  9086. {nArg, SQLITE_UTF8, flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0}
  9087. #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
  9088. {nArg, SQLITE_UTF8, nc*8, SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0}
  9089. /*
  9090. ** All current savepoints are stored in a linked list starting at
  9091. ** sqlite3.pSavepoint. The first element in the list is the most recently
  9092. ** opened savepoint. Savepoints are added to the list by the vdbe
  9093. ** OP_Savepoint instruction.
  9094. */
  9095. struct Savepoint {
  9096. char *zName; /* Savepoint name (nul-terminated) */
  9097. Savepoint *pNext; /* Parent savepoint (if any) */
  9098. };
  9099. /*
  9100. ** The following are used as the second parameter to sqlite3Savepoint(),
  9101. ** and as the P1 argument to the OP_Savepoint instruction.
  9102. */
  9103. #define SAVEPOINT_BEGIN 0
  9104. #define SAVEPOINT_RELEASE 1
  9105. #define SAVEPOINT_ROLLBACK 2
  9106. /*
  9107. ** Each SQLite module (virtual table definition) is defined by an
  9108. ** instance of the following structure, stored in the sqlite3.aModule
  9109. ** hash table.
  9110. */
  9111. struct Module {
  9112. const sqlite3_module *pModule; /* Callback pointers */
  9113. const char *zName; /* Name passed to create_module() */
  9114. void *pAux; /* pAux passed to create_module() */
  9115. void (*xDestroy)(void *); /* Module destructor function */
  9116. };
  9117. /*
  9118. ** information about each column of an SQL table is held in an instance
  9119. ** of this structure.
  9120. */
  9121. struct Column {
  9122. char *zName; /* Name of this column */
  9123. Expr *pDflt; /* Default value of this column */
  9124. char *zType; /* Data type for this column */
  9125. char *zColl; /* Collating sequence. If NULL, use the default */
  9126. u8 notNull; /* True if there is a NOT NULL constraint */
  9127. u8 isPrimKey; /* True if this column is part of the PRIMARY KEY */
  9128. char affinity; /* One of the SQLITE_AFF_... values */
  9129. #ifndef SQLITE_OMIT_VIRTUALTABLE
  9130. u8 isHidden; /* True if this column is 'hidden' */
  9131. #endif
  9132. };
  9133. /*
  9134. ** A "Collating Sequence" is defined by an instance of the following
  9135. ** structure. Conceptually, a collating sequence consists of a name and
  9136. ** a comparison routine that defines the order of that sequence.
  9137. **
  9138. ** There may two separate implementations of the collation function, one
  9139. ** that processes text in UTF-8 encoding (CollSeq.xCmp) and another that
  9140. ** processes text encoded in UTF-16 (CollSeq.xCmp16), using the machine
  9141. ** native byte order. When a collation sequence is invoked, SQLite selects
  9142. ** the version that will require the least expensive encoding
  9143. ** translations, if any.
  9144. **
  9145. ** The CollSeq.pUser member variable is an extra parameter that passed in
  9146. ** as the first argument to the UTF-8 comparison function, xCmp.
  9147. ** CollSeq.pUser16 is the equivalent for the UTF-16 comparison function,
  9148. ** xCmp16.
  9149. **
  9150. ** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the
  9151. ** collating sequence is undefined. Indices built on an undefined
  9152. ** collating sequence may not be read or written.
  9153. */
  9154. struct CollSeq {
  9155. char *zName; /* Name of the collating sequence, UTF-8 encoded */
  9156. u8 enc; /* Text encoding handled by xCmp() */
  9157. u8 type; /* One of the SQLITE_COLL_... values below */
  9158. void *pUser; /* First argument to xCmp() */
  9159. int (*xCmp)(void*,int, const void*, int, const void*);
  9160. void (*xDel)(void*); /* Destructor for pUser */
  9161. };
  9162. /*
  9163. ** Allowed values of CollSeq.type:
  9164. */
  9165. #define SQLITE_COLL_BINARY 1 /* The default memcmp() collating sequence */
  9166. #define SQLITE_COLL_NOCASE 2 /* The built-in NOCASE collating sequence */
  9167. #define SQLITE_COLL_REVERSE 3 /* The built-in REVERSE collating sequence */
  9168. #define SQLITE_COLL_USER 0 /* Any other user-defined collating sequence */
  9169. /*
  9170. ** A sort order can be either ASC or DESC.
  9171. */
  9172. #define SQLITE_SO_ASC 0 /* Sort in ascending order */
  9173. #define SQLITE_SO_DESC 1 /* Sort in ascending order */
  9174. /*
  9175. ** Column affinity types.
  9176. **
  9177. ** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and
  9178. ** 't' for SQLITE_AFF_TEXT. But we can save a little space and improve
  9179. ** the speed a little by numbering the values consecutively.
  9180. **
  9181. ** But rather than start with 0 or 1, we begin with 'a'. That way,
  9182. ** when multiple affinity types are concatenated into a string and
  9183. ** used as the P4 operand, they will be more readable.
  9184. **
  9185. ** Note also that the numeric types are grouped together so that testing
  9186. ** for a numeric type is a single comparison.
  9187. */
  9188. #define SQLITE_AFF_TEXT 'a'
  9189. #define SQLITE_AFF_NONE 'b'
  9190. #define SQLITE_AFF_NUMERIC 'c'
  9191. #define SQLITE_AFF_INTEGER 'd'
  9192. #define SQLITE_AFF_REAL 'e'
  9193. #define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC)
  9194. /*
  9195. ** The SQLITE_AFF_MASK values masks off the significant bits of an
  9196. ** affinity value.
  9197. */
  9198. #define SQLITE_AFF_MASK 0x67
  9199. /*
  9200. ** Additional bit values that can be ORed with an affinity without
  9201. ** changing the affinity.
  9202. */
  9203. #define SQLITE_JUMPIFNULL 0x08 /* jumps if either operand is NULL */
  9204. #define SQLITE_STOREP2 0x10 /* Store result in reg[P2] rather than jump */
  9205. /*
  9206. ** Each SQL table is represented in memory by an instance of the
  9207. ** following structure.
  9208. **
  9209. ** Table.zName is the name of the table. The case of the original
  9210. ** CREATE TABLE statement is stored, but case is not significant for
  9211. ** comparisons.
  9212. **
  9213. ** Table.nCol is the number of columns in this table. Table.aCol is a
  9214. ** pointer to an array of Column structures, one for each column.
  9215. **
  9216. ** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of
  9217. ** the column that is that key. Otherwise Table.iPKey is negative. Note
  9218. ** that the datatype of the PRIMARY KEY must be INTEGER for this field to
  9219. ** be set. An INTEGER PRIMARY KEY is used as the rowid for each row of
  9220. ** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid
  9221. ** is generated for each row of the table. TF_HasPrimaryKey is set if
  9222. ** the table has any PRIMARY KEY, INTEGER or otherwise.
  9223. **
  9224. ** Table.tnum is the page number for the root BTree page of the table in the
  9225. ** database file. If Table.iDb is the index of the database table backend
  9226. ** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that
  9227. ** holds temporary tables and indices. If TF_Ephemeral is set
  9228. ** then the table is stored in a file that is automatically deleted
  9229. ** when the VDBE cursor to the table is closed. In this case Table.tnum
  9230. ** refers VDBE cursor number that holds the table open, not to the root
  9231. ** page number. Transient tables are used to hold the results of a
  9232. ** sub-query that appears instead of a real table name in the FROM clause
  9233. ** of a SELECT statement.
  9234. */
  9235. struct Table {
  9236. sqlite3 *db; /* Associated database connection. Might be NULL. */
  9237. char *zName; /* Name of the table or view */
  9238. int iPKey; /* If not negative, use aCol[iPKey] as the primary key */
  9239. int nCol; /* Number of columns in this table */
  9240. Column *aCol; /* Information about each column */
  9241. Index *pIndex; /* List of SQL indexes on this table. */
  9242. int tnum; /* Root BTree node for this table (see note above) */
  9243. Select *pSelect; /* NULL for tables. Points to definition if a view. */
  9244. u16 nRef; /* Number of pointers to this Table */
  9245. u8 tabFlags; /* Mask of TF_* values */
  9246. u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
  9247. Trigger *pTrigger; /* List of SQL triggers on this table */
  9248. FKey *pFKey; /* Linked list of all foreign keys in this table */
  9249. char *zColAff; /* String defining the affinity of each column */
  9250. #ifndef SQLITE_OMIT_CHECK
  9251. Expr *pCheck; /* The AND of all CHECK constraints */
  9252. #endif
  9253. #ifndef SQLITE_OMIT_ALTERTABLE
  9254. int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
  9255. #endif
  9256. #ifndef SQLITE_OMIT_VIRTUALTABLE
  9257. Module *pMod; /* Pointer to the implementation of the module */
  9258. sqlite3_vtab *pVtab; /* Pointer to the module instance */
  9259. int nModuleArg; /* Number of arguments to the module */
  9260. char **azModuleArg; /* Text of all module args. [0] is module name */
  9261. #endif
  9262. Schema *pSchema; /* Schema that contains this table */
  9263. Table *pNextZombie; /* Next on the Parse.pZombieTab list */
  9264. };
  9265. /*
  9266. ** Allowed values for Tabe.tabFlags.
  9267. */
  9268. #define TF_Readonly 0x01 /* Read-only system table */
  9269. #define TF_Ephemeral 0x02 /* An ephemeral table */
  9270. #define TF_HasPrimaryKey 0x04 /* Table has a primary key */
  9271. #define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */
  9272. #define TF_Virtual 0x10 /* Is a virtual table */
  9273. #define TF_NeedMetadata 0x20 /* aCol[].zType and aCol[].pColl missing */
  9274. /*
  9275. ** Test to see whether or not a table is a virtual table. This is
  9276. ** done as a macro so that it will be optimized out when virtual
  9277. ** table support is omitted from the build.
  9278. */
  9279. #ifndef SQLITE_OMIT_VIRTUALTABLE
  9280. # define IsVirtual(X) (((X)->tabFlags & TF_Virtual)!=0)
  9281. # define IsHiddenColumn(X) ((X)->isHidden)
  9282. #else
  9283. # define IsVirtual(X) 0
  9284. # define IsHiddenColumn(X) 0
  9285. #endif
  9286. /*
  9287. ** Each foreign key constraint is an instance of the following structure.
  9288. **
  9289. ** A foreign key is associated with two tables. The "from" table is
  9290. ** the table that contains the REFERENCES clause that creates the foreign
  9291. ** key. The "to" table is the table that is named in the REFERENCES clause.
  9292. ** Consider this example:
  9293. **
  9294. ** CREATE TABLE ex1(
  9295. ** a INTEGER PRIMARY KEY,
  9296. ** b INTEGER CONSTRAINT fk1 REFERENCES ex2(x)
  9297. ** );
  9298. **
  9299. ** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2".
  9300. **
  9301. ** Each REFERENCES clause generates an instance of the following structure
  9302. ** which is attached to the from-table. The to-table need not exist when
  9303. ** the from-table is created. The existence of the to-table is not checked
  9304. ** until an attempt is made to insert data into the from-table.
  9305. **
  9306. ** The sqlite.aFKey hash table stores pointers to this structure
  9307. ** given the name of a to-table. For each to-table, all foreign keys
  9308. ** associated with that table are on a linked list using the FKey.pNextTo
  9309. ** field.
  9310. */
  9311. struct FKey {
  9312. Table *pFrom; /* The table that contains the REFERENCES clause */
  9313. FKey *pNextFrom; /* Next foreign key in pFrom */
  9314. char *zTo; /* Name of table that the key points to */
  9315. FKey *pNextTo; /* Next foreign key that points to zTo */
  9316. int nCol; /* Number of columns in this key */
  9317. struct sColMap { /* Mapping of columns in pFrom to columns in zTo */
  9318. int iFrom; /* Index of column in pFrom */
  9319. char *zCol; /* Name of column in zTo. If 0 use PRIMARY KEY */
  9320. } *aCol; /* One entry for each of nCol column s */
  9321. u8 isDeferred; /* True if constraint checking is deferred till COMMIT */
  9322. u8 updateConf; /* How to resolve conflicts that occur on UPDATE */
  9323. u8 deleteConf; /* How to resolve conflicts that occur on DELETE */
  9324. u8 insertConf; /* How to resolve conflicts that occur on INSERT */
  9325. };
  9326. /*
  9327. ** SQLite supports many different ways to resolve a constraint
  9328. ** error. ROLLBACK processing means that a constraint violation
  9329. ** causes the operation in process to fail and for the current transaction
  9330. ** to be rolled back. ABORT processing means the operation in process
  9331. ** fails and any prior changes from that one operation are backed out,
  9332. ** but the transaction is not rolled back. FAIL processing means that
  9333. ** the operation in progress stops and returns an error code. But prior
  9334. ** changes due to the same operation are not backed out and no rollback
  9335. ** occurs. IGNORE means that the particular row that caused the constraint
  9336. ** error is not inserted or updated. Processing continues and no error
  9337. ** is returned. REPLACE means that preexisting database rows that caused
  9338. ** a UNIQUE constraint violation are removed so that the new insert or
  9339. ** update can proceed. Processing continues and no error is reported.
  9340. **
  9341. ** RESTRICT, SETNULL, and CASCADE actions apply only to foreign keys.
  9342. ** RESTRICT is the same as ABORT for IMMEDIATE foreign keys and the
  9343. ** same as ROLLBACK for DEFERRED keys. SETNULL means that the foreign
  9344. ** key is set to NULL. CASCADE means that a DELETE or UPDATE of the
  9345. ** referenced table row is propagated into the row that holds the
  9346. ** foreign key.
  9347. **
  9348. ** The following symbolic values are used to record which type
  9349. ** of action to take.
  9350. */
  9351. #define OE_None 0 /* There is no constraint to check */
  9352. #define OE_Rollback 1 /* Fail the operation and rollback the transaction */
  9353. #define OE_Abort 2 /* Back out changes but do no rollback transaction */
  9354. #define OE_Fail 3 /* Stop the operation but leave all prior changes */
  9355. #define OE_Ignore 4 /* Ignore the error. Do not do the INSERT or UPDATE */
  9356. #define OE_Replace 5 /* Delete existing record, then do INSERT or UPDATE */
  9357. #define OE_Restrict 6 /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */
  9358. #define OE_SetNull 7 /* Set the foreign key value to NULL */
  9359. #define OE_SetDflt 8 /* Set the foreign key value to its default */
  9360. #define OE_Cascade 9 /* Cascade the changes */
  9361. #define OE_Default 99 /* Do whatever the default action is */
  9362. /*
  9363. ** An instance of the following structure is passed as the first
  9364. ** argument to sqlite3VdbeKeyCompare and is used to control the
  9365. ** comparison of the two index keys.
  9366. */
  9367. struct KeyInfo {
  9368. sqlite3 *db; /* The database connection */
  9369. u8 enc; /* Text encoding - one of the TEXT_Utf* values */
  9370. u16 nField; /* Number of entries in aColl[] */
  9371. u8 *aSortOrder; /* If defined an aSortOrder[i] is true, sort DESC */
  9372. CollSeq *aColl[1]; /* Collating sequence for each term of the key */
  9373. };
  9374. /*
  9375. ** An instance of the following structure holds information about a
  9376. ** single index record that has already been parsed out into individual
  9377. ** values.
  9378. **
  9379. ** A record is an object that contains one or more fields of data.
  9380. ** Records are used to store the content of a table row and to store
  9381. ** the key of an index. A blob encoding of a record is created by
  9382. ** the OP_MakeRecord opcode of the VDBE and is disassembled by the
  9383. ** OP_Column opcode.
  9384. **
  9385. ** This structure holds a record that has already been disassembled
  9386. ** into its constituent fields.
  9387. */
  9388. struct UnpackedRecord {
  9389. KeyInfo *pKeyInfo; /* Collation and sort-order information */
  9390. u16 nField; /* Number of entries in apMem[] */
  9391. u16 flags; /* Boolean settings. UNPACKED_... below */
  9392. Mem *aMem; /* Values */
  9393. };
  9394. /*
  9395. ** Allowed values of UnpackedRecord.flags
  9396. */
  9397. #define UNPACKED_NEED_FREE 0x0001 /* Memory is from sqlite3Malloc() */
  9398. #define UNPACKED_NEED_DESTROY 0x0002 /* apMem[]s should all be destroyed */
  9399. #define UNPACKED_IGNORE_ROWID 0x0004 /* Ignore trailing rowid on key1 */
  9400. #define UNPACKED_INCRKEY 0x0008 /* Make this key an epsilon larger */
  9401. #define UNPACKED_PREFIX_MATCH 0x0010 /* A prefix match is considered OK */
  9402. /*
  9403. ** Each SQL index is represented in memory by an
  9404. ** instance of the following structure.
  9405. **
  9406. ** The columns of the table that are to be indexed are described
  9407. ** by the aiColumn[] field of this structure. For example, suppose
  9408. ** we have the following table and index:
  9409. **
  9410. ** CREATE TABLE Ex1(c1 int, c2 int, c3 text);
  9411. ** CREATE INDEX Ex2 ON Ex1(c3,c1);
  9412. **
  9413. ** In the Table structure describing Ex1, nCol==3 because there are
  9414. ** three columns in the table. In the Index structure describing
  9415. ** Ex2, nColumn==2 since 2 of the 3 columns of Ex1 are indexed.
  9416. ** The value of aiColumn is {2, 0}. aiColumn[0]==2 because the
  9417. ** first column to be indexed (c3) has an index of 2 in Ex1.aCol[].
  9418. ** The second column to be indexed (c1) has an index of 0 in
  9419. ** Ex1.aCol[], hence Ex2.aiColumn[1]==0.
  9420. **
  9421. ** The Index.onError field determines whether or not the indexed columns
  9422. ** must be unique and what to do if they are not. When Index.onError=OE_None,
  9423. ** it means this is not a unique index. Otherwise it is a unique index
  9424. ** and the value of Index.onError indicate the which conflict resolution
  9425. ** algorithm to employ whenever an attempt is made to insert a non-unique
  9426. ** element.
  9427. */
  9428. struct Index {
  9429. char *zName; /* Name of this index */
  9430. int nColumn; /* Number of columns in the table used by this index */
  9431. int *aiColumn; /* Which columns are used by this index. 1st is 0 */
  9432. unsigned *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */
  9433. Table *pTable; /* The SQL table being indexed */
  9434. int tnum; /* Page containing root of this index in database file */
  9435. u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
  9436. u8 autoIndex; /* True if is automatically created (ex: by UNIQUE) */
  9437. char *zColAff; /* String defining the affinity of each column */
  9438. Index *pNext; /* The next index associated with the same table */
  9439. Schema *pSchema; /* Schema containing this index */
  9440. u8 *aSortOrder; /* Array of size Index.nColumn. True==DESC, False==ASC */
  9441. char **azColl; /* Array of collation sequence names for index */
  9442. };
  9443. /*
  9444. ** Each token coming out of the lexer is an instance of
  9445. ** this structure. Tokens are also used as part of an expression.
  9446. **
  9447. ** Note if Token.z==0 then Token.dyn and Token.n are undefined and
  9448. ** may contain random values. Do not make any assumptions about Token.dyn
  9449. ** and Token.n when Token.z==0.
  9450. */
  9451. struct Token {
  9452. const unsigned char *z; /* Text of the token. Not NULL-terminated! */
  9453. unsigned dyn : 1; /* True for malloced memory, false for static */
  9454. unsigned n : 31; /* Number of characters in this token */
  9455. };
  9456. /*
  9457. ** An instance of this structure contains information needed to generate
  9458. ** code for a SELECT that contains aggregate functions.
  9459. **
  9460. ** If Expr.op==TK_AGG_COLUMN or TK_AGG_FUNCTION then Expr.pAggInfo is a
  9461. ** pointer to this structure. The Expr.iColumn field is the index in
  9462. ** AggInfo.aCol[] or AggInfo.aFunc[] of information needed to generate
  9463. ** code for that node.
  9464. **
  9465. ** AggInfo.pGroupBy and AggInfo.aFunc.pExpr point to fields within the
  9466. ** original Select structure that describes the SELECT statement. These
  9467. ** fields do not need to be freed when deallocating the AggInfo structure.
  9468. */
  9469. struct AggInfo {
  9470. u8 directMode; /* Direct rendering mode means take data directly
  9471. ** from source tables rather than from accumulators */
  9472. u8 useSortingIdx; /* In direct mode, reference the sorting index rather
  9473. ** than the source table */
  9474. int sortingIdx; /* Cursor number of the sorting index */
  9475. ExprList *pGroupBy; /* The group by clause */
  9476. int nSortingColumn; /* Number of columns in the sorting index */
  9477. struct AggInfo_col { /* For each column used in source tables */
  9478. Table *pTab; /* Source table */
  9479. int iTable; /* Cursor number of the source table */
  9480. int iColumn; /* Column number within the source table */
  9481. int iSorterColumn; /* Column number in the sorting index */
  9482. int iMem; /* Memory location that acts as accumulator */
  9483. Expr *pExpr; /* The original expression */
  9484. } *aCol;
  9485. int nColumn; /* Number of used entries in aCol[] */
  9486. int nColumnAlloc; /* Number of slots allocated for aCol[] */
  9487. int nAccumulator; /* Number of columns that show through to the output.
  9488. ** Additional columns are used only as parameters to
  9489. ** aggregate functions */
  9490. struct AggInfo_func { /* For each aggregate function */
  9491. Expr *pExpr; /* Expression encoding the function */
  9492. FuncDef *pFunc; /* The aggregate function implementation */
  9493. int iMem; /* Memory location that acts as accumulator */
  9494. int iDistinct; /* Ephemeral table used to enforce DISTINCT */
  9495. } *aFunc;
  9496. int nFunc; /* Number of entries in aFunc[] */
  9497. int nFuncAlloc; /* Number of slots allocated for aFunc[] */
  9498. };
  9499. /*
  9500. ** Each node of an expression in the parse tree is an instance
  9501. ** of this structure.
  9502. **
  9503. ** Expr.op is the opcode. The integer parser token codes are reused
  9504. ** as opcodes here. For example, the parser defines TK_GE to be an integer
  9505. ** code representing the ">=" operator. This same integer code is reused
  9506. ** to represent the greater-than-or-equal-to operator in the expression
  9507. ** tree.
  9508. **
  9509. ** Expr.pRight and Expr.pLeft are subexpressions. Expr.pList is a list
  9510. ** of argument if the expression is a function.
  9511. **
  9512. ** Expr.token is the operator token for this node. For some expressions
  9513. ** that have subexpressions, Expr.token can be the complete text that gave
  9514. ** rise to the Expr. In the latter case, the token is marked as being
  9515. ** a compound token.
  9516. **
  9517. ** An expression of the form ID or ID.ID refers to a column in a table.
  9518. ** For such expressions, Expr.op is set to TK_COLUMN and Expr.iTable is
  9519. ** the integer cursor number of a VDBE cursor pointing to that table and
  9520. ** Expr.iColumn is the column number for the specific column. If the
  9521. ** expression is used as a result in an aggregate SELECT, then the
  9522. ** value is also stored in the Expr.iAgg column in the aggregate so that
  9523. ** it can be accessed after all aggregates are computed.
  9524. **
  9525. ** If the expression is a function, the Expr.iTable is an integer code
  9526. ** representing which function. If the expression is an unbound variable
  9527. ** marker (a question mark character '?' in the original SQL) then the
  9528. ** Expr.iTable holds the index number for that variable.
  9529. **
  9530. ** If the expression is a subquery then Expr.iColumn holds an integer
  9531. ** register number containing the result of the subquery. If the
  9532. ** subquery gives a constant result, then iTable is -1. If the subquery
  9533. ** gives a different answer at different times during statement processing
  9534. ** then iTable is the address of a subroutine that computes the subquery.
  9535. **
  9536. ** The Expr.pSelect field points to a SELECT statement. The SELECT might
  9537. ** be the right operand of an IN operator. Or, if a scalar SELECT appears
  9538. ** in an expression the opcode is TK_SELECT and Expr.pSelect is the only
  9539. ** operand.
  9540. **
  9541. ** If the Expr is of type OP_Column, and the table it is selecting from
  9542. ** is a disk table or the "old.*" pseudo-table, then pTab points to the
  9543. ** corresponding table definition.
  9544. */
  9545. struct Expr {
  9546. u8 op; /* Operation performed by this node */
  9547. char affinity; /* The affinity of the column or 0 if not a column */
  9548. u16 flags; /* Various flags. See below */
  9549. CollSeq *pColl; /* The collation type of the column or 0 */
  9550. Expr *pLeft, *pRight; /* Left and right subnodes */
  9551. ExprList *pList; /* A list of expressions used as function arguments
  9552. ** or in "<expr> IN (<expr-list)" */
  9553. Token token; /* An operand token */
  9554. Token span; /* Complete text of the expression */
  9555. int iTable, iColumn; /* When op==TK_COLUMN, then this expr node means the
  9556. ** iColumn-th field of the iTable-th table. */
  9557. AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
  9558. int iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
  9559. int iRightJoinTable; /* If EP_FromJoin, the right table of the join */
  9560. Select *pSelect; /* When the expression is a sub-select. Also the
  9561. ** right side of "<expr> IN (<select>)" */
  9562. Table *pTab; /* Table for TK_COLUMN expressions. */
  9563. #if SQLITE_MAX_EXPR_DEPTH>0
  9564. int nHeight; /* Height of the tree headed by this node */
  9565. #endif
  9566. };
  9567. /*
  9568. ** The following are the meanings of bits in the Expr.flags field.
  9569. */
  9570. #define EP_FromJoin 0x0001 /* Originated in ON or USING clause of a join */
  9571. #define EP_Agg 0x0002 /* Contains one or more aggregate functions */
  9572. #define EP_Resolved 0x0004 /* IDs have been resolved to COLUMNs */
  9573. #define EP_Error 0x0008 /* Expression contains one or more errors */
  9574. #define EP_Distinct 0x0010 /* Aggregate function with DISTINCT keyword */
  9575. #define EP_VarSelect 0x0020 /* pSelect is correlated, not constant */
  9576. #define EP_Dequoted 0x0040 /* True if the string has been dequoted */
  9577. #define EP_InfixFunc 0x0080 /* True for an infix function: LIKE, GLOB, etc */
  9578. #define EP_ExpCollate 0x0100 /* Collating sequence specified explicitly */
  9579. #define EP_AnyAff 0x0200 /* Can take a cached column of any affinity */
  9580. #define EP_FixedDest 0x0400 /* Result needed in a specific register */
  9581. #define EP_IntValue 0x0800 /* Integer value contained in iTable */
  9582. /*
  9583. ** These macros can be used to test, set, or clear bits in the
  9584. ** Expr.flags field.
  9585. */
  9586. #define ExprHasProperty(E,P) (((E)->flags&(P))==(P))
  9587. #define ExprHasAnyProperty(E,P) (((E)->flags&(P))!=0)
  9588. #define ExprSetProperty(E,P) (E)->flags|=(P)
  9589. #define ExprClearProperty(E,P) (E)->flags&=~(P)
  9590. /*
  9591. ** A list of expressions. Each expression may optionally have a
  9592. ** name. An expr/name combination can be used in several ways, such
  9593. ** as the list of "expr AS ID" fields following a "SELECT" or in the
  9594. ** list of "ID = expr" items in an UPDATE. A list of expressions can
  9595. ** also be used as the argument to a function, in which case the a.zName
  9596. ** field is not used.
  9597. */
  9598. struct ExprList {
  9599. int nExpr; /* Number of expressions on the list */
  9600. int nAlloc; /* Number of entries allocated below */
  9601. int iECursor; /* VDBE Cursor associated with this ExprList */
  9602. struct ExprList_item {
  9603. Expr *pExpr; /* The list of expressions */
  9604. char *zName; /* Token associated with this expression */
  9605. u8 sortOrder; /* 1 for DESC or 0 for ASC */
  9606. u8 done; /* A flag to indicate when processing is finished */
  9607. u16 iCol; /* For ORDER BY, column number in result set */
  9608. u16 iAlias; /* Index into Parse.aAlias[] for zName */
  9609. } *a; /* One entry for each expression */
  9610. };
  9611. /*
  9612. ** An instance of this structure can hold a simple list of identifiers,
  9613. ** such as the list "a,b,c" in the following statements:
  9614. **
  9615. ** INSERT INTO t(a,b,c) VALUES ...;
  9616. ** CREATE INDEX idx ON t(a,b,c);
  9617. ** CREATE TRIGGER trig BEFORE UPDATE ON t(a,b,c) ...;
  9618. **
  9619. ** The IdList.a.idx field is used when the IdList represents the list of
  9620. ** column names after a table name in an INSERT statement. In the statement
  9621. **
  9622. ** INSERT INTO t(a,b,c) ...
  9623. **
  9624. ** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
  9625. */
  9626. struct IdList {
  9627. struct IdList_item {
  9628. char *zName; /* Name of the identifier */
  9629. int idx; /* Index in some Table.aCol[] of a column named zName */
  9630. } *a;
  9631. int nId; /* Number of identifiers on the list */
  9632. int nAlloc; /* Number of entries allocated for a[] below */
  9633. };
  9634. /*
  9635. ** The bitmask datatype defined below is used for various optimizations.
  9636. **
  9637. ** Changing this from a 64-bit to a 32-bit type limits the number of
  9638. ** tables in a join to 32 instead of 64. But it also reduces the size
  9639. ** of the library by 738 bytes on ix86.
  9640. */
  9641. typedef u64 Bitmask;
  9642. /*
  9643. ** The number of bits in a Bitmask. "BMS" means "BitMask Size".
  9644. */
  9645. #define BMS ((int)(sizeof(Bitmask)*8))
  9646. /*
  9647. ** The following structure describes the FROM clause of a SELECT statement.
  9648. ** Each table or subquery in the FROM clause is a separate element of
  9649. ** the SrcList.a[] array.
  9650. **
  9651. ** With the addition of multiple database support, the following structure
  9652. ** can also be used to describe a particular table such as the table that
  9653. ** is modified by an INSERT, DELETE, or UPDATE statement. In standard SQL,
  9654. ** such a table must be a simple name: ID. But in SQLite, the table can
  9655. ** now be identified by a database name, a dot, then the table name: ID.ID.
  9656. **
  9657. ** The jointype starts out showing the join type between the current table
  9658. ** and the next table on the list. The parser builds the list this way.
  9659. ** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each
  9660. ** jointype expresses the join between the table and the previous table.
  9661. */
  9662. struct SrcList {
  9663. i16 nSrc; /* Number of tables or subqueries in the FROM clause */
  9664. i16 nAlloc; /* Number of entries allocated in a[] below */
  9665. struct SrcList_item {
  9666. char *zDatabase; /* Name of database holding this table */
  9667. char *zName; /* Name of the table */
  9668. char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */
  9669. Table *pTab; /* An SQL table corresponding to zName */
  9670. Select *pSelect; /* A SELECT statement used in place of a table name */
  9671. u8 isPopulated; /* Temporary table associated with SELECT is populated */
  9672. u8 jointype; /* Type of join between this able and the previous */
  9673. u8 notIndexed; /* True if there is a NOT INDEXED clause */
  9674. int iCursor; /* The VDBE cursor number used to access this table */
  9675. Expr *pOn; /* The ON clause of a join */
  9676. IdList *pUsing; /* The USING clause of a join */
  9677. Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
  9678. char *zIndex; /* Identifier from "INDEXED BY <zIndex>" clause */
  9679. Index *pIndex; /* Index structure corresponding to zIndex, if any */
  9680. } a[1]; /* One entry for each identifier on the list */
  9681. };
  9682. /*
  9683. ** Permitted values of the SrcList.a.jointype field
  9684. */
  9685. #define JT_INNER 0x0001 /* Any kind of inner or cross join */
  9686. #define JT_CROSS 0x0002 /* Explicit use of the CROSS keyword */
  9687. #define JT_NATURAL 0x0004 /* True for a "natural" join */
  9688. #define JT_LEFT 0x0008 /* Left outer join */
  9689. #define JT_RIGHT 0x0010 /* Right outer join */
  9690. #define JT_OUTER 0x0020 /* The "OUTER" keyword is present */
  9691. #define JT_ERROR 0x0040 /* unknown or unsupported join type */
  9692. /*
  9693. ** A WherePlan object holds information that describes a lookup
  9694. ** strategy.
  9695. **
  9696. ** This object is intended to be opaque outside of the where.c module.
  9697. ** It is included here only so that that compiler will know how big it
  9698. ** is. None of the fields in this object should be used outside of
  9699. ** the where.c module.
  9700. **
  9701. ** Within the union, pIdx is only used when wsFlags&WHERE_INDEXED is true.
  9702. ** pTerm is only used when wsFlags&WHERE_MULTI_OR is true. And pVtabIdx
  9703. ** is only used when wsFlags&WHERE_VIRTUALTABLE is true. It is never the
  9704. ** case that more than one of these conditions is true.
  9705. */
  9706. struct WherePlan {
  9707. u32 wsFlags; /* WHERE_* flags that describe the strategy */
  9708. u32 nEq; /* Number of == constraints */
  9709. union {
  9710. Index *pIdx; /* Index when WHERE_INDEXED is true */
  9711. struct WhereTerm *pTerm; /* WHERE clause term for OR-search */
  9712. sqlite3_index_info *pVtabIdx; /* Virtual table index to use */
  9713. } u;
  9714. };
  9715. /*
  9716. ** For each nested loop in a WHERE clause implementation, the WhereInfo
  9717. ** structure contains a single instance of this structure. This structure
  9718. ** is intended to be private the the where.c module and should not be
  9719. ** access or modified by other modules.
  9720. **
  9721. ** The pIdxInfo field is used to help pick the best index on a
  9722. ** virtual table. The pIdxInfo pointer contains indexing
  9723. ** information for the i-th table in the FROM clause before reordering.
  9724. ** All the pIdxInfo pointers are freed by whereInfoFree() in where.c.
  9725. ** All other information in the i-th WhereLevel object for the i-th table
  9726. ** after FROM clause ordering.
  9727. */
  9728. struct WhereLevel {
  9729. WherePlan plan; /* query plan for this element of the FROM clause */
  9730. int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
  9731. int iTabCur; /* The VDBE cursor used to access the table */
  9732. int iIdxCur; /* The VDBE cursor used to access pIdx */
  9733. int addrBrk; /* Jump here to break out of the loop */
  9734. int addrNxt; /* Jump here to start the next IN combination */
  9735. int addrCont; /* Jump here to continue with the next loop cycle */
  9736. int addrFirst; /* First instruction of interior of the loop */
  9737. u8 iFrom; /* Which entry in the FROM clause */
  9738. u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */
  9739. int p1, p2; /* Operands of the opcode used to ends the loop */
  9740. union { /* Information that depends on plan.wsFlags */
  9741. struct {
  9742. int nIn; /* Number of entries in aInLoop[] */
  9743. struct InLoop {
  9744. int iCur; /* The VDBE cursor used by this IN operator */
  9745. int addrInTop; /* Top of the IN loop */
  9746. } *aInLoop; /* Information about each nested IN operator */
  9747. } in; /* Used when plan.wsFlags&WHERE_IN_ABLE */
  9748. struct {
  9749. WherePlan *aPlan; /* Plans for each term of the WHERE clause */
  9750. } or; /* Used when plan.wsFlags&WHERE_MULTI_OR */
  9751. } u;
  9752. /* The following field is really not part of the current level. But
  9753. ** we need a place to cache virtual table index information for each
  9754. ** virtual table in the FROM clause and the WhereLevel structure is
  9755. ** a convenient place since there is one WhereLevel for each FROM clause
  9756. ** element.
  9757. */
  9758. sqlite3_index_info *pIdxInfo; /* Index info for n-th source table */
  9759. };
  9760. /*
  9761. ** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin().
  9762. */
  9763. #define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
  9764. #define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
  9765. #define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
  9766. #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
  9767. #define WHERE_FILL_ROWSET 0x0008 /* Save results in a RowSet object */
  9768. #define WHERE_OMIT_OPEN 0x0010 /* Table cursor are already open */
  9769. #define WHERE_OMIT_CLOSE 0x0020 /* Omit close of table & index cursors */
  9770. /*
  9771. ** The WHERE clause processing routine has two halves. The
  9772. ** first part does the start of the WHERE loop and the second
  9773. ** half does the tail of the WHERE loop. An instance of
  9774. ** this structure is returned by the first half and passed
  9775. ** into the second half to give some continuity.
  9776. */
  9777. struct WhereInfo {
  9778. Parse *pParse; /* Parsing and code generating context */
  9779. u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
  9780. u8 okOnePass; /* Ok to use one-pass algorithm for UPDATE or DELETE */
  9781. int regRowSet; /* Store rowids in this rowset if >=0 */
  9782. SrcList *pTabList; /* List of tables in the join */
  9783. int iTop; /* The very beginning of the WHERE loop */
  9784. int iContinue; /* Jump here to continue with next record */
  9785. int iBreak; /* Jump here to break out of the loop */
  9786. int nLevel; /* Number of nested loop */
  9787. struct WhereClause *pWC; /* Decomposition of the WHERE clause */
  9788. WhereLevel a[1]; /* Information about each nest loop in WHERE */
  9789. };
  9790. /*
  9791. ** A NameContext defines a context in which to resolve table and column
  9792. ** names. The context consists of a list of tables (the pSrcList) field and
  9793. ** a list of named expression (pEList). The named expression list may
  9794. ** be NULL. The pSrc corresponds to the FROM clause of a SELECT or
  9795. ** to the table being operated on by INSERT, UPDATE, or DELETE. The
  9796. ** pEList corresponds to the result set of a SELECT and is NULL for
  9797. ** other statements.
  9798. **
  9799. ** NameContexts can be nested. When resolving names, the inner-most
  9800. ** context is searched first. If no match is found, the next outer
  9801. ** context is checked. If there is still no match, the next context
  9802. ** is checked. This process continues until either a match is found
  9803. ** or all contexts are check. When a match is found, the nRef member of
  9804. ** the context containing the match is incremented.
  9805. **
  9806. ** Each subquery gets a new NameContext. The pNext field points to the
  9807. ** NameContext in the parent query. Thus the process of scanning the
  9808. ** NameContext list corresponds to searching through successively outer
  9809. ** subqueries looking for a match.
  9810. */
  9811. struct NameContext {
  9812. Parse *pParse; /* The parser */
  9813. SrcList *pSrcList; /* One or more tables used to resolve names */
  9814. ExprList *pEList; /* Optional list of named expressions */
  9815. int nRef; /* Number of names resolved by this context */
  9816. int nErr; /* Number of errors encountered while resolving names */
  9817. u8 allowAgg; /* Aggregate functions allowed here */
  9818. u8 hasAgg; /* True if aggregates are seen */
  9819. u8 isCheck; /* True if resolving names in a CHECK constraint */
  9820. int nDepth; /* Depth of subquery recursion. 1 for no recursion */
  9821. AggInfo *pAggInfo; /* Information about aggregates at this level */
  9822. NameContext *pNext; /* Next outer name context. NULL for outermost */
  9823. };
  9824. /*
  9825. ** An instance of the following structure contains all information
  9826. ** needed to generate code for a single SELECT statement.
  9827. **
  9828. ** nLimit is set to -1 if there is no LIMIT clause. nOffset is set to 0.
  9829. ** If there is a LIMIT clause, the parser sets nLimit to the value of the
  9830. ** limit and nOffset to the value of the offset (or 0 if there is not
  9831. ** offset). But later on, nLimit and nOffset become the memory locations
  9832. ** in the VDBE that record the limit and offset counters.
  9833. **
  9834. ** addrOpenEphm[] entries contain the address of OP_OpenEphemeral opcodes.
  9835. ** These addresses must be stored so that we can go back and fill in
  9836. ** the P4_KEYINFO and P2 parameters later. Neither the KeyInfo nor
  9837. ** the number of columns in P2 can be computed at the same time
  9838. ** as the OP_OpenEphm instruction is coded because not
  9839. ** enough information about the compound query is known at that point.
  9840. ** The KeyInfo for addrOpenTran[0] and [1] contains collating sequences
  9841. ** for the result set. The KeyInfo for addrOpenTran[2] contains collating
  9842. ** sequences for the ORDER BY clause.
  9843. */
  9844. struct Select {
  9845. ExprList *pEList; /* The fields of the result */
  9846. u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
  9847. char affinity; /* MakeRecord with this affinity for SRT_Set */
  9848. u16 selFlags; /* Various SF_* values */
  9849. SrcList *pSrc; /* The FROM clause */
  9850. Expr *pWhere; /* The WHERE clause */
  9851. ExprList *pGroupBy; /* The GROUP BY clause */
  9852. Expr *pHaving; /* The HAVING clause */
  9853. ExprList *pOrderBy; /* The ORDER BY clause */
  9854. Select *pPrior; /* Prior select in a compound select statement */
  9855. Select *pNext; /* Next select to the left in a compound */
  9856. Select *pRightmost; /* Right-most select in a compound select statement */
  9857. Expr *pLimit; /* LIMIT expression. NULL means not used. */
  9858. Expr *pOffset; /* OFFSET expression. NULL means not used. */
  9859. int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */
  9860. int addrOpenEphm[3]; /* OP_OpenEphem opcodes related to this select */
  9861. };
  9862. /*
  9863. ** Allowed values for Select.selFlags. The "SF" prefix stands for
  9864. ** "Select Flag".
  9865. */
  9866. #define SF_Distinct 0x0001 /* Output should be DISTINCT */
  9867. #define SF_Resolved 0x0002 /* Identifiers have been resolved */
  9868. #define SF_Aggregate 0x0004 /* Contains aggregate functions */
  9869. #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
  9870. #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
  9871. #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
  9872. /*
  9873. ** The results of a select can be distributed in several ways. The
  9874. ** "SRT" prefix means "SELECT Result Type".
  9875. */
  9876. #define SRT_Union 1 /* Store result as keys in an index */
  9877. #define SRT_Except 2 /* Remove result from a UNION index */
  9878. #define SRT_Exists 3 /* Store 1 if the result is not empty */
  9879. #define SRT_Discard 4 /* Do not save the results anywhere */
  9880. /* The ORDER BY clause is ignored for all of the above */
  9881. #define IgnorableOrderby(X) ((X->eDest)<=SRT_Discard)
  9882. #define SRT_Output 5 /* Output each row of result */
  9883. #define SRT_Mem 6 /* Store result in a memory cell */
  9884. #define SRT_Set 7 /* Store results as keys in an index */
  9885. #define SRT_Table 8 /* Store result as data with an automatic rowid */
  9886. #define SRT_EphemTab 9 /* Create transient tab and store like SRT_Table */
  9887. #define SRT_Coroutine 10 /* Generate a single row of result */
  9888. /*
  9889. ** A structure used to customize the behavior of sqlite3Select(). See
  9890. ** comments above sqlite3Select() for details.
  9891. */
  9892. typedef struct SelectDest SelectDest;
  9893. struct SelectDest {
  9894. u8 eDest; /* How to dispose of the results */
  9895. u8 affinity; /* Affinity used when eDest==SRT_Set */
  9896. int iParm; /* A parameter used by the eDest disposal method */
  9897. int iMem; /* Base register where results are written */
  9898. int nMem; /* Number of registers allocated */
  9899. };
  9900. /*
  9901. ** An SQL parser context. A copy of this structure is passed through
  9902. ** the parser and down into all the parser action routine in order to
  9903. ** carry around information that is global to the entire parse.
  9904. **
  9905. ** The structure is divided into two parts. When the parser and code
  9906. ** generate call themselves recursively, the first part of the structure
  9907. ** is constant but the second part is reset at the beginning and end of
  9908. ** each recursion.
  9909. **
  9910. ** The nTableLock and aTableLock variables are only used if the shared-cache
  9911. ** feature is enabled (if sqlite3Tsd()->useSharedData is true). They are
  9912. ** used to store the set of table-locks required by the statement being
  9913. ** compiled. Function sqlite3TableLock() is used to add entries to the
  9914. ** list.
  9915. */
  9916. struct Parse {
  9917. sqlite3 *db; /* The main database structure */
  9918. int rc; /* Return code from execution */
  9919. char *zErrMsg; /* An error message */
  9920. Vdbe *pVdbe; /* An engine for executing database bytecode */
  9921. u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */
  9922. u8 nameClash; /* A permanent table name clashes with temp table name */
  9923. u8 checkSchema; /* Causes schema cookie check after an error */
  9924. u8 nested; /* Number of nested calls to the parser/code generator */
  9925. u8 parseError; /* True after a parsing error. Ticket #1794 */
  9926. u8 nTempReg; /* Number of temporary registers in aTempReg[] */
  9927. u8 nTempInUse; /* Number of aTempReg[] currently checked out */
  9928. int aTempReg[8]; /* Holding area for temporary registers */
  9929. int nRangeReg; /* Size of the temporary register block */
  9930. int iRangeReg; /* First register in temporary register block */
  9931. int nErr; /* Number of errors seen */
  9932. int nTab; /* Number of previously allocated VDBE cursors */
  9933. int nMem; /* Number of memory cells used so far */
  9934. int nSet; /* Number of sets used so far */
  9935. int ckBase; /* Base register of data during check constraints */
  9936. int disableColCache; /* True to disable adding to column cache */
  9937. int nColCache; /* Number of entries in the column cache */
  9938. int iColCache; /* Next entry of the cache to replace */
  9939. struct yColCache {
  9940. int iTable; /* Table cursor number */
  9941. int iColumn; /* Table column number */
  9942. char affChange; /* True if this register has had an affinity change */
  9943. int iReg; /* Register holding value of this column */
  9944. } aColCache[10]; /* One for each valid column cache entry */
  9945. u32 writeMask; /* Start a write transaction on these databases */
  9946. u32 cookieMask; /* Bitmask of schema verified databases */
  9947. int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
  9948. int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */
  9949. #ifndef SQLITE_OMIT_SHARED_CACHE
  9950. int nTableLock; /* Number of locks in aTableLock */
  9951. TableLock *aTableLock; /* Required table locks for shared-cache mode */
  9952. #endif
  9953. int regRowid; /* Register holding rowid of CREATE TABLE entry */
  9954. int regRoot; /* Register holding root page number for new objects */
  9955. /* Above is constant between recursions. Below is reset before and after
  9956. ** each recursion */
  9957. int nVar; /* Number of '?' variables seen in the SQL so far */
  9958. int nVarExpr; /* Number of used slots in apVarExpr[] */
  9959. int nVarExprAlloc; /* Number of allocated slots in apVarExpr[] */
  9960. Expr **apVarExpr; /* Pointers to :aaa and $aaaa wildcard expressions */
  9961. int nAlias; /* Number of aliased result set columns */
  9962. int nAliasAlloc; /* Number of allocated slots for aAlias[] */
  9963. int *aAlias; /* Register used to hold aliased result */
  9964. u8 explain; /* True if the EXPLAIN flag is found on the query */
  9965. Token sErrToken; /* The token at which the error occurred */
  9966. Token sNameToken; /* Token with unqualified schema object name */
  9967. Token sLastToken; /* The last token parsed */
  9968. const char *zSql; /* All SQL text */
  9969. const char *zTail; /* All SQL text past the last semicolon parsed */
  9970. Table *pNewTable; /* A table being constructed by CREATE TABLE */
  9971. Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */
  9972. TriggerStack *trigStack; /* Trigger actions being coded */
  9973. const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
  9974. #ifndef SQLITE_OMIT_VIRTUALTABLE
  9975. Token sArg; /* Complete text of a module argument */
  9976. u8 declareVtab; /* True if inside sqlite3_declare_vtab() */
  9977. int nVtabLock; /* Number of virtual tables to lock */
  9978. Table **apVtabLock; /* Pointer to virtual tables needing locking */
  9979. #endif
  9980. int nHeight; /* Expression tree height of current sub-select */
  9981. Table *pZombieTab; /* List of Table objects to delete after code gen */
  9982. };
  9983. #ifdef SQLITE_OMIT_VIRTUALTABLE
  9984. #define IN_DECLARE_VTAB 0
  9985. #else
  9986. #define IN_DECLARE_VTAB (pParse->declareVtab)
  9987. #endif
  9988. /*
  9989. ** An instance of the following structure can be declared on a stack and used
  9990. ** to save the Parse.zAuthContext value so that it can be restored later.
  9991. */
  9992. struct AuthContext {
  9993. const char *zAuthContext; /* Put saved Parse.zAuthContext here */
  9994. Parse *pParse; /* The Parse structure */
  9995. };
  9996. /*
  9997. ** Bitfield flags for P2 value in OP_Insert and OP_Delete
  9998. */
  9999. #define OPFLAG_NCHANGE 1 /* Set to update db->nChange */
  10000. #define OPFLAG_LASTROWID 2 /* Set to update db->lastRowid */
  10001. #define OPFLAG_ISUPDATE 4 /* This OP_Insert is an sql UPDATE */
  10002. #define OPFLAG_APPEND 8 /* This is likely to be an append */
  10003. /*
  10004. * Each trigger present in the database schema is stored as an instance of
  10005. * struct Trigger.
  10006. *
  10007. * Pointers to instances of struct Trigger are stored in two ways.
  10008. * 1. In the "trigHash" hash table (part of the sqlite3* that represents the
  10009. * database). This allows Trigger structures to be retrieved by name.
  10010. * 2. All triggers associated with a single table form a linked list, using the
  10011. * pNext member of struct Trigger. A pointer to the first element of the
  10012. * linked list is stored as the "pTrigger" member of the associated
  10013. * struct Table.
  10014. *
  10015. * The "step_list" member points to the first element of a linked list
  10016. * containing the SQL statements specified as the trigger program.
  10017. */
  10018. struct Trigger {
  10019. char *name; /* The name of the trigger */
  10020. char *table; /* The table or view to which the trigger applies */
  10021. u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */
  10022. u8 tr_tm; /* One of TRIGGER_BEFORE, TRIGGER_AFTER */
  10023. Expr *pWhen; /* The WHEN clause of the expression (may be NULL) */
  10024. IdList *pColumns; /* If this is an UPDATE OF <column-list> trigger,
  10025. the <column-list> is stored here */
  10026. Token nameToken; /* Token containing zName. Use during parsing only */
  10027. Schema *pSchema; /* Schema containing the trigger */
  10028. Schema *pTabSchema; /* Schema containing the table */
  10029. TriggerStep *step_list; /* Link list of trigger program steps */
  10030. Trigger *pNext; /* Next trigger associated with the table */
  10031. };
  10032. /*
  10033. ** A trigger is either a BEFORE or an AFTER trigger. The following constants
  10034. ** determine which.
  10035. **
  10036. ** If there are multiple triggers, you might of some BEFORE and some AFTER.
  10037. ** In that cases, the constants below can be ORed together.
  10038. */
  10039. #define TRIGGER_BEFORE 1
  10040. #define TRIGGER_AFTER 2
  10041. /*
  10042. * An instance of struct TriggerStep is used to store a single SQL statement
  10043. * that is a part of a trigger-program.
  10044. *
  10045. * Instances of struct TriggerStep are stored in a singly linked list (linked
  10046. * using the "pNext" member) referenced by the "step_list" member of the
  10047. * associated struct Trigger instance. The first element of the linked list is
  10048. * the first step of the trigger-program.
  10049. *
  10050. * The "op" member indicates whether this is a "DELETE", "INSERT", "UPDATE" or
  10051. * "SELECT" statement. The meanings of the other members is determined by the
  10052. * value of "op" as follows:
  10053. *
  10054. * (op == TK_INSERT)
  10055. * orconf -> stores the ON CONFLICT algorithm
  10056. * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then
  10057. * this stores a pointer to the SELECT statement. Otherwise NULL.
  10058. * target -> A token holding the name of the table to insert into.
  10059. * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then
  10060. * this stores values to be inserted. Otherwise NULL.
  10061. * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ...
  10062. * statement, then this stores the column-names to be
  10063. * inserted into.
  10064. *
  10065. * (op == TK_DELETE)
  10066. * target -> A token holding the name of the table to delete from.
  10067. * pWhere -> The WHERE clause of the DELETE statement if one is specified.
  10068. * Otherwise NULL.
  10069. *
  10070. * (op == TK_UPDATE)
  10071. * target -> A token holding the name of the table to update rows of.
  10072. * pWhere -> The WHERE clause of the UPDATE statement if one is specified.
  10073. * Otherwise NULL.
  10074. * pExprList -> A list of the columns to update and the expressions to update
  10075. * them to. See sqlite3Update() documentation of "pChanges"
  10076. * argument.
  10077. *
  10078. */
  10079. struct TriggerStep {
  10080. int op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
  10081. int orconf; /* OE_Rollback etc. */
  10082. Trigger *pTrig; /* The trigger that this step is a part of */
  10083. Select *pSelect; /* Valid for SELECT and sometimes
  10084. INSERT steps (when pExprList == 0) */
  10085. Token target; /* Valid for DELETE, UPDATE, INSERT steps */
  10086. Expr *pWhere; /* Valid for DELETE, UPDATE steps */
  10087. ExprList *pExprList; /* Valid for UPDATE statements and sometimes
  10088. INSERT steps (when pSelect == 0) */
  10089. IdList *pIdList; /* Valid for INSERT statements only */
  10090. TriggerStep *pNext; /* Next in the link-list */
  10091. TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */
  10092. };
  10093. /*
  10094. * An instance of struct TriggerStack stores information required during code
  10095. * generation of a single trigger program. While the trigger program is being
  10096. * coded, its associated TriggerStack instance is pointed to by the
  10097. * "pTriggerStack" member of the Parse structure.
  10098. *
  10099. * The pTab member points to the table that triggers are being coded on. The
  10100. * newIdx member contains the index of the vdbe cursor that points at the temp
  10101. * table that stores the new.* references. If new.* references are not valid
  10102. * for the trigger being coded (for example an ON DELETE trigger), then newIdx
  10103. * is set to -1. The oldIdx member is analogous to newIdx, for old.* references.
  10104. *
  10105. * The ON CONFLICT policy to be used for the trigger program steps is stored
  10106. * as the orconf member. If this is OE_Default, then the ON CONFLICT clause
  10107. * specified for individual triggers steps is used.
  10108. *
  10109. * struct TriggerStack has a "pNext" member, to allow linked lists to be
  10110. * constructed. When coding nested triggers (triggers fired by other triggers)
  10111. * each nested trigger stores its parent trigger's TriggerStack as the "pNext"
  10112. * pointer. Once the nested trigger has been coded, the pNext value is restored
  10113. * to the pTriggerStack member of the Parse stucture and coding of the parent
  10114. * trigger continues.
  10115. *
  10116. * Before a nested trigger is coded, the linked list pointed to by the
  10117. * pTriggerStack is scanned to ensure that the trigger is not about to be coded
  10118. * recursively. If this condition is detected, the nested trigger is not coded.
  10119. */
  10120. struct TriggerStack {
  10121. Table *pTab; /* Table that triggers are currently being coded on */
  10122. int newIdx; /* Index of vdbe cursor to "new" temp table */
  10123. int oldIdx; /* Index of vdbe cursor to "old" temp table */
  10124. u32 newColMask;
  10125. u32 oldColMask;
  10126. int orconf; /* Current orconf policy */
  10127. int ignoreJump; /* where to jump to for a RAISE(IGNORE) */
  10128. Trigger *pTrigger; /* The trigger currently being coded */
  10129. TriggerStack *pNext; /* Next trigger down on the trigger stack */
  10130. };
  10131. /*
  10132. ** The following structure contains information used by the sqliteFix...
  10133. ** routines as they walk the parse tree to make database references
  10134. ** explicit.
  10135. */
  10136. typedef struct DbFixer DbFixer;
  10137. struct DbFixer {
  10138. Parse *pParse; /* The parsing context. Error messages written here */
  10139. const char *zDb; /* Make sure all objects are contained in this database */
  10140. const char *zType; /* Type of the container - used for error messages */
  10141. const Token *pName; /* Name of the container - used for error messages */
  10142. };
  10143. /*
  10144. ** An objected used to accumulate the text of a string where we
  10145. ** do not necessarily know how big the string will be in the end.
  10146. */
  10147. struct StrAccum {
  10148. sqlite3 *db; /* Optional database for lookaside. Can be NULL */
  10149. char *zBase; /* A base allocation. Not from malloc. */
  10150. char *zText; /* The string collected so far */
  10151. int nChar; /* Length of the string so far */
  10152. int nAlloc; /* Amount of space allocated in zText */
  10153. int mxAlloc; /* Maximum allowed string length */
  10154. u8 mallocFailed; /* Becomes true if any memory allocation fails */
  10155. u8 useMalloc; /* True if zText is enlargeable using realloc */
  10156. u8 tooBig; /* Becomes true if string size exceeds limits */
  10157. };
  10158. /*
  10159. ** A pointer to this structure is used to communicate information
  10160. ** from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback.
  10161. */
  10162. typedef struct {
  10163. sqlite3 *db; /* The database being initialized */
  10164. int iDb; /* 0 for main database. 1 for TEMP, 2.. for ATTACHed */
  10165. char **pzErrMsg; /* Error message stored here */
  10166. int rc; /* Result code stored here */
  10167. } InitData;
  10168. /*
  10169. ** Structure containing global configuration data for the SQLite library.
  10170. **
  10171. ** This structure also contains some state information.
  10172. */
  10173. struct Sqlite3Config {
  10174. int bMemstat; /* True to enable memory status */
  10175. int bCoreMutex; /* True to enable core mutexing */
  10176. int bFullMutex; /* True to enable full mutexing */
  10177. int mxStrlen; /* Maximum string length */
  10178. int szLookaside; /* Default lookaside buffer size */
  10179. int nLookaside; /* Default lookaside buffer count */
  10180. sqlite3_mem_methods m; /* Low-level memory allocation interface */
  10181. sqlite3_mutex_methods mutex; /* Low-level mutex interface */
  10182. sqlite3_pcache_methods pcache; /* Low-level page-cache interface */
  10183. void *pHeap; /* Heap storage space */
  10184. int nHeap; /* Size of pHeap[] */
  10185. int mnReq, mxReq; /* Min and max heap requests sizes */
  10186. void *pScratch; /* Scratch memory */
  10187. int szScratch; /* Size of each scratch buffer */
  10188. int nScratch; /* Number of scratch buffers */
  10189. void *pPage; /* Page cache memory */
  10190. int szPage; /* Size of each page in pPage[] */
  10191. int nPage; /* Number of pages in pPage[] */
  10192. int mxParserStack; /* maximum depth of the parser stack */
  10193. int sharedCacheEnabled; /* true if shared-cache mode enabled */
  10194. /* The above might be initialized to non-zero. The following need to always
  10195. ** initially be zero, however. */
  10196. int isInit; /* True after initialization has finished */
  10197. int inProgress; /* True while initialization in progress */
  10198. int isMallocInit; /* True after malloc is initialized */
  10199. sqlite3_mutex *pInitMutex; /* Mutex used by sqlite3_initialize() */
  10200. int nRefInitMutex; /* Number of users of pInitMutex */
  10201. };
  10202. /*
  10203. ** Context pointer passed down through the tree-walk.
  10204. */
  10205. struct Walker {
  10206. int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */
  10207. int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */
  10208. Parse *pParse; /* Parser context. */
  10209. union { /* Extra data for callback */
  10210. NameContext *pNC; /* Naming context */
  10211. int i; /* Integer value */
  10212. } u;
  10213. };
  10214. /* Forward declarations */
  10215. SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*);
  10216. SQLITE_PRIVATE int sqlite3WalkExprList(Walker*, ExprList*);
  10217. SQLITE_PRIVATE int sqlite3WalkSelect(Walker*, Select*);
  10218. SQLITE_PRIVATE int sqlite3WalkSelectExpr(Walker*, Select*);
  10219. SQLITE_PRIVATE int sqlite3WalkSelectFrom(Walker*, Select*);
  10220. /*
  10221. ** Return code from the parse-tree walking primitives and their
  10222. ** callbacks.
  10223. */
  10224. #define WRC_Continue 0 /* Continue down into children */
  10225. #define WRC_Prune 1 /* Omit children but continue walking siblings */
  10226. #define WRC_Abort 2 /* Abandon the tree walk */
  10227. /*
  10228. ** Assuming zIn points to the first byte of a UTF-8 character,
  10229. ** advance zIn to point to the first byte of the next UTF-8 character.
  10230. */
  10231. #define SQLITE_SKIP_UTF8(zIn) { \
  10232. if( (*(zIn++))>=0xc0 ){ \
  10233. while( (*zIn & 0xc0)==0x80 ){ zIn++; } \
  10234. } \
  10235. }
  10236. /*
  10237. ** The SQLITE_CORRUPT_BKPT macro can be either a constant (for production
  10238. ** builds) or a function call (for debugging). If it is a function call,
  10239. ** it allows the operator to set a breakpoint at the spot where database
  10240. ** corruption is first detected.
  10241. */
  10242. #ifdef SQLITE_DEBUG
  10243. SQLITE_PRIVATE int sqlite3Corrupt(void);
  10244. # define SQLITE_CORRUPT_BKPT sqlite3Corrupt()
  10245. #else
  10246. # define SQLITE_CORRUPT_BKPT SQLITE_CORRUPT
  10247. #endif
  10248. /*
  10249. ** Internal function prototypes
  10250. */
  10251. SQLITE_PRIVATE int sqlite3StrICmp(const char *, const char *);
  10252. SQLITE_PRIVATE int sqlite3StrNICmp(const char *, const char *, int);
  10253. SQLITE_PRIVATE int sqlite3IsNumber(const char*, int*, u8);
  10254. SQLITE_PRIVATE int sqlite3Strlen(sqlite3*, const char*);
  10255. SQLITE_PRIVATE int sqlite3Strlen30(const char*);
  10256. SQLITE_PRIVATE int sqlite3MallocInit(void);
  10257. SQLITE_PRIVATE void sqlite3MallocEnd(void);
  10258. SQLITE_PRIVATE void *sqlite3Malloc(int);
  10259. SQLITE_PRIVATE void *sqlite3MallocZero(int);
  10260. SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3*, int);
  10261. SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3*, int);
  10262. SQLITE_PRIVATE char *sqlite3DbStrDup(sqlite3*,const char*);
  10263. SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3*,const char*, int);
  10264. SQLITE_PRIVATE void *sqlite3Realloc(void*, int);
  10265. SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, int);
  10266. SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, int);
  10267. SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
  10268. SQLITE_PRIVATE int sqlite3MallocSize(void*);
  10269. SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*);
  10270. SQLITE_PRIVATE void *sqlite3ScratchMalloc(int);
  10271. SQLITE_PRIVATE void sqlite3ScratchFree(void*);
  10272. SQLITE_PRIVATE void *sqlite3PageMalloc(int);
  10273. SQLITE_PRIVATE void sqlite3PageFree(void*);
  10274. SQLITE_PRIVATE void sqlite3MemSetDefault(void);
  10275. SQLITE_PRIVATE void sqlite3BenignMallocHooks(void (*)(void), void (*)(void));
  10276. SQLITE_PRIVATE int sqlite3MemoryAlarm(void (*)(void*, sqlite3_int64, int), void*, sqlite3_int64);
  10277. #ifdef SQLITE_ENABLE_MEMSYS3
  10278. SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetMemsys3(void);
  10279. #endif
  10280. #ifdef SQLITE_ENABLE_MEMSYS5
  10281. SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetMemsys5(void);
  10282. #endif
  10283. #ifndef SQLITE_MUTEX_OMIT
  10284. SQLITE_PRIVATE sqlite3_mutex_methods *sqlite3DefaultMutex(void);
  10285. SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int);
  10286. SQLITE_PRIVATE int sqlite3MutexInit(void);
  10287. SQLITE_PRIVATE int sqlite3MutexEnd(void);
  10288. #endif
  10289. SQLITE_PRIVATE int sqlite3StatusValue(int);
  10290. SQLITE_PRIVATE void sqlite3StatusAdd(int, int);
  10291. SQLITE_PRIVATE void sqlite3StatusSet(int, int);
  10292. SQLITE_PRIVATE int sqlite3IsNaN(double);
  10293. SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, int, const char*, va_list);
  10294. SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...);
  10295. SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
  10296. SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...);
  10297. #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
  10298. SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
  10299. #endif
  10300. #if defined(SQLITE_TEST)
  10301. SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*);
  10302. #endif
  10303. SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*, ...);
  10304. SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
  10305. SQLITE_PRIVATE void sqlite3ErrorClear(Parse*);
  10306. SQLITE_PRIVATE void sqlite3Dequote(char*);
  10307. SQLITE_PRIVATE void sqlite3DequoteExpr(sqlite3*, Expr*);
  10308. SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int);
  10309. SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **);
  10310. SQLITE_PRIVATE void sqlite3FinishCoding(Parse*);
  10311. SQLITE_PRIVATE int sqlite3GetTempReg(Parse*);
  10312. SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse*,int);
  10313. SQLITE_PRIVATE int sqlite3GetTempRange(Parse*,int);
  10314. SQLITE_PRIVATE void sqlite3ReleaseTempRange(Parse*,int,int);
  10315. SQLITE_PRIVATE Expr *sqlite3Expr(sqlite3*, int, Expr*, Expr*, const Token*);
  10316. SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
  10317. SQLITE_PRIVATE Expr *sqlite3RegisterExpr(Parse*,Token*);
  10318. SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
  10319. SQLITE_PRIVATE void sqlite3ExprSpan(Expr*,Token*,Token*);
  10320. SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
  10321. SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*);
  10322. SQLITE_PRIVATE void sqlite3ExprClear(sqlite3*, Expr*);
  10323. SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
  10324. SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*,Token*);
  10325. SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
  10326. SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
  10327. SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
  10328. SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
  10329. SQLITE_PRIVATE void sqlite3ResetInternalSchema(sqlite3*, int);
  10330. SQLITE_PRIVATE void sqlite3BeginParse(Parse*,int);
  10331. SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
  10332. SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*);
  10333. SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *, int);
  10334. SQLITE_PRIVATE void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
  10335. SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token*);
  10336. SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int);
  10337. SQLITE_PRIVATE void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
  10338. SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*);
  10339. SQLITE_PRIVATE void sqlite3AddColumnType(Parse*,Token*);
  10340. SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*);
  10341. SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
  10342. SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,Select*);
  10343. SQLITE_PRIVATE Bitvec *sqlite3BitvecCreate(u32);
  10344. SQLITE_PRIVATE int sqlite3BitvecTest(Bitvec*, u32);
  10345. SQLITE_PRIVATE int sqlite3BitvecSet(Bitvec*, u32);
  10346. SQLITE_PRIVATE void sqlite3BitvecClear(Bitvec*, u32);
  10347. SQLITE_PRIVATE void sqlite3BitvecDestroy(Bitvec*);
  10348. SQLITE_PRIVATE int sqlite3BitvecBuiltinTest(int,int*);
  10349. SQLITE_PRIVATE RowSet *sqlite3RowSetInit(sqlite3*, void*, unsigned int);
  10350. SQLITE_PRIVATE void sqlite3RowSetClear(RowSet*);
  10351. SQLITE_PRIVATE void sqlite3RowSetInsert(RowSet*, i64);
  10352. SQLITE_PRIVATE int sqlite3RowSetNext(RowSet*, i64*);
  10353. SQLITE_PRIVATE void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int,int);
  10354. #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
  10355. SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse*,Table*);
  10356. #else
  10357. # define sqlite3ViewGetColumnNames(A,B) 0
  10358. #endif
  10359. SQLITE_PRIVATE void sqlite3DropTable(Parse*, SrcList*, int, int);
  10360. SQLITE_PRIVATE void sqlite3DeleteTable(Table*);
  10361. SQLITE_PRIVATE void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
  10362. SQLITE_PRIVATE void *sqlite3ArrayAllocate(sqlite3*,void*,int,int,int*,int*,int*);
  10363. SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*);
  10364. SQLITE_PRIVATE int sqlite3IdListIndex(IdList*,const char*);
  10365. SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);
  10366. SQLITE_PRIVATE SrcList *sqlite3SrcListAppend(sqlite3*, SrcList*, Token*, Token*);
  10367. SQLITE_PRIVATE SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*,
  10368. Token*, Select*, Expr*, IdList*);
  10369. SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *, SrcList *, Token *);
  10370. SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, struct SrcList_item *);
  10371. SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList*);
  10372. SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse*, SrcList*);
  10373. SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3*, IdList*);
  10374. SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3*, SrcList*);
  10375. SQLITE_PRIVATE void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
  10376. Token*, int, int);
  10377. SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int);
  10378. SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
  10379. SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
  10380. Expr*,ExprList*,int,Expr*,Expr*);
  10381. SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3*, Select*);
  10382. SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse*, SrcList*);
  10383. SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, int);
  10384. SQLITE_PRIVATE void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
  10385. #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
  10386. SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse *, SrcList *, Expr *, ExprList *, Expr *, Expr *, char *);
  10387. #endif
  10388. SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
  10389. SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
  10390. SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**, u8, int);
  10391. SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*);
  10392. SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, int);
  10393. SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
  10394. SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, int, int, int);
  10395. SQLITE_PRIVATE void sqlite3ExprClearColumnCache(Parse*, int);
  10396. SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
  10397. SQLITE_PRIVATE void sqlite3ExprWritableRegister(Parse*,int);
  10398. SQLITE_PRIVATE void sqlite3ExprHardCopy(Parse*,int,int);
  10399. SQLITE_PRIVATE int sqlite3ExprCode(Parse*, Expr*, int);
  10400. SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
  10401. SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
  10402. SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse*, Expr*, int);
  10403. SQLITE_PRIVATE void sqlite3ExprCodeConstants(Parse*, Expr*);
  10404. SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int);
  10405. SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
  10406. SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
  10407. SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
  10408. SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
  10409. SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
  10410. SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*);
  10411. SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
  10412. SQLITE_PRIVATE void sqlite3Vacuum(Parse*);
  10413. SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*);
  10414. SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*);
  10415. SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*);
  10416. SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
  10417. SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
  10418. SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
  10419. SQLITE_PRIVATE Expr *sqlite3CreateIdExpr(Parse *, const char*);
  10420. SQLITE_PRIVATE void sqlite3PrngSaveState(void);
  10421. SQLITE_PRIVATE void sqlite3PrngRestoreState(void);
  10422. SQLITE_PRIVATE void sqlite3PrngResetState(void);
  10423. SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*);
  10424. SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int);
  10425. SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int);
  10426. SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*);
  10427. SQLITE_PRIVATE void sqlite3RollbackTransaction(Parse*);
  10428. SQLITE_PRIVATE void sqlite3Savepoint(Parse*, int, Token*);
  10429. SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
  10430. SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
  10431. SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
  10432. SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*);
  10433. SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
  10434. SQLITE_PRIVATE int sqlite3IsRowid(const char*);
  10435. SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*, Table*, int, int, int);
  10436. SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int*);
  10437. SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int);
  10438. SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int,int,
  10439. int*,int,int,int,int);
  10440. SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*, Table*, int, int, int*, int, int, int);
  10441. SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, int);
  10442. SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int);
  10443. SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3*,Expr*);
  10444. SQLITE_PRIVATE void sqlite3TokenCopy(sqlite3*,Token*, Token*);
  10445. SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3*,ExprList*);
  10446. SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3*,SrcList*);
  10447. SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3*,IdList*);
  10448. SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3*,Select*);
  10449. SQLITE_PRIVATE void sqlite3FuncDefInsert(FuncDefHash*, FuncDef*);
  10450. SQLITE_PRIVATE FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,int);
  10451. SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(sqlite3*);
  10452. SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void);
  10453. SQLITE_PRIVATE void sqlite3RegisterGlobalFunctions(void);
  10454. #ifdef SQLITE_DEBUG
  10455. SQLITE_PRIVATE int sqlite3SafetyOn(sqlite3*);
  10456. SQLITE_PRIVATE int sqlite3SafetyOff(sqlite3*);
  10457. #else
  10458. # define sqlite3SafetyOn(A) 0
  10459. # define sqlite3SafetyOff(A) 0
  10460. #endif
  10461. SQLITE_PRIVATE int sqlite3SafetyCheckOk(sqlite3*);
  10462. SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk(sqlite3*);
  10463. SQLITE_PRIVATE void sqlite3ChangeCookie(Parse*, int);
  10464. #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
  10465. SQLITE_PRIVATE void sqlite3MaterializeView(Parse*, Table*, Expr*, int);
  10466. #endif
  10467. #ifndef SQLITE_OMIT_TRIGGER
  10468. SQLITE_PRIVATE void sqlite3BeginTrigger(Parse*, Token*,Token*,int,int,IdList*,SrcList*,
  10469. Expr*,int, int);
  10470. SQLITE_PRIVATE void sqlite3FinishTrigger(Parse*, TriggerStep*, Token*);
  10471. SQLITE_PRIVATE void sqlite3DropTrigger(Parse*, SrcList*, int);
  10472. SQLITE_PRIVATE void sqlite3DropTriggerPtr(Parse*, Trigger*);
  10473. SQLITE_PRIVATE int sqlite3TriggersExist(Table*, int, ExprList*);
  10474. SQLITE_PRIVATE int sqlite3CodeRowTrigger(Parse*, int, ExprList*, int, Table *, int, int,
  10475. int, int, u32*, u32*);
  10476. void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*);
  10477. SQLITE_PRIVATE void sqlite3DeleteTriggerStep(sqlite3*, TriggerStep*);
  10478. SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(sqlite3*,Select*);
  10479. SQLITE_PRIVATE TriggerStep *sqlite3TriggerInsertStep(sqlite3*,Token*, IdList*,
  10480. ExprList*,Select*,int);
  10481. SQLITE_PRIVATE TriggerStep *sqlite3TriggerUpdateStep(sqlite3*,Token*,ExprList*, Expr*, int);
  10482. SQLITE_PRIVATE TriggerStep *sqlite3TriggerDeleteStep(sqlite3*,Token*, Expr*);
  10483. SQLITE_PRIVATE void sqlite3DeleteTrigger(sqlite3*, Trigger*);
  10484. SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger(sqlite3*,int,const char*);
  10485. #else
  10486. # define sqlite3TriggersExist(B,C,D,E,F) 0
  10487. # define sqlite3DeleteTrigger(A,B)
  10488. # define sqlite3DropTriggerPtr(A,B)
  10489. # define sqlite3UnlinkAndDeleteTrigger(A,B,C)
  10490. # define sqlite3CodeRowTrigger(A,B,C,D,E,F,G,H,I,J,K) 0
  10491. #endif
  10492. SQLITE_PRIVATE int sqlite3JoinType(Parse*, Token*, Token*, Token*);
  10493. SQLITE_PRIVATE void sqlite3CreateForeignKey(Parse*, ExprList*, Token*, ExprList*, int);
  10494. SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse*, int);
  10495. #ifndef SQLITE_OMIT_AUTHORIZATION
  10496. SQLITE_PRIVATE void sqlite3AuthRead(Parse*,Expr*,Schema*,SrcList*);
  10497. SQLITE_PRIVATE int sqlite3AuthCheck(Parse*,int, const char*, const char*, const char*);
  10498. SQLITE_PRIVATE void sqlite3AuthContextPush(Parse*, AuthContext*, const char*);
  10499. SQLITE_PRIVATE void sqlite3AuthContextPop(AuthContext*);
  10500. #else
  10501. # define sqlite3AuthRead(a,b,c,d)
  10502. # define sqlite3AuthCheck(a,b,c,d,e) SQLITE_OK
  10503. # define sqlite3AuthContextPush(a,b,c)
  10504. # define sqlite3AuthContextPop(a) ((void)(a))
  10505. #endif
  10506. SQLITE_PRIVATE void sqlite3Attach(Parse*, Expr*, Expr*, Expr*);
  10507. SQLITE_PRIVATE void sqlite3Detach(Parse*, Expr*);
  10508. SQLITE_PRIVATE int sqlite3BtreeFactory(const sqlite3 *db, const char *zFilename,
  10509. int omitJournal, int nCache, int flags, Btree **ppBtree);
  10510. SQLITE_PRIVATE int sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*);
  10511. SQLITE_PRIVATE int sqlite3FixSrcList(DbFixer*, SrcList*);
  10512. SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*);
  10513. SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*);
  10514. SQLITE_PRIVATE int sqlite3FixExprList(DbFixer*, ExprList*);
  10515. SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
  10516. SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*);
  10517. SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
  10518. SQLITE_PRIVATE int sqlite3FitsIn64Bits(const char *, int);
  10519. SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nChar);
  10520. SQLITE_PRIVATE int sqlite3Utf8CharLen(const char *pData, int nByte);
  10521. SQLITE_PRIVATE int sqlite3Utf8Read(const u8*, const u8*, const u8**);
  10522. /*
  10523. ** Routines to read and write variable-length integers. These used to
  10524. ** be defined locally, but now we use the varint routines in the util.c
  10525. ** file. Code should use the MACRO forms below, as the Varint32 versions
  10526. ** are coded to assume the single byte case is already handled (which
  10527. ** the MACRO form does).
  10528. */
  10529. SQLITE_PRIVATE int sqlite3PutVarint(unsigned char*, u64);
  10530. SQLITE_PRIVATE int sqlite3PutVarint32(unsigned char*, u32);
  10531. SQLITE_PRIVATE u8 sqlite3GetVarint(const unsigned char *, u64 *);
  10532. SQLITE_PRIVATE u8 sqlite3GetVarint32(const unsigned char *, u32 *);
  10533. SQLITE_PRIVATE int sqlite3VarintLen(u64 v);
  10534. /*
  10535. ** The header of a record consists of a sequence variable-length integers.
  10536. ** These integers are almost always small and are encoded as a single byte.
  10537. ** The following macros take advantage this fact to provide a fast encode
  10538. ** and decode of the integers in a record header. It is