PageRenderTime 50ms CodeModel.GetById 41ms RepoModel.GetById 1ms app.codeStats 1ms

/db/sqlite3/src/sqlite3.c

https://bitbucket.org/soko/mozilla-central
C | 10892 lines | 2863 code | 471 blank | 7558 comment | 37 complexity | f34bca82efdadb1451d829710755bce9 MD5 | raw file
Possible License(s): GPL-2.0, JSON, 0BSD, LGPL-3.0, AGPL-1.0, MIT, MPL-2.0-no-copyleft-exception, BSD-3-Clause, LGPL-2.1, Apache-2.0
  1. /******************************************************************************
  2. ** This file is an amalgamation of many separate C source files from SQLite
  3. ** version 3.7.11. By combining all the individual C code files into this
  4. ** single large file, the entire code can be compiled as a single 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% or 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 embedded within
  14. ** the text of this file. Search for "Begin file sqlite3.h" to find the start
  15. ** of the embedded sqlite3.h header file.) Additional code files may be needed
  16. ** if you want a wrapper to interface SQLite with your choice of programming
  17. ** language. The code for the "sqlite3" command-line shell is also in a
  18. ** separate file. This file contains only code for the core SQLite library.
  19. */
  20. #define SQLITE_CORE 1
  21. #define SQLITE_AMALGAMATION 1
  22. #ifndef SQLITE_PRIVATE
  23. # define SQLITE_PRIVATE static
  24. #endif
  25. #ifndef SQLITE_API
  26. # define SQLITE_API
  27. #endif
  28. /************** Begin file sqliteInt.h ***************************************/
  29. /*
  30. ** 2001 September 15
  31. **
  32. ** The author disclaims copyright to this source code. In place of
  33. ** a legal notice, here is a blessing:
  34. **
  35. ** May you do good and not evil.
  36. ** May you find forgiveness for yourself and forgive others.
  37. ** May you share freely, never taking more than you give.
  38. **
  39. *************************************************************************
  40. ** Internal interface definitions for SQLite.
  41. **
  42. */
  43. #ifndef _SQLITEINT_H_
  44. #define _SQLITEINT_H_
  45. /*
  46. ** These #defines should enable >2GB file support on POSIX if the
  47. ** underlying operating system supports it. If the OS lacks
  48. ** large file support, or if the OS is windows, these should be no-ops.
  49. **
  50. ** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any
  51. ** system #includes. Hence, this block of code must be the very first
  52. ** code in all source files.
  53. **
  54. ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
  55. ** on the compiler command line. This is necessary if you are compiling
  56. ** on a recent machine (ex: Red Hat 7.2) but you want your code to work
  57. ** on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2
  58. ** without this option, LFS is enable. But LFS does not exist in the kernel
  59. ** in Red Hat 6.0, so the code won't work. Hence, for maximum binary
  60. ** portability you should omit LFS.
  61. **
  62. ** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later.
  63. */
  64. #ifndef SQLITE_DISABLE_LFS
  65. # define _LARGE_FILE 1
  66. # ifndef _FILE_OFFSET_BITS
  67. # define _FILE_OFFSET_BITS 64
  68. # endif
  69. # define _LARGEFILE_SOURCE 1
  70. #endif
  71. /*
  72. ** Include the configuration header output by 'configure' if we're using the
  73. ** autoconf-based build
  74. */
  75. #ifdef _HAVE_SQLITE_CONFIG_H
  76. #include "config.h"
  77. #endif
  78. /************** Include sqliteLimit.h in the middle of sqliteInt.h ***********/
  79. /************** Begin file sqliteLimit.h *************************************/
  80. /*
  81. ** 2007 May 7
  82. **
  83. ** The author disclaims copyright to this source code. In place of
  84. ** a legal notice, here is a blessing:
  85. **
  86. ** May you do good and not evil.
  87. ** May you find forgiveness for yourself and forgive others.
  88. ** May you share freely, never taking more than you give.
  89. **
  90. *************************************************************************
  91. **
  92. ** This file defines various limits of what SQLite can process.
  93. */
  94. /*
  95. ** The maximum length of a TEXT or BLOB in bytes. This also
  96. ** limits the size of a row in a table or index.
  97. **
  98. ** The hard limit is the ability of a 32-bit signed integer
  99. ** to count the size: 2^31-1 or 2147483647.
  100. */
  101. #ifndef SQLITE_MAX_LENGTH
  102. # define SQLITE_MAX_LENGTH 1000000000
  103. #endif
  104. /*
  105. ** This is the maximum number of
  106. **
  107. ** * Columns in a table
  108. ** * Columns in an index
  109. ** * Columns in a view
  110. ** * Terms in the SET clause of an UPDATE statement
  111. ** * Terms in the result set of a SELECT statement
  112. ** * Terms in the GROUP BY or ORDER BY clauses of a SELECT statement.
  113. ** * Terms in the VALUES clause of an INSERT statement
  114. **
  115. ** The hard upper limit here is 32676. Most database people will
  116. ** tell you that in a well-normalized database, you usually should
  117. ** not have more than a dozen or so columns in any table. And if
  118. ** that is the case, there is no point in having more than a few
  119. ** dozen values in any of the other situations described above.
  120. */
  121. #ifndef SQLITE_MAX_COLUMN
  122. # define SQLITE_MAX_COLUMN 2000
  123. #endif
  124. /*
  125. ** The maximum length of a single SQL statement in bytes.
  126. **
  127. ** It used to be the case that setting this value to zero would
  128. ** turn the limit off. That is no longer true. It is not possible
  129. ** to turn this limit off.
  130. */
  131. #ifndef SQLITE_MAX_SQL_LENGTH
  132. # define SQLITE_MAX_SQL_LENGTH 1000000000
  133. #endif
  134. /*
  135. ** The maximum depth of an expression tree. This is limited to
  136. ** some extent by SQLITE_MAX_SQL_LENGTH. But sometime you might
  137. ** want to place more severe limits on the complexity of an
  138. ** expression.
  139. **
  140. ** A value of 0 used to mean that the limit was not enforced.
  141. ** But that is no longer true. The limit is now strictly enforced
  142. ** at all times.
  143. */
  144. #ifndef SQLITE_MAX_EXPR_DEPTH
  145. # define SQLITE_MAX_EXPR_DEPTH 1000
  146. #endif
  147. /*
  148. ** The maximum number of terms in a compound SELECT statement.
  149. ** The code generator for compound SELECT statements does one
  150. ** level of recursion for each term. A stack overflow can result
  151. ** if the number of terms is too large. In practice, most SQL
  152. ** never has more than 3 or 4 terms. Use a value of 0 to disable
  153. ** any limit on the number of terms in a compount SELECT.
  154. */
  155. #ifndef SQLITE_MAX_COMPOUND_SELECT
  156. # define SQLITE_MAX_COMPOUND_SELECT 500
  157. #endif
  158. /*
  159. ** The maximum number of opcodes in a VDBE program.
  160. ** Not currently enforced.
  161. */
  162. #ifndef SQLITE_MAX_VDBE_OP
  163. # define SQLITE_MAX_VDBE_OP 25000
  164. #endif
  165. /*
  166. ** The maximum number of arguments to an SQL function.
  167. */
  168. #ifndef SQLITE_MAX_FUNCTION_ARG
  169. # define SQLITE_MAX_FUNCTION_ARG 127
  170. #endif
  171. /*
  172. ** The maximum number of in-memory pages to use for the main database
  173. ** table and for temporary tables. The SQLITE_DEFAULT_CACHE_SIZE
  174. */
  175. #ifndef SQLITE_DEFAULT_CACHE_SIZE
  176. # define SQLITE_DEFAULT_CACHE_SIZE 2000
  177. #endif
  178. #ifndef SQLITE_DEFAULT_TEMP_CACHE_SIZE
  179. # define SQLITE_DEFAULT_TEMP_CACHE_SIZE 500
  180. #endif
  181. /*
  182. ** The default number of frames to accumulate in the log file before
  183. ** checkpointing the database in WAL mode.
  184. */
  185. #ifndef SQLITE_DEFAULT_WAL_AUTOCHECKPOINT
  186. # define SQLITE_DEFAULT_WAL_AUTOCHECKPOINT 1000
  187. #endif
  188. /*
  189. ** The maximum number of attached databases. This must be between 0
  190. ** and 62. The upper bound on 62 is because a 64-bit integer bitmap
  191. ** is used internally to track attached databases.
  192. */
  193. #ifndef SQLITE_MAX_ATTACHED
  194. # define SQLITE_MAX_ATTACHED 10
  195. #endif
  196. /*
  197. ** The maximum value of a ?nnn wildcard that the parser will accept.
  198. */
  199. #ifndef SQLITE_MAX_VARIABLE_NUMBER
  200. # define SQLITE_MAX_VARIABLE_NUMBER 999
  201. #endif
  202. /* Maximum page size. The upper bound on this value is 65536. This a limit
  203. ** imposed by the use of 16-bit offsets within each page.
  204. **
  205. ** Earlier versions of SQLite allowed the user to change this value at
  206. ** compile time. This is no longer permitted, on the grounds that it creates
  207. ** a library that is technically incompatible with an SQLite library
  208. ** compiled with a different limit. If a process operating on a database
  209. ** with a page-size of 65536 bytes crashes, then an instance of SQLite
  210. ** compiled with the default page-size limit will not be able to rollback
  211. ** the aborted transaction. This could lead to database corruption.
  212. */
  213. #ifdef SQLITE_MAX_PAGE_SIZE
  214. # undef SQLITE_MAX_PAGE_SIZE
  215. #endif
  216. #define SQLITE_MAX_PAGE_SIZE 65536
  217. /*
  218. ** The default size of a database page.
  219. */
  220. #ifndef SQLITE_DEFAULT_PAGE_SIZE
  221. # define SQLITE_DEFAULT_PAGE_SIZE 1024
  222. #endif
  223. #if SQLITE_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE
  224. # undef SQLITE_DEFAULT_PAGE_SIZE
  225. # define SQLITE_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE
  226. #endif
  227. /*
  228. ** Ordinarily, if no value is explicitly provided, SQLite creates databases
  229. ** with page size SQLITE_DEFAULT_PAGE_SIZE. However, based on certain
  230. ** device characteristics (sector-size and atomic write() support),
  231. ** SQLite may choose a larger value. This constant is the maximum value
  232. ** SQLite will choose on its own.
  233. */
  234. #ifndef SQLITE_MAX_DEFAULT_PAGE_SIZE
  235. # define SQLITE_MAX_DEFAULT_PAGE_SIZE 8192
  236. #endif
  237. #if SQLITE_MAX_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE
  238. # undef SQLITE_MAX_DEFAULT_PAGE_SIZE
  239. # define SQLITE_MAX_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE
  240. #endif
  241. /*
  242. ** Maximum number of pages in one database file.
  243. **
  244. ** This is really just the default value for the max_page_count pragma.
  245. ** This value can be lowered (or raised) at run-time using that the
  246. ** max_page_count macro.
  247. */
  248. #ifndef SQLITE_MAX_PAGE_COUNT
  249. # define SQLITE_MAX_PAGE_COUNT 1073741823
  250. #endif
  251. /*
  252. ** Maximum length (in bytes) of the pattern in a LIKE or GLOB
  253. ** operator.
  254. */
  255. #ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH
  256. # define SQLITE_MAX_LIKE_PATTERN_LENGTH 50000
  257. #endif
  258. /*
  259. ** Maximum depth of recursion for triggers.
  260. **
  261. ** A value of 1 means that a trigger program will not be able to itself
  262. ** fire any triggers. A value of 0 means that no trigger programs at all
  263. ** may be executed.
  264. */
  265. #ifndef SQLITE_MAX_TRIGGER_DEPTH
  266. # define SQLITE_MAX_TRIGGER_DEPTH 1000
  267. #endif
  268. /************** End of sqliteLimit.h *****************************************/
  269. /************** Continuing where we left off in sqliteInt.h ******************/
  270. /* Disable nuisance warnings on Borland compilers */
  271. #if defined(__BORLANDC__)
  272. #pragma warn -rch /* unreachable code */
  273. #pragma warn -ccc /* Condition is always true or false */
  274. #pragma warn -aus /* Assigned value is never used */
  275. #pragma warn -csu /* Comparing signed and unsigned */
  276. #pragma warn -spa /* Suspicious pointer arithmetic */
  277. #endif
  278. /* Needed for various definitions... */
  279. #ifndef _GNU_SOURCE
  280. # define _GNU_SOURCE
  281. #endif
  282. /*
  283. ** Include standard header files as necessary
  284. */
  285. #ifdef HAVE_STDINT_H
  286. #include <stdint.h>
  287. #endif
  288. #ifdef HAVE_INTTYPES_H
  289. #include <inttypes.h>
  290. #endif
  291. /*
  292. ** The following macros are used to cast pointers to integers and
  293. ** integers to pointers. The way you do this varies from one compiler
  294. ** to the next, so we have developed the following set of #if statements
  295. ** to generate appropriate macros for a wide range of compilers.
  296. **
  297. ** The correct "ANSI" way to do this is to use the intptr_t type.
  298. ** Unfortunately, that typedef is not available on all compilers, or
  299. ** if it is available, it requires an #include of specific headers
  300. ** that vary from one machine to the next.
  301. **
  302. ** Ticket #3860: The llvm-gcc-4.2 compiler from Apple chokes on
  303. ** the ((void*)&((char*)0)[X]) construct. But MSVC chokes on ((void*)(X)).
  304. ** So we have to define the macros in different ways depending on the
  305. ** compiler.
  306. */
  307. #if defined(__PTRDIFF_TYPE__) /* This case should work for GCC */
  308. # define SQLITE_INT_TO_PTR(X) ((void*)(__PTRDIFF_TYPE__)(X))
  309. # define SQLITE_PTR_TO_INT(X) ((int)(__PTRDIFF_TYPE__)(X))
  310. #elif !defined(__GNUC__) /* Works for compilers other than LLVM */
  311. # define SQLITE_INT_TO_PTR(X) ((void*)&((char*)0)[X])
  312. # define SQLITE_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0))
  313. #elif defined(HAVE_STDINT_H) /* Use this case if we have ANSI headers */
  314. # define SQLITE_INT_TO_PTR(X) ((void*)(intptr_t)(X))
  315. # define SQLITE_PTR_TO_INT(X) ((int)(intptr_t)(X))
  316. #else /* Generates a warning - but it always works */
  317. # define SQLITE_INT_TO_PTR(X) ((void*)(X))
  318. # define SQLITE_PTR_TO_INT(X) ((int)(X))
  319. #endif
  320. /*
  321. ** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
  322. ** 0 means mutexes are permanently disable and the library is never
  323. ** threadsafe. 1 means the library is serialized which is the highest
  324. ** level of threadsafety. 2 means the libary is multithreaded - multiple
  325. ** threads can use SQLite as long as no two threads try to use the same
  326. ** database connection at the same time.
  327. **
  328. ** Older versions of SQLite used an optional THREADSAFE macro.
  329. ** We support that for legacy.
  330. */
  331. #if !defined(SQLITE_THREADSAFE)
  332. #if defined(THREADSAFE)
  333. # define SQLITE_THREADSAFE THREADSAFE
  334. #else
  335. # define SQLITE_THREADSAFE 1 /* IMP: R-07272-22309 */
  336. #endif
  337. #endif
  338. /*
  339. ** Powersafe overwrite is on by default. But can be turned off using
  340. ** the -DSQLITE_POWERSAFE_OVERWRITE=0 command-line option.
  341. */
  342. #ifndef SQLITE_POWERSAFE_OVERWRITE
  343. # define SQLITE_POWERSAFE_OVERWRITE 1
  344. #endif
  345. /*
  346. ** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1.
  347. ** It determines whether or not the features related to
  348. ** SQLITE_CONFIG_MEMSTATUS are available by default or not. This value can
  349. ** be overridden at runtime using the sqlite3_config() API.
  350. */
  351. #if !defined(SQLITE_DEFAULT_MEMSTATUS)
  352. # define SQLITE_DEFAULT_MEMSTATUS 1
  353. #endif
  354. /*
  355. ** Exactly one of the following macros must be defined in order to
  356. ** specify which memory allocation subsystem to use.
  357. **
  358. ** SQLITE_SYSTEM_MALLOC // Use normal system malloc()
  359. ** SQLITE_WIN32_MALLOC // Use Win32 native heap API
  360. ** SQLITE_MEMDEBUG // Debugging version of system malloc()
  361. **
  362. ** On Windows, if the SQLITE_WIN32_MALLOC_VALIDATE macro is defined and the
  363. ** assert() macro is enabled, each call into the Win32 native heap subsystem
  364. ** will cause HeapValidate to be called. If heap validation should fail, an
  365. ** assertion will be triggered.
  366. **
  367. ** (Historical note: There used to be several other options, but we've
  368. ** pared it down to just these three.)
  369. **
  370. ** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as
  371. ** the default.
  372. */
  373. #if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_WIN32_MALLOC)+defined(SQLITE_MEMDEBUG)>1
  374. # error "At most one of the following compile-time configuration options\
  375. is allows: SQLITE_SYSTEM_MALLOC, SQLITE_WIN32_MALLOC, SQLITE_MEMDEBUG"
  376. #endif
  377. #if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_WIN32_MALLOC)+defined(SQLITE_MEMDEBUG)==0
  378. # define SQLITE_SYSTEM_MALLOC 1
  379. #endif
  380. /*
  381. ** If SQLITE_MALLOC_SOFT_LIMIT is not zero, then try to keep the
  382. ** sizes of memory allocations below this value where possible.
  383. */
  384. #if !defined(SQLITE_MALLOC_SOFT_LIMIT)
  385. # define SQLITE_MALLOC_SOFT_LIMIT 1024
  386. #endif
  387. /*
  388. ** We need to define _XOPEN_SOURCE as follows in order to enable
  389. ** recursive mutexes on most Unix systems. But Mac OS X is different.
  390. ** The _XOPEN_SOURCE define causes problems for Mac OS X we are told,
  391. ** so it is omitted there. See ticket #2673.
  392. **
  393. ** Later we learn that _XOPEN_SOURCE is poorly or incorrectly
  394. ** implemented on some systems. So we avoid defining it at all
  395. ** if it is already defined or if it is unneeded because we are
  396. ** not doing a threadsafe build. Ticket #2681.
  397. **
  398. ** See also ticket #2741.
  399. */
  400. #if !defined(_XOPEN_SOURCE) && !defined(__DARWIN__) && !defined(__APPLE__) && SQLITE_THREADSAFE
  401. # define _XOPEN_SOURCE 500 /* Needed to enable pthread recursive mutexes */
  402. #endif
  403. /*
  404. ** The TCL headers are only needed when compiling the TCL bindings.
  405. */
  406. #if defined(SQLITE_TCL) || defined(TCLSH)
  407. # include <tcl.h>
  408. #endif
  409. /*
  410. ** Many people are failing to set -DNDEBUG=1 when compiling SQLite.
  411. ** Setting NDEBUG makes the code smaller and run faster. So the following
  412. ** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1
  413. ** option is set. Thus NDEBUG becomes an opt-in rather than an opt-out
  414. ** feature.
  415. */
  416. #if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
  417. # define NDEBUG 1
  418. #endif
  419. /*
  420. ** The testcase() macro is used to aid in coverage testing. When
  421. ** doing coverage testing, the condition inside the argument to
  422. ** testcase() must be evaluated both true and false in order to
  423. ** get full branch coverage. The testcase() macro is inserted
  424. ** to help ensure adequate test coverage in places where simple
  425. ** condition/decision coverage is inadequate. For example, testcase()
  426. ** can be used to make sure boundary values are tested. For
  427. ** bitmask tests, testcase() can be used to make sure each bit
  428. ** is significant and used at least once. On switch statements
  429. ** where multiple cases go to the same block of code, testcase()
  430. ** can insure that all cases are evaluated.
  431. **
  432. */
  433. #ifdef SQLITE_COVERAGE_TEST
  434. SQLITE_PRIVATE void sqlite3Coverage(int);
  435. # define testcase(X) if( X ){ sqlite3Coverage(__LINE__); }
  436. #else
  437. # define testcase(X)
  438. #endif
  439. /*
  440. ** The TESTONLY macro is used to enclose variable declarations or
  441. ** other bits of code that are needed to support the arguments
  442. ** within testcase() and assert() macros.
  443. */
  444. #if !defined(NDEBUG) || defined(SQLITE_COVERAGE_TEST)
  445. # define TESTONLY(X) X
  446. #else
  447. # define TESTONLY(X)
  448. #endif
  449. /*
  450. ** Sometimes we need a small amount of code such as a variable initialization
  451. ** to setup for a later assert() statement. We do not want this code to
  452. ** appear when assert() is disabled. The following macro is therefore
  453. ** used to contain that setup code. The "VVA" acronym stands for
  454. ** "Verification, Validation, and Accreditation". In other words, the
  455. ** code within VVA_ONLY() will only run during verification processes.
  456. */
  457. #ifndef NDEBUG
  458. # define VVA_ONLY(X) X
  459. #else
  460. # define VVA_ONLY(X)
  461. #endif
  462. /*
  463. ** The ALWAYS and NEVER macros surround boolean expressions which
  464. ** are intended to always be true or false, respectively. Such
  465. ** expressions could be omitted from the code completely. But they
  466. ** are included in a few cases in order to enhance the resilience
  467. ** of SQLite to unexpected behavior - to make the code "self-healing"
  468. ** or "ductile" rather than being "brittle" and crashing at the first
  469. ** hint of unplanned behavior.
  470. **
  471. ** In other words, ALWAYS and NEVER are added for defensive code.
  472. **
  473. ** When doing coverage testing ALWAYS and NEVER are hard-coded to
  474. ** be true and false so that the unreachable code then specify will
  475. ** not be counted as untested code.
  476. */
  477. #if defined(SQLITE_COVERAGE_TEST)
  478. # define ALWAYS(X) (1)
  479. # define NEVER(X) (0)
  480. #elif !defined(NDEBUG)
  481. # define ALWAYS(X) ((X)?1:(assert(0),0))
  482. # define NEVER(X) ((X)?(assert(0),1):0)
  483. #else
  484. # define ALWAYS(X) (X)
  485. # define NEVER(X) (X)
  486. #endif
  487. /*
  488. ** Return true (non-zero) if the input is a integer that is too large
  489. ** to fit in 32-bits. This macro is used inside of various testcase()
  490. ** macros to verify that we have tested SQLite for large-file support.
  491. */
  492. #define IS_BIG_INT(X) (((X)&~(i64)0xffffffff)!=0)
  493. /*
  494. ** The macro unlikely() is a hint that surrounds a boolean
  495. ** expression that is usually false. Macro likely() surrounds
  496. ** a boolean expression that is usually true. GCC is able to
  497. ** use these hints to generate better code, sometimes.
  498. */
  499. #if defined(__GNUC__) && 0
  500. # define likely(X) __builtin_expect((X),1)
  501. # define unlikely(X) __builtin_expect((X),0)
  502. #else
  503. # define likely(X) !!(X)
  504. # define unlikely(X) !!(X)
  505. #endif
  506. /************** Include sqlite3.h in the middle of sqliteInt.h ***************/
  507. /************** Begin file sqlite3.h *****************************************/
  508. /*
  509. ** 2001 September 15
  510. **
  511. ** The author disclaims copyright to this source code. In place of
  512. ** a legal notice, here is a blessing:
  513. **
  514. ** May you do good and not evil.
  515. ** May you find forgiveness for yourself and forgive others.
  516. ** May you share freely, never taking more than you give.
  517. **
  518. *************************************************************************
  519. ** This header file defines the interface that the SQLite library
  520. ** presents to client programs. If a C-function, structure, datatype,
  521. ** or constant definition does not appear in this file, then it is
  522. ** not a published API of SQLite, is subject to change without
  523. ** notice, and should not be referenced by programs that use SQLite.
  524. **
  525. ** Some of the definitions that are in this file are marked as
  526. ** "experimental". Experimental interfaces are normally new
  527. ** features recently added to SQLite. We do not anticipate changes
  528. ** to experimental interfaces but reserve the right to make minor changes
  529. ** if experience from use "in the wild" suggest such changes are prudent.
  530. **
  531. ** The official C-language API documentation for SQLite is derived
  532. ** from comments in this file. This file is the authoritative source
  533. ** on how SQLite interfaces are suppose to operate.
  534. **
  535. ** The name of this file under configuration management is "sqlite.h.in".
  536. ** The makefile makes some minor changes to this file (such as inserting
  537. ** the version number) and changes its name to "sqlite3.h" as
  538. ** part of the build process.
  539. */
  540. #ifndef _SQLITE3_H_
  541. #define _SQLITE3_H_
  542. #include <stdarg.h> /* Needed for the definition of va_list */
  543. /*
  544. ** Make sure we can call this stuff from C++.
  545. */
  546. #if 0
  547. extern "C" {
  548. #endif
  549. /*
  550. ** Add the ability to override 'extern'
  551. */
  552. #ifndef SQLITE_EXTERN
  553. # define SQLITE_EXTERN extern
  554. #endif
  555. #ifndef SQLITE_API
  556. # define SQLITE_API
  557. #endif
  558. /*
  559. ** These no-op macros are used in front of interfaces to mark those
  560. ** interfaces as either deprecated or experimental. New applications
  561. ** should not use deprecated interfaces - they are support for backwards
  562. ** compatibility only. Application writers should be aware that
  563. ** experimental interfaces are subject to change in point releases.
  564. **
  565. ** These macros used to resolve to various kinds of compiler magic that
  566. ** would generate warning messages when they were used. But that
  567. ** compiler magic ended up generating such a flurry of bug reports
  568. ** that we have taken it all out and gone back to using simple
  569. ** noop macros.
  570. */
  571. #define SQLITE_DEPRECATED
  572. #define SQLITE_EXPERIMENTAL
  573. /*
  574. ** Ensure these symbols were not defined by some previous header file.
  575. */
  576. #ifdef SQLITE_VERSION
  577. # undef SQLITE_VERSION
  578. #endif
  579. #ifdef SQLITE_VERSION_NUMBER
  580. # undef SQLITE_VERSION_NUMBER
  581. #endif
  582. /*
  583. ** CAPI3REF: Compile-Time Library Version Numbers
  584. **
  585. ** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header
  586. ** evaluates to a string literal that is the SQLite version in the
  587. ** format "X.Y.Z" where X is the major version number (always 3 for
  588. ** SQLite3) and Y is the minor version number and Z is the release number.)^
  589. ** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer
  590. ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
  591. ** numbers used in [SQLITE_VERSION].)^
  592. ** The SQLITE_VERSION_NUMBER for any given release of SQLite will also
  593. ** be larger than the release from which it is derived. Either Y will
  594. ** be held constant and Z will be incremented or else Y will be incremented
  595. ** and Z will be reset to zero.
  596. **
  597. ** Since version 3.6.18, SQLite source code has been stored in the
  598. ** <a href="http://www.fossil-scm.org/">Fossil configuration management
  599. ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to
  600. ** a string which identifies a particular check-in of SQLite
  601. ** within its configuration management system. ^The SQLITE_SOURCE_ID
  602. ** string contains the date and time of the check-in (UTC) and an SHA1
  603. ** hash of the entire source tree.
  604. **
  605. ** See also: [sqlite3_libversion()],
  606. ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
  607. ** [sqlite_version()] and [sqlite_source_id()].
  608. */
  609. #define SQLITE_VERSION "3.7.11"
  610. #define SQLITE_VERSION_NUMBER 3007011
  611. #define SQLITE_SOURCE_ID "2012-03-20 11:35:50 00bb9c9ce4f465e6ac321ced2a9d0062dc364669"
  612. /*
  613. ** CAPI3REF: Run-Time Library Version Numbers
  614. ** KEYWORDS: sqlite3_version, sqlite3_sourceid
  615. **
  616. ** These interfaces provide the same information as the [SQLITE_VERSION],
  617. ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
  618. ** but are associated with the library instead of the header file. ^(Cautious
  619. ** programmers might include assert() statements in their application to
  620. ** verify that values returned by these interfaces match the macros in
  621. ** the header, and thus insure that the application is
  622. ** compiled with matching library and header files.
  623. **
  624. ** <blockquote><pre>
  625. ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
  626. ** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 );
  627. ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
  628. ** </pre></blockquote>)^
  629. **
  630. ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
  631. ** macro. ^The sqlite3_libversion() function returns a pointer to the
  632. ** to the sqlite3_version[] string constant. The sqlite3_libversion()
  633. ** function is provided for use in DLLs since DLL users usually do not have
  634. ** direct access to string constants within the DLL. ^The
  635. ** sqlite3_libversion_number() function returns an integer equal to
  636. ** [SQLITE_VERSION_NUMBER]. ^The sqlite3_sourceid() function returns
  637. ** a pointer to a string constant whose value is the same as the
  638. ** [SQLITE_SOURCE_ID] C preprocessor macro.
  639. **
  640. ** See also: [sqlite_version()] and [sqlite_source_id()].
  641. */
  642. SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
  643. SQLITE_API const char *sqlite3_libversion(void);
  644. SQLITE_API const char *sqlite3_sourceid(void);
  645. SQLITE_API int sqlite3_libversion_number(void);
  646. /*
  647. ** CAPI3REF: Run-Time Library Compilation Options Diagnostics
  648. **
  649. ** ^The sqlite3_compileoption_used() function returns 0 or 1
  650. ** indicating whether the specified option was defined at
  651. ** compile time. ^The SQLITE_ prefix may be omitted from the
  652. ** option name passed to sqlite3_compileoption_used().
  653. **
  654. ** ^The sqlite3_compileoption_get() function allows iterating
  655. ** over the list of options that were defined at compile time by
  656. ** returning the N-th compile time option string. ^If N is out of range,
  657. ** sqlite3_compileoption_get() returns a NULL pointer. ^The SQLITE_
  658. ** prefix is omitted from any strings returned by
  659. ** sqlite3_compileoption_get().
  660. **
  661. ** ^Support for the diagnostic functions sqlite3_compileoption_used()
  662. ** and sqlite3_compileoption_get() may be omitted by specifying the
  663. ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
  664. **
  665. ** See also: SQL functions [sqlite_compileoption_used()] and
  666. ** [sqlite_compileoption_get()] and the [compile_options pragma].
  667. */
  668. #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
  669. SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
  670. SQLITE_API const char *sqlite3_compileoption_get(int N);
  671. #endif
  672. /*
  673. ** CAPI3REF: Test To See If The Library Is Threadsafe
  674. **
  675. ** ^The sqlite3_threadsafe() function returns zero if and only if
  676. ** SQLite was compiled with mutexing code omitted due to the
  677. ** [SQLITE_THREADSAFE] compile-time option being set to 0.
  678. **
  679. ** SQLite can be compiled with or without mutexes. When
  680. ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes
  681. ** are enabled and SQLite is threadsafe. When the
  682. ** [SQLITE_THREADSAFE] macro is 0,
  683. ** the mutexes are omitted. Without the mutexes, it is not safe
  684. ** to use SQLite concurrently from more than one thread.
  685. **
  686. ** Enabling mutexes incurs a measurable performance penalty.
  687. ** So if speed is of utmost importance, it makes sense to disable
  688. ** the mutexes. But for maximum safety, mutexes should be enabled.
  689. ** ^The default behavior is for mutexes to be enabled.
  690. **
  691. ** This interface can be used by an application to make sure that the
  692. ** version of SQLite that it is linking against was compiled with
  693. ** the desired setting of the [SQLITE_THREADSAFE] macro.
  694. **
  695. ** This interface only reports on the compile-time mutex setting
  696. ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
  697. ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
  698. ** can be fully or partially disabled using a call to [sqlite3_config()]
  699. ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
  700. ** or [SQLITE_CONFIG_MUTEX]. ^(The return value of the
  701. ** sqlite3_threadsafe() function shows only the compile-time setting of
  702. ** thread safety, not any run-time changes to that setting made by
  703. ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
  704. ** is unchanged by calls to sqlite3_config().)^
  705. **
  706. ** See the [threading mode] documentation for additional information.
  707. */
  708. SQLITE_API int sqlite3_threadsafe(void);
  709. /*
  710. ** CAPI3REF: Database Connection Handle
  711. ** KEYWORDS: {database connection} {database connections}
  712. **
  713. ** Each open SQLite database is represented by a pointer to an instance of
  714. ** the opaque structure named "sqlite3". It is useful to think of an sqlite3
  715. ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and
  716. ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
  717. ** is its destructor. There are many other interfaces (such as
  718. ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
  719. ** [sqlite3_busy_timeout()] to name but three) that are methods on an
  720. ** sqlite3 object.
  721. */
  722. typedef struct sqlite3 sqlite3;
  723. /*
  724. ** CAPI3REF: 64-Bit Integer Types
  725. ** KEYWORDS: sqlite_int64 sqlite_uint64
  726. **
  727. ** Because there is no cross-platform way to specify 64-bit integer types
  728. ** SQLite includes typedefs for 64-bit signed and unsigned integers.
  729. **
  730. ** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
  731. ** The sqlite_int64 and sqlite_uint64 types are supported for backwards
  732. ** compatibility only.
  733. **
  734. ** ^The sqlite3_int64 and sqlite_int64 types can store integer values
  735. ** between -9223372036854775808 and +9223372036854775807 inclusive. ^The
  736. ** sqlite3_uint64 and sqlite_uint64 types can store integer values
  737. ** between 0 and +18446744073709551615 inclusive.
  738. */
  739. #ifdef SQLITE_INT64_TYPE
  740. typedef SQLITE_INT64_TYPE sqlite_int64;
  741. typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
  742. #elif defined(_MSC_VER) || defined(__BORLANDC__)
  743. typedef __int64 sqlite_int64;
  744. typedef unsigned __int64 sqlite_uint64;
  745. #else
  746. typedef long long int sqlite_int64;
  747. typedef unsigned long long int sqlite_uint64;
  748. #endif
  749. typedef sqlite_int64 sqlite3_int64;
  750. typedef sqlite_uint64 sqlite3_uint64;
  751. /*
  752. ** If compiling for a processor that lacks floating point support,
  753. ** substitute integer for floating-point.
  754. */
  755. #ifdef SQLITE_OMIT_FLOATING_POINT
  756. # define double sqlite3_int64
  757. #endif
  758. /*
  759. ** CAPI3REF: Closing A Database Connection
  760. **
  761. ** ^The sqlite3_close() routine is the destructor for the [sqlite3] object.
  762. ** ^Calls to sqlite3_close() return SQLITE_OK if the [sqlite3] object is
  763. ** successfully destroyed and all associated resources are deallocated.
  764. **
  765. ** Applications must [sqlite3_finalize | finalize] all [prepared statements]
  766. ** and [sqlite3_blob_close | close] all [BLOB handles] associated with
  767. ** the [sqlite3] object prior to attempting to close the object. ^If
  768. ** sqlite3_close() is called on a [database connection] that still has
  769. ** outstanding [prepared statements] or [BLOB handles], then it returns
  770. ** SQLITE_BUSY.
  771. **
  772. ** ^If [sqlite3_close()] is invoked while a transaction is open,
  773. ** the transaction is automatically rolled back.
  774. **
  775. ** The C parameter to [sqlite3_close(C)] must be either a NULL
  776. ** pointer or an [sqlite3] object pointer obtained
  777. ** from [sqlite3_open()], [sqlite3_open16()], or
  778. ** [sqlite3_open_v2()], and not previously closed.
  779. ** ^Calling sqlite3_close() with a NULL pointer argument is a
  780. ** harmless no-op.
  781. */
  782. SQLITE_API int sqlite3_close(sqlite3 *);
  783. /*
  784. ** The type for a callback function.
  785. ** This is legacy and deprecated. It is included for historical
  786. ** compatibility and is not documented.
  787. */
  788. typedef int (*sqlite3_callback)(void*,int,char**, char**);
  789. /*
  790. ** CAPI3REF: One-Step Query Execution Interface
  791. **
  792. ** The sqlite3_exec() interface is a convenience wrapper around
  793. ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
  794. ** that allows an application to run multiple statements of SQL
  795. ** without having to use a lot of C code.
  796. **
  797. ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
  798. ** semicolon-separate SQL statements passed into its 2nd argument,
  799. ** in the context of the [database connection] passed in as its 1st
  800. ** argument. ^If the callback function of the 3rd argument to
  801. ** sqlite3_exec() is not NULL, then it is invoked for each result row
  802. ** coming out of the evaluated SQL statements. ^The 4th argument to
  803. ** sqlite3_exec() is relayed through to the 1st argument of each
  804. ** callback invocation. ^If the callback pointer to sqlite3_exec()
  805. ** is NULL, then no callback is ever invoked and result rows are
  806. ** ignored.
  807. **
  808. ** ^If an error occurs while evaluating the SQL statements passed into
  809. ** sqlite3_exec(), then execution of the current statement stops and
  810. ** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec()
  811. ** is not NULL then any error message is written into memory obtained
  812. ** from [sqlite3_malloc()] and passed back through the 5th parameter.
  813. ** To avoid memory leaks, the application should invoke [sqlite3_free()]
  814. ** on error message strings returned through the 5th parameter of
  815. ** of sqlite3_exec() after the error message string is no longer needed.
  816. ** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors
  817. ** occur, then sqlite3_exec() sets the pointer in its 5th parameter to
  818. ** NULL before returning.
  819. **
  820. ** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec()
  821. ** routine returns SQLITE_ABORT without invoking the callback again and
  822. ** without running any subsequent SQL statements.
  823. **
  824. ** ^The 2nd argument to the sqlite3_exec() callback function is the
  825. ** number of columns in the result. ^The 3rd argument to the sqlite3_exec()
  826. ** callback is an array of pointers to strings obtained as if from
  827. ** [sqlite3_column_text()], one for each column. ^If an element of a
  828. ** result row is NULL then the corresponding string pointer for the
  829. ** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the
  830. ** sqlite3_exec() callback is an array of pointers to strings where each
  831. ** entry represents the name of corresponding result column as obtained
  832. ** from [sqlite3_column_name()].
  833. **
  834. ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
  835. ** to an empty string, or a pointer that contains only whitespace and/or
  836. ** SQL comments, then no SQL statements are evaluated and the database
  837. ** is not changed.
  838. **
  839. ** Restrictions:
  840. **
  841. ** <ul>
  842. ** <li> The application must insure that the 1st parameter to sqlite3_exec()
  843. ** is a valid and open [database connection].
  844. ** <li> The application must not close [database connection] specified by
  845. ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
  846. ** <li> The application must not modify the SQL statement text passed into
  847. ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
  848. ** </ul>
  849. */
  850. SQLITE_API int sqlite3_exec(
  851. sqlite3*, /* An open database */
  852. const char *sql, /* SQL to be evaluated */
  853. int (*callback)(void*,int,char**,char**), /* Callback function */
  854. void *, /* 1st argument to callback */
  855. char **errmsg /* Error msg written here */
  856. );
  857. /*
  858. ** CAPI3REF: Result Codes
  859. ** KEYWORDS: SQLITE_OK {error code} {error codes}
  860. ** KEYWORDS: {result code} {result codes}
  861. **
  862. ** Many SQLite functions return an integer result code from the set shown
  863. ** here in order to indicate success or failure.
  864. **
  865. ** New error codes may be added in future versions of SQLite.
  866. **
  867. ** See also: [SQLITE_IOERR_READ | extended result codes],
  868. ** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes].
  869. */
  870. #define SQLITE_OK 0 /* Successful result */
  871. /* beginning-of-error-codes */
  872. #define SQLITE_ERROR 1 /* SQL error or missing database */
  873. #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
  874. #define SQLITE_PERM 3 /* Access permission denied */
  875. #define SQLITE_ABORT 4 /* Callback routine requested an abort */
  876. #define SQLITE_BUSY 5 /* The database file is locked */
  877. #define SQLITE_LOCKED 6 /* A table in the database is locked */
  878. #define SQLITE_NOMEM 7 /* A malloc() failed */
  879. #define SQLITE_READONLY 8 /* Attempt to write a readonly database */
  880. #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
  881. #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
  882. #define SQLITE_CORRUPT 11 /* The database disk image is malformed */
  883. #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
  884. #define SQLITE_FULL 13 /* Insertion failed because database is full */
  885. #define SQLITE_CANTOPEN 14 /* Unable to open the database file */
  886. #define SQLITE_PROTOCOL 15 /* Database lock protocol error */
  887. #define SQLITE_EMPTY 16 /* Database is empty */
  888. #define SQLITE_SCHEMA 17 /* The database schema changed */
  889. #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
  890. #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
  891. #define SQLITE_MISMATCH 20 /* Data type mismatch */
  892. #define SQLITE_MISUSE 21 /* Library used incorrectly */
  893. #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
  894. #define SQLITE_AUTH 23 /* Authorization denied */
  895. #define SQLITE_FORMAT 24 /* Auxiliary database format error */
  896. #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
  897. #define SQLITE_NOTADB 26 /* File opened that is not a database file */
  898. #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
  899. #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
  900. /* end-of-error-codes */
  901. /*
  902. ** CAPI3REF: Extended Result Codes
  903. ** KEYWORDS: {extended error code} {extended error codes}
  904. ** KEYWORDS: {extended result code} {extended result codes}
  905. **
  906. ** In its default configuration, SQLite API routines return one of 26 integer
  907. ** [SQLITE_OK | result codes]. However, experience has shown that many of
  908. ** these result codes are too coarse-grained. They do not provide as
  909. ** much information about problems as programmers might like. In an effort to
  910. ** address this, newer versions of SQLite (version 3.3.8 and later) include
  911. ** support for additional result codes that provide more detailed information
  912. ** about errors. The extended result codes are enabled or disabled
  913. ** on a per database connection basis using the
  914. ** [sqlite3_extended_result_codes()] API.
  915. **
  916. ** Some of the available extended result codes are listed here.
  917. ** One may expect the number of extended result codes will be expand
  918. ** over time. Software that uses extended result codes should expect
  919. ** to see new result codes in future releases of SQLite.
  920. **
  921. ** The SQLITE_OK result code will never be extended. It will always
  922. ** be exactly zero.
  923. */
  924. #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))
  925. #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))
  926. #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8))
  927. #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8))
  928. #define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8))
  929. #define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8))
  930. #define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8))
  931. #define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8))
  932. #define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8))
  933. #define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8))
  934. #define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8))
  935. #define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8))
  936. #define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8))
  937. #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
  938. #define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8))
  939. #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8))
  940. #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8))
  941. #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8))
  942. #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8))
  943. #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8))
  944. #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8))
  945. #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
  946. #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
  947. #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
  948. #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
  949. #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
  950. #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
  951. #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
  952. #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
  953. /*
  954. ** CAPI3REF: Flags For File Open Operations
  955. **
  956. ** These bit values are intended for use in the
  957. ** 3rd parameter to the [sqlite3_open_v2()] interface and
  958. ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
  959. */
  960. #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
  961. #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
  962. #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
  963. #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
  964. #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
  965. #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
  966. #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */
  967. #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
  968. #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
  969. #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
  970. #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
  971. #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
  972. #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */
  973. #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */
  974. #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
  975. #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
  976. #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
  977. #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
  978. #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
  979. /* Reserved: 0x00F00000 */
  980. /*
  981. ** CAPI3REF: Device Characteristics
  982. **
  983. ** The xDeviceCharacteristics 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(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
  999. ** after reboot following a crash or power loss, the only bytes in a
  1000. ** file that were written at the application level might have changed
  1001. ** and that adjacent bytes, even bytes within the same sector are
  1002. ** guaranteed to be unchanged.
  1003. */
  1004. #define SQLITE_IOCAP_ATOMIC 0x00000001
  1005. #define SQLITE_IOCAP_ATOMIC512 0x00000002
  1006. #define SQLITE_IOCAP_ATOMIC1K 0x00000004
  1007. #define SQLITE_IOCAP_ATOMIC2K 0x00000008
  1008. #define SQLITE_IOCAP_ATOMIC4K 0x00000010
  1009. #define SQLITE_IOCAP_ATOMIC8K 0x00000020
  1010. #define SQLITE_IOCAP_ATOMIC16K 0x00000040
  1011. #define SQLITE_IOCAP_ATOMIC32K 0x00000080
  1012. #define SQLITE_IOCAP_ATOMIC64K 0x00000100
  1013. #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
  1014. #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
  1015. #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800
  1016. #define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000
  1017. /*
  1018. ** CAPI3REF: File Locking Levels
  1019. **
  1020. ** SQLite uses one of these integer values as the second
  1021. ** argument to calls it makes to the xLock() and xUnlock() methods
  1022. ** of an [sqlite3_io_methods] object.
  1023. */
  1024. #define SQLITE_LOCK_NONE 0
  1025. #define SQLITE_LOCK_SHARED 1
  1026. #define SQLITE_LOCK_RESERVED 2
  1027. #define SQLITE_LOCK_PENDING 3
  1028. #define SQLITE_LOCK_EXCLUSIVE 4
  1029. /*
  1030. ** CAPI3REF: Synchronization Type Flags
  1031. **
  1032. ** When SQLite invokes the xSync() method of an
  1033. ** [sqlite3_io_methods] object it uses a combination of
  1034. ** these integer values as the second argument.
  1035. **
  1036. ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
  1037. ** sync operation only needs to flush data to mass storage. Inode
  1038. ** information need not be flushed. If the lower four bits of the flag
  1039. ** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics.
  1040. ** If the lower four bits equal SQLITE_SYNC_FULL, that means
  1041. ** to use Mac OS X style fullsync instead of fsync().
  1042. **
  1043. ** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags
  1044. ** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL
  1045. ** settings. The [synchronous pragma] determines when calls to the
  1046. ** xSync VFS method occur and applies uniformly across all platforms.
  1047. ** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how
  1048. ** energetic or rigorous or forceful the sync operations are and
  1049. ** only make a difference on Mac OSX for the default SQLite code.
  1050. ** (Third-party VFS implementations might also make the distinction
  1051. ** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the
  1052. ** operating systems natively supported by SQLite, only Mac OSX
  1053. ** cares about the difference.)
  1054. */
  1055. #define SQLITE_SYNC_NORMAL 0x00002
  1056. #define SQLITE_SYNC_FULL 0x00003
  1057. #define SQLITE_SYNC_DATAONLY 0x00010
  1058. /*
  1059. ** CAPI3REF: OS Interface Open File Handle
  1060. **
  1061. ** An [sqlite3_file] object represents an open file in the
  1062. ** [sqlite3_vfs | OS interface layer]. Individual OS interface
  1063. ** implementations will
  1064. ** want to subclass this object by appending additional fields
  1065. ** for their own use. The pMethods entry is a pointer to an
  1066. ** [sqlite3_io_methods] object that defines methods for performing
  1067. ** I/O operations on the open file.
  1068. */
  1069. typedef struct sqlite3_file sqlite3_file;
  1070. struct sqlite3_file {
  1071. const struct sqlite3_io_methods *pMethods; /* Methods for an open file */
  1072. };
  1073. /*
  1074. ** CAPI3REF: OS Interface File Virtual Methods Object
  1075. **
  1076. ** Every file opened by the [sqlite3_vfs.xOpen] method populates an
  1077. ** [sqlite3_file] object (or, more commonly, a subclass of the
  1078. ** [sqlite3_file] object) with a pointer to an instance of this object.
  1079. ** This object defines the methods used to perform various operations
  1080. ** against the open file represented by the [sqlite3_file] object.
  1081. **
  1082. ** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element
  1083. ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
  1084. ** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The
  1085. ** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]
  1086. ** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element
  1087. ** to NULL.
  1088. **
  1089. ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
  1090. ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
  1091. ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]
  1092. ** flag may be ORed in to indicate that only the data of the file
  1093. ** and not its inode needs to be synced.
  1094. **
  1095. ** The integer values to xLock() and xUnlock() are one of
  1096. ** <ul>
  1097. ** <li> [SQLITE_LOCK_NONE],
  1098. ** <li> [SQLITE_LOCK_SHARED],
  1099. ** <li> [SQLITE_LOCK_RESERVED],
  1100. ** <li> [SQLITE_LOCK_PENDING], or
  1101. ** <li> [SQLITE_LOCK_EXCLUSIVE].
  1102. ** </ul>
  1103. ** xLock() increases the lock. xUnlock() decreases the lock.
  1104. ** The xCheckReservedLock() method checks whether any database connection,
  1105. ** either in this process or in some other process, is holding a RESERVED,
  1106. ** PENDING, or EXCLUSIVE lock on the file. It returns true
  1107. ** if such a lock exists and false otherwise.
  1108. **
  1109. ** The xFileControl() method is a generic interface that allows custom
  1110. ** VFS implementations to directly control an open file using the
  1111. ** [sqlite3_file_control()] interface. The second "op" argument is an
  1112. ** integer opcode. The third argument is a generic pointer intended to
  1113. ** point to a structure that may contain arguments or space in which to
  1114. ** write return values. Potential uses for xFileControl() might be
  1115. ** functions to enable blocking locks with timeouts, to change the
  1116. ** locking strategy (for example to use dot-file locks), to inquire
  1117. ** about the status of a lock, or to break stale locks. The SQLite
  1118. ** core reserves all opcodes less than 100 for its own use.
  1119. ** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available.
  1120. ** Applications that define a custom xFileControl method should use opcodes
  1121. ** greater than 100 to avoid conflicts. VFS implementations should
  1122. ** return [SQLITE_NOTFOUND] for file control opcodes that they do not
  1123. ** recognize.
  1124. **
  1125. ** The xSectorSize() method returns the sector size of the
  1126. ** device that underlies the file. The sector size is the
  1127. ** minimum write that can be performed without disturbing
  1128. ** other bytes in the file. The xDeviceCharacteristics()
  1129. ** method returns a bit vector describing behaviors of the
  1130. ** underlying device:
  1131. **
  1132. ** <ul>
  1133. ** <li> [SQLITE_IOCAP_ATOMIC]
  1134. ** <li> [SQLITE_IOCAP_ATOMIC512]
  1135. ** <li> [SQLITE_IOCAP_ATOMIC1K]
  1136. ** <li> [SQLITE_IOCAP_ATOMIC2K]
  1137. ** <li> [SQLITE_IOCAP_ATOMIC4K]
  1138. ** <li> [SQLITE_IOCAP_ATOMIC8K]
  1139. ** <li> [SQLITE_IOCAP_ATOMIC16K]
  1140. ** <li> [SQLITE_IOCAP_ATOMIC32K]
  1141. ** <li> [SQLITE_IOCAP_ATOMIC64K]
  1142. ** <li> [SQLITE_IOCAP_SAFE_APPEND]
  1143. ** <li> [SQLITE_IOCAP_SEQUENTIAL]
  1144. ** </ul>
  1145. **
  1146. ** The SQLITE_IOCAP_ATOMIC property means that all writes of
  1147. ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
  1148. ** mean that writes of blocks that are nnn bytes in size and
  1149. ** are aligned to an address which is an integer multiple of
  1150. ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
  1151. ** that when data is appended to a file, the data is appended
  1152. ** first then the size of the file is extended, never the other
  1153. ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
  1154. ** information is written to disk in the same order as calls
  1155. ** to xWrite().
  1156. **
  1157. ** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
  1158. ** in the unread portions of the buffer with zeros. A VFS that
  1159. ** fails to zero-fill short reads might seem to work. However,
  1160. ** failure to zero-fill short reads will eventually lead to
  1161. ** database corruption.
  1162. */
  1163. typedef struct sqlite3_io_methods sqlite3_io_methods;
  1164. struct sqlite3_io_methods {
  1165. int iVersion;
  1166. int (*xClose)(sqlite3_file*);
  1167. int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
  1168. int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
  1169. int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
  1170. int (*xSync)(sqlite3_file*, int flags);
  1171. int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
  1172. int (*xLock)(sqlite3_file*, int);
  1173. int (*xUnlock)(sqlite3_file*, int);
  1174. int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);
  1175. int (*xFileControl)(sqlite3_file*, int op, void *pArg);
  1176. int (*xSectorSize)(sqlite3_file*);
  1177. int (*xDeviceCharacteristics)(sqlite3_file*);
  1178. /* Methods above are valid for version 1 */
  1179. int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
  1180. int (*xShmLock)(sqlite3_file*, int offset, int n, int flags);
  1181. void (*xShmBarrier)(sqlite3_file*);
  1182. int (*xShmUnmap)(sqlite3_file*, int deleteFlag);
  1183. /* Methods above are valid for version 2 */
  1184. /* Additional methods may be added in future releases */
  1185. };
  1186. /*
  1187. ** CAPI3REF: Standard File Control Opcodes
  1188. **
  1189. ** These integer constants are opcodes for the xFileControl method
  1190. ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
  1191. ** interface.
  1192. **
  1193. ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This
  1194. ** opcode causes the xFileControl method to write the current state of
  1195. ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
  1196. ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
  1197. ** into an integer that the pArg argument points to. This capability
  1198. ** is used during testing and only needs to be supported when SQLITE_TEST
  1199. ** is defined.
  1200. ** <ul>
  1201. ** <li>[[SQLITE_FCNTL_SIZE_HINT]]
  1202. ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
  1203. ** layer a hint of how large the database file will grow to be during the
  1204. ** current transaction. This hint is not guaranteed to be accurate but it
  1205. ** is often close. The underlying VFS might choose to preallocate database
  1206. ** file space based on this hint in order to help writes to the database
  1207. ** file run faster.
  1208. **
  1209. ** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
  1210. ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
  1211. ** extends and truncates the database file in chunks of a size specified
  1212. ** by the user. The fourth argument to [sqlite3_file_control()] should
  1213. ** point to an integer (type int) containing the new chunk-size to use
  1214. ** for the nominated database. Allocating database file space in large
  1215. ** chunks (say 1MB at a time), may reduce file-system fragmentation and
  1216. ** improve performance on some systems.
  1217. **
  1218. ** <li>[[SQLITE_FCNTL_FILE_POINTER]]
  1219. ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
  1220. ** to the [sqlite3_file] object associated with a particular database
  1221. ** connection. See the [sqlite3_file_control()] documentation for
  1222. ** additional information.
  1223. **
  1224. ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
  1225. ** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by
  1226. ** SQLite and sent to all VFSes in place of a call to the xSync method
  1227. ** when the database connection has [PRAGMA synchronous] set to OFF.)^
  1228. ** Some specialized VFSes need this signal in order to operate correctly
  1229. ** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most
  1230. ** VFSes do not need this signal and should silently ignore this opcode.
  1231. ** Applications should not call [sqlite3_file_control()] with this
  1232. ** opcode as doing so may disrupt the operation of the specialized VFSes
  1233. ** that do require it.
  1234. **
  1235. ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
  1236. ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
  1237. ** retry counts and intervals for certain disk I/O operations for the
  1238. ** windows [VFS] in order to provide robustness in the presence of
  1239. ** anti-virus programs. By default, the windows VFS will retry file read,
  1240. ** file write, and file delete operations up to 10 times, with a delay
  1241. ** of 25 milliseconds before the first retry and with the delay increasing
  1242. ** by an additional 25 milliseconds with each subsequent retry. This
  1243. ** opcode allows these two values (10 retries and 25 milliseconds of delay)
  1244. ** to be adjusted. The values are changed for all database connections
  1245. ** within the same process. The argument is a pointer to an array of two
  1246. ** integers where the first integer i the new retry count and the second
  1247. ** integer is the delay. If either integer is negative, then the setting
  1248. ** is not changed but instead the prior value of that setting is written
  1249. ** into the array entry, allowing the current retry settings to be
  1250. ** interrogated. The zDbName parameter is ignored.
  1251. **
  1252. ** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
  1253. ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
  1254. ** persistent [WAL | Write AHead Log] setting. By default, the auxiliary
  1255. ** write ahead log and shared memory files used for transaction control
  1256. ** are automatically deleted when the latest connection to the database
  1257. ** closes. Setting persistent WAL mode causes those files to persist after
  1258. ** close. Persisting the files is useful when other processes that do not
  1259. ** have write permission on the directory containing the database file want
  1260. ** to read the database file, as the WAL and shared memory files must exist
  1261. ** in order for the database to be readable. The fourth parameter to
  1262. ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
  1263. ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
  1264. ** WAL mode. If the integer is -1, then it is overwritten with the current
  1265. ** WAL persistence setting.
  1266. **
  1267. ** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]]
  1268. ** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the
  1269. ** persistent "powersafe-overwrite" or "PSOW" setting. The PSOW setting
  1270. ** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the
  1271. ** xDeviceCharacteristics methods. The fourth parameter to
  1272. ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
  1273. ** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage
  1274. ** mode. If the integer is -1, then it is overwritten with the current
  1275. ** zero-damage mode setting.
  1276. **
  1277. ** <li>[[SQLITE_FCNTL_OVERWRITE]]
  1278. ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
  1279. ** a write transaction to indicate that, unless it is rolled back for some
  1280. ** reason, the entire database file will be overwritten by the current
  1281. ** transaction. This is used by VACUUM operations.
  1282. **
  1283. ** <li>[[SQLITE_FCNTL_VFSNAME]]
  1284. ** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
  1285. ** all [VFSes] in the VFS stack. The names are of all VFS shims and the
  1286. ** final bottom-level VFS are written into memory obtained from
  1287. ** [sqlite3_malloc()] and the result is stored in the char* variable
  1288. ** that the fourth parameter of [sqlite3_file_control()] points to.
  1289. ** The caller is responsible for freeing the memory when done. As with
  1290. ** all file-control actions, there is no guarantee that this will actually
  1291. ** do anything. Callers should initialize the char* variable to a NULL
  1292. ** pointer in case this file-control is not implemented. This file-control
  1293. ** is intended for diagnostic use only.
  1294. **
  1295. ** <li>[[SQLITE_FCNTL_PRAGMA]]
  1296. ** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA]
  1297. ** file control is sent to the open [sqlite3_file] object corresponding
  1298. ** to the database file to which the pragma statement refers. ^The argument
  1299. ** to the [SQLITE_FCNTL_PRAGMA] file control is an array of
  1300. ** pointers to strings (char**) in which the second element of the array
  1301. ** is the name of the pragma and the third element is the argument to the
  1302. ** pragma or NULL if the pragma has no argument. ^The handler for an
  1303. ** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element
  1304. ** of the char** argument point to a string obtained from [sqlite3_mprintf()]
  1305. ** or the equivalent and that string will become the result of the pragma or
  1306. ** the error message if the pragma fails. ^If the
  1307. ** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal
  1308. ** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA]
  1309. ** file control returns [SQLITE_OK], then the parser assumes that the
  1310. ** VFS has handled the PRAGMA itself and the parser generates a no-op
  1311. ** prepared statement. ^If the [SQLITE_FCNTL_PRAGMA] file control returns
  1312. ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
  1313. ** that the VFS encountered an error while handling the [PRAGMA] and the
  1314. ** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA]
  1315. ** file control occurs at the beginning of pragma statement analysis and so
  1316. ** it is able to override built-in [PRAGMA] statements.
  1317. ** </ul>
  1318. */
  1319. #define SQLITE_FCNTL_LOCKSTATE 1
  1320. #define SQLITE_GET_LOCKPROXYFILE 2
  1321. #define SQLITE_SET_LOCKPROXYFILE 3
  1322. #define SQLITE_LAST_ERRNO 4
  1323. #define SQLITE_FCNTL_SIZE_HINT 5
  1324. #define SQLITE_FCNTL_CHUNK_SIZE 6
  1325. #define SQLITE_FCNTL_FILE_POINTER 7
  1326. #define SQLITE_FCNTL_SYNC_OMITTED 8
  1327. #define SQLITE_FCNTL_WIN32_AV_RETRY 9
  1328. #define SQLITE_FCNTL_PERSIST_WAL 10
  1329. #define SQLITE_FCNTL_OVERWRITE 11
  1330. #define SQLITE_FCNTL_VFSNAME 12
  1331. #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13
  1332. #define SQLITE_FCNTL_PRAGMA 14
  1333. /*
  1334. ** CAPI3REF: Mutex Handle
  1335. **
  1336. ** The mutex module within SQLite defines [sqlite3_mutex] to be an
  1337. ** abstract type for a mutex object. The SQLite core never looks
  1338. ** at the internal representation of an [sqlite3_mutex]. It only
  1339. ** deals with pointers to the [sqlite3_mutex] object.
  1340. **
  1341. ** Mutexes are created using [sqlite3_mutex_alloc()].
  1342. */
  1343. typedef struct sqlite3_mutex sqlite3_mutex;
  1344. /*
  1345. ** CAPI3REF: OS Interface Object
  1346. **
  1347. ** An instance of the sqlite3_vfs object defines the interface between
  1348. ** the SQLite core and the underlying operating system. The "vfs"
  1349. ** in the name of the object stands for "virtual file system". See
  1350. ** the [VFS | VFS documentation] for further information.
  1351. **
  1352. ** The value of the iVersion field is initially 1 but may be larger in
  1353. ** future versions of SQLite. Additional fields may be appended to this
  1354. ** object when the iVersion value is increased. Note that the structure
  1355. ** of the sqlite3_vfs object changes in the transaction between
  1356. ** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not
  1357. ** modified.
  1358. **
  1359. ** The szOsFile field is the size of the subclassed [sqlite3_file]
  1360. ** structure used by this VFS. mxPathname is the maximum length of
  1361. ** a pathname in this VFS.
  1362. **
  1363. ** Registered sqlite3_vfs objects are kept on a linked list formed by
  1364. ** the pNext pointer. The [sqlite3_vfs_register()]
  1365. ** and [sqlite3_vfs_unregister()] interfaces manage this list
  1366. ** in a thread-safe way. The [sqlite3_vfs_find()] interface
  1367. ** searches the list. Neither the application code nor the VFS
  1368. ** implementation should use the pNext pointer.
  1369. **
  1370. ** The pNext field is the only field in the sqlite3_vfs
  1371. ** structure that SQLite will ever modify. SQLite will only access
  1372. ** or modify this field while holding a particular static mutex.
  1373. ** The application should never modify anything within the sqlite3_vfs
  1374. ** object once the object has been registered.
  1375. **
  1376. ** The zName field holds the name of the VFS module. The name must
  1377. ** be unique across all VFS modules.
  1378. **
  1379. ** [[sqlite3_vfs.xOpen]]
  1380. ** ^SQLite guarantees that the zFilename parameter to xOpen
  1381. ** is either a NULL pointer or string obtained
  1382. ** from xFullPathname() with an optional suffix added.
  1383. ** ^If a suffix is added to the zFilename parameter, it will
  1384. ** consist of a single "-" character followed by no more than
  1385. ** 11 alphanumeric and/or "-" characters.
  1386. ** ^SQLite further guarantees that
  1387. ** the string will be valid and unchanged until xClose() is
  1388. ** called. Because of the previous sentence,
  1389. ** the [sqlite3_file] can safely store a pointer to the
  1390. ** filename if it needs to remember the filename for some reason.
  1391. ** If the zFilename parameter to xOpen is a NULL pointer then xOpen
  1392. ** must invent its own temporary name for the file. ^Whenever the
  1393. ** xFilename parameter is NULL it will also be the case that the
  1394. ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
  1395. **
  1396. ** The flags argument to xOpen() includes all bits set in
  1397. ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]
  1398. ** or [sqlite3_open16()] is used, then flags includes at least
  1399. ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
  1400. ** If xOpen() opens a file read-only then it sets *pOutFlags to
  1401. ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.
  1402. **
  1403. ** ^(SQLite will also add one of the following flags to the xOpen()
  1404. ** call, depending on the object being opened:
  1405. **
  1406. ** <ul>
  1407. ** <li> [SQLITE_OPEN_MAIN_DB]
  1408. ** <li> [SQLITE_OPEN_MAIN_JOURNAL]
  1409. ** <li> [SQLITE_OPEN_TEMP_DB]
  1410. ** <li> [SQLITE_OPEN_TEMP_JOURNAL]
  1411. ** <li> [SQLITE_OPEN_TRANSIENT_DB]
  1412. ** <li> [SQLITE_OPEN_SUBJOURNAL]
  1413. ** <li> [SQLITE_OPEN_MASTER_JOURNAL]
  1414. ** <li> [SQLITE_OPEN_WAL]
  1415. ** </ul>)^
  1416. **
  1417. ** The file I/O implementation can use the object type flags to
  1418. ** change the way it deals with files. For example, an application
  1419. ** that does not care about crash recovery or rollback might make
  1420. ** the open of a journal file a no-op. Writes to this journal would
  1421. ** also be no-ops, and any attempt to read the journal would return
  1422. ** SQLITE_IOERR. Or the implementation might recognize that a database
  1423. ** file will be doing page-aligned sector reads and writes in a random
  1424. ** order and set up its I/O subsystem accordingly.
  1425. **
  1426. ** SQLite might also add one of the following flags to the xOpen method:
  1427. **
  1428. ** <ul>
  1429. ** <li> [SQLITE_OPEN_DELETEONCLOSE]
  1430. ** <li> [SQLITE_OPEN_EXCLUSIVE]
  1431. ** </ul>
  1432. **
  1433. ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
  1434. ** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE]
  1435. ** will be set for TEMP databases and their journals, transient
  1436. ** databases, and subjournals.
  1437. **
  1438. ** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
  1439. ** with the [SQLITE_OPEN_CREATE] flag, which are both directly
  1440. ** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
  1441. ** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the
  1442. ** SQLITE_OPEN_CREATE, is used to indicate that file should always
  1443. ** be created, and that it is an error if it already exists.
  1444. ** It is <i>not</i> used to indicate the file should be opened
  1445. ** for exclusive access.
  1446. **
  1447. ** ^At least szOsFile bytes of memory are allocated by SQLite
  1448. ** to hold the [sqlite3_file] structure passed as the third
  1449. ** argument to xOpen. The xOpen method does not have to
  1450. ** allocate the structure; it should just fill it in. Note that
  1451. ** the xOpen method must set the sqlite3_file.pMethods to either
  1452. ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
  1453. ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
  1454. ** element will be valid after xOpen returns regardless of the success
  1455. ** or failure of the xOpen call.
  1456. **
  1457. ** [[sqlite3_vfs.xAccess]]
  1458. ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
  1459. ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
  1460. ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
  1461. ** to test whether a file is at least readable. The file can be a
  1462. ** directory.
  1463. **
  1464. ** ^SQLite will always allocate at least mxPathname+1 bytes for the
  1465. ** output buffer xFullPathname. The exact size of the output buffer
  1466. ** is also passed as a parameter to both methods. If the output buffer
  1467. ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
  1468. ** handled as a fatal error by SQLite, vfs implementations should endeavor
  1469. ** to prevent this by setting mxPathname to a sufficiently large value.
  1470. **
  1471. ** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
  1472. ** interfaces are not strictly a part of the filesystem, but they are
  1473. ** included in the VFS structure for completeness.
  1474. ** The xRandomness() function attempts to return nBytes bytes
  1475. ** of good-quality randomness into zOut. The return value is
  1476. ** the actual number of bytes of randomness obtained.
  1477. ** The xSleep() method causes the calling thread to sleep for at
  1478. ** least the number of microseconds given. ^The xCurrentTime()
  1479. ** method returns a Julian Day Number for the current date and time as
  1480. ** a floating point value.
  1481. ** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
  1482. ** Day Number multiplied by 86400000 (the number of milliseconds in
  1483. ** a 24-hour day).
  1484. ** ^SQLite will use the xCurrentTimeInt64() method to get the current
  1485. ** date and time if that method is available (if iVersion is 2 or
  1486. ** greater and the function pointer is not NULL) and will fall back
  1487. ** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
  1488. **
  1489. ** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
  1490. ** are not used by the SQLite core. These optional interfaces are provided
  1491. ** by some VFSes to facilitate testing of the VFS code. By overriding
  1492. ** system calls with functions under its control, a test program can
  1493. ** simulate faults and error conditions that would otherwise be difficult
  1494. ** or impossible to induce. The set of system calls that can be overridden
  1495. ** varies from one VFS to another, and from one version of the same VFS to the
  1496. ** next. Applications that use these interfaces must be prepared for any
  1497. ** or all of these interfaces to be NULL or for their behavior to change
  1498. ** from one release to the next. Applications must not attempt to access
  1499. ** any of these methods if the iVersion of the VFS is less than 3.
  1500. */
  1501. typedef struct sqlite3_vfs sqlite3_vfs;
  1502. typedef void (*sqlite3_syscall_ptr)(void);
  1503. struct sqlite3_vfs {
  1504. int iVersion; /* Structure version number (currently 3) */
  1505. int szOsFile; /* Size of subclassed sqlite3_file */
  1506. int mxPathname; /* Maximum file pathname length */
  1507. sqlite3_vfs *pNext; /* Next registered VFS */
  1508. const char *zName; /* Name of this virtual file system */
  1509. void *pAppData; /* Pointer to application-specific data */
  1510. int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*,
  1511. int flags, int *pOutFlags);
  1512. int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
  1513. int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
  1514. int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
  1515. void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
  1516. void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
  1517. void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
  1518. void (*xDlClose)(sqlite3_vfs*, void*);
  1519. int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
  1520. int (*xSleep)(sqlite3_vfs*, int microseconds);
  1521. int (*xCurrentTime)(sqlite3_vfs*, double*);
  1522. int (*xGetLastError)(sqlite3_vfs*, int, char *);
  1523. /*
  1524. ** The methods above are in version 1 of the sqlite_vfs object
  1525. ** definition. Those that follow are added in version 2 or later
  1526. */
  1527. int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
  1528. /*
  1529. ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
  1530. ** Those below are for version 3 and greater.
  1531. */
  1532. int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);
  1533. sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);
  1534. const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
  1535. /*
  1536. ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
  1537. ** New fields may be appended in figure versions. The iVersion
  1538. ** value will increment whenever this happens.
  1539. */
  1540. };
  1541. /*
  1542. ** CAPI3REF: Flags for the xAccess VFS method
  1543. **
  1544. ** These integer constants can be used as the third parameter to
  1545. ** the xAccess method of an [sqlite3_vfs] object. They determine
  1546. ** what kind of permissions the xAccess method is looking for.
  1547. ** With SQLITE_ACCESS_EXISTS, the xAccess method
  1548. ** simply checks whether the file exists.
  1549. ** With SQLITE_ACCESS_READWRITE, the xAccess method
  1550. ** checks whether the named directory is both readable and writable
  1551. ** (in other words, if files can be added, removed, and renamed within
  1552. ** the directory).
  1553. ** The SQLITE_ACCESS_READWRITE constant is currently used only by the
  1554. ** [temp_store_directory pragma], though this could change in a future
  1555. ** release of SQLite.
  1556. ** With SQLITE_ACCESS_READ, the xAccess method
  1557. ** checks whether the file is readable. The SQLITE_ACCESS_READ constant is
  1558. ** currently unused, though it might be used in a future release of
  1559. ** SQLite.
  1560. */
  1561. #define SQLITE_ACCESS_EXISTS 0
  1562. #define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */
  1563. #define SQLITE_ACCESS_READ 2 /* Unused */
  1564. /*
  1565. ** CAPI3REF: Flags for the xShmLock VFS method
  1566. **
  1567. ** These integer constants define the various locking operations
  1568. ** allowed by the xShmLock method of [sqlite3_io_methods]. The
  1569. ** following are the only legal combinations of flags to the
  1570. ** xShmLock method:
  1571. **
  1572. ** <ul>
  1573. ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_SHARED
  1574. ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE
  1575. ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
  1576. ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
  1577. ** </ul>
  1578. **
  1579. ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as
  1580. ** was given no the corresponding lock.
  1581. **
  1582. ** The xShmLock method can transition between unlocked and SHARED or
  1583. ** between unlocked and EXCLUSIVE. It cannot transition between SHARED
  1584. ** and EXCLUSIVE.
  1585. */
  1586. #define SQLITE_SHM_UNLOCK 1
  1587. #define SQLITE_SHM_LOCK 2
  1588. #define SQLITE_SHM_SHARED 4
  1589. #define SQLITE_SHM_EXCLUSIVE 8
  1590. /*
  1591. ** CAPI3REF: Maximum xShmLock index
  1592. **
  1593. ** The xShmLock method on [sqlite3_io_methods] may use values
  1594. ** between 0 and this upper bound as its "offset" argument.
  1595. ** The SQLite core will never attempt to acquire or release a
  1596. ** lock outside of this range
  1597. */
  1598. #define SQLITE_SHM_NLOCK 8
  1599. /*
  1600. ** CAPI3REF: Initialize The SQLite Library
  1601. **
  1602. ** ^The sqlite3_initialize() routine initializes the
  1603. ** SQLite library. ^The sqlite3_shutdown() routine
  1604. ** deallocates any resources that were allocated by sqlite3_initialize().
  1605. ** These routines are designed to aid in process initialization and
  1606. ** shutdown on embedded systems. Workstation applications using
  1607. ** SQLite normally do not need to invoke either of these routines.
  1608. **
  1609. ** A call to sqlite3_initialize() is an "effective" call if it is
  1610. ** the first time sqlite3_initialize() is invoked during the lifetime of
  1611. ** the process, or if it is the first time sqlite3_initialize() is invoked
  1612. ** following a call to sqlite3_shutdown(). ^(Only an effective call
  1613. ** of sqlite3_initialize() does any initialization. All other calls
  1614. ** are harmless no-ops.)^
  1615. **
  1616. ** A call to sqlite3_shutdown() is an "effective" call if it is the first
  1617. ** call to sqlite3_shutdown() since the last sqlite3_initialize(). ^(Only
  1618. ** an effective call to sqlite3_shutdown() does any deinitialization.
  1619. ** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^
  1620. **
  1621. ** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown()
  1622. ** is not. The sqlite3_shutdown() interface must only be called from a
  1623. ** single thread. All open [database connections] must be closed and all
  1624. ** other SQLite resources must be deallocated prior to invoking
  1625. ** sqlite3_shutdown().
  1626. **
  1627. ** Among other things, ^sqlite3_initialize() will invoke
  1628. ** sqlite3_os_init(). Similarly, ^sqlite3_shutdown()
  1629. ** will invoke sqlite3_os_end().
  1630. **
  1631. ** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success.
  1632. ** ^If for some reason, sqlite3_initialize() is unable to initialize
  1633. ** the library (perhaps it is unable to allocate a needed resource such
  1634. ** as a mutex) it returns an [error code] other than [SQLITE_OK].
  1635. **
  1636. ** ^The sqlite3_initialize() routine is called internally by many other
  1637. ** SQLite interfaces so that an application usually does not need to
  1638. ** invoke sqlite3_initialize() directly. For example, [sqlite3_open()]
  1639. ** calls sqlite3_initialize() so the SQLite library will be automatically
  1640. ** initialized when [sqlite3_open()] is called if it has not be initialized
  1641. ** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
  1642. ** compile-time option, then the automatic calls to sqlite3_initialize()
  1643. ** are omitted and the application must call sqlite3_initialize() directly
  1644. ** prior to using any other SQLite interface. For maximum portability,
  1645. ** it is recommended that applications always invoke sqlite3_initialize()
  1646. ** directly prior to using any other SQLite interface. Future releases
  1647. ** of SQLite may require this. In other words, the behavior exhibited
  1648. ** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the
  1649. ** default behavior in some future release of SQLite.
  1650. **
  1651. ** The sqlite3_os_init() routine does operating-system specific
  1652. ** initialization of the SQLite library. The sqlite3_os_end()
  1653. ** routine undoes the effect of sqlite3_os_init(). Typical tasks
  1654. ** performed by these routines include allocation or deallocation
  1655. ** of static resources, initialization of global variables,
  1656. ** setting up a default [sqlite3_vfs] module, or setting up
  1657. ** a default configuration using [sqlite3_config()].
  1658. **
  1659. ** The application should never invoke either sqlite3_os_init()
  1660. ** or sqlite3_os_end() directly. The application should only invoke
  1661. ** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init()
  1662. ** interface is called automatically by sqlite3_initialize() and
  1663. ** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate
  1664. ** implementations for sqlite3_os_init() and sqlite3_os_end()
  1665. ** are built into SQLite when it is compiled for Unix, Windows, or OS/2.
  1666. ** When [custom builds | built for other platforms]
  1667. ** (using the [SQLITE_OS_OTHER=1] compile-time
  1668. ** option) the application must supply a suitable implementation for
  1669. ** sqlite3_os_init() and sqlite3_os_end(). An application-supplied
  1670. ** implementation of sqlite3_os_init() or sqlite3_os_end()
  1671. ** must return [SQLITE_OK] on success and some other [error code] upon
  1672. ** failure.
  1673. */
  1674. SQLITE_API int sqlite3_initialize(void);
  1675. SQLITE_API int sqlite3_shutdown(void);
  1676. SQLITE_API int sqlite3_os_init(void);
  1677. SQLITE_API int sqlite3_os_end(void);
  1678. /*
  1679. ** CAPI3REF: Configuring The SQLite Library
  1680. **
  1681. ** The sqlite3_config() interface is used to make global configuration
  1682. ** changes to SQLite in order to tune SQLite to the specific needs of
  1683. ** the application. The default configuration is recommended for most
  1684. ** applications and so this routine is usually not necessary. It is
  1685. ** provided to support rare applications with unusual needs.
  1686. **
  1687. ** The sqlite3_config() interface is not threadsafe. The application
  1688. ** must insure that no other SQLite interfaces are invoked by other
  1689. ** threads while sqlite3_config() is running. Furthermore, sqlite3_config()
  1690. ** may only be invoked prior to library initialization using
  1691. ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
  1692. ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before
  1693. ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
  1694. ** Note, however, that ^sqlite3_config() can be called as part of the
  1695. ** implementation of an application-defined [sqlite3_os_init()].
  1696. **
  1697. ** The first argument to sqlite3_config() is an integer
  1698. ** [configuration option] that determines
  1699. ** what property of SQLite is to be configured. Subsequent arguments
  1700. ** vary depending on the [configuration option]
  1701. ** in the first argument.
  1702. **
  1703. ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
  1704. ** ^If the option is unknown or SQLite is unable to set the option
  1705. ** then this routine returns a non-zero [error code].
  1706. */
  1707. SQLITE_API int sqlite3_config(int, ...);
  1708. /*
  1709. ** CAPI3REF: Configure database connections
  1710. **
  1711. ** The sqlite3_db_config() interface is used to make configuration
  1712. ** changes to a [database connection]. The interface is similar to
  1713. ** [sqlite3_config()] except that the changes apply to a single
  1714. ** [database connection] (specified in the first argument).
  1715. **
  1716. ** The second argument to sqlite3_db_config(D,V,...) is the
  1717. ** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code
  1718. ** that indicates what aspect of the [database connection] is being configured.
  1719. ** Subsequent arguments vary depending on the configuration verb.
  1720. **
  1721. ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
  1722. ** the call is considered successful.
  1723. */
  1724. SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
  1725. /*
  1726. ** CAPI3REF: Memory Allocation Routines
  1727. **
  1728. ** An instance of this object defines the interface between SQLite
  1729. ** and low-level memory allocation routines.
  1730. **
  1731. ** This object is used in only one place in the SQLite interface.
  1732. ** A pointer to an instance of this object is the argument to
  1733. ** [sqlite3_config()] when the configuration option is
  1734. ** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC].
  1735. ** By creating an instance of this object
  1736. ** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC])
  1737. ** during configuration, an application can specify an alternative
  1738. ** memory allocation subsystem for SQLite to use for all of its
  1739. ** dynamic memory needs.
  1740. **
  1741. ** Note that SQLite comes with several [built-in memory allocators]
  1742. ** that are perfectly adequate for the overwhelming majority of applications
  1743. ** and that this object is only useful to a tiny minority of applications
  1744. ** with specialized memory allocation requirements. This object is
  1745. ** also used during testing of SQLite in order to specify an alternative
  1746. ** memory allocator that simulates memory out-of-memory conditions in
  1747. ** order to verify that SQLite recovers gracefully from such
  1748. ** conditions.
  1749. **
  1750. ** The xMalloc, xRealloc, and xFree methods must work like the
  1751. ** malloc(), realloc() and free() functions from the standard C library.
  1752. ** ^SQLite guarantees that the second argument to
  1753. ** xRealloc is always a value returned by a prior call to xRoundup.
  1754. **
  1755. ** xSize should return the allocated size of a memory allocation
  1756. ** previously obtained from xMalloc or xRealloc. The allocated size
  1757. ** is always at least as big as the requested size but may be larger.
  1758. **
  1759. ** The xRoundup method returns what would be the allocated size of
  1760. ** a memory allocation given a particular requested size. Most memory
  1761. ** allocators round up memory allocations at least to the next multiple
  1762. ** of 8. Some allocators round up to a larger multiple or to a power of 2.
  1763. ** Every memory allocation request coming in through [sqlite3_malloc()]
  1764. ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
  1765. ** that causes the corresponding memory allocation to fail.
  1766. **
  1767. ** The xInit method initializes the memory allocator. (For example,
  1768. ** it might allocate any require mutexes or initialize internal data
  1769. ** structures. The xShutdown method is invoked (indirectly) by
  1770. ** [sqlite3_shutdown()] and should deallocate any resources acquired
  1771. ** by xInit. The pAppData pointer is used as the only parameter to
  1772. ** xInit and xShutdown.
  1773. **
  1774. ** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes
  1775. ** the xInit method, so the xInit method need not be threadsafe. The
  1776. ** xShutdown method is only called from [sqlite3_shutdown()] so it does
  1777. ** not need to be threadsafe either. For all other methods, SQLite
  1778. ** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
  1779. ** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
  1780. ** it is by default) and so the methods are automatically serialized.
  1781. ** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other
  1782. ** methods must be threadsafe or else make their own arrangements for
  1783. ** serialization.
  1784. **
  1785. ** SQLite will never invoke xInit() more than once without an intervening
  1786. ** call to xShutdown().
  1787. */
  1788. typedef struct sqlite3_mem_methods sqlite3_mem_methods;
  1789. struct sqlite3_mem_methods {
  1790. void *(*xMalloc)(int); /* Memory allocation function */
  1791. void (*xFree)(void*); /* Free a prior allocation */
  1792. void *(*xRealloc)(void*,int); /* Resize an allocation */
  1793. int (*xSize)(void*); /* Return the size of an allocation */
  1794. int (*xRoundup)(int); /* Round up request size to allocation size */
  1795. int (*xInit)(void*); /* Initialize the memory allocator */
  1796. void (*xShutdown)(void*); /* Deinitialize the memory allocator */
  1797. void *pAppData; /* Argument to xInit() and xShutdown() */
  1798. };
  1799. /*
  1800. ** CAPI3REF: Configuration Options
  1801. ** KEYWORDS: {configuration option}
  1802. **
  1803. ** These constants are the available integer configuration options that
  1804. ** can be passed as the first argument to the [sqlite3_config()] interface.
  1805. **
  1806. ** New configuration options may be added in future releases of SQLite.
  1807. ** Existing configuration options might be discontinued. Applications
  1808. ** should check the return code from [sqlite3_config()] to make sure that
  1809. ** the call worked. The [sqlite3_config()] interface will return a
  1810. ** non-zero [error code] if a discontinued or unsupported configuration option
  1811. ** is invoked.
  1812. **
  1813. ** <dl>
  1814. ** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
  1815. ** <dd>There are no arguments to this option. ^This option sets the
  1816. ** [threading mode] to Single-thread. In other words, it disables
  1817. ** all mutexing and puts SQLite into a mode where it can only be used
  1818. ** by a single thread. ^If SQLite is compiled with
  1819. ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1820. ** it is not possible to change the [threading mode] from its default
  1821. ** value of Single-thread and so [sqlite3_config()] will return
  1822. ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
  1823. ** configuration option.</dd>
  1824. **
  1825. ** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>
  1826. ** <dd>There are no arguments to this option. ^This option sets the
  1827. ** [threading mode] to Multi-thread. In other words, it disables
  1828. ** mutexing on [database connection] and [prepared statement] objects.
  1829. ** The application is responsible for serializing access to
  1830. ** [database connections] and [prepared statements]. But other mutexes
  1831. ** are enabled so that SQLite will be safe to use in a multi-threaded
  1832. ** environment as long as no two threads attempt to use the same
  1833. ** [database connection] at the same time. ^If SQLite is compiled with
  1834. ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1835. ** it is not possible to set the Multi-thread [threading mode] and
  1836. ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
  1837. ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
  1838. **
  1839. ** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>
  1840. ** <dd>There are no arguments to this option. ^This option sets the
  1841. ** [threading mode] to Serialized. In other words, this option enables
  1842. ** all mutexes including the recursive
  1843. ** mutexes on [database connection] and [prepared statement] objects.
  1844. ** In this mode (which is the default when SQLite is compiled with
  1845. ** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access
  1846. ** to [database connections] and [prepared statements] so that the
  1847. ** application is free to use the same [database connection] or the
  1848. ** same [prepared statement] in different threads at the same time.
  1849. ** ^If SQLite is compiled with
  1850. ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1851. ** it is not possible to set the Serialized [threading mode] and
  1852. ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
  1853. ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
  1854. **
  1855. ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
  1856. ** <dd> ^(This option takes a single argument which is a pointer to an
  1857. ** instance of the [sqlite3_mem_methods] structure. The argument specifies
  1858. ** alternative low-level memory allocation routines to be used in place of
  1859. ** the memory allocation routines built into SQLite.)^ ^SQLite makes
  1860. ** its own private copy of the content of the [sqlite3_mem_methods] structure
  1861. ** before the [sqlite3_config()] call returns.</dd>
  1862. **
  1863. ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
  1864. ** <dd> ^(This option takes a single argument which is a pointer to an
  1865. ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods]
  1866. ** structure is filled with the currently defined memory allocation routines.)^
  1867. ** This option can be used to overload the default memory allocation
  1868. ** routines with a wrapper that simulations memory allocation failure or
  1869. ** tracks memory usage, for example. </dd>
  1870. **
  1871. ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
  1872. ** <dd> ^This option takes single argument of type int, interpreted as a
  1873. ** boolean, which enables or disables the collection of memory allocation
  1874. ** statistics. ^(When memory allocation statistics are disabled, the
  1875. ** following SQLite interfaces become non-operational:
  1876. ** <ul>
  1877. ** <li> [sqlite3_memory_used()]
  1878. ** <li> [sqlite3_memory_highwater()]
  1879. ** <li> [sqlite3_soft_heap_limit64()]
  1880. ** <li> [sqlite3_status()]
  1881. ** </ul>)^
  1882. ** ^Memory allocation statistics are enabled by default unless SQLite is
  1883. ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
  1884. ** allocation statistics are disabled by default.
  1885. ** </dd>
  1886. **
  1887. ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
  1888. ** <dd> ^This option specifies a static memory buffer that SQLite can use for
  1889. ** scratch memory. There are three arguments: A pointer an 8-byte
  1890. ** aligned memory buffer from which the scratch allocations will be
  1891. ** drawn, the size of each scratch allocation (sz),
  1892. ** and the maximum number of scratch allocations (N). The sz
  1893. ** argument must be a multiple of 16.
  1894. ** The first argument must be a pointer to an 8-byte aligned buffer
  1895. ** of at least sz*N bytes of memory.
  1896. ** ^SQLite will use no more than two scratch buffers per thread. So
  1897. ** N should be set to twice the expected maximum number of threads.
  1898. ** ^SQLite will never require a scratch buffer that is more than 6
  1899. ** times the database page size. ^If SQLite needs needs additional
  1900. ** scratch memory beyond what is provided by this configuration option, then
  1901. ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
  1902. **
  1903. ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
  1904. ** <dd> ^This option specifies a static memory buffer that SQLite can use for
  1905. ** the database page cache with the default page cache implementation.
  1906. ** This configuration should not be used if an application-define page
  1907. ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE2 option.
  1908. ** There are three arguments to this option: A pointer to 8-byte aligned
  1909. ** memory, the size of each page buffer (sz), and the number of pages (N).
  1910. ** The sz argument should be the size of the largest database page
  1911. ** (a power of two between 512 and 32768) plus a little extra for each
  1912. ** page header. ^The page header size is 20 to 40 bytes depending on
  1913. ** the host architecture. ^It is harmless, apart from the wasted memory,
  1914. ** to make sz a little too large. The first
  1915. ** argument should point to an allocation of at least sz*N bytes of memory.
  1916. ** ^SQLite will use the memory provided by the first argument to satisfy its
  1917. ** memory needs for the first N pages that it adds to cache. ^If additional
  1918. ** page cache memory is needed beyond what is provided by this option, then
  1919. ** SQLite goes to [sqlite3_malloc()] for the additional storage space.
  1920. ** The pointer in the first argument must
  1921. ** be aligned to an 8-byte boundary or subsequent behavior of SQLite
  1922. ** will be undefined.</dd>
  1923. **
  1924. ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
  1925. ** <dd> ^This option specifies a static memory buffer that SQLite will use
  1926. ** for all of its dynamic memory allocation needs beyond those provided
  1927. ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
  1928. ** There are three arguments: An 8-byte aligned pointer to the memory,
  1929. ** the number of bytes in the memory buffer, and the minimum allocation size.
  1930. ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
  1931. ** to using its default memory allocator (the system malloc() implementation),
  1932. ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
  1933. ** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
  1934. ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
  1935. ** allocator is engaged to handle all of SQLites memory allocation needs.
  1936. ** The first pointer (the memory pointer) must be aligned to an 8-byte
  1937. ** boundary or subsequent behavior of SQLite will be undefined.
  1938. ** The minimum allocation size is capped at 2**12. Reasonable values
  1939. ** for the minimum allocation size are 2**5 through 2**8.</dd>
  1940. **
  1941. ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
  1942. ** <dd> ^(This option takes a single argument which is a pointer to an
  1943. ** instance of the [sqlite3_mutex_methods] structure. The argument specifies
  1944. ** alternative low-level mutex routines to be used in place
  1945. ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the
  1946. ** content of the [sqlite3_mutex_methods] structure before the call to
  1947. ** [sqlite3_config()] returns. ^If SQLite is compiled with
  1948. ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1949. ** the entire mutexing subsystem is omitted from the build and hence calls to
  1950. ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
  1951. ** return [SQLITE_ERROR].</dd>
  1952. **
  1953. ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
  1954. ** <dd> ^(This option takes a single argument which is a pointer to an
  1955. ** instance of the [sqlite3_mutex_methods] structure. The
  1956. ** [sqlite3_mutex_methods]
  1957. ** structure is filled with the currently defined mutex routines.)^
  1958. ** This option can be used to overload the default mutex allocation
  1959. ** routines with a wrapper used to track mutex usage for performance
  1960. ** profiling or testing, for example. ^If SQLite is compiled with
  1961. ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1962. ** the entire mutexing subsystem is omitted from the build and hence calls to
  1963. ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
  1964. ** return [SQLITE_ERROR].</dd>
  1965. **
  1966. ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
  1967. ** <dd> ^(This option takes two arguments that determine the default
  1968. ** memory allocation for the lookaside memory allocator on each
  1969. ** [database connection]. The first argument is the
  1970. ** size of each lookaside buffer slot and the second is the number of
  1971. ** slots allocated to each database connection.)^ ^(This option sets the
  1972. ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
  1973. ** verb to [sqlite3_db_config()] can be used to change the lookaside
  1974. ** configuration on individual connections.)^ </dd>
  1975. **
  1976. ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
  1977. ** <dd> ^(This option takes a single argument which is a pointer to
  1978. ** an [sqlite3_pcache_methods2] object. This object specifies the interface
  1979. ** to a custom page cache implementation.)^ ^SQLite makes a copy of the
  1980. ** object and uses it for page cache memory allocations.</dd>
  1981. **
  1982. ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
  1983. ** <dd> ^(This option takes a single argument which is a pointer to an
  1984. ** [sqlite3_pcache_methods2] object. SQLite copies of the current
  1985. ** page cache implementation into that object.)^ </dd>
  1986. **
  1987. ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
  1988. ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
  1989. ** function with a call signature of void(*)(void*,int,const char*),
  1990. ** and a pointer to void. ^If the function pointer is not NULL, it is
  1991. ** invoked by [sqlite3_log()] to process each logging event. ^If the
  1992. ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
  1993. ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
  1994. ** passed through as the first parameter to the application-defined logger
  1995. ** function whenever that function is invoked. ^The second parameter to
  1996. ** the logger function is a copy of the first parameter to the corresponding
  1997. ** [sqlite3_log()] call and is intended to be a [result code] or an
  1998. ** [extended result code]. ^The third parameter passed to the logger is
  1999. ** log message after formatting via [sqlite3_snprintf()].
  2000. ** The SQLite logging interface is not reentrant; the logger function
  2001. ** supplied by the application must not invoke any SQLite interface.
  2002. ** In a multi-threaded application, the application-defined logger
  2003. ** function must be threadsafe. </dd>
  2004. **
  2005. ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
  2006. ** <dd> This option takes a single argument of type int. If non-zero, then
  2007. ** URI handling is globally enabled. If the parameter is zero, then URI handling
  2008. ** is globally disabled. If URI handling is globally enabled, all filenames
  2009. ** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or
  2010. ** specified as part of [ATTACH] commands are interpreted as URIs, regardless
  2011. ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
  2012. ** connection is opened. If it is globally disabled, filenames are
  2013. ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
  2014. ** database connection is opened. By default, URI handling is globally
  2015. ** disabled. The default value may be changed by compiling with the
  2016. ** [SQLITE_USE_URI] symbol defined.
  2017. **
  2018. ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
  2019. ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFNIG_GETPCACHE
  2020. ** <dd> These options are obsolete and should not be used by new code.
  2021. ** They are retained for backwards compatibility but are now no-ops.
  2022. ** </dl>
  2023. */
  2024. #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
  2025. #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
  2026. #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
  2027. #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
  2028. #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */
  2029. #define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */
  2030. #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */
  2031. #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */
  2032. #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */
  2033. #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */
  2034. #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */
  2035. /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
  2036. #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */
  2037. #define SQLITE_CONFIG_PCACHE 14 /* no-op */
  2038. #define SQLITE_CONFIG_GETPCACHE 15 /* no-op */
  2039. #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
  2040. #define SQLITE_CONFIG_URI 17 /* int */
  2041. #define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */
  2042. #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
  2043. /*
  2044. ** CAPI3REF: Database Connection Configuration Options
  2045. **
  2046. ** These constants are the available integer configuration options that
  2047. ** can be passed as the second argument to the [sqlite3_db_config()] interface.
  2048. **
  2049. ** New configuration options may be added in future releases of SQLite.
  2050. ** Existing configuration options might be discontinued. Applications
  2051. ** should check the return code from [sqlite3_db_config()] to make sure that
  2052. ** the call worked. ^The [sqlite3_db_config()] interface will return a
  2053. ** non-zero [error code] if a discontinued or unsupported configuration option
  2054. ** is invoked.
  2055. **
  2056. ** <dl>
  2057. ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
  2058. ** <dd> ^This option takes three additional arguments that determine the
  2059. ** [lookaside memory allocator] configuration for the [database connection].
  2060. ** ^The first argument (the third parameter to [sqlite3_db_config()] is a
  2061. ** pointer to a memory buffer to use for lookaside memory.
  2062. ** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
  2063. ** may be NULL in which case SQLite will allocate the
  2064. ** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the
  2065. ** size of each lookaside buffer slot. ^The third argument is the number of
  2066. ** slots. The size of the buffer in the first argument must be greater than
  2067. ** or equal to the product of the second and third arguments. The buffer
  2068. ** must be aligned to an 8-byte boundary. ^If the second argument to
  2069. ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
  2070. ** rounded down to the next smaller multiple of 8. ^(The lookaside memory
  2071. ** configuration for a database connection can only be changed when that
  2072. ** connection is not currently using lookaside memory, or in other words
  2073. ** when the "current value" returned by
  2074. ** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
  2075. ** Any attempt to change the lookaside memory configuration when lookaside
  2076. ** memory is in use leaves the configuration unchanged and returns
  2077. ** [SQLITE_BUSY].)^</dd>
  2078. **
  2079. ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
  2080. ** <dd> ^This option is used to enable or disable the enforcement of
  2081. ** [foreign key constraints]. There should be two additional arguments.
  2082. ** The first argument is an integer which is 0 to disable FK enforcement,
  2083. ** positive to enable FK enforcement or negative to leave FK enforcement
  2084. ** unchanged. The second parameter is a pointer to an integer into which
  2085. ** is written 0 or 1 to indicate whether FK enforcement is off or on
  2086. ** following this call. The second parameter may be a NULL pointer, in
  2087. ** which case the FK enforcement setting is not reported back. </dd>
  2088. **
  2089. ** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
  2090. ** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
  2091. ** There should be two additional arguments.
  2092. ** The first argument is an integer which is 0 to disable triggers,
  2093. ** positive to enable triggers or negative to leave the setting unchanged.
  2094. ** The second parameter is a pointer to an integer into which
  2095. ** is written 0 or 1 to indicate whether triggers are disabled or enabled
  2096. ** following this call. The second parameter may be a NULL pointer, in
  2097. ** which case the trigger setting is not reported back. </dd>
  2098. **
  2099. ** </dl>
  2100. */
  2101. #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
  2102. #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
  2103. #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
  2104. /*
  2105. ** CAPI3REF: Enable Or Disable Extended Result Codes
  2106. **
  2107. ** ^The sqlite3_extended_result_codes() routine enables or disables the
  2108. ** [extended result codes] feature of SQLite. ^The extended result
  2109. ** codes are disabled by default for historical compatibility.
  2110. */
  2111. SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
  2112. /*
  2113. ** CAPI3REF: Last Insert Rowid
  2114. **
  2115. ** ^Each entry in an SQLite table has a unique 64-bit signed
  2116. ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
  2117. ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
  2118. ** names are not also used by explicitly declared columns. ^If
  2119. ** the table has a column of type [INTEGER PRIMARY KEY] then that column
  2120. ** is another alias for the rowid.
  2121. **
  2122. ** ^This routine returns the [rowid] of the most recent
  2123. ** successful [INSERT] into the database from the [database connection]
  2124. ** in the first argument. ^As of SQLite version 3.7.7, this routines
  2125. ** records the last insert rowid of both ordinary tables and [virtual tables].
  2126. ** ^If no successful [INSERT]s
  2127. ** have ever occurred on that database connection, zero is returned.
  2128. **
  2129. ** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
  2130. ** method, then this routine will return the [rowid] of the inserted
  2131. ** row as long as the trigger or virtual table method is running.
  2132. ** But once the trigger or virtual table method ends, the value returned
  2133. ** by this routine reverts to what it was before the trigger or virtual
  2134. ** table method began.)^
  2135. **
  2136. ** ^An [INSERT] that fails due to a constraint violation is not a
  2137. ** successful [INSERT] and does not change the value returned by this
  2138. ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
  2139. ** and INSERT OR ABORT make no changes to the return value of this
  2140. ** routine when their insertion fails. ^(When INSERT OR REPLACE
  2141. ** encounters a constraint violation, it does not fail. The
  2142. ** INSERT continues to completion after deleting rows that caused
  2143. ** the constraint problem so INSERT OR REPLACE will always change
  2144. ** the return value of this interface.)^
  2145. **
  2146. ** ^For the purposes of this routine, an [INSERT] is considered to
  2147. ** be successful even if it is subsequently rolled back.
  2148. **
  2149. ** This function is accessible to SQL statements via the
  2150. ** [last_insert_rowid() SQL function].
  2151. **
  2152. ** If a separate thread performs a new [INSERT] on the same
  2153. ** database connection while the [sqlite3_last_insert_rowid()]
  2154. ** function is running and thus changes the last insert [rowid],
  2155. ** then the value returned by [sqlite3_last_insert_rowid()] is
  2156. ** unpredictable and might not equal either the old or the new
  2157. ** last insert [rowid].
  2158. */
  2159. SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
  2160. /*
  2161. ** CAPI3REF: Count The Number Of Rows Modified
  2162. **
  2163. ** ^This function returns the number of database rows that were changed
  2164. ** or inserted or deleted by the most recently completed SQL statement
  2165. ** on the [database connection] specified by the first parameter.
  2166. ** ^(Only changes that are directly specified by the [INSERT], [UPDATE],
  2167. ** or [DELETE] statement are counted. Auxiliary changes caused by
  2168. ** triggers or [foreign key actions] are not counted.)^ Use the
  2169. ** [sqlite3_total_changes()] function to find the total number of changes
  2170. ** including changes caused by triggers and foreign key actions.
  2171. **
  2172. ** ^Changes to a view that are simulated by an [INSTEAD OF trigger]
  2173. ** are not counted. Only real table changes are counted.
  2174. **
  2175. ** ^(A "row change" is a change to a single row of a single table
  2176. ** caused by an INSERT, DELETE, or UPDATE statement. Rows that
  2177. ** are changed as side effects of [REPLACE] constraint resolution,
  2178. ** rollback, ABORT processing, [DROP TABLE], or by any other
  2179. ** mechanisms do not count as direct row changes.)^
  2180. **
  2181. ** A "trigger context" is a scope of execution that begins and
  2182. ** ends with the script of a [CREATE TRIGGER | trigger].
  2183. ** Most SQL statements are
  2184. ** evaluated outside of any trigger. This is the "top level"
  2185. ** trigger context. If a trigger fires from the top level, a
  2186. ** new trigger context is entered for the duration of that one
  2187. ** trigger. Subtriggers create subcontexts for their duration.
  2188. **
  2189. ** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does
  2190. ** not create a new trigger context.
  2191. **
  2192. ** ^This function returns the number of direct row changes in the
  2193. ** most recent INSERT, UPDATE, or DELETE statement within the same
  2194. ** trigger context.
  2195. **
  2196. ** ^Thus, when called from the top level, this function returns the
  2197. ** number of changes in the most recent INSERT, UPDATE, or DELETE
  2198. ** that also occurred at the top level. ^(Within the body of a trigger,
  2199. ** the sqlite3_changes() interface can be called to find the number of
  2200. ** changes in the most recently completed INSERT, UPDATE, or DELETE
  2201. ** statement within the body of the same trigger.
  2202. ** However, the number returned does not include changes
  2203. ** caused by subtriggers since those have their own context.)^
  2204. **
  2205. ** See also the [sqlite3_total_changes()] interface, the
  2206. ** [count_changes pragma], and the [changes() SQL function].
  2207. **
  2208. ** If a separate thread makes changes on the same database connection
  2209. ** while [sqlite3_changes()] is running then the value returned
  2210. ** is unpredictable and not meaningful.
  2211. */
  2212. SQLITE_API int sqlite3_changes(sqlite3*);
  2213. /*
  2214. ** CAPI3REF: Total Number Of Rows Modified
  2215. **
  2216. ** ^This function returns the number of row changes caused by [INSERT],
  2217. ** [UPDATE] or [DELETE] statements since the [database connection] was opened.
  2218. ** ^(The count returned by sqlite3_total_changes() includes all changes
  2219. ** from all [CREATE TRIGGER | trigger] contexts and changes made by
  2220. ** [foreign key actions]. However,
  2221. ** the count does not include changes used to implement [REPLACE] constraints,
  2222. ** do rollbacks or ABORT processing, or [DROP TABLE] processing. The
  2223. ** count does not include rows of views that fire an [INSTEAD OF trigger],
  2224. ** though if the INSTEAD OF trigger makes changes of its own, those changes
  2225. ** are counted.)^
  2226. ** ^The sqlite3_total_changes() function counts the changes as soon as
  2227. ** the statement that makes them is completed (when the statement handle
  2228. ** is passed to [sqlite3_reset()] or [sqlite3_finalize()]).
  2229. **
  2230. ** See also the [sqlite3_changes()] interface, the
  2231. ** [count_changes pragma], and the [total_changes() SQL function].
  2232. **
  2233. ** If a separate thread makes changes on the same database connection
  2234. ** while [sqlite3_total_changes()] is running then the value
  2235. ** returned is unpredictable and not meaningful.
  2236. */
  2237. SQLITE_API int sqlite3_total_changes(sqlite3*);
  2238. /*
  2239. ** CAPI3REF: Interrupt A Long-Running Query
  2240. **
  2241. ** ^This function causes any pending database operation to abort and
  2242. ** return at its earliest opportunity. This routine is typically
  2243. ** called in response to a user action such as pressing "Cancel"
  2244. ** or Ctrl-C where the user wants a long query operation to halt
  2245. ** immediately.
  2246. **
  2247. ** ^It is safe to call this routine from a thread different from the
  2248. ** thread that is currently running the database operation. But it
  2249. ** is not safe to call this routine with a [database connection] that
  2250. ** is closed or might close before sqlite3_interrupt() returns.
  2251. **
  2252. ** ^If an SQL operation is very nearly finished at the time when
  2253. ** sqlite3_interrupt() is called, then it might not have an opportunity
  2254. ** to be interrupted and might continue to completion.
  2255. **
  2256. ** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT].
  2257. ** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
  2258. ** that is inside an explicit transaction, then the entire transaction
  2259. ** will be rolled back automatically.
  2260. **
  2261. ** ^The sqlite3_interrupt(D) call is in effect until all currently running
  2262. ** SQL statements on [database connection] D complete. ^Any new SQL statements
  2263. ** that are started after the sqlite3_interrupt() call and before the
  2264. ** running statements reaches zero are interrupted as if they had been
  2265. ** running prior to the sqlite3_interrupt() call. ^New SQL statements
  2266. ** that are started after the running statement count reaches zero are
  2267. ** not effected by the sqlite3_interrupt().
  2268. ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
  2269. ** SQL statements is a no-op and has no effect on SQL statements
  2270. ** that are started after the sqlite3_interrupt() call returns.
  2271. **
  2272. ** If the database connection closes while [sqlite3_interrupt()]
  2273. ** is running then bad things will likely happen.
  2274. */
  2275. SQLITE_API void sqlite3_interrupt(sqlite3*);
  2276. /*
  2277. ** CAPI3REF: Determine If An SQL Statement Is Complete
  2278. **
  2279. ** These routines are useful during command-line input to determine if the
  2280. ** currently entered text seems to form a complete SQL statement or
  2281. ** if additional input is needed before sending the text into
  2282. ** SQLite for parsing. ^These routines return 1 if the input string
  2283. ** appears to be a complete SQL statement. ^A statement is judged to be
  2284. ** complete if it ends with a semicolon token and is not a prefix of a
  2285. ** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within
  2286. ** string literals or quoted identifier names or comments are not
  2287. ** independent tokens (they are part of the token in which they are
  2288. ** embedded) and thus do not count as a statement terminator. ^Whitespace
  2289. ** and comments that follow the final semicolon are ignored.
  2290. **
  2291. ** ^These routines return 0 if the statement is incomplete. ^If a
  2292. ** memory allocation fails, then SQLITE_NOMEM is returned.
  2293. **
  2294. ** ^These routines do not parse the SQL statements thus
  2295. ** will not detect syntactically incorrect SQL.
  2296. **
  2297. ** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior
  2298. ** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
  2299. ** automatically by sqlite3_complete16(). If that initialization fails,
  2300. ** then the return value from sqlite3_complete16() will be non-zero
  2301. ** regardless of whether or not the input SQL is complete.)^
  2302. **
  2303. ** The input to [sqlite3_complete()] must be a zero-terminated
  2304. ** UTF-8 string.
  2305. **
  2306. ** The input to [sqlite3_complete16()] must be a zero-terminated
  2307. ** UTF-16 string in native byte order.
  2308. */
  2309. SQLITE_API int sqlite3_complete(const char *sql);
  2310. SQLITE_API int sqlite3_complete16(const void *sql);
  2311. /*
  2312. ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
  2313. **
  2314. ** ^This routine sets a callback function that might be invoked whenever
  2315. ** an attempt is made to open a database table that another thread
  2316. ** or process has locked.
  2317. **
  2318. ** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]
  2319. ** is returned immediately upon encountering the lock. ^If the busy callback
  2320. ** is not NULL, then the callback might be invoked with two arguments.
  2321. **
  2322. ** ^The first argument to the busy handler is a copy of the void* pointer which
  2323. ** is the third argument to sqlite3_busy_handler(). ^The second argument to
  2324. ** the busy handler callback is the number of times that the busy handler has
  2325. ** been invoked for this locking event. ^If the
  2326. ** busy callback returns 0, then no additional attempts are made to
  2327. ** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned.
  2328. ** ^If the callback returns non-zero, then another attempt
  2329. ** is made to open the database for reading and the cycle repeats.
  2330. **
  2331. ** The presence of a busy handler does not guarantee that it will be invoked
  2332. ** when there is lock contention. ^If SQLite determines that invoking the busy
  2333. ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
  2334. ** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler.
  2335. ** Consider a scenario where one process is holding a read lock that
  2336. ** it is trying to promote to a reserved lock and
  2337. ** a second process is holding a reserved lock that it is trying
  2338. ** to promote to an exclusive lock. The first process cannot proceed
  2339. ** because it is blocked by the second and the second process cannot
  2340. ** proceed because it is blocked by the first. If both processes
  2341. ** invoke the busy handlers, neither will make any progress. Therefore,
  2342. ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
  2343. ** will induce the first process to release its read lock and allow
  2344. ** the second process to proceed.
  2345. **
  2346. ** ^The default busy callback is NULL.
  2347. **
  2348. ** ^The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED]
  2349. ** when SQLite is in the middle of a large transaction where all the
  2350. ** changes will not fit into the in-memory cache. SQLite will
  2351. ** already hold a RESERVED lock on the database file, but it needs
  2352. ** to promote this lock to EXCLUSIVE so that it can spill cache
  2353. ** pages into the database file without harm to concurrent
  2354. ** readers. ^If it is unable to promote the lock, then the in-memory
  2355. ** cache will be left in an inconsistent state and so the error
  2356. ** code is promoted from the relatively benign [SQLITE_BUSY] to
  2357. ** the more severe [SQLITE_IOERR_BLOCKED]. ^This error code promotion
  2358. ** forces an automatic rollback of the changes. See the
  2359. ** <a href="/cvstrac/wiki?p=CorruptionFollowingBusyError">
  2360. ** CorruptionFollowingBusyError</a> wiki page for a discussion of why
  2361. ** this is important.
  2362. **
  2363. ** ^(There can only be a single busy handler defined for each
  2364. ** [database connection]. Setting a new busy handler clears any
  2365. ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()]
  2366. ** will also set or clear the busy handler.
  2367. **
  2368. ** The busy callback should not take any actions which modify the
  2369. ** database connection that invoked the busy handler. Any such actions
  2370. ** result in undefined behavior.
  2371. **
  2372. ** A busy handler must not close the database connection
  2373. ** or [prepared statement] that invoked the busy handler.
  2374. */
  2375. SQLITE_API int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
  2376. /*
  2377. ** CAPI3REF: Set A Busy Timeout
  2378. **
  2379. ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
  2380. ** for a specified amount of time when a table is locked. ^The handler
  2381. ** will sleep multiple times until at least "ms" milliseconds of sleeping
  2382. ** have accumulated. ^After at least "ms" milliseconds of sleeping,
  2383. ** the handler returns 0 which causes [sqlite3_step()] to return
  2384. ** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED].
  2385. **
  2386. ** ^Calling this routine with an argument less than or equal to zero
  2387. ** turns off all busy handlers.
  2388. **
  2389. ** ^(There can only be a single busy handler for a particular
  2390. ** [database connection] any any given moment. If another busy handler
  2391. ** was defined (using [sqlite3_busy_handler()]) prior to calling
  2392. ** this routine, that other busy handler is cleared.)^
  2393. */
  2394. SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
  2395. /*
  2396. ** CAPI3REF: Convenience Routines For Running Queries
  2397. **
  2398. ** This is a legacy interface that is preserved for backwards compatibility.
  2399. ** Use of this interface is not recommended.
  2400. **
  2401. ** Definition: A <b>result table</b> is memory data structure created by the
  2402. ** [sqlite3_get_table()] interface. A result table records the
  2403. ** complete query results from one or more queries.
  2404. **
  2405. ** The table conceptually has a number of rows and columns. But
  2406. ** these numbers are not part of the result table itself. These
  2407. ** numbers are obtained separately. Let N be the number of rows
  2408. ** and M be the number of columns.
  2409. **
  2410. ** A result table is an array of pointers to zero-terminated UTF-8 strings.
  2411. ** There are (N+1)*M elements in the array. The first M pointers point
  2412. ** to zero-terminated strings that contain the names of the columns.
  2413. ** The remaining entries all point to query results. NULL values result
  2414. ** in NULL pointers. All other values are in their UTF-8 zero-terminated
  2415. ** string representation as returned by [sqlite3_column_text()].
  2416. **
  2417. ** A result table might consist of one or more memory allocations.
  2418. ** It is not safe to pass a result table directly to [sqlite3_free()].
  2419. ** A result table should be deallocated using [sqlite3_free_table()].
  2420. **
  2421. ** ^(As an example of the result table format, suppose a query result
  2422. ** is as follows:
  2423. **
  2424. ** <blockquote><pre>
  2425. ** Name | Age
  2426. ** -----------------------
  2427. ** Alice | 43
  2428. ** Bob | 28
  2429. ** Cindy | 21
  2430. ** </pre></blockquote>
  2431. **
  2432. ** There are two column (M==2) and three rows (N==3). Thus the
  2433. ** result table has 8 entries. Suppose the result table is stored
  2434. ** in an array names azResult. Then azResult holds this content:
  2435. **
  2436. ** <blockquote><pre>
  2437. ** azResult&#91;0] = "Name";
  2438. ** azResult&#91;1] = "Age";
  2439. ** azResult&#91;2] = "Alice";
  2440. ** azResult&#91;3] = "43";
  2441. ** azResult&#91;4] = "Bob";
  2442. ** azResult&#91;5] = "28";
  2443. ** azResult&#91;6] = "Cindy";
  2444. ** azResult&#91;7] = "21";
  2445. ** </pre></blockquote>)^
  2446. **
  2447. ** ^The sqlite3_get_table() function evaluates one or more
  2448. ** semicolon-separated SQL statements in the zero-terminated UTF-8
  2449. ** string of its 2nd parameter and returns a result table to the
  2450. ** pointer given in its 3rd parameter.
  2451. **
  2452. ** After the application has finished with the result from sqlite3_get_table(),
  2453. ** it must pass the result table pointer to sqlite3_free_table() in order to
  2454. ** release the memory that was malloced. Because of the way the
  2455. ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
  2456. ** function must not try to call [sqlite3_free()] directly. Only
  2457. ** [sqlite3_free_table()] is able to release the memory properly and safely.
  2458. **
  2459. ** The sqlite3_get_table() interface is implemented as a wrapper around
  2460. ** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access
  2461. ** to any internal data structures of SQLite. It uses only the public
  2462. ** interface defined here. As a consequence, errors that occur in the
  2463. ** wrapper layer outside of the internal [sqlite3_exec()] call are not
  2464. ** reflected in subsequent calls to [sqlite3_errcode()] or
  2465. ** [sqlite3_errmsg()].
  2466. */
  2467. SQLITE_API int sqlite3_get_table(
  2468. sqlite3 *db, /* An open database */
  2469. const char *zSql, /* SQL to be evaluated */
  2470. char ***pazResult, /* Results of the query */
  2471. int *pnRow, /* Number of result rows written here */
  2472. int *pnColumn, /* Number of result columns written here */
  2473. char **pzErrmsg /* Error msg written here */
  2474. );
  2475. SQLITE_API void sqlite3_free_table(char **result);
  2476. /*
  2477. ** CAPI3REF: Formatted String Printing Functions
  2478. **
  2479. ** These routines are work-alikes of the "printf()" family of functions
  2480. ** from the standard C library.
  2481. **
  2482. ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
  2483. ** results into memory obtained from [sqlite3_malloc()].
  2484. ** The strings returned by these two routines should be
  2485. ** released by [sqlite3_free()]. ^Both routines return a
  2486. ** NULL pointer if [sqlite3_malloc()] is unable to allocate enough
  2487. ** memory to hold the resulting string.
  2488. **
  2489. ** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from
  2490. ** the standard C library. The result is written into the
  2491. ** buffer supplied as the second parameter whose size is given by
  2492. ** the first parameter. Note that the order of the
  2493. ** first two parameters is reversed from snprintf().)^ This is an
  2494. ** historical accident that cannot be fixed without breaking
  2495. ** backwards compatibility. ^(Note also that sqlite3_snprintf()
  2496. ** returns a pointer to its buffer instead of the number of
  2497. ** characters actually written into the buffer.)^ We admit that
  2498. ** the number of characters written would be a more useful return
  2499. ** value but we cannot change the implementation of sqlite3_snprintf()
  2500. ** now without breaking compatibility.
  2501. **
  2502. ** ^As long as the buffer size is greater than zero, sqlite3_snprintf()
  2503. ** guarantees that the buffer is always zero-terminated. ^The first
  2504. ** parameter "n" is the total size of the buffer, including space for
  2505. ** the zero terminator. So the longest string that can be completely
  2506. ** written will be n-1 characters.
  2507. **
  2508. ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
  2509. **
  2510. ** These routines all implement some additional formatting
  2511. ** options that are useful for constructing SQL statements.
  2512. ** All of the usual printf() formatting options apply. In addition, there
  2513. ** is are "%q", "%Q", and "%z" options.
  2514. **
  2515. ** ^(The %q option works like %s in that it substitutes a nul-terminated
  2516. ** string from the argument list. But %q also doubles every '\'' character.
  2517. ** %q is designed for use inside a string literal.)^ By doubling each '\''
  2518. ** character it escapes that character and allows it to be inserted into
  2519. ** the string.
  2520. **
  2521. ** For example, assume the string variable zText contains text as follows:
  2522. **
  2523. ** <blockquote><pre>
  2524. ** char *zText = "It's a happy day!";
  2525. ** </pre></blockquote>
  2526. **
  2527. ** One can use this text in an SQL statement as follows:
  2528. **
  2529. ** <blockquote><pre>
  2530. ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);
  2531. ** sqlite3_exec(db, zSQL, 0, 0, 0);
  2532. ** sqlite3_free(zSQL);
  2533. ** </pre></blockquote>
  2534. **
  2535. ** Because the %q format string is used, the '\'' character in zText
  2536. ** is escaped and the SQL generated is as follows:
  2537. **
  2538. ** <blockquote><pre>
  2539. ** INSERT INTO table1 VALUES('It''s a happy day!')
  2540. ** </pre></blockquote>
  2541. **
  2542. ** This is correct. Had we used %s instead of %q, the generated SQL
  2543. ** would have looked like this:
  2544. **
  2545. ** <blockquote><pre>
  2546. ** INSERT INTO table1 VALUES('It's a happy day!');
  2547. ** </pre></blockquote>
  2548. **
  2549. ** This second example is an SQL syntax error. As a general rule you should
  2550. ** always use %q instead of %s when inserting text into a string literal.
  2551. **
  2552. ** ^(The %Q option works like %q except it also adds single quotes around
  2553. ** the outside of the total string. Additionally, if the parameter in the
  2554. ** argument list is a NULL pointer, %Q substitutes the text "NULL" (without
  2555. ** single quotes).)^ So, for example, one could say:
  2556. **
  2557. ** <blockquote><pre>
  2558. ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
  2559. ** sqlite3_exec(db, zSQL, 0, 0, 0);
  2560. ** sqlite3_free(zSQL);
  2561. ** </pre></blockquote>
  2562. **
  2563. ** The code above will render a correct SQL statement in the zSQL
  2564. ** variable even if the zText variable is a NULL pointer.
  2565. **
  2566. ** ^(The "%z" formatting option works like "%s" but with the
  2567. ** addition that after the string has been read and copied into
  2568. ** the result, [sqlite3_free()] is called on the input string.)^
  2569. */
  2570. SQLITE_API char *sqlite3_mprintf(const char*,...);
  2571. SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
  2572. SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
  2573. SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
  2574. /*
  2575. ** CAPI3REF: Memory Allocation Subsystem
  2576. **
  2577. ** The SQLite core uses these three routines for all of its own
  2578. ** internal memory allocation needs. "Core" in the previous sentence
  2579. ** does not include operating-system specific VFS implementation. The
  2580. ** Windows VFS uses native malloc() and free() for some operations.
  2581. **
  2582. ** ^The sqlite3_malloc() routine returns a pointer to a block
  2583. ** of memory at least N bytes in length, where N is the parameter.
  2584. ** ^If sqlite3_malloc() is unable to obtain sufficient free
  2585. ** memory, it returns a NULL pointer. ^If the parameter N to
  2586. ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
  2587. ** a NULL pointer.
  2588. **
  2589. ** ^Calling sqlite3_free() with a pointer previously returned
  2590. ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
  2591. ** that it might be reused. ^The sqlite3_free() routine is
  2592. ** a no-op if is called with a NULL pointer. Passing a NULL pointer
  2593. ** to sqlite3_free() is harmless. After being freed, memory
  2594. ** should neither be read nor written. Even reading previously freed
  2595. ** memory might result in a segmentation fault or other severe error.
  2596. ** Memory corruption, a segmentation fault, or other severe error
  2597. ** might result if sqlite3_free() is called with a non-NULL pointer that
  2598. ** was not obtained from sqlite3_malloc() or sqlite3_realloc().
  2599. **
  2600. ** ^(The sqlite3_realloc() interface attempts to resize a
  2601. ** prior memory allocation to be at least N bytes, where N is the
  2602. ** second parameter. The memory allocation to be resized is the first
  2603. ** parameter.)^ ^ If the first parameter to sqlite3_realloc()
  2604. ** is a NULL pointer then its behavior is identical to calling
  2605. ** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc().
  2606. ** ^If the second parameter to sqlite3_realloc() is zero or
  2607. ** negative then the behavior is exactly the same as calling
  2608. ** sqlite3_free(P) where P is the first parameter to sqlite3_realloc().
  2609. ** ^sqlite3_realloc() returns a pointer to a memory allocation
  2610. ** of at least N bytes in size or NULL if sufficient memory is unavailable.
  2611. ** ^If M is the size of the prior allocation, then min(N,M) bytes
  2612. ** of the prior allocation are copied into the beginning of buffer returned
  2613. ** by sqlite3_realloc() and the prior allocation is freed.
  2614. ** ^If sqlite3_realloc() returns NULL, then the prior allocation
  2615. ** is not freed.
  2616. **
  2617. ** ^The memory returned by sqlite3_malloc() and sqlite3_realloc()
  2618. ** is always aligned to at least an 8 byte boundary, or to a
  2619. ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
  2620. ** option is used.
  2621. **
  2622. ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
  2623. ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
  2624. ** implementation of these routines to be omitted. That capability
  2625. ** is no longer provided. Only built-in memory allocators can be used.
  2626. **
  2627. ** The Windows OS interface layer calls
  2628. ** the system malloc() and free() directly when converting
  2629. ** filenames between the UTF-8 encoding used by SQLite
  2630. ** and whatever filename encoding is used by the particular Windows
  2631. ** installation. Memory allocation errors are detected, but
  2632. ** they are reported back as [SQLITE_CANTOPEN] or
  2633. ** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
  2634. **
  2635. ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
  2636. ** must be either NULL or else pointers obtained from a prior
  2637. ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
  2638. ** not yet been released.
  2639. **
  2640. ** The application must not read or write any part of
  2641. ** a block of memory after it has been released using
  2642. ** [sqlite3_free()] or [sqlite3_realloc()].
  2643. */
  2644. SQLITE_API void *sqlite3_malloc(int);
  2645. SQLITE_API void *sqlite3_realloc(void*, int);
  2646. SQLITE_API void sqlite3_free(void*);
  2647. /*
  2648. ** CAPI3REF: Memory Allocator Statistics
  2649. **
  2650. ** SQLite provides these two interfaces for reporting on the status
  2651. ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
  2652. ** routines, which form the built-in memory allocation subsystem.
  2653. **
  2654. ** ^The [sqlite3_memory_used()] routine returns the number of bytes
  2655. ** of memory currently outstanding (malloced but not freed).
  2656. ** ^The [sqlite3_memory_highwater()] routine returns the maximum
  2657. ** value of [sqlite3_memory_used()] since the high-water mark
  2658. ** was last reset. ^The values returned by [sqlite3_memory_used()] and
  2659. ** [sqlite3_memory_highwater()] include any overhead
  2660. ** added by SQLite in its implementation of [sqlite3_malloc()],
  2661. ** but not overhead added by the any underlying system library
  2662. ** routines that [sqlite3_malloc()] may call.
  2663. **
  2664. ** ^The memory high-water mark is reset to the current value of
  2665. ** [sqlite3_memory_used()] if and only if the parameter to
  2666. ** [sqlite3_memory_highwater()] is true. ^The value returned
  2667. ** by [sqlite3_memory_highwater(1)] is the high-water mark
  2668. ** prior to the reset.
  2669. */
  2670. SQLITE_API sqlite3_int64 sqlite3_memory_used(void);
  2671. SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
  2672. /*
  2673. ** CAPI3REF: Pseudo-Random Number Generator
  2674. **
  2675. ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
  2676. ** select random [ROWID | ROWIDs] when inserting new records into a table that
  2677. ** already uses the largest possible [ROWID]. The PRNG is also used for
  2678. ** the build-in random() and randomblob() SQL functions. This interface allows
  2679. ** applications to access the same PRNG for other purposes.
  2680. **
  2681. ** ^A call to this routine stores N bytes of randomness into buffer P.
  2682. **
  2683. ** ^The first time this routine is invoked (either internally or by
  2684. ** the application) the PRNG is seeded using randomness obtained
  2685. ** from the xRandomness method of the default [sqlite3_vfs] object.
  2686. ** ^On all subsequent invocations, the pseudo-randomness is generated
  2687. ** internally and without recourse to the [sqlite3_vfs] xRandomness
  2688. ** method.
  2689. */
  2690. SQLITE_API void sqlite3_randomness(int N, void *P);
  2691. /*
  2692. ** CAPI3REF: Compile-Time Authorization Callbacks
  2693. **
  2694. ** ^This routine registers an authorizer callback with a particular
  2695. ** [database connection], supplied in the first argument.
  2696. ** ^The authorizer callback is invoked as SQL statements are being compiled
  2697. ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
  2698. ** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()]. ^At various
  2699. ** points during the compilation process, as logic is being created
  2700. ** to perform various actions, the authorizer callback is invoked to
  2701. ** see if those actions are allowed. ^The authorizer callback should
  2702. ** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the
  2703. ** specific action but allow the SQL statement to continue to be
  2704. ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
  2705. ** rejected with an error. ^If the authorizer callback returns
  2706. ** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]
  2707. ** then the [sqlite3_prepare_v2()] or equivalent call that triggered
  2708. ** the authorizer will fail with an error message.
  2709. **
  2710. ** When the callback returns [SQLITE_OK], that means the operation
  2711. ** requested is ok. ^When the callback returns [SQLITE_DENY], the
  2712. ** [sqlite3_prepare_v2()] or equivalent call that triggered the
  2713. ** authorizer will fail with an error message explaining that
  2714. ** access is denied.
  2715. **
  2716. ** ^The first parameter to the authorizer callback is a copy of the third
  2717. ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
  2718. ** to the callback is an integer [SQLITE_COPY | action code] that specifies
  2719. ** the particular action to be authorized. ^The third through sixth parameters
  2720. ** to the callback are zero-terminated strings that contain additional
  2721. ** details about the action to be authorized.
  2722. **
  2723. ** ^If the action code is [SQLITE_READ]
  2724. ** and the callback returns [SQLITE_IGNORE] then the
  2725. ** [prepared statement] statement is constructed to substitute
  2726. ** a NULL value in place of the table column that would have
  2727. ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE]
  2728. ** return can be used to deny an untrusted user access to individual
  2729. ** columns of a table.
  2730. ** ^If the action code is [SQLITE_DELETE] and the callback returns
  2731. ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
  2732. ** [truncate optimization] is disabled and all rows are deleted individually.
  2733. **
  2734. ** An authorizer is used when [sqlite3_prepare | preparing]
  2735. ** SQL statements from an untrusted source, to ensure that the SQL statements
  2736. ** do not try to access data they are not allowed to see, or that they do not
  2737. ** try to execute malicious statements that damage the database. For
  2738. ** example, an application may allow a user to enter arbitrary
  2739. ** SQL queries for evaluation by a database. But the application does
  2740. ** not want the user to be able to make arbitrary changes to the
  2741. ** database. An authorizer could then be put in place while the
  2742. ** user-entered SQL is being [sqlite3_prepare | prepared] that
  2743. ** disallows everything except [SELECT] statements.
  2744. **
  2745. ** Applications that need to process SQL from untrusted sources
  2746. ** might also consider lowering resource limits using [sqlite3_limit()]
  2747. ** and limiting database size using the [max_page_count] [PRAGMA]
  2748. ** in addition to using an authorizer.
  2749. **
  2750. ** ^(Only a single authorizer can be in place on a database connection
  2751. ** at a time. Each call to sqlite3_set_authorizer overrides the
  2752. ** previous call.)^ ^Disable the authorizer by installing a NULL callback.
  2753. ** The authorizer is disabled by default.
  2754. **
  2755. ** The authorizer callback must not do anything that will modify
  2756. ** the database connection that invoked the authorizer callback.
  2757. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  2758. ** database connections for the meaning of "modify" in this paragraph.
  2759. **
  2760. ** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the
  2761. ** statement might be re-prepared during [sqlite3_step()] due to a
  2762. ** schema change. Hence, the application should ensure that the
  2763. ** correct authorizer callback remains in place during the [sqlite3_step()].
  2764. **
  2765. ** ^Note that the authorizer callback is invoked only during
  2766. ** [sqlite3_prepare()] or its variants. Authorization is not
  2767. ** performed during statement evaluation in [sqlite3_step()], unless
  2768. ** as stated in the previous paragraph, sqlite3_step() invokes
  2769. ** sqlite3_prepare_v2() to reprepare a statement after a schema change.
  2770. */
  2771. SQLITE_API int sqlite3_set_authorizer(
  2772. sqlite3*,
  2773. int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
  2774. void *pUserData
  2775. );
  2776. /*
  2777. ** CAPI3REF: Authorizer Return Codes
  2778. **
  2779. ** The [sqlite3_set_authorizer | authorizer callback function] must
  2780. ** return either [SQLITE_OK] or one of these two constants in order
  2781. ** to signal SQLite whether or not the action is permitted. See the
  2782. ** [sqlite3_set_authorizer | authorizer documentation] for additional
  2783. ** information.
  2784. **
  2785. ** Note that SQLITE_IGNORE is also used as a [SQLITE_ROLLBACK | return code]
  2786. ** from the [sqlite3_vtab_on_conflict()] interface.
  2787. */
  2788. #define SQLITE_DENY 1 /* Abort the SQL statement with an error */
  2789. #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
  2790. /*
  2791. ** CAPI3REF: Authorizer Action Codes
  2792. **
  2793. ** The [sqlite3_set_authorizer()] interface registers a callback function
  2794. ** that is invoked to authorize certain SQL statement actions. The
  2795. ** second parameter to the callback is an integer code that specifies
  2796. ** what action is being authorized. These are the integer action codes that
  2797. ** the authorizer callback may be passed.
  2798. **
  2799. ** These action code values signify what kind of operation is to be
  2800. ** authorized. The 3rd and 4th parameters to the authorization
  2801. ** callback function will be parameters or NULL depending on which of these
  2802. ** codes is used as the second parameter. ^(The 5th parameter to the
  2803. ** authorizer callback is the name of the database ("main", "temp",
  2804. ** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback
  2805. ** is the name of the inner-most trigger or view that is responsible for
  2806. ** the access attempt or NULL if this access attempt is directly from
  2807. ** top-level SQL code.
  2808. */
  2809. /******************************************* 3rd ************ 4th ***********/
  2810. #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
  2811. #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
  2812. #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
  2813. #define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */
  2814. #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */
  2815. #define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */
  2816. #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */
  2817. #define SQLITE_CREATE_VIEW 8 /* View Name NULL */
  2818. #define SQLITE_DELETE 9 /* Table Name NULL */
  2819. #define SQLITE_DROP_INDEX 10 /* Index Name Table Name */
  2820. #define SQLITE_DROP_TABLE 11 /* Table Name NULL */
  2821. #define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */
  2822. #define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */
  2823. #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */
  2824. #define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */
  2825. #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */
  2826. #define SQLITE_DROP_VIEW 17 /* View Name NULL */
  2827. #define SQLITE_INSERT 18 /* Table Name NULL */
  2828. #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */
  2829. #define SQLITE_READ 20 /* Table Name Column Name */
  2830. #define SQLITE_SELECT 21 /* NULL NULL */
  2831. #define SQLITE_TRANSACTION 22 /* Operation NULL */
  2832. #define SQLITE_UPDATE 23 /* Table Name Column Name */
  2833. #define SQLITE_ATTACH 24 /* Filename NULL */
  2834. #define SQLITE_DETACH 25 /* Database Name NULL */
  2835. #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
  2836. #define SQLITE_REINDEX 27 /* Index Name NULL */
  2837. #define SQLITE_ANALYZE 28 /* Table Name NULL */
  2838. #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
  2839. #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
  2840. #define SQLITE_FUNCTION 31 /* NULL Function Name */
  2841. #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
  2842. #define SQLITE_COPY 0 /* No longer used */
  2843. /*
  2844. ** CAPI3REF: Tracing And Profiling Functions
  2845. **
  2846. ** These routines register callback functions that can be used for
  2847. ** tracing and profiling the execution of SQL statements.
  2848. **
  2849. ** ^The callback function registered by sqlite3_trace() is invoked at
  2850. ** various times when an SQL statement is being run by [sqlite3_step()].
  2851. ** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the
  2852. ** SQL statement text as the statement first begins executing.
  2853. ** ^(Additional sqlite3_trace() callbacks might occur
  2854. ** as each triggered subprogram is entered. The callbacks for triggers
  2855. ** contain a UTF-8 SQL comment that identifies the trigger.)^
  2856. **
  2857. ** ^The callback function registered by sqlite3_profile() is invoked
  2858. ** as each SQL statement finishes. ^The profile callback contains
  2859. ** the original statement text and an estimate of wall-clock time
  2860. ** of how long that statement took to run. ^The profile callback
  2861. ** time is in units of nanoseconds, however the current implementation
  2862. ** is only capable of millisecond resolution so the six least significant
  2863. ** digits in the time are meaningless. Future versions of SQLite
  2864. ** might provide greater resolution on the profiler callback. The
  2865. ** sqlite3_profile() function is considered experimental and is
  2866. ** subject to change in future versions of SQLite.
  2867. */
  2868. SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
  2869. SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
  2870. void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
  2871. /*
  2872. ** CAPI3REF: Query Progress Callbacks
  2873. **
  2874. ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
  2875. ** function X to be invoked periodically during long running calls to
  2876. ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
  2877. ** database connection D. An example use for this
  2878. ** interface is to keep a GUI updated during a large query.
  2879. **
  2880. ** ^The parameter P is passed through as the only parameter to the
  2881. ** callback function X. ^The parameter N is the number of
  2882. ** [virtual machine instructions] that are evaluated between successive
  2883. ** invocations of the callback X.
  2884. **
  2885. ** ^Only a single progress handler may be defined at one time per
  2886. ** [database connection]; setting a new progress handler cancels the
  2887. ** old one. ^Setting parameter X to NULL disables the progress handler.
  2888. ** ^The progress handler is also disabled by setting N to a value less
  2889. ** than 1.
  2890. **
  2891. ** ^If the progress callback returns non-zero, the operation is
  2892. ** interrupted. This feature can be used to implement a
  2893. ** "Cancel" button on a GUI progress dialog box.
  2894. **
  2895. ** The progress handler callback must not do anything that will modify
  2896. ** the database connection that invoked the progress handler.
  2897. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  2898. ** database connections for the meaning of "modify" in this paragraph.
  2899. **
  2900. */
  2901. SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
  2902. /*
  2903. ** CAPI3REF: Opening A New Database Connection
  2904. **
  2905. ** ^These routines open an SQLite database file as specified by the
  2906. ** filename argument. ^The filename argument is interpreted as UTF-8 for
  2907. ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
  2908. ** order for sqlite3_open16(). ^(A [database connection] handle is usually
  2909. ** returned in *ppDb, even if an error occurs. The only exception is that
  2910. ** if SQLite is unable to allocate memory to hold the [sqlite3] object,
  2911. ** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]
  2912. ** object.)^ ^(If the database is opened (and/or created) successfully, then
  2913. ** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The
  2914. ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
  2915. ** an English language description of the error following a failure of any
  2916. ** of the sqlite3_open() routines.
  2917. **
  2918. ** ^The default encoding for the database will be UTF-8 if
  2919. ** sqlite3_open() or sqlite3_open_v2() is called and
  2920. ** UTF-16 in the native byte order if sqlite3_open16() is used.
  2921. **
  2922. ** Whether or not an error occurs when it is opened, resources
  2923. ** associated with the [database connection] handle should be released by
  2924. ** passing it to [sqlite3_close()] when it is no longer required.
  2925. **
  2926. ** The sqlite3_open_v2() interface works like sqlite3_open()
  2927. ** except that it accepts two additional parameters for additional control
  2928. ** over the new database connection. ^(The flags parameter to
  2929. ** sqlite3_open_v2() can take one of
  2930. ** the following three values, optionally combined with the
  2931. ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
  2932. ** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^
  2933. **
  2934. ** <dl>
  2935. ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
  2936. ** <dd>The database is opened in read-only mode. If the database does not
  2937. ** already exist, an error is returned.</dd>)^
  2938. **
  2939. ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
  2940. ** <dd>The database is opened for reading and writing if possible, or reading
  2941. ** only if the file is write protected by the operating system. In either
  2942. ** case the database must already exist, otherwise an error is returned.</dd>)^
  2943. **
  2944. ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
  2945. ** <dd>The database is opened for reading and writing, and is created if
  2946. ** it does not already exist. This is the behavior that is always used for
  2947. ** sqlite3_open() and sqlite3_open16().</dd>)^
  2948. ** </dl>
  2949. **
  2950. ** If the 3rd parameter to sqlite3_open_v2() is not one of the
  2951. ** combinations shown above optionally combined with other
  2952. ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
  2953. ** then the behavior is undefined.
  2954. **
  2955. ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
  2956. ** opens in the multi-thread [threading mode] as long as the single-thread
  2957. ** mode has not been set at compile-time or start-time. ^If the
  2958. ** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens
  2959. ** in the serialized [threading mode] unless single-thread was
  2960. ** previously selected at compile-time or start-time.
  2961. ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be
  2962. ** eligible to use [shared cache mode], regardless of whether or not shared
  2963. ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The
  2964. ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not
  2965. ** participate in [shared cache mode] even if it is enabled.
  2966. **
  2967. ** ^The fourth parameter to sqlite3_open_v2() is the name of the
  2968. ** [sqlite3_vfs] object that defines the operating system interface that
  2969. ** the new database connection should use. ^If the fourth parameter is
  2970. ** a NULL pointer then the default [sqlite3_vfs] object is used.
  2971. **
  2972. ** ^If the filename is ":memory:", then a private, temporary in-memory database
  2973. ** is created for the connection. ^This in-memory database will vanish when
  2974. ** the database connection is closed. Future versions of SQLite might
  2975. ** make use of additional special filenames that begin with the ":" character.
  2976. ** It is recommended that when a database filename actually does begin with
  2977. ** a ":" character you should prefix the filename with a pathname such as
  2978. ** "./" to avoid ambiguity.
  2979. **
  2980. ** ^If the filename is an empty string, then a private, temporary
  2981. ** on-disk database will be created. ^This private database will be
  2982. ** automatically deleted as soon as the database connection is closed.
  2983. **
  2984. ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
  2985. **
  2986. ** ^If [URI filename] interpretation is enabled, and the filename argument
  2987. ** begins with "file:", then the filename is interpreted as a URI. ^URI
  2988. ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
  2989. ** set in the fourth argument to sqlite3_open_v2(), or if it has
  2990. ** been enabled globally using the [SQLITE_CONFIG_URI] option with the
  2991. ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
  2992. ** As of SQLite version 3.7.7, URI filename interpretation is turned off
  2993. ** by default, but future releases of SQLite might enable URI filename
  2994. ** interpretation by default. See "[URI filenames]" for additional
  2995. ** information.
  2996. **
  2997. ** URI filenames are parsed according to RFC 3986. ^If the URI contains an
  2998. ** authority, then it must be either an empty string or the string
  2999. ** "localhost". ^If the authority is not an empty string or "localhost", an
  3000. ** error is returned to the caller. ^The fragment component of a URI, if
  3001. ** present, is ignored.
  3002. **
  3003. ** ^SQLite uses the path component of the URI as the name of the disk file
  3004. ** which contains the database. ^If the path begins with a '/' character,
  3005. ** then it is interpreted as an absolute path. ^If the path does not begin
  3006. ** with a '/' (meaning that the authority section is omitted from the URI)
  3007. ** then the path is interpreted as a relative path.
  3008. ** ^On windows, the first component of an absolute path
  3009. ** is a drive specification (e.g. "C:").
  3010. **
  3011. ** [[core URI query parameters]]
  3012. ** The query component of a URI may contain parameters that are interpreted
  3013. ** either by SQLite itself, or by a [VFS | custom VFS implementation].
  3014. ** SQLite interprets the following three query parameters:
  3015. **
  3016. ** <ul>
  3017. ** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
  3018. ** a VFS object that provides the operating system interface that should
  3019. ** be used to access the database file on disk. ^If this option is set to
  3020. ** an empty string the default VFS object is used. ^Specifying an unknown
  3021. ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
  3022. ** present, then the VFS specified by the option takes precedence over
  3023. ** the value passed as the fourth parameter to sqlite3_open_v2().
  3024. **
  3025. ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw" or
  3026. ** "rwc". Attempting to set it to any other value is an error)^.
  3027. ** ^If "ro" is specified, then the database is opened for read-only
  3028. ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
  3029. ** third argument to sqlite3_prepare_v2(). ^If the mode option is set to
  3030. ** "rw", then the database is opened for read-write (but not create)
  3031. ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
  3032. ** been set. ^Value "rwc" is equivalent to setting both
  3033. ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If sqlite3_open_v2() is
  3034. ** used, it is an error to specify a value for the mode parameter that is
  3035. ** less restrictive than that specified by the flags passed as the third
  3036. ** parameter.
  3037. **
  3038. ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
  3039. ** "private". ^Setting it to "shared" is equivalent to setting the
  3040. ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
  3041. ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
  3042. ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
  3043. ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
  3044. ** a URI filename, its value overrides any behaviour requested by setting
  3045. ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
  3046. ** </ul>
  3047. **
  3048. ** ^Specifying an unknown parameter in the query component of a URI is not an
  3049. ** error. Future versions of SQLite might understand additional query
  3050. ** parameters. See "[query parameters with special meaning to SQLite]" for
  3051. ** additional information.
  3052. **
  3053. ** [[URI filename examples]] <h3>URI filename examples</h3>
  3054. **
  3055. ** <table border="1" align=center cellpadding=5>
  3056. ** <tr><th> URI filenames <th> Results
  3057. ** <tr><td> file:data.db <td>
  3058. ** Open the file "data.db" in the current directory.
  3059. ** <tr><td> file:/home/fred/data.db<br>
  3060. ** file:///home/fred/data.db <br>
  3061. ** file://localhost/home/fred/data.db <br> <td>
  3062. ** Open the database file "/home/fred/data.db".
  3063. ** <tr><td> file://darkstar/home/fred/data.db <td>
  3064. ** An error. "darkstar" is not a recognized authority.
  3065. ** <tr><td style="white-space:nowrap">
  3066. ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
  3067. ** <td> Windows only: Open the file "data.db" on fred's desktop on drive
  3068. ** C:. Note that the %20 escaping in this example is not strictly
  3069. ** necessary - space characters can be used literally
  3070. ** in URI filenames.
  3071. ** <tr><td> file:data.db?mode=ro&cache=private <td>
  3072. ** Open file "data.db" in the current directory for read-only access.
  3073. ** Regardless of whether or not shared-cache mode is enabled by
  3074. ** default, use a private cache.
  3075. ** <tr><td> file:/home/fred/data.db?vfs=unix-nolock <td>
  3076. ** Open file "/home/fred/data.db". Use the special VFS "unix-nolock".
  3077. ** <tr><td> file:data.db?mode=readonly <td>
  3078. ** An error. "readonly" is not a valid option for the "mode" parameter.
  3079. ** </table>
  3080. **
  3081. ** ^URI hexadecimal escape sequences (%HH) are supported within the path and
  3082. ** query components of a URI. A hexadecimal escape sequence consists of a
  3083. ** percent sign - "%" - followed by exactly two hexadecimal digits
  3084. ** specifying an octet value. ^Before the path or query components of a
  3085. ** URI filename are interpreted, they are encoded using UTF-8 and all
  3086. ** hexadecimal escape sequences replaced by a single byte containing the
  3087. ** corresponding octet. If this process generates an invalid UTF-8 encoding,
  3088. ** the results are undefined.
  3089. **
  3090. ** <b>Note to Windows users:</b> The encoding used for the filename argument
  3091. ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
  3092. ** codepage is currently defined. Filenames containing international
  3093. ** characters must be converted to UTF-8 prior to passing them into
  3094. ** sqlite3_open() or sqlite3_open_v2().
  3095. */
  3096. SQLITE_API int sqlite3_open(
  3097. const char *filename, /* Database filename (UTF-8) */
  3098. sqlite3 **ppDb /* OUT: SQLite db handle */
  3099. );
  3100. SQLITE_API int sqlite3_open16(
  3101. const void *filename, /* Database filename (UTF-16) */
  3102. sqlite3 **ppDb /* OUT: SQLite db handle */
  3103. );
  3104. SQLITE_API int sqlite3_open_v2(
  3105. const char *filename, /* Database filename (UTF-8) */
  3106. sqlite3 **ppDb, /* OUT: SQLite db handle */
  3107. int flags, /* Flags */
  3108. const char *zVfs /* Name of VFS module to use */
  3109. );
  3110. /*
  3111. ** CAPI3REF: Obtain Values For URI Parameters
  3112. **
  3113. ** These are utility routines, useful to VFS implementations, that check
  3114. ** to see if a database file was a URI that contained a specific query
  3115. ** parameter, and if so obtains the value of that query parameter.
  3116. **
  3117. ** If F is the database filename pointer passed into the xOpen() method of
  3118. ** a VFS implementation when the flags parameter to xOpen() has one or
  3119. ** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and
  3120. ** P is the name of the query parameter, then
  3121. ** sqlite3_uri_parameter(F,P) returns the value of the P
  3122. ** parameter if it exists or a NULL pointer if P does not appear as a
  3123. ** query parameter on F. If P is a query parameter of F
  3124. ** has no explicit value, then sqlite3_uri_parameter(F,P) returns
  3125. ** a pointer to an empty string.
  3126. **
  3127. ** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
  3128. ** parameter and returns true (1) or false (0) according to the value
  3129. ** of P. The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the
  3130. ** value of query parameter P is one of "yes", "true", or "on" in any
  3131. ** case or if the value begins with a non-zero number. The
  3132. ** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
  3133. ** query parameter P is one of "no", "false", or "off" in any case or
  3134. ** if the value begins with a numeric zero. If P is not a query
  3135. ** parameter on F or if the value of P is does not match any of the
  3136. ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
  3137. **
  3138. ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
  3139. ** 64-bit signed integer and returns that integer, or D if P does not
  3140. ** exist. If the value of P is something other than an integer, then
  3141. ** zero is returned.
  3142. **
  3143. ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
  3144. ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and
  3145. ** is not a database file pathname pointer that SQLite passed into the xOpen
  3146. ** VFS method, then the behavior of this routine is undefined and probably
  3147. ** undesirable.
  3148. */
  3149. SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
  3150. SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
  3151. SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
  3152. /*
  3153. ** CAPI3REF: Error Codes And Messages
  3154. **
  3155. ** ^The sqlite3_errcode() interface returns the numeric [result code] or
  3156. ** [extended result code] for the most recent failed sqlite3_* API call
  3157. ** associated with a [database connection]. If a prior API call failed
  3158. ** but the most recent API call succeeded, the return value from
  3159. ** sqlite3_errcode() is undefined. ^The sqlite3_extended_errcode()
  3160. ** interface is the same except that it always returns the
  3161. ** [extended result code] even when extended result codes are
  3162. ** disabled.
  3163. **
  3164. ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
  3165. ** text that describes the error, as either UTF-8 or UTF-16 respectively.
  3166. ** ^(Memory to hold the error message string is managed internally.
  3167. ** The application does not need to worry about freeing the result.
  3168. ** However, the error string might be overwritten or deallocated by
  3169. ** subsequent calls to other SQLite interface functions.)^
  3170. **
  3171. ** When the serialized [threading mode] is in use, it might be the
  3172. ** case that a second error occurs on a separate thread in between
  3173. ** the time of the first error and the call to these interfaces.
  3174. ** When that happens, the second error will be reported since these
  3175. ** interfaces always report the most recent result. To avoid
  3176. ** this, each thread can obtain exclusive use of the [database connection] D
  3177. ** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning
  3178. ** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after
  3179. ** all calls to the interfaces listed here are completed.
  3180. **
  3181. ** If an interface fails with SQLITE_MISUSE, that means the interface
  3182. ** was invoked incorrectly by the application. In that case, the
  3183. ** error code and message may or may not be set.
  3184. */
  3185. SQLITE_API int sqlite3_errcode(sqlite3 *db);
  3186. SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
  3187. SQLITE_API const char *sqlite3_errmsg(sqlite3*);
  3188. SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
  3189. /*
  3190. ** CAPI3REF: SQL Statement Object
  3191. ** KEYWORDS: {prepared statement} {prepared statements}
  3192. **
  3193. ** An instance of this object represents a single SQL statement.
  3194. ** This object is variously known as a "prepared statement" or a
  3195. ** "compiled SQL statement" or simply as a "statement".
  3196. **
  3197. ** The life of a statement object goes something like this:
  3198. **
  3199. ** <ol>
  3200. ** <li> Create the object using [sqlite3_prepare_v2()] or a related
  3201. ** function.
  3202. ** <li> Bind values to [host parameters] using the sqlite3_bind_*()
  3203. ** interfaces.
  3204. ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
  3205. ** <li> Reset the statement using [sqlite3_reset()] then go back
  3206. ** to step 2. Do this zero or more times.
  3207. ** <li> Destroy the object using [sqlite3_finalize()].
  3208. ** </ol>
  3209. **
  3210. ** Refer to documentation on individual methods above for additional
  3211. ** information.
  3212. */
  3213. typedef struct sqlite3_stmt sqlite3_stmt;
  3214. /*
  3215. ** CAPI3REF: Run-time Limits
  3216. **
  3217. ** ^(This interface allows the size of various constructs to be limited
  3218. ** on a connection by connection basis. The first parameter is the
  3219. ** [database connection] whose limit is to be set or queried. The
  3220. ** second parameter is one of the [limit categories] that define a
  3221. ** class of constructs to be size limited. The third parameter is the
  3222. ** new limit for that construct.)^
  3223. **
  3224. ** ^If the new limit is a negative number, the limit is unchanged.
  3225. ** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a
  3226. ** [limits | hard upper bound]
  3227. ** set at compile-time by a C preprocessor macro called
  3228. ** [limits | SQLITE_MAX_<i>NAME</i>].
  3229. ** (The "_LIMIT_" in the name is changed to "_MAX_".))^
  3230. ** ^Attempts to increase a limit above its hard upper bound are
  3231. ** silently truncated to the hard upper bound.
  3232. **
  3233. ** ^Regardless of whether or not the limit was changed, the
  3234. ** [sqlite3_limit()] interface returns the prior value of the limit.
  3235. ** ^Hence, to find the current value of a limit without changing it,
  3236. ** simply invoke this interface with the third parameter set to -1.
  3237. **
  3238. ** Run-time limits are intended for use in applications that manage
  3239. ** both their own internal database and also databases that are controlled
  3240. ** by untrusted external sources. An example application might be a
  3241. ** web browser that has its own databases for storing history and
  3242. ** separate databases controlled by JavaScript applications downloaded
  3243. ** off the Internet. The internal databases can be given the
  3244. ** large, default limits. Databases managed by external sources can
  3245. ** be given much smaller limits designed to prevent a denial of service
  3246. ** attack. Developers might also want to use the [sqlite3_set_authorizer()]
  3247. ** interface to further control untrusted SQL. The size of the database
  3248. ** created by an untrusted script can be contained using the
  3249. ** [max_page_count] [PRAGMA].
  3250. **
  3251. ** New run-time limit categories may be added in future releases.
  3252. */
  3253. SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
  3254. /*
  3255. ** CAPI3REF: Run-Time Limit Categories
  3256. ** KEYWORDS: {limit category} {*limit categories}
  3257. **
  3258. ** These constants define various performance limits
  3259. ** that can be lowered at run-time using [sqlite3_limit()].
  3260. ** The synopsis of the meanings of the various limits is shown below.
  3261. ** Additional information is available at [limits | Limits in SQLite].
  3262. **
  3263. ** <dl>
  3264. ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
  3265. ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
  3266. **
  3267. ** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
  3268. ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
  3269. **
  3270. ** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>
  3271. ** <dd>The maximum number of columns in a table definition or in the
  3272. ** result set of a [SELECT] or the maximum number of columns in an index
  3273. ** or in an ORDER BY or GROUP BY clause.</dd>)^
  3274. **
  3275. ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
  3276. ** <dd>The maximum depth of the parse tree on any expression.</dd>)^
  3277. **
  3278. ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
  3279. ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
  3280. **
  3281. ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
  3282. ** <dd>The maximum number of instructions in a virtual machine program
  3283. ** used to implement an SQL statement. This limit is not currently
  3284. ** enforced, though that might be added in some future release of
  3285. ** SQLite.</dd>)^
  3286. **
  3287. ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
  3288. ** <dd>The maximum number of arguments on a function.</dd>)^
  3289. **
  3290. ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
  3291. ** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
  3292. **
  3293. ** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]
  3294. ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
  3295. ** <dd>The maximum length of the pattern argument to the [LIKE] or
  3296. ** [GLOB] operators.</dd>)^
  3297. **
  3298. ** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
  3299. ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
  3300. ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
  3301. **
  3302. ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
  3303. ** <dd>The maximum depth of recursion for triggers.</dd>)^
  3304. ** </dl>
  3305. */
  3306. #define SQLITE_LIMIT_LENGTH 0
  3307. #define SQLITE_LIMIT_SQL_LENGTH 1
  3308. #define SQLITE_LIMIT_COLUMN 2
  3309. #define SQLITE_LIMIT_EXPR_DEPTH 3
  3310. #define SQLITE_LIMIT_COMPOUND_SELECT 4
  3311. #define SQLITE_LIMIT_VDBE_OP 5
  3312. #define SQLITE_LIMIT_FUNCTION_ARG 6
  3313. #define SQLITE_LIMIT_ATTACHED 7
  3314. #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
  3315. #define SQLITE_LIMIT_VARIABLE_NUMBER 9
  3316. #define SQLITE_LIMIT_TRIGGER_DEPTH 10
  3317. /*
  3318. ** CAPI3REF: Compiling An SQL Statement
  3319. ** KEYWORDS: {SQL statement compiler}
  3320. **
  3321. ** To execute an SQL query, it must first be compiled into a byte-code
  3322. ** program using one of these routines.
  3323. **
  3324. ** The first argument, "db", is a [database connection] obtained from a
  3325. ** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or
  3326. ** [sqlite3_open16()]. The database connection must not have been closed.
  3327. **
  3328. ** The second argument, "zSql", is the statement to be compiled, encoded
  3329. ** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2()
  3330. ** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2()
  3331. ** use UTF-16.
  3332. **
  3333. ** ^If the nByte argument is less than zero, then zSql is read up to the
  3334. ** first zero terminator. ^If nByte is non-negative, then it is the maximum
  3335. ** number of bytes read from zSql. ^When nByte is non-negative, the
  3336. ** zSql string ends at either the first '\000' or '\u0000' character or
  3337. ** the nByte-th byte, whichever comes first. If the caller knows
  3338. ** that the supplied string is nul-terminated, then there is a small
  3339. ** performance advantage to be gained by passing an nByte parameter that
  3340. ** is equal to the number of bytes in the input string <i>including</i>
  3341. ** the nul-terminator bytes as this saves SQLite from having to
  3342. ** make a copy of the input string.
  3343. **
  3344. ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
  3345. ** past the end of the first SQL statement in zSql. These routines only
  3346. ** compile the first statement in zSql, so *pzTail is left pointing to
  3347. ** what remains uncompiled.
  3348. **
  3349. ** ^*ppStmt is left pointing to a compiled [prepared statement] that can be
  3350. ** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set
  3351. ** to NULL. ^If the input text contains no SQL (if the input is an empty
  3352. ** string or a comment) then *ppStmt is set to NULL.
  3353. ** The calling procedure is responsible for deleting the compiled
  3354. ** SQL statement using [sqlite3_finalize()] after it has finished with it.
  3355. ** ppStmt may not be NULL.
  3356. **
  3357. ** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK];
  3358. ** otherwise an [error code] is returned.
  3359. **
  3360. ** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are
  3361. ** recommended for all new programs. The two older interfaces are retained
  3362. ** for backwards compatibility, but their use is discouraged.
  3363. ** ^In the "v2" interfaces, the prepared statement
  3364. ** that is returned (the [sqlite3_stmt] object) contains a copy of the
  3365. ** original SQL text. This causes the [sqlite3_step()] interface to
  3366. ** behave differently in three ways:
  3367. **
  3368. ** <ol>
  3369. ** <li>
  3370. ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
  3371. ** always used to do, [sqlite3_step()] will automatically recompile the SQL
  3372. ** statement and try to run it again.
  3373. ** </li>
  3374. **
  3375. ** <li>
  3376. ** ^When an error occurs, [sqlite3_step()] will return one of the detailed
  3377. ** [error codes] or [extended error codes]. ^The legacy behavior was that
  3378. ** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code
  3379. ** and the application would have to make a second call to [sqlite3_reset()]
  3380. ** in order to find the underlying cause of the problem. With the "v2" prepare
  3381. ** interfaces, the underlying reason for the error is returned immediately.
  3382. ** </li>
  3383. **
  3384. ** <li>
  3385. ** ^If the specific value bound to [parameter | host parameter] in the
  3386. ** WHERE clause might influence the choice of query plan for a statement,
  3387. ** then the statement will be automatically recompiled, as if there had been
  3388. ** a schema change, on the first [sqlite3_step()] call following any change
  3389. ** to the [sqlite3_bind_text | bindings] of that [parameter].
  3390. ** ^The specific value of WHERE-clause [parameter] might influence the
  3391. ** choice of query plan if the parameter is the left-hand side of a [LIKE]
  3392. ** or [GLOB] operator or if the parameter is compared to an indexed column
  3393. ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
  3394. ** the
  3395. ** </li>
  3396. ** </ol>
  3397. */
  3398. SQLITE_API int sqlite3_prepare(
  3399. sqlite3 *db, /* Database handle */
  3400. const char *zSql, /* SQL statement, UTF-8 encoded */
  3401. int nByte, /* Maximum length of zSql in bytes. */
  3402. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  3403. const char **pzTail /* OUT: Pointer to unused portion of zSql */
  3404. );
  3405. SQLITE_API int sqlite3_prepare_v2(
  3406. sqlite3 *db, /* Database handle */
  3407. const char *zSql, /* SQL statement, UTF-8 encoded */
  3408. int nByte, /* Maximum length of zSql in bytes. */
  3409. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  3410. const char **pzTail /* OUT: Pointer to unused portion of zSql */
  3411. );
  3412. SQLITE_API int sqlite3_prepare16(
  3413. sqlite3 *db, /* Database handle */
  3414. const void *zSql, /* SQL statement, UTF-16 encoded */
  3415. int nByte, /* Maximum length of zSql in bytes. */
  3416. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  3417. const void **pzTail /* OUT: Pointer to unused portion of zSql */
  3418. );
  3419. SQLITE_API int sqlite3_prepare16_v2(
  3420. sqlite3 *db, /* Database handle */
  3421. const void *zSql, /* SQL statement, UTF-16 encoded */
  3422. int nByte, /* Maximum length of zSql in bytes. */
  3423. sqlite3_stmt **ppStmt, /* OUT: Statement handle */
  3424. const void **pzTail /* OUT: Pointer to unused portion of zSql */
  3425. );
  3426. /*
  3427. ** CAPI3REF: Retrieving Statement SQL
  3428. **
  3429. ** ^This interface can be used to retrieve a saved copy of the original
  3430. ** SQL text used to create a [prepared statement] if that statement was
  3431. ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
  3432. */
  3433. SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
  3434. /*
  3435. ** CAPI3REF: Determine If An SQL Statement Writes The Database
  3436. **
  3437. ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
  3438. ** and only if the [prepared statement] X makes no direct changes to
  3439. ** the content of the database file.
  3440. **
  3441. ** Note that [application-defined SQL functions] or
  3442. ** [virtual tables] might change the database indirectly as a side effect.
  3443. ** ^(For example, if an application defines a function "eval()" that
  3444. ** calls [sqlite3_exec()], then the following SQL statement would
  3445. ** change the database file through side-effects:
  3446. **
  3447. ** <blockquote><pre>
  3448. ** SELECT eval('DELETE FROM t1') FROM t2;
  3449. ** </pre></blockquote>
  3450. **
  3451. ** But because the [SELECT] statement does not change the database file
  3452. ** directly, sqlite3_stmt_readonly() would still return true.)^
  3453. **
  3454. ** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
  3455. ** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
  3456. ** since the statements themselves do not actually modify the database but
  3457. ** rather they control the timing of when other statements modify the
  3458. ** database. ^The [ATTACH] and [DETACH] statements also cause
  3459. ** sqlite3_stmt_readonly() to return true since, while those statements
  3460. ** change the configuration of a database connection, they do not make
  3461. ** changes to the content of the database files on disk.
  3462. */
  3463. SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
  3464. /*
  3465. ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
  3466. **
  3467. ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
  3468. ** [prepared statement] S has been stepped at least once using
  3469. ** [sqlite3_step(S)] but has not run to completion and/or has not
  3470. ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
  3471. ** interface returns false if S is a NULL pointer. If S is not a
  3472. ** NULL pointer and is not a pointer to a valid [prepared statement]
  3473. ** object, then the behavior is undefined and probably undesirable.
  3474. **
  3475. ** This interface can be used in combination [sqlite3_next_stmt()]
  3476. ** to locate all prepared statements associated with a database
  3477. ** connection that are in need of being reset. This can be used,
  3478. ** for example, in diagnostic routines to search for prepared
  3479. ** statements that are holding a transaction open.
  3480. */
  3481. SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*);
  3482. /*
  3483. ** CAPI3REF: Dynamically Typed Value Object
  3484. ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
  3485. **
  3486. ** SQLite uses the sqlite3_value object to represent all values
  3487. ** that can be stored in a database table. SQLite uses dynamic typing
  3488. ** for the values it stores. ^Values stored in sqlite3_value objects
  3489. ** can be integers, floating point values, strings, BLOBs, or NULL.
  3490. **
  3491. ** An sqlite3_value object may be either "protected" or "unprotected".
  3492. ** Some interfaces require a protected sqlite3_value. Other interfaces
  3493. ** will accept either a protected or an unprotected sqlite3_value.
  3494. ** Every interface that accepts sqlite3_value arguments specifies
  3495. ** whether or not it requires a protected sqlite3_value.
  3496. **
  3497. ** The terms "protected" and "unprotected" refer to whether or not
  3498. ** a mutex is held. An internal mutex is held for a protected
  3499. ** sqlite3_value object but no mutex is held for an unprotected
  3500. ** sqlite3_value object. If SQLite is compiled to be single-threaded
  3501. ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
  3502. ** or if SQLite is run in one of reduced mutex modes
  3503. ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
  3504. ** then there is no distinction between protected and unprotected
  3505. ** sqlite3_value objects and they can be used interchangeably. However,
  3506. ** for maximum code portability it is recommended that applications
  3507. ** still make the distinction between protected and unprotected
  3508. ** sqlite3_value objects even when not strictly required.
  3509. **
  3510. ** ^The sqlite3_value objects that are passed as parameters into the
  3511. ** implementation of [application-defined SQL functions] are protected.
  3512. ** ^The sqlite3_value object returned by
  3513. ** [sqlite3_column_value()] is unprotected.
  3514. ** Unprotected sqlite3_value objects may only be used with
  3515. ** [sqlite3_result_value()] and [sqlite3_bind_value()].
  3516. ** The [sqlite3_value_blob | sqlite3_value_type()] family of
  3517. ** interfaces require protected sqlite3_value objects.
  3518. */
  3519. typedef struct Mem sqlite3_value;
  3520. /*
  3521. ** CAPI3REF: SQL Function Context Object
  3522. **
  3523. ** The context in which an SQL function executes is stored in an
  3524. ** sqlite3_context object. ^A pointer to an sqlite3_context object
  3525. ** is always first parameter to [application-defined SQL functions].
  3526. ** The application-defined SQL function implementation will pass this
  3527. ** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
  3528. ** [sqlite3_aggregate_context()], [sqlite3_user_data()],
  3529. ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
  3530. ** and/or [sqlite3_set_auxdata()].
  3531. */
  3532. typedef struct sqlite3_context sqlite3_context;
  3533. /*
  3534. ** CAPI3REF: Binding Values To Prepared Statements
  3535. ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
  3536. ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
  3537. **
  3538. ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
  3539. ** literals may be replaced by a [parameter] that matches one of following
  3540. ** templates:
  3541. **
  3542. ** <ul>
  3543. ** <li> ?
  3544. ** <li> ?NNN
  3545. ** <li> :VVV
  3546. ** <li> @VVV
  3547. ** <li> $VVV
  3548. ** </ul>
  3549. **
  3550. ** In the templates above, NNN represents an integer literal,
  3551. ** and VVV represents an alphanumeric identifier.)^ ^The values of these
  3552. ** parameters (also called "host parameter names" or "SQL parameters")
  3553. ** can be set using the sqlite3_bind_*() routines defined here.
  3554. **
  3555. ** ^The first argument to the sqlite3_bind_*() routines is always
  3556. ** a pointer to the [sqlite3_stmt] object returned from
  3557. ** [sqlite3_prepare_v2()] or its variants.
  3558. **
  3559. ** ^The second argument is the index of the SQL parameter to be set.
  3560. ** ^The leftmost SQL parameter has an index of 1. ^When the same named
  3561. ** SQL parameter is used more than once, second and subsequent
  3562. ** occurrences have the same index as the first occurrence.
  3563. ** ^The index for named parameters can be looked up using the
  3564. ** [sqlite3_bind_parameter_index()] API if desired. ^The index
  3565. ** for "?NNN" parameters is the value of NNN.
  3566. ** ^The NNN value must be between 1 and the [sqlite3_limit()]
  3567. ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
  3568. **
  3569. ** ^The third argument is the value to bind to the parameter.
  3570. **
  3571. ** ^(In those routines that have a fourth argument, its value is the
  3572. ** number of bytes in the parameter. To be clear: the value is the
  3573. ** number of <u>bytes</u> in the value, not the number of characters.)^
  3574. ** ^If the fourth parameter is negative, the length of the string is
  3575. ** the number of bytes up to the first zero terminator.
  3576. ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
  3577. ** or sqlite3_bind_text16() then that parameter must be the byte offset
  3578. ** where the NUL terminator would occur assuming the string were NUL
  3579. ** terminated. If any NUL characters occur at byte offsets less than
  3580. ** the value of the fourth parameter then the resulting string value will
  3581. ** contain embedded NULs. The result of expressions involving strings
  3582. ** with embedded NULs is undefined.
  3583. **
  3584. ** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
  3585. ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
  3586. ** string after SQLite has finished with it. ^The destructor is called
  3587. ** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(),
  3588. ** sqlite3_bind_text(), or sqlite3_bind_text16() fails.
  3589. ** ^If the fifth argument is
  3590. ** the special value [SQLITE_STATIC], then SQLite assumes that the
  3591. ** information is in static, unmanaged space and does not need to be freed.
  3592. ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
  3593. ** SQLite makes its own private copy of the data immediately, before
  3594. ** the sqlite3_bind_*() routine returns.
  3595. **
  3596. ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
  3597. ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory
  3598. ** (just an integer to hold its size) while it is being processed.
  3599. ** Zeroblobs are intended to serve as placeholders for BLOBs whose
  3600. ** content is later written using
  3601. ** [sqlite3_blob_open | incremental BLOB I/O] routines.
  3602. ** ^A negative value for the zeroblob results in a zero-length BLOB.
  3603. **
  3604. ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
  3605. ** for the [prepared statement] or with a prepared statement for which
  3606. ** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
  3607. ** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_()
  3608. ** routine is passed a [prepared statement] that has been finalized, the
  3609. ** result is undefined and probably harmful.
  3610. **
  3611. ** ^Bindings are not cleared by the [sqlite3_reset()] routine.
  3612. ** ^Unbound parameters are interpreted as NULL.
  3613. **
  3614. ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
  3615. ** [error code] if anything goes wrong.
  3616. ** ^[SQLITE_RANGE] is returned if the parameter
  3617. ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails.
  3618. **
  3619. ** See also: [sqlite3_bind_parameter_count()],
  3620. ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
  3621. */
  3622. SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
  3623. SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
  3624. SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
  3625. SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
  3626. SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
  3627. SQLITE_API int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));
  3628. SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
  3629. SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
  3630. SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
  3631. /*
  3632. ** CAPI3REF: Number Of SQL Parameters
  3633. **
  3634. ** ^This routine can be used to find the number of [SQL parameters]
  3635. ** in a [prepared statement]. SQL parameters are tokens of the
  3636. ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
  3637. ** placeholders for values that are [sqlite3_bind_blob | bound]
  3638. ** to the parameters at a later time.
  3639. **
  3640. ** ^(This routine actually returns the index of the largest (rightmost)
  3641. ** parameter. For all forms except ?NNN, this will correspond to the
  3642. ** number of unique parameters. If parameters of the ?NNN form are used,
  3643. ** there may be gaps in the list.)^
  3644. **
  3645. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  3646. ** [sqlite3_bind_parameter_name()], and
  3647. ** [sqlite3_bind_parameter_index()].
  3648. */
  3649. SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*);
  3650. /*
  3651. ** CAPI3REF: Name Of A Host Parameter
  3652. **
  3653. ** ^The sqlite3_bind_parameter_name(P,N) interface returns
  3654. ** the name of the N-th [SQL parameter] in the [prepared statement] P.
  3655. ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
  3656. ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
  3657. ** respectively.
  3658. ** In other words, the initial ":" or "$" or "@" or "?"
  3659. ** is included as part of the name.)^
  3660. ** ^Parameters of the form "?" without a following integer have no name
  3661. ** and are referred to as "nameless" or "anonymous parameters".
  3662. **
  3663. ** ^The first host parameter has an index of 1, not 0.
  3664. **
  3665. ** ^If the value N is out of range or if the N-th parameter is
  3666. ** nameless, then NULL is returned. ^The returned string is
  3667. ** always in UTF-8 encoding even if the named parameter was
  3668. ** originally specified as UTF-16 in [sqlite3_prepare16()] or
  3669. ** [sqlite3_prepare16_v2()].
  3670. **
  3671. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  3672. ** [sqlite3_bind_parameter_count()], and
  3673. ** [sqlite3_bind_parameter_index()].
  3674. */
  3675. SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
  3676. /*
  3677. ** CAPI3REF: Index Of A Parameter With A Given Name
  3678. **
  3679. ** ^Return the index of an SQL parameter given its name. ^The
  3680. ** index value returned is suitable for use as the second
  3681. ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
  3682. ** is returned if no matching parameter is found. ^The parameter
  3683. ** name must be given in UTF-8 even if the original statement
  3684. ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()].
  3685. **
  3686. ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  3687. ** [sqlite3_bind_parameter_count()], and
  3688. ** [sqlite3_bind_parameter_index()].
  3689. */
  3690. SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
  3691. /*
  3692. ** CAPI3REF: Reset All Bindings On A Prepared Statement
  3693. **
  3694. ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
  3695. ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
  3696. ** ^Use this routine to reset all host parameters to NULL.
  3697. */
  3698. SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*);
  3699. /*
  3700. ** CAPI3REF: Number Of Columns In A Result Set
  3701. **
  3702. ** ^Return the number of columns in the result set returned by the
  3703. ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
  3704. ** statement that does not return data (for example an [UPDATE]).
  3705. **
  3706. ** See also: [sqlite3_data_count()]
  3707. */
  3708. SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
  3709. /*
  3710. ** CAPI3REF: Column Names In A Result Set
  3711. **
  3712. ** ^These routines return the name assigned to a particular column
  3713. ** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
  3714. ** interface returns a pointer to a zero-terminated UTF-8 string
  3715. ** and sqlite3_column_name16() returns a pointer to a zero-terminated
  3716. ** UTF-16 string. ^The first parameter is the [prepared statement]
  3717. ** that implements the [SELECT] statement. ^The second parameter is the
  3718. ** column number. ^The leftmost column is number 0.
  3719. **
  3720. ** ^The returned string pointer is valid until either the [prepared statement]
  3721. ** is destroyed by [sqlite3_finalize()] or until the statement is automatically
  3722. ** reprepared by the first call to [sqlite3_step()] for a particular run
  3723. ** or until the next call to
  3724. ** sqlite3_column_name() or sqlite3_column_name16() on the same column.
  3725. **
  3726. ** ^If sqlite3_malloc() fails during the processing of either routine
  3727. ** (for example during a conversion from UTF-8 to UTF-16) then a
  3728. ** NULL pointer is returned.
  3729. **
  3730. ** ^The name of a result column is the value of the "AS" clause for
  3731. ** that column, if there is an AS clause. If there is no AS clause
  3732. ** then the name of the column is unspecified and may change from
  3733. ** one release of SQLite to the next.
  3734. */
  3735. SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N);
  3736. SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N);
  3737. /*
  3738. ** CAPI3REF: Source Of Data In A Query Result
  3739. **
  3740. ** ^These routines provide a means to determine the database, table, and
  3741. ** table column that is the origin of a particular result column in
  3742. ** [SELECT] statement.
  3743. ** ^The name of the database or table or column can be returned as
  3744. ** either a UTF-8 or UTF-16 string. ^The _database_ routines return
  3745. ** the database name, the _table_ routines return the table name, and
  3746. ** the origin_ routines return the column name.
  3747. ** ^The returned string is valid until the [prepared statement] is destroyed
  3748. ** using [sqlite3_finalize()] or until the statement is automatically
  3749. ** reprepared by the first call to [sqlite3_step()] for a particular run
  3750. ** or until the same information is requested
  3751. ** again in a different encoding.
  3752. **
  3753. ** ^The names returned are the original un-aliased names of the
  3754. ** database, table, and column.
  3755. **
  3756. ** ^The first argument to these interfaces is a [prepared statement].
  3757. ** ^These functions return information about the Nth result column returned by
  3758. ** the statement, where N is the second function argument.
  3759. ** ^The left-most column is column 0 for these routines.
  3760. **
  3761. ** ^If the Nth column returned by the statement is an expression or
  3762. ** subquery and is not a column value, then all of these functions return
  3763. ** NULL. ^These routine might also return NULL if a memory allocation error
  3764. ** occurs. ^Otherwise, they return the name of the attached database, table,
  3765. ** or column that query result column was extracted from.
  3766. **
  3767. ** ^As with all other SQLite APIs, those whose names end with "16" return
  3768. ** UTF-16 encoded strings and the other functions return UTF-8.
  3769. **
  3770. ** ^These APIs are only available if the library was compiled with the
  3771. ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
  3772. **
  3773. ** If two or more threads call one or more of these routines against the same
  3774. ** prepared statement and column at the same time then the results are
  3775. ** undefined.
  3776. **
  3777. ** If two or more threads call one or more
  3778. ** [sqlite3_column_database_name | column metadata interfaces]
  3779. ** for the same [prepared statement] and result column
  3780. ** at the same time then the results are undefined.
  3781. */
  3782. SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int);
  3783. SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
  3784. SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int);
  3785. SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
  3786. SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
  3787. SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
  3788. /*
  3789. ** CAPI3REF: Declared Datatype Of A Query Result
  3790. **
  3791. ** ^(The first parameter is a [prepared statement].
  3792. ** If this statement is a [SELECT] statement and the Nth column of the
  3793. ** returned result set of that [SELECT] is a table column (not an
  3794. ** expression or subquery) then the declared type of the table
  3795. ** column is returned.)^ ^If the Nth column of the result set is an
  3796. ** expression or subquery, then a NULL pointer is returned.
  3797. ** ^The returned string is always UTF-8 encoded.
  3798. **
  3799. ** ^(For example, given the database schema:
  3800. **
  3801. ** CREATE TABLE t1(c1 VARIANT);
  3802. **
  3803. ** and the following statement to be compiled:
  3804. **
  3805. ** SELECT c1 + 1, c1 FROM t1;
  3806. **
  3807. ** this routine would return the string "VARIANT" for the second result
  3808. ** column (i==1), and a NULL pointer for the first result column (i==0).)^
  3809. **
  3810. ** ^SQLite uses dynamic run-time typing. ^So just because a column
  3811. ** is declared to contain a particular type does not mean that the
  3812. ** data stored in that column is of the declared type. SQLite is
  3813. ** strongly typed, but the typing is dynamic not static. ^Type
  3814. ** is associated with individual values, not with the containers
  3815. ** used to hold those values.
  3816. */
  3817. SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int);
  3818. SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
  3819. /*
  3820. ** CAPI3REF: Evaluate An SQL Statement
  3821. **
  3822. ** After a [prepared statement] has been prepared using either
  3823. ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
  3824. ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
  3825. ** must be called one or more times to evaluate the statement.
  3826. **
  3827. ** The details of the behavior of the sqlite3_step() interface depend
  3828. ** on whether the statement was prepared using the newer "v2" interface
  3829. ** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy
  3830. ** interface [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the
  3831. ** new "v2" interface is recommended for new applications but the legacy
  3832. ** interface will continue to be supported.
  3833. **
  3834. ** ^In the legacy interface, the return value will be either [SQLITE_BUSY],
  3835. ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
  3836. ** ^With the "v2" interface, any of the other [result codes] or
  3837. ** [extended result codes] might be returned as well.
  3838. **
  3839. ** ^[SQLITE_BUSY] means that the database engine was unable to acquire the
  3840. ** database locks it needs to do its job. ^If the statement is a [COMMIT]
  3841. ** or occurs outside of an explicit transaction, then you can retry the
  3842. ** statement. If the statement is not a [COMMIT] and occurs within an
  3843. ** explicit transaction then you should rollback the transaction before
  3844. ** continuing.
  3845. **
  3846. ** ^[SQLITE_DONE] means that the statement has finished executing
  3847. ** successfully. sqlite3_step() should not be called again on this virtual
  3848. ** machine without first calling [sqlite3_reset()] to reset the virtual
  3849. ** machine back to its initial state.
  3850. **
  3851. ** ^If the SQL statement being executed returns any data, then [SQLITE_ROW]
  3852. ** is returned each time a new row of data is ready for processing by the
  3853. ** caller. The values may be accessed using the [column access functions].
  3854. ** sqlite3_step() is called again to retrieve the next row of data.
  3855. **
  3856. ** ^[SQLITE_ERROR] means that a run-time error (such as a constraint
  3857. ** violation) has occurred. sqlite3_step() should not be called again on
  3858. ** the VM. More information may be found by calling [sqlite3_errmsg()].
  3859. ** ^With the legacy interface, a more specific error code (for example,
  3860. ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
  3861. ** can be obtained by calling [sqlite3_reset()] on the
  3862. ** [prepared statement]. ^In the "v2" interface,
  3863. ** the more specific error code is returned directly by sqlite3_step().
  3864. **
  3865. ** [SQLITE_MISUSE] means that the this routine was called inappropriately.
  3866. ** Perhaps it was called on a [prepared statement] that has
  3867. ** already been [sqlite3_finalize | finalized] or on one that had
  3868. ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could
  3869. ** be the case that the same database connection is being used by two or
  3870. ** more threads at the same moment in time.
  3871. **
  3872. ** For all versions of SQLite up to and including 3.6.23.1, a call to
  3873. ** [sqlite3_reset()] was required after sqlite3_step() returned anything
  3874. ** other than [SQLITE_ROW] before any subsequent invocation of
  3875. ** sqlite3_step(). Failure to reset the prepared statement using
  3876. ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
  3877. ** sqlite3_step(). But after version 3.6.23.1, sqlite3_step() began
  3878. ** calling [sqlite3_reset()] automatically in this circumstance rather
  3879. ** than returning [SQLITE_MISUSE]. This is not considered a compatibility
  3880. ** break because any application that ever receives an SQLITE_MISUSE error
  3881. ** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option
  3882. ** can be used to restore the legacy behavior.
  3883. **
  3884. ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
  3885. ** API always returns a generic error code, [SQLITE_ERROR], following any
  3886. ** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call
  3887. ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the
  3888. ** specific [error codes] that better describes the error.
  3889. ** We admit that this is a goofy design. The problem has been fixed
  3890. ** with the "v2" interface. If you prepare all of your SQL statements
  3891. ** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead
  3892. ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,
  3893. ** then the more specific [error codes] are returned directly
  3894. ** by sqlite3_step(). The use of the "v2" interface is recommended.
  3895. */
  3896. SQLITE_API int sqlite3_step(sqlite3_stmt*);
  3897. /*
  3898. ** CAPI3REF: Number of columns in a result set
  3899. **
  3900. ** ^The sqlite3_data_count(P) interface returns the number of columns in the
  3901. ** current row of the result set of [prepared statement] P.
  3902. ** ^If prepared statement P does not have results ready to return
  3903. ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
  3904. ** interfaces) then sqlite3_data_count(P) returns 0.
  3905. ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
  3906. ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
  3907. ** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)
  3908. ** will return non-zero if previous call to [sqlite3_step](P) returned
  3909. ** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]
  3910. ** where it always returns zero since each step of that multi-step
  3911. ** pragma returns 0 columns of data.
  3912. **
  3913. ** See also: [sqlite3_column_count()]
  3914. */
  3915. SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
  3916. /*
  3917. ** CAPI3REF: Fundamental Datatypes
  3918. ** KEYWORDS: SQLITE_TEXT
  3919. **
  3920. ** ^(Every value in SQLite has one of five fundamental datatypes:
  3921. **
  3922. ** <ul>
  3923. ** <li> 64-bit signed integer
  3924. ** <li> 64-bit IEEE floating point number
  3925. ** <li> string
  3926. ** <li> BLOB
  3927. ** <li> NULL
  3928. ** </ul>)^
  3929. **
  3930. ** These constants are codes for each of those types.
  3931. **
  3932. ** Note that the SQLITE_TEXT constant was also used in SQLite version 2
  3933. ** for a completely different meaning. Software that links against both
  3934. ** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not
  3935. ** SQLITE_TEXT.
  3936. */
  3937. #define SQLITE_INTEGER 1
  3938. #define SQLITE_FLOAT 2
  3939. #define SQLITE_BLOB 4
  3940. #define SQLITE_NULL 5
  3941. #ifdef SQLITE_TEXT
  3942. # undef SQLITE_TEXT
  3943. #else
  3944. # define SQLITE_TEXT 3
  3945. #endif
  3946. #define SQLITE3_TEXT 3
  3947. /*
  3948. ** CAPI3REF: Result Values From A Query
  3949. ** KEYWORDS: {column access functions}
  3950. **
  3951. ** These routines form the "result set" interface.
  3952. **
  3953. ** ^These routines return information about a single column of the current
  3954. ** result row of a query. ^In every case the first argument is a pointer
  3955. ** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]
  3956. ** that was returned from [sqlite3_prepare_v2()] or one of its variants)
  3957. ** and the second argument is the index of the column for which information
  3958. ** should be returned. ^The leftmost column of the result set has the index 0.
  3959. ** ^The number of columns in the result can be determined using
  3960. ** [sqlite3_column_count()].
  3961. **
  3962. ** If the SQL statement does not currently point to a valid row, or if the
  3963. ** column index is out of range, the result is undefined.
  3964. ** These routines may only be called when the most recent call to
  3965. ** [sqlite3_step()] has returned [SQLITE_ROW] and neither
  3966. ** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently.
  3967. ** If any of these routines are called after [sqlite3_reset()] or
  3968. ** [sqlite3_finalize()] or after [sqlite3_step()] has returned
  3969. ** something other than [SQLITE_ROW], the results are undefined.
  3970. ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()]
  3971. ** are called from a different thread while any of these routines
  3972. ** are pending, then the results are undefined.
  3973. **
  3974. ** ^The sqlite3_column_type() routine returns the
  3975. ** [SQLITE_INTEGER | datatype code] for the initial data type
  3976. ** of the result column. ^The returned value is one of [SQLITE_INTEGER],
  3977. ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. The value
  3978. ** returned by sqlite3_column_type() is only meaningful if no type
  3979. ** conversions have occurred as described below. After a type conversion,
  3980. ** the value returned by sqlite3_column_type() is undefined. Future
  3981. ** versions of SQLite may change the behavior of sqlite3_column_type()
  3982. ** following a type conversion.
  3983. **
  3984. ** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
  3985. ** routine returns the number of bytes in that BLOB or string.
  3986. ** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts
  3987. ** the string to UTF-8 and then returns the number of bytes.
  3988. ** ^If the result is a numeric value then sqlite3_column_bytes() uses
  3989. ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
  3990. ** the number of bytes in that string.
  3991. ** ^If the result is NULL, then sqlite3_column_bytes() returns zero.
  3992. **
  3993. ** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16()
  3994. ** routine returns the number of bytes in that BLOB or string.
  3995. ** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts
  3996. ** the string to UTF-16 and then returns the number of bytes.
  3997. ** ^If the result is a numeric value then sqlite3_column_bytes16() uses
  3998. ** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns
  3999. ** the number of bytes in that string.
  4000. ** ^If the result is NULL, then sqlite3_column_bytes16() returns zero.
  4001. **
  4002. ** ^The values returned by [sqlite3_column_bytes()] and
  4003. ** [sqlite3_column_bytes16()] do not include the zero terminators at the end
  4004. ** of the string. ^For clarity: the values returned by
  4005. ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of
  4006. ** bytes in the string, not the number of characters.
  4007. **
  4008. ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
  4009. ** even empty strings, are always zero-terminated. ^The return
  4010. ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
  4011. **
  4012. ** ^The object returned by [sqlite3_column_value()] is an
  4013. ** [unprotected sqlite3_value] object. An unprotected sqlite3_value object
  4014. ** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()].
  4015. ** If the [unprotected sqlite3_value] object returned by
  4016. ** [sqlite3_column_value()] is used in any other way, including calls
  4017. ** to routines like [sqlite3_value_int()], [sqlite3_value_text()],
  4018. ** or [sqlite3_value_bytes()], then the behavior is undefined.
  4019. **
  4020. ** These routines attempt to convert the value where appropriate. ^For
  4021. ** example, if the internal representation is FLOAT and a text result
  4022. ** is requested, [sqlite3_snprintf()] is used internally to perform the
  4023. ** conversion automatically. ^(The following table details the conversions
  4024. ** that are applied:
  4025. **
  4026. ** <blockquote>
  4027. ** <table border="1">
  4028. ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion
  4029. **
  4030. ** <tr><td> NULL <td> INTEGER <td> Result is 0
  4031. ** <tr><td> NULL <td> FLOAT <td> Result is 0.0
  4032. ** <tr><td> NULL <td> TEXT <td> Result is NULL pointer
  4033. ** <tr><td> NULL <td> BLOB <td> Result is NULL pointer
  4034. ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
  4035. ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
  4036. ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT
  4037. ** <tr><td> FLOAT <td> INTEGER <td> Convert from float to integer
  4038. ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
  4039. ** <tr><td> FLOAT <td> BLOB <td> Same as FLOAT->TEXT
  4040. ** <tr><td> TEXT <td> INTEGER <td> Use atoi()
  4041. ** <tr><td> TEXT <td> FLOAT <td> Use atof()
  4042. ** <tr><td> TEXT <td> BLOB <td> No change
  4043. ** <tr><td> BLOB <td> INTEGER <td> Convert to TEXT then use atoi()
  4044. ** <tr><td> BLOB <td> FLOAT <td> Convert to TEXT then use atof()
  4045. ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed
  4046. ** </table>
  4047. ** </blockquote>)^
  4048. **
  4049. ** The table above makes reference to standard C library functions atoi()
  4050. ** and atof(). SQLite does not really use these functions. It has its
  4051. ** own equivalent internal routines. The atoi() and atof() names are
  4052. ** used in the table for brevity and because they are familiar to most
  4053. ** C programmers.
  4054. **
  4055. ** Note that when type conversions occur, pointers returned by prior
  4056. ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
  4057. ** sqlite3_column_text16() may be invalidated.
  4058. ** Type conversions and pointer invalidations might occur
  4059. ** in the following cases:
  4060. **
  4061. ** <ul>
  4062. ** <li> The initial content is a BLOB and sqlite3_column_text() or
  4063. ** sqlite3_column_text16() is called. A zero-terminator might
  4064. ** need to be added to the string.</li>
  4065. ** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or
  4066. ** sqlite3_column_text16() is called. The content must be converted
  4067. ** to UTF-16.</li>
  4068. ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
  4069. ** sqlite3_column_text() is called. The content must be converted
  4070. ** to UTF-8.</li>
  4071. ** </ul>
  4072. **
  4073. ** ^Conversions between UTF-16be and UTF-16le are always done in place and do
  4074. ** not invalidate a prior pointer, though of course the content of the buffer
  4075. ** that the prior pointer references will have been modified. Other kinds
  4076. ** of conversion are done in place when it is possible, but sometimes they
  4077. ** are not possible and in those cases prior pointers are invalidated.
  4078. **
  4079. ** The safest and easiest to remember policy is to invoke these routines
  4080. ** in one of the following ways:
  4081. **
  4082. ** <ul>
  4083. ** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
  4084. ** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
  4085. ** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
  4086. ** </ul>
  4087. **
  4088. ** In other words, you should call sqlite3_column_text(),
  4089. ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
  4090. ** into the desired format, then invoke sqlite3_column_bytes() or
  4091. ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls
  4092. ** to sqlite3_column_text() or sqlite3_column_blob() with calls to
  4093. ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()
  4094. ** with calls to sqlite3_column_bytes().
  4095. **
  4096. ** ^The pointers returned are valid until a type conversion occurs as
  4097. ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
  4098. ** [sqlite3_finalize()] is called. ^The memory space used to hold strings
  4099. ** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned
  4100. ** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
  4101. ** [sqlite3_free()].
  4102. **
  4103. ** ^(If a memory allocation error occurs during the evaluation of any
  4104. ** of these routines, a default value is returned. The default value
  4105. ** is either the integer 0, the floating point number 0.0, or a NULL
  4106. ** pointer. Subsequent calls to [sqlite3_errcode()] will return
  4107. ** [SQLITE_NOMEM].)^
  4108. */
  4109. SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
  4110. SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
  4111. SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
  4112. SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol);
  4113. SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol);
  4114. SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
  4115. SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
  4116. SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
  4117. SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol);
  4118. SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
  4119. /*
  4120. ** CAPI3REF: Destroy A Prepared Statement Object
  4121. **
  4122. ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
  4123. ** ^If the most recent evaluation of the statement encountered no errors
  4124. ** or if the statement is never been evaluated, then sqlite3_finalize() returns
  4125. ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
  4126. ** sqlite3_finalize(S) returns the appropriate [error code] or
  4127. ** [extended error code].
  4128. **
  4129. ** ^The sqlite3_finalize(S) routine can be called at any point during
  4130. ** the life cycle of [prepared statement] S:
  4131. ** before statement S is ever evaluated, after
  4132. ** one or more calls to [sqlite3_reset()], or after any call
  4133. ** to [sqlite3_step()] regardless of whether or not the statement has
  4134. ** completed execution.
  4135. **
  4136. ** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op.
  4137. **
  4138. ** The application must finalize every [prepared statement] in order to avoid
  4139. ** resource leaks. It is a grievous error for the application to try to use
  4140. ** a prepared statement after it has been finalized. Any use of a prepared
  4141. ** statement after it has been finalized can result in undefined and
  4142. ** undesirable behavior such as segfaults and heap corruption.
  4143. */
  4144. SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
  4145. /*
  4146. ** CAPI3REF: Reset A Prepared Statement Object
  4147. **
  4148. ** The sqlite3_reset() function is called to reset a [prepared statement]
  4149. ** object back to its initial state, ready to be re-executed.
  4150. ** ^Any SQL statement variables that had values bound to them using
  4151. ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
  4152. ** Use [sqlite3_clear_bindings()] to reset the bindings.
  4153. **
  4154. ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S
  4155. ** back to the beginning of its program.
  4156. **
  4157. ** ^If the most recent call to [sqlite3_step(S)] for the
  4158. ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE],
  4159. ** or if [sqlite3_step(S)] has never before been called on S,
  4160. ** then [sqlite3_reset(S)] returns [SQLITE_OK].
  4161. **
  4162. ** ^If the most recent call to [sqlite3_step(S)] for the
  4163. ** [prepared statement] S indicated an error, then
  4164. ** [sqlite3_reset(S)] returns an appropriate [error code].
  4165. **
  4166. ** ^The [sqlite3_reset(S)] interface does not change the values
  4167. ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
  4168. */
  4169. SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
  4170. /*
  4171. ** CAPI3REF: Create Or Redefine SQL Functions
  4172. ** KEYWORDS: {function creation routines}
  4173. ** KEYWORDS: {application-defined SQL function}
  4174. ** KEYWORDS: {application-defined SQL functions}
  4175. **
  4176. ** ^These functions (collectively known as "function creation routines")
  4177. ** are used to add SQL functions or aggregates or to redefine the behavior
  4178. ** of existing SQL functions or aggregates. The only differences between
  4179. ** these routines are the text encoding expected for
  4180. ** the second parameter (the name of the function being created)
  4181. ** and the presence or absence of a destructor callback for
  4182. ** the application data pointer.
  4183. **
  4184. ** ^The first parameter is the [database connection] to which the SQL
  4185. ** function is to be added. ^If an application uses more than one database
  4186. ** connection then application-defined SQL functions must be added
  4187. ** to each database connection separately.
  4188. **
  4189. ** ^The second parameter is the name of the SQL function to be created or
  4190. ** redefined. ^The length of the name is limited to 255 bytes in a UTF-8
  4191. ** representation, exclusive of the zero-terminator. ^Note that the name
  4192. ** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.
  4193. ** ^Any attempt to create a function with a longer name
  4194. ** will result in [SQLITE_MISUSE] being returned.
  4195. **
  4196. ** ^The third parameter (nArg)
  4197. ** is the number of arguments that the SQL function or
  4198. ** aggregate takes. ^If this parameter is -1, then the SQL function or
  4199. ** aggregate may take any number of arguments between 0 and the limit
  4200. ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third
  4201. ** parameter is less than -1 or greater than 127 then the behavior is
  4202. ** undefined.
  4203. **
  4204. ** ^The fourth parameter, eTextRep, specifies what
  4205. ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
  4206. ** its parameters. Every SQL function implementation must be able to work
  4207. ** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
  4208. ** more efficient with one encoding than another. ^An application may
  4209. ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
  4210. ** times with the same function but with different values of eTextRep.
  4211. ** ^When multiple implementations of the same function are available, SQLite
  4212. ** will pick the one that involves the least amount of data conversion.
  4213. ** If there is only a single implementation which does not care what text
  4214. ** encoding is used, then the fourth argument should be [SQLITE_ANY].
  4215. **
  4216. ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
  4217. ** function can gain access to this pointer using [sqlite3_user_data()].)^
  4218. **
  4219. ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
  4220. ** pointers to C-language functions that implement the SQL function or
  4221. ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
  4222. ** callback only; NULL pointers must be passed as the xStep and xFinal
  4223. ** parameters. ^An aggregate SQL function requires an implementation of xStep
  4224. ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
  4225. ** SQL function or aggregate, pass NULL pointers for all three function
  4226. ** callbacks.
  4227. **
  4228. ** ^(If the ninth parameter to sqlite3_create_function_v2() is not NULL,
  4229. ** then it is destructor for the application data pointer.
  4230. ** The destructor is invoked when the function is deleted, either by being
  4231. ** overloaded or when the database connection closes.)^
  4232. ** ^The destructor is also invoked if the call to
  4233. ** sqlite3_create_function_v2() fails.
  4234. ** ^When the destructor callback of the tenth parameter is invoked, it
  4235. ** is passed a single argument which is a copy of the application data
  4236. ** pointer which was the fifth parameter to sqlite3_create_function_v2().
  4237. **
  4238. ** ^It is permitted to register multiple implementations of the same
  4239. ** functions with the same name but with either differing numbers of
  4240. ** arguments or differing preferred text encodings. ^SQLite will use
  4241. ** the implementation that most closely matches the way in which the
  4242. ** SQL function is used. ^A function implementation with a non-negative
  4243. ** nArg parameter is a better match than a function implementation with
  4244. ** a negative nArg. ^A function where the preferred text encoding
  4245. ** matches the database encoding is a better
  4246. ** match than a function where the encoding is different.
  4247. ** ^A function where the encoding difference is between UTF16le and UTF16be
  4248. ** is a closer match than a function where the encoding difference is
  4249. ** between UTF8 and UTF16.
  4250. **
  4251. ** ^Built-in functions may be overloaded by new application-defined functions.
  4252. **
  4253. ** ^An application-defined function is permitted to call other
  4254. ** SQLite interfaces. However, such calls must not
  4255. ** close the database connection nor finalize or reset the prepared
  4256. ** statement in which the function is running.
  4257. */
  4258. SQLITE_API int sqlite3_create_function(
  4259. sqlite3 *db,
  4260. const char *zFunctionName,
  4261. int nArg,
  4262. int eTextRep,
  4263. void *pApp,
  4264. void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  4265. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  4266. void (*xFinal)(sqlite3_context*)
  4267. );
  4268. SQLITE_API int sqlite3_create_function16(
  4269. sqlite3 *db,
  4270. const void *zFunctionName,
  4271. int nArg,
  4272. int eTextRep,
  4273. void *pApp,
  4274. void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  4275. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  4276. void (*xFinal)(sqlite3_context*)
  4277. );
  4278. SQLITE_API int sqlite3_create_function_v2(
  4279. sqlite3 *db,
  4280. const char *zFunctionName,
  4281. int nArg,
  4282. int eTextRep,
  4283. void *pApp,
  4284. void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  4285. void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  4286. void (*xFinal)(sqlite3_context*),
  4287. void(*xDestroy)(void*)
  4288. );
  4289. /*
  4290. ** CAPI3REF: Text Encodings
  4291. **
  4292. ** These constant define integer codes that represent the various
  4293. ** text encodings supported by SQLite.
  4294. */
  4295. #define SQLITE_UTF8 1
  4296. #define SQLITE_UTF16LE 2
  4297. #define SQLITE_UTF16BE 3
  4298. #define SQLITE_UTF16 4 /* Use native byte order */
  4299. #define SQLITE_ANY 5 /* sqlite3_create_function only */
  4300. #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
  4301. /*
  4302. ** CAPI3REF: Deprecated Functions
  4303. ** DEPRECATED
  4304. **
  4305. ** These functions are [deprecated]. In order to maintain
  4306. ** backwards compatibility with older code, these functions continue
  4307. ** to be supported. However, new applications should avoid
  4308. ** the use of these functions. To help encourage people to avoid
  4309. ** using these functions, we are not going to tell you what they do.
  4310. */
  4311. #ifndef SQLITE_OMIT_DEPRECATED
  4312. SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
  4313. SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
  4314. SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
  4315. SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);
  4316. SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
  4317. SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64);
  4318. #endif
  4319. /*
  4320. ** CAPI3REF: Obtaining SQL Function Parameter Values
  4321. **
  4322. ** The C-language implementation of SQL functions and aggregates uses
  4323. ** this set of interface routines to access the parameter values on
  4324. ** the function or aggregate.
  4325. **
  4326. ** The xFunc (for scalar functions) or xStep (for aggregates) parameters
  4327. ** to [sqlite3_create_function()] and [sqlite3_create_function16()]
  4328. ** define callbacks that implement the SQL functions and aggregates.
  4329. ** The 3rd parameter to these callbacks is an array of pointers to
  4330. ** [protected sqlite3_value] objects. There is one [sqlite3_value] object for
  4331. ** each parameter to the SQL function. These routines are used to
  4332. ** extract values from the [sqlite3_value] objects.
  4333. **
  4334. ** These routines work only with [protected sqlite3_value] objects.
  4335. ** Any attempt to use these routines on an [unprotected sqlite3_value]
  4336. ** object results in undefined behavior.
  4337. **
  4338. ** ^These routines work just like the corresponding [column access functions]
  4339. ** except that these routines take a single [protected sqlite3_value] object
  4340. ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
  4341. **
  4342. ** ^The sqlite3_value_text16() interface extracts a UTF-16 string
  4343. ** in the native byte-order of the host machine. ^The
  4344. ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
  4345. ** extract UTF-16 strings as big-endian and little-endian respectively.
  4346. **
  4347. ** ^(The sqlite3_value_numeric_type() interface attempts to apply
  4348. ** numeric affinity to the value. This means that an attempt is
  4349. ** made to convert the value to an integer or floating point. If
  4350. ** such a conversion is possible without loss of information (in other
  4351. ** words, if the value is a string that looks like a number)
  4352. ** then the conversion is performed. Otherwise no conversion occurs.
  4353. ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
  4354. **
  4355. ** Please pay particular attention to the fact that the pointer returned
  4356. ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
  4357. ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
  4358. ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
  4359. ** or [sqlite3_value_text16()].
  4360. **
  4361. ** These routines must be called from the same thread as
  4362. ** the SQL function that supplied the [sqlite3_value*] parameters.
  4363. */
  4364. SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);
  4365. SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
  4366. SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
  4367. SQLITE_API double sqlite3_value_double(sqlite3_value*);
  4368. SQLITE_API int sqlite3_value_int(sqlite3_value*);
  4369. SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
  4370. SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);
  4371. SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);
  4372. SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);
  4373. SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
  4374. SQLITE_API int sqlite3_value_type(sqlite3_value*);
  4375. SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
  4376. /*
  4377. ** CAPI3REF: Obtain Aggregate Function Context
  4378. **
  4379. ** Implementations of aggregate SQL functions use this
  4380. ** routine to allocate memory for storing their state.
  4381. **
  4382. ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
  4383. ** for a particular aggregate function, SQLite
  4384. ** allocates N of memory, zeroes out that memory, and returns a pointer
  4385. ** to the new memory. ^On second and subsequent calls to
  4386. ** sqlite3_aggregate_context() for the same aggregate function instance,
  4387. ** the same buffer is returned. Sqlite3_aggregate_context() is normally
  4388. ** called once for each invocation of the xStep callback and then one
  4389. ** last time when the xFinal callback is invoked. ^(When no rows match
  4390. ** an aggregate query, the xStep() callback of the aggregate function
  4391. ** implementation is never called and xFinal() is called exactly once.
  4392. ** In those cases, sqlite3_aggregate_context() might be called for the
  4393. ** first time from within xFinal().)^
  4394. **
  4395. ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer if N is
  4396. ** less than or equal to zero or if a memory allocate error occurs.
  4397. **
  4398. ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
  4399. ** determined by the N parameter on first successful call. Changing the
  4400. ** value of N in subsequent call to sqlite3_aggregate_context() within
  4401. ** the same aggregate function instance will not resize the memory
  4402. ** allocation.)^
  4403. **
  4404. ** ^SQLite automatically frees the memory allocated by
  4405. ** sqlite3_aggregate_context() when the aggregate query concludes.
  4406. **
  4407. ** The first parameter must be a copy of the
  4408. ** [sqlite3_context | SQL function context] that is the first parameter
  4409. ** to the xStep or xFinal callback routine that implements the aggregate
  4410. ** function.
  4411. **
  4412. ** This routine must be called from the same thread in which
  4413. ** the aggregate SQL function is running.
  4414. */
  4415. SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
  4416. /*
  4417. ** CAPI3REF: User Data For Functions
  4418. **
  4419. ** ^The sqlite3_user_data() interface returns a copy of
  4420. ** the pointer that was the pUserData parameter (the 5th parameter)
  4421. ** of the [sqlite3_create_function()]
  4422. ** and [sqlite3_create_function16()] routines that originally
  4423. ** registered the application defined function.
  4424. **
  4425. ** This routine must be called from the same thread in which
  4426. ** the application-defined function is running.
  4427. */
  4428. SQLITE_API void *sqlite3_user_data(sqlite3_context*);
  4429. /*
  4430. ** CAPI3REF: Database Connection For Functions
  4431. **
  4432. ** ^The sqlite3_context_db_handle() interface returns a copy of
  4433. ** the pointer to the [database connection] (the 1st parameter)
  4434. ** of the [sqlite3_create_function()]
  4435. ** and [sqlite3_create_function16()] routines that originally
  4436. ** registered the application defined function.
  4437. */
  4438. SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
  4439. /*
  4440. ** CAPI3REF: Function Auxiliary Data
  4441. **
  4442. ** The following two functions may be used by scalar SQL functions to
  4443. ** associate metadata with argument values. If the same value is passed to
  4444. ** multiple invocations of the same SQL function during query execution, under
  4445. ** some circumstances the associated metadata may be preserved. This may
  4446. ** be used, for example, to add a regular-expression matching scalar
  4447. ** function. The compiled version of the regular expression is stored as
  4448. ** metadata associated with the SQL value passed as the regular expression
  4449. ** pattern. The compiled regular expression can be reused on multiple
  4450. ** invocations of the same function so that the original pattern string
  4451. ** does not need to be recompiled on each invocation.
  4452. **
  4453. ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
  4454. ** associated by the sqlite3_set_auxdata() function with the Nth argument
  4455. ** value to the application-defined function. ^If no metadata has been ever
  4456. ** been set for the Nth argument of the function, or if the corresponding
  4457. ** function parameter has changed since the meta-data was set,
  4458. ** then sqlite3_get_auxdata() returns a NULL pointer.
  4459. **
  4460. ** ^The sqlite3_set_auxdata() interface saves the metadata
  4461. ** pointed to by its 3rd parameter as the metadata for the N-th
  4462. ** argument of the application-defined function. Subsequent
  4463. ** calls to sqlite3_get_auxdata() might return this data, if it has
  4464. ** not been destroyed.
  4465. ** ^If it is not NULL, SQLite will invoke the destructor
  4466. ** function given by the 4th parameter to sqlite3_set_auxdata() on
  4467. ** the metadata when the corresponding function parameter changes
  4468. ** or when the SQL statement completes, whichever comes first.
  4469. **
  4470. ** SQLite is free to call the destructor and drop metadata on any
  4471. ** parameter of any function at any time. ^The only guarantee is that
  4472. ** the destructor will be called before the metadata is dropped.
  4473. **
  4474. ** ^(In practice, metadata is preserved between function calls for
  4475. ** expressions that are constant at compile time. This includes literal
  4476. ** values and [parameters].)^
  4477. **
  4478. ** These routines must be called from the same thread in which
  4479. ** the SQL function is running.
  4480. */
  4481. SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
  4482. SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
  4483. /*
  4484. ** CAPI3REF: Constants Defining Special Destructor Behavior
  4485. **
  4486. ** These are special values for the destructor that is passed in as the
  4487. ** final argument to routines like [sqlite3_result_blob()]. ^If the destructor
  4488. ** argument is SQLITE_STATIC, it means that the content pointer is constant
  4489. ** and will never change. It does not need to be destroyed. ^The
  4490. ** SQLITE_TRANSIENT value means that the content will likely change in
  4491. ** the near future and that SQLite should make its own private copy of
  4492. ** the content before returning.
  4493. **
  4494. ** The typedef is necessary to work around problems in certain
  4495. ** C++ compilers. See ticket #2191.
  4496. */
  4497. typedef void (*sqlite3_destructor_type)(void*);
  4498. #define SQLITE_STATIC ((sqlite3_destructor_type)0)
  4499. #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
  4500. /*
  4501. ** CAPI3REF: Setting The Result Of An SQL Function
  4502. **
  4503. ** These routines are used by the xFunc or xFinal callbacks that
  4504. ** implement SQL functions and aggregates. See
  4505. ** [sqlite3_create_function()] and [sqlite3_create_function16()]
  4506. ** for additional information.
  4507. **
  4508. ** These functions work very much like the [parameter binding] family of
  4509. ** functions used to bind values to host parameters in prepared statements.
  4510. ** Refer to the [SQL parameter] documentation for additional information.
  4511. **
  4512. ** ^The sqlite3_result_blob() interface sets the result from
  4513. ** an application-defined function to be the BLOB whose content is pointed
  4514. ** to by the second parameter and which is N bytes long where N is the
  4515. ** third parameter.
  4516. **
  4517. ** ^The sqlite3_result_zeroblob() interfaces set the result of
  4518. ** the application-defined function to be a BLOB containing all zero
  4519. ** bytes and N bytes in size, where N is the value of the 2nd parameter.
  4520. **
  4521. ** ^The sqlite3_result_double() interface sets the result from
  4522. ** an application-defined function to be a floating point value specified
  4523. ** by its 2nd argument.
  4524. **
  4525. ** ^The sqlite3_result_error() and sqlite3_result_error16() functions
  4526. ** cause the implemented SQL function to throw an exception.
  4527. ** ^SQLite uses the string pointed to by the
  4528. ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
  4529. ** as the text of an error message. ^SQLite interprets the error
  4530. ** message string from sqlite3_result_error() as UTF-8. ^SQLite
  4531. ** interprets the string from sqlite3_result_error16() as UTF-16 in native
  4532. ** byte order. ^If the third parameter to sqlite3_result_error()
  4533. ** or sqlite3_result_error16() is negative then SQLite takes as the error
  4534. ** message all text up through the first zero character.
  4535. ** ^If the third parameter to sqlite3_result_error() or
  4536. ** sqlite3_result_error16() is non-negative then SQLite takes that many
  4537. ** bytes (not characters) from the 2nd parameter as the error message.
  4538. ** ^The sqlite3_result_error() and sqlite3_result_error16()
  4539. ** routines make a private copy of the error message text before
  4540. ** they return. Hence, the calling function can deallocate or
  4541. ** modify the text after they return without harm.
  4542. ** ^The sqlite3_result_error_code() function changes the error code
  4543. ** returned by SQLite as a result of an error in a function. ^By default,
  4544. ** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error()
  4545. ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
  4546. **
  4547. ** ^The sqlite3_result_toobig() interface causes SQLite to throw an error
  4548. ** indicating that a string or BLOB is too long to represent.
  4549. **
  4550. ** ^The sqlite3_result_nomem() interface causes SQLite to throw an error
  4551. ** indicating that a memory allocation failed.
  4552. **
  4553. ** ^The sqlite3_result_int() interface sets the return value
  4554. ** of the application-defined function to be the 32-bit signed integer
  4555. ** value given in the 2nd argument.
  4556. ** ^The sqlite3_result_int64() interface sets the return value
  4557. ** of the application-defined function to be the 64-bit signed integer
  4558. ** value given in the 2nd argument.
  4559. **
  4560. ** ^The sqlite3_result_null() interface sets the return value
  4561. ** of the application-defined function to be NULL.
  4562. **
  4563. ** ^The sqlite3_result_text(), sqlite3_result_text16(),
  4564. ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
  4565. ** set the return value of the application-defined function to be
  4566. ** a text string which is represented as UTF-8, UTF-16 native byte order,
  4567. ** UTF-16 little endian, or UTF-16 big endian, respectively.
  4568. ** ^SQLite takes the text result from the application from
  4569. ** the 2nd parameter of the sqlite3_result_text* interfaces.
  4570. ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
  4571. ** is negative, then SQLite takes result text from the 2nd parameter
  4572. ** through the first zero character.
  4573. ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
  4574. ** is non-negative, then as many bytes (not characters) of the text
  4575. ** pointed to by the 2nd parameter are taken as the application-defined
  4576. ** function result. If the 3rd parameter is non-negative, then it
  4577. ** must be the byte offset into the string where the NUL terminator would
  4578. ** appear if the string where NUL terminated. If any NUL characters occur
  4579. ** in the string at a byte offset that is less than the value of the 3rd
  4580. ** parameter, then the resulting string will contain embedded NULs and the
  4581. ** result of expressions operating on strings with embedded NULs is undefined.
  4582. ** ^If the 4th parameter to the sqlite3_result_text* interfaces
  4583. ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
  4584. ** function as the destructor on the text or BLOB result when it has
  4585. ** finished using that result.
  4586. ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to
  4587. ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite
  4588. ** assumes that the text or BLOB result is in constant space and does not
  4589. ** copy the content of the parameter nor call a destructor on the content
  4590. ** when it has finished using that result.
  4591. ** ^If the 4th parameter to the sqlite3_result_text* interfaces
  4592. ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
  4593. ** then SQLite makes a copy of the result into space obtained from
  4594. ** from [sqlite3_malloc()] before it returns.
  4595. **
  4596. ** ^The sqlite3_result_value() interface sets the result of
  4597. ** the application-defined function to be a copy the
  4598. ** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The
  4599. ** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
  4600. ** so that the [sqlite3_value] specified in the parameter may change or
  4601. ** be deallocated after sqlite3_result_value() returns without harm.
  4602. ** ^A [protected sqlite3_value] object may always be used where an
  4603. ** [unprotected sqlite3_value] object is required, so either
  4604. ** kind of [sqlite3_value] object can be used with this interface.
  4605. **
  4606. ** If these routines are called from within the different thread
  4607. ** than the one containing the application-defined function that received
  4608. ** the [sqlite3_context] pointer, the results are undefined.
  4609. */
  4610. SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
  4611. SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
  4612. SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
  4613. SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
  4614. SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
  4615. SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
  4616. SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int);
  4617. SQLITE_API void sqlite3_result_int(sqlite3_context*, int);
  4618. SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
  4619. SQLITE_API void sqlite3_result_null(sqlite3_context*);
  4620. SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
  4621. SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
  4622. SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
  4623. SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
  4624. SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
  4625. SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
  4626. /*
  4627. ** CAPI3REF: Define New Collating Sequences
  4628. **
  4629. ** ^These functions add, remove, or modify a [collation] associated
  4630. ** with the [database connection] specified as the first argument.
  4631. **
  4632. ** ^The name of the collation is a UTF-8 string
  4633. ** for sqlite3_create_collation() and sqlite3_create_collation_v2()
  4634. ** and a UTF-16 string in native byte order for sqlite3_create_collation16().
  4635. ** ^Collation names that compare equal according to [sqlite3_strnicmp()] are
  4636. ** considered to be the same name.
  4637. **
  4638. ** ^(The third argument (eTextRep) must be one of the constants:
  4639. ** <ul>
  4640. ** <li> [SQLITE_UTF8],
  4641. ** <li> [SQLITE_UTF16LE],
  4642. ** <li> [SQLITE_UTF16BE],
  4643. ** <li> [SQLITE_UTF16], or
  4644. ** <li> [SQLITE_UTF16_ALIGNED].
  4645. ** </ul>)^
  4646. ** ^The eTextRep argument determines the encoding of strings passed
  4647. ** to the collating function callback, xCallback.
  4648. ** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
  4649. ** force strings to be UTF16 with native byte order.
  4650. ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
  4651. ** on an even byte address.
  4652. **
  4653. ** ^The fourth argument, pArg, is an application data pointer that is passed
  4654. ** through as the first argument to the collating function callback.
  4655. **
  4656. ** ^The fifth argument, xCallback, is a pointer to the collating function.
  4657. ** ^Multiple collating functions can be registered using the same name but
  4658. ** with different eTextRep parameters and SQLite will use whichever
  4659. ** function requires the least amount of data transformation.
  4660. ** ^If the xCallback argument is NULL then the collating function is
  4661. ** deleted. ^When all collating functions having the same name are deleted,
  4662. ** that collation is no longer usable.
  4663. **
  4664. ** ^The collating function callback is invoked with a copy of the pArg
  4665. ** application data pointer and with two strings in the encoding specified
  4666. ** by the eTextRep argument. The collating function must return an
  4667. ** integer that is negative, zero, or positive
  4668. ** if the first string is less than, equal to, or greater than the second,
  4669. ** respectively. A collating function must always return the same answer
  4670. ** given the same inputs. If two or more collating functions are registered
  4671. ** to the same collation name (using different eTextRep values) then all
  4672. ** must give an equivalent answer when invoked with equivalent strings.
  4673. ** The collating function must obey the following properties for all
  4674. ** strings A, B, and C:
  4675. **
  4676. ** <ol>
  4677. ** <li> If A==B then B==A.
  4678. ** <li> If A==B and B==C then A==C.
  4679. ** <li> If A&lt;B THEN B&gt;A.
  4680. ** <li> If A&lt;B and B&lt;C then A&lt;C.
  4681. ** </ol>
  4682. **
  4683. ** If a collating function fails any of the above constraints and that
  4684. ** collating function is registered and used, then the behavior of SQLite
  4685. ** is undefined.
  4686. **
  4687. ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
  4688. ** with the addition that the xDestroy callback is invoked on pArg when
  4689. ** the collating function is deleted.
  4690. ** ^Collating functions are deleted when they are overridden by later
  4691. ** calls to the collation creation functions or when the
  4692. ** [database connection] is closed using [sqlite3_close()].
  4693. **
  4694. ** ^The xDestroy callback is <u>not</u> called if the
  4695. ** sqlite3_create_collation_v2() function fails. Applications that invoke
  4696. ** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should
  4697. ** check the return code and dispose of the application data pointer
  4698. ** themselves rather than expecting SQLite to deal with it for them.
  4699. ** This is different from every other SQLite interface. The inconsistency
  4700. ** is unfortunate but cannot be changed without breaking backwards
  4701. ** compatibility.
  4702. **
  4703. ** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
  4704. */
  4705. SQLITE_API int sqlite3_create_collation(
  4706. sqlite3*,
  4707. const char *zName,
  4708. int eTextRep,
  4709. void *pArg,
  4710. int(*xCompare)(void*,int,const void*,int,const void*)
  4711. );
  4712. SQLITE_API int sqlite3_create_collation_v2(
  4713. sqlite3*,
  4714. const char *zName,
  4715. int eTextRep,
  4716. void *pArg,
  4717. int(*xCompare)(void*,int,const void*,int,const void*),
  4718. void(*xDestroy)(void*)
  4719. );
  4720. SQLITE_API int sqlite3_create_collation16(
  4721. sqlite3*,
  4722. const void *zName,
  4723. int eTextRep,
  4724. void *pArg,
  4725. int(*xCompare)(void*,int,const void*,int,const void*)
  4726. );
  4727. /*
  4728. ** CAPI3REF: Collation Needed Callbacks
  4729. **
  4730. ** ^To avoid having to register all collation sequences before a database
  4731. ** can be used, a single callback function may be registered with the
  4732. ** [database connection] to be invoked whenever an undefined collation
  4733. ** sequence is required.
  4734. **
  4735. ** ^If the function is registered using the sqlite3_collation_needed() API,
  4736. ** then it is passed the names of undefined collation sequences as strings
  4737. ** encoded in UTF-8. ^If sqlite3_collation_needed16() is used,
  4738. ** the names are passed as UTF-16 in machine native byte order.
  4739. ** ^A call to either function replaces the existing collation-needed callback.
  4740. **
  4741. ** ^(When the callback is invoked, the first argument passed is a copy
  4742. ** of the second argument to sqlite3_collation_needed() or
  4743. ** sqlite3_collation_needed16(). The second argument is the database
  4744. ** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE],
  4745. ** or [SQLITE_UTF16LE], indicating the most desirable form of the collation
  4746. ** sequence function required. The fourth parameter is the name of the
  4747. ** required collation sequence.)^
  4748. **
  4749. ** The callback function should register the desired collation using
  4750. ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
  4751. ** [sqlite3_create_collation_v2()].
  4752. */
  4753. SQLITE_API int sqlite3_collation_needed(
  4754. sqlite3*,
  4755. void*,
  4756. void(*)(void*,sqlite3*,int eTextRep,const char*)
  4757. );
  4758. SQLITE_API int sqlite3_collation_needed16(
  4759. sqlite3*,
  4760. void*,
  4761. void(*)(void*,sqlite3*,int eTextRep,const void*)
  4762. );
  4763. #ifdef SQLITE_HAS_CODEC
  4764. /*
  4765. ** Specify the key for an encrypted database. This routine should be
  4766. ** called right after sqlite3_open().
  4767. **
  4768. ** The code to implement this API is not available in the public release
  4769. ** of SQLite.
  4770. */
  4771. SQLITE_API int sqlite3_key(
  4772. sqlite3 *db, /* Database to be rekeyed */
  4773. const void *pKey, int nKey /* The key */
  4774. );
  4775. /*
  4776. ** Change the key on an open database. If the current database is not
  4777. ** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the
  4778. ** database is decrypted.
  4779. **
  4780. ** The code to implement this API is not available in the public release
  4781. ** of SQLite.
  4782. */
  4783. SQLITE_API int sqlite3_rekey(
  4784. sqlite3 *db, /* Database to be rekeyed */
  4785. const void *pKey, int nKey /* The new key */
  4786. );
  4787. /*
  4788. ** Specify the activation key for a SEE database. Unless
  4789. ** activated, none of the SEE routines will work.
  4790. */
  4791. SQLITE_API void sqlite3_activate_see(
  4792. const char *zPassPhrase /* Activation phrase */
  4793. );
  4794. #endif
  4795. #ifdef SQLITE_ENABLE_CEROD
  4796. /*
  4797. ** Specify the activation key for a CEROD database. Unless
  4798. ** activated, none of the CEROD routines will work.
  4799. */
  4800. SQLITE_API void sqlite3_activate_cerod(
  4801. const char *zPassPhrase /* Activation phrase */
  4802. );
  4803. #endif
  4804. /*
  4805. ** CAPI3REF: Suspend Execution For A Short Time
  4806. **
  4807. ** The sqlite3_sleep() function causes the current thread to suspend execution
  4808. ** for at least a number of milliseconds specified in its parameter.
  4809. **
  4810. ** If the operating system does not support sleep requests with
  4811. ** millisecond time resolution, then the time will be rounded up to
  4812. ** the nearest second. The number of milliseconds of sleep actually
  4813. ** requested from the operating system is returned.
  4814. **
  4815. ** ^SQLite implements this interface by calling the xSleep()
  4816. ** method of the default [sqlite3_vfs] object. If the xSleep() method
  4817. ** of the default VFS is not implemented correctly, or not implemented at
  4818. ** all, then the behavior of sqlite3_sleep() may deviate from the description
  4819. ** in the previous paragraphs.
  4820. */
  4821. SQLITE_API int sqlite3_sleep(int);
  4822. /*
  4823. ** CAPI3REF: Name Of The Folder Holding Temporary Files
  4824. **
  4825. ** ^(If this global variable is made to point to a string which is
  4826. ** the name of a folder (a.k.a. directory), then all temporary files
  4827. ** created by SQLite when using a built-in [sqlite3_vfs | VFS]
  4828. ** will be placed in that directory.)^ ^If this variable
  4829. ** is a NULL pointer, then SQLite performs a search for an appropriate
  4830. ** temporary file directory.
  4831. **
  4832. ** It is not safe to read or modify this variable in more than one
  4833. ** thread at a time. It is not safe to read or modify this variable
  4834. ** if a [database connection] is being used at the same time in a separate
  4835. ** thread.
  4836. ** It is intended that this variable be set once
  4837. ** as part of process initialization and before any SQLite interface
  4838. ** routines have been called and that this variable remain unchanged
  4839. ** thereafter.
  4840. **
  4841. ** ^The [temp_store_directory pragma] may modify this variable and cause
  4842. ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore,
  4843. ** the [temp_store_directory pragma] always assumes that any string
  4844. ** that this variable points to is held in memory obtained from
  4845. ** [sqlite3_malloc] and the pragma may attempt to free that memory
  4846. ** using [sqlite3_free].
  4847. ** Hence, if this variable is modified directly, either it should be
  4848. ** made NULL or made to point to memory obtained from [sqlite3_malloc]
  4849. ** or else the use of the [temp_store_directory pragma] should be avoided.
  4850. */
  4851. SQLITE_API char *sqlite3_temp_directory;
  4852. /*
  4853. ** CAPI3REF: Test For Auto-Commit Mode
  4854. ** KEYWORDS: {autocommit mode}
  4855. **
  4856. ** ^The sqlite3_get_autocommit() interface returns non-zero or
  4857. ** zero if the given database connection is or is not in autocommit mode,
  4858. ** respectively. ^Autocommit mode is on by default.
  4859. ** ^Autocommit mode is disabled by a [BEGIN] statement.
  4860. ** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].
  4861. **
  4862. ** If certain kinds of errors occur on a statement within a multi-statement
  4863. ** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR],
  4864. ** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the
  4865. ** transaction might be rolled back automatically. The only way to
  4866. ** find out whether SQLite automatically rolled back the transaction after
  4867. ** an error is to use this function.
  4868. **
  4869. ** If another thread changes the autocommit status of the database
  4870. ** connection while this routine is running, then the return value
  4871. ** is undefined.
  4872. */
  4873. SQLITE_API int sqlite3_get_autocommit(sqlite3*);
  4874. /*
  4875. ** CAPI3REF: Find The Database Handle Of A Prepared Statement
  4876. **
  4877. ** ^The sqlite3_db_handle interface returns the [database connection] handle
  4878. ** to which a [prepared statement] belongs. ^The [database connection]
  4879. ** returned by sqlite3_db_handle is the same [database connection]
  4880. ** that was the first argument
  4881. ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
  4882. ** create the statement in the first place.
  4883. */
  4884. SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
  4885. /*
  4886. ** CAPI3REF: Return The Filename For A Database Connection
  4887. **
  4888. ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
  4889. ** associated with database N of connection D. ^The main database file
  4890. ** has the name "main". If there is no attached database N on the database
  4891. ** connection D, or if database N is a temporary or in-memory database, then
  4892. ** a NULL pointer is returned.
  4893. **
  4894. ** ^The filename returned by this function is the output of the
  4895. ** xFullPathname method of the [VFS]. ^In other words, the filename
  4896. ** will be an absolute pathname, even if the filename used
  4897. ** to open the database originally was a URI or relative pathname.
  4898. */
  4899. SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
  4900. /*
  4901. ** CAPI3REF: Determine if a database is read-only
  4902. **
  4903. ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
  4904. ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
  4905. ** the name of a database on connection D.
  4906. */
  4907. SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
  4908. /*
  4909. ** CAPI3REF: Find the next prepared statement
  4910. **
  4911. ** ^This interface returns a pointer to the next [prepared statement] after
  4912. ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
  4913. ** then this interface returns a pointer to the first prepared statement
  4914. ** associated with the database connection pDb. ^If no prepared statement
  4915. ** satisfies the conditions of this routine, it returns NULL.
  4916. **
  4917. ** The [database connection] pointer D in a call to
  4918. ** [sqlite3_next_stmt(D,S)] must refer to an open database
  4919. ** connection and in particular must not be a NULL pointer.
  4920. */
  4921. SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
  4922. /*
  4923. ** CAPI3REF: Commit And Rollback Notification Callbacks
  4924. **
  4925. ** ^The sqlite3_commit_hook() interface registers a callback
  4926. ** function to be invoked whenever a transaction is [COMMIT | committed].
  4927. ** ^Any callback set by a previous call to sqlite3_commit_hook()
  4928. ** for the same database connection is overridden.
  4929. ** ^The sqlite3_rollback_hook() interface registers a callback
  4930. ** function to be invoked whenever a transaction is [ROLLBACK | rolled back].
  4931. ** ^Any callback set by a previous call to sqlite3_rollback_hook()
  4932. ** for the same database connection is overridden.
  4933. ** ^The pArg argument is passed through to the callback.
  4934. ** ^If the callback on a commit hook function returns non-zero,
  4935. ** then the commit is converted into a rollback.
  4936. **
  4937. ** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions
  4938. ** return the P argument from the previous call of the same function
  4939. ** on the same [database connection] D, or NULL for
  4940. ** the first call for each function on D.
  4941. **
  4942. ** The commit and rollback hook callbacks are not reentrant.
  4943. ** The callback implementation must not do anything that will modify
  4944. ** the database connection that invoked the callback. Any actions
  4945. ** to modify the database connection must be deferred until after the
  4946. ** completion of the [sqlite3_step()] call that triggered the commit
  4947. ** or rollback hook in the first place.
  4948. ** Note that running any other SQL statements, including SELECT statements,
  4949. ** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify
  4950. ** the database connections for the meaning of "modify" in this paragraph.
  4951. **
  4952. ** ^Registering a NULL function disables the callback.
  4953. **
  4954. ** ^When the commit hook callback routine returns zero, the [COMMIT]
  4955. ** operation is allowed to continue normally. ^If the commit hook
  4956. ** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK].
  4957. ** ^The rollback hook is invoked on a rollback that results from a commit
  4958. ** hook returning non-zero, just as it would be with any other rollback.
  4959. **
  4960. ** ^For the purposes of this API, a transaction is said to have been
  4961. ** rolled back if an explicit "ROLLBACK" statement is executed, or
  4962. ** an error or constraint causes an implicit rollback to occur.
  4963. ** ^The rollback callback is not invoked if a transaction is
  4964. ** automatically rolled back because the database connection is closed.
  4965. **
  4966. ** See also the [sqlite3_update_hook()] interface.
  4967. */
  4968. SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
  4969. SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
  4970. /*
  4971. ** CAPI3REF: Data Change Notification Callbacks
  4972. **
  4973. ** ^The sqlite3_update_hook() interface registers a callback function
  4974. ** with the [database connection] identified by the first argument
  4975. ** to be invoked whenever a row is updated, inserted or deleted.
  4976. ** ^Any callback set by a previous call to this function
  4977. ** for the same database connection is overridden.
  4978. **
  4979. ** ^The second argument is a pointer to the function to invoke when a
  4980. ** row is updated, inserted or deleted.
  4981. ** ^The first argument to the callback is a copy of the third argument
  4982. ** to sqlite3_update_hook().
  4983. ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
  4984. ** or [SQLITE_UPDATE], depending on the operation that caused the callback
  4985. ** to be invoked.
  4986. ** ^The third and fourth arguments to the callback contain pointers to the
  4987. ** database and table name containing the affected row.
  4988. ** ^The final callback parameter is the [rowid] of the row.
  4989. ** ^In the case of an update, this is the [rowid] after the update takes place.
  4990. **
  4991. ** ^(The update hook is not invoked when internal system tables are
  4992. ** modified (i.e. sqlite_master and sqlite_sequence).)^
  4993. **
  4994. ** ^In the current implementation, the update hook
  4995. ** is not invoked when duplication rows are deleted because of an
  4996. ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
  4997. ** invoked when rows are deleted using the [truncate optimization].
  4998. ** The exceptions defined in this paragraph might change in a future
  4999. ** release of SQLite.
  5000. **
  5001. ** The update hook implementation must not do anything that will modify
  5002. ** the database connection that invoked the update hook. Any actions
  5003. ** to modify the database connection must be deferred until after the
  5004. ** completion of the [sqlite3_step()] call that triggered the update hook.
  5005. ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  5006. ** database connections for the meaning of "modify" in this paragraph.
  5007. **
  5008. ** ^The sqlite3_update_hook(D,C,P) function
  5009. ** returns the P argument from the previous call
  5010. ** on the same [database connection] D, or NULL for
  5011. ** the first call on D.
  5012. **
  5013. ** See also the [sqlite3_commit_hook()] and [sqlite3_rollback_hook()]
  5014. ** interfaces.
  5015. */
  5016. SQLITE_API void *sqlite3_update_hook(
  5017. sqlite3*,
  5018. void(*)(void *,int ,char const *,char const *,sqlite3_int64),
  5019. void*
  5020. );
  5021. /*
  5022. ** CAPI3REF: Enable Or Disable Shared Pager Cache
  5023. ** KEYWORDS: {shared cache}
  5024. **
  5025. ** ^(This routine enables or disables the sharing of the database cache
  5026. ** and schema data structures between [database connection | connections]
  5027. ** to the same database. Sharing is enabled if the argument is true
  5028. ** and disabled if the argument is false.)^
  5029. **
  5030. ** ^Cache sharing is enabled and disabled for an entire process.
  5031. ** This is a change as of SQLite version 3.5.0. In prior versions of SQLite,
  5032. ** sharing was enabled or disabled for each thread separately.
  5033. **
  5034. ** ^(The cache sharing mode set by this interface effects all subsequent
  5035. ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
  5036. ** Existing database connections continue use the sharing mode
  5037. ** that was in effect at the time they were opened.)^
  5038. **
  5039. ** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled
  5040. ** successfully. An [error code] is returned otherwise.)^
  5041. **
  5042. ** ^Shared cache is disabled by default. But this might change in
  5043. ** future releases of SQLite. Applications that care about shared
  5044. ** cache setting should set it explicitly.
  5045. **
  5046. ** See Also: [SQLite Shared-Cache Mode]
  5047. */
  5048. SQLITE_API int sqlite3_enable_shared_cache(int);
  5049. /*
  5050. ** CAPI3REF: Attempt To Free Heap Memory
  5051. **
  5052. ** ^The sqlite3_release_memory() interface attempts to free N bytes
  5053. ** of heap memory by deallocating non-essential memory allocations
  5054. ** held by the database library. Memory used to cache database
  5055. ** pages to improve performance is an example of non-essential memory.
  5056. ** ^sqlite3_release_memory() returns the number of bytes actually freed,
  5057. ** which might be more or less than the amount requested.
  5058. ** ^The sqlite3_release_memory() routine is a no-op returning zero
  5059. ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT].
  5060. **
  5061. ** See also: [sqlite3_db_release_memory()]
  5062. */
  5063. SQLITE_API int sqlite3_release_memory(int);
  5064. /*
  5065. ** CAPI3REF: Free Memory Used By A Database Connection
  5066. **
  5067. ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
  5068. ** memory as possible from database connection D. Unlike the
  5069. ** [sqlite3_release_memory()] interface, this interface is effect even
  5070. ** when then [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
  5071. ** omitted.
  5072. **
  5073. ** See also: [sqlite3_release_memory()]
  5074. */
  5075. SQLITE_API int sqlite3_db_release_memory(sqlite3*);
  5076. /*
  5077. ** CAPI3REF: Impose A Limit On Heap Size
  5078. **
  5079. ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
  5080. ** soft limit on the amount of heap memory that may be allocated by SQLite.
  5081. ** ^SQLite strives to keep heap memory utilization below the soft heap
  5082. ** limit by reducing the number of pages held in the page cache
  5083. ** as heap memory usages approaches the limit.
  5084. ** ^The soft heap limit is "soft" because even though SQLite strives to stay
  5085. ** below the limit, it will exceed the limit rather than generate
  5086. ** an [SQLITE_NOMEM] error. In other words, the soft heap limit
  5087. ** is advisory only.
  5088. **
  5089. ** ^The return value from sqlite3_soft_heap_limit64() is the size of
  5090. ** the soft heap limit prior to the call, or negative in the case of an
  5091. ** error. ^If the argument N is negative
  5092. ** then no change is made to the soft heap limit. Hence, the current
  5093. ** size of the soft heap limit can be determined by invoking
  5094. ** sqlite3_soft_heap_limit64() with a negative argument.
  5095. **
  5096. ** ^If the argument N is zero then the soft heap limit is disabled.
  5097. **
  5098. ** ^(The soft heap limit is not enforced in the current implementation
  5099. ** if one or more of following conditions are true:
  5100. **
  5101. ** <ul>
  5102. ** <li> The soft heap limit is set to zero.
  5103. ** <li> Memory accounting is disabled using a combination of the
  5104. ** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and
  5105. ** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.
  5106. ** <li> An alternative page cache implementation is specified using
  5107. ** [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...).
  5108. ** <li> The page cache allocates from its own memory pool supplied
  5109. ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
  5110. ** from the heap.
  5111. ** </ul>)^
  5112. **
  5113. ** Beginning with SQLite version 3.7.3, the soft heap limit is enforced
  5114. ** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT]
  5115. ** compile-time option is invoked. With [SQLITE_ENABLE_MEMORY_MANAGEMENT],
  5116. ** the soft heap limit is enforced on every memory allocation. Without
  5117. ** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced
  5118. ** when memory is allocated by the page cache. Testing suggests that because
  5119. ** the page cache is the predominate memory user in SQLite, most
  5120. ** applications will achieve adequate soft heap limit enforcement without
  5121. ** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT].
  5122. **
  5123. ** The circumstances under which SQLite will enforce the soft heap limit may
  5124. ** changes in future releases of SQLite.
  5125. */
  5126. SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
  5127. /*
  5128. ** CAPI3REF: Deprecated Soft Heap Limit Interface
  5129. ** DEPRECATED
  5130. **
  5131. ** This is a deprecated version of the [sqlite3_soft_heap_limit64()]
  5132. ** interface. This routine is provided for historical compatibility
  5133. ** only. All new applications should use the
  5134. ** [sqlite3_soft_heap_limit64()] interface rather than this one.
  5135. */
  5136. SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N);
  5137. /*
  5138. ** CAPI3REF: Extract Metadata About A Column Of A Table
  5139. **
  5140. ** ^This routine returns metadata about a specific column of a specific
  5141. ** database table accessible using the [database connection] handle
  5142. ** passed as the first function argument.
  5143. **
  5144. ** ^The column is identified by the second, third and fourth parameters to
  5145. ** this function. ^The second parameter is either the name of the database
  5146. ** (i.e. "main", "temp", or an attached database) containing the specified
  5147. ** table or NULL. ^If it is NULL, then all attached databases are searched
  5148. ** for the table using the same algorithm used by the database engine to
  5149. ** resolve unqualified table references.
  5150. **
  5151. ** ^The third and fourth parameters to this function are the table and column
  5152. ** name of the desired column, respectively. Neither of these parameters
  5153. ** may be NULL.
  5154. **
  5155. ** ^Metadata is returned by writing to the memory locations passed as the 5th
  5156. ** and subsequent parameters to this function. ^Any of these arguments may be
  5157. ** NULL, in which case the corresponding element of metadata is omitted.
  5158. **
  5159. ** ^(<blockquote>
  5160. ** <table border="1">
  5161. ** <tr><th> Parameter <th> Output<br>Type <th> Description
  5162. **
  5163. ** <tr><td> 5th <td> const char* <td> Data type
  5164. ** <tr><td> 6th <td> const char* <td> Name of default collation sequence
  5165. ** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint
  5166. ** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY
  5167. ** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT]
  5168. ** </table>
  5169. ** </blockquote>)^
  5170. **
  5171. ** ^The memory pointed to by the character pointers returned for the
  5172. ** declaration type and collation sequence is valid only until the next
  5173. ** call to any SQLite API function.
  5174. **
  5175. ** ^If the specified table is actually a view, an [error code] is returned.
  5176. **
  5177. ** ^If the specified column is "rowid", "oid" or "_rowid_" and an
  5178. ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
  5179. ** parameters are set for the explicitly declared column. ^(If there is no
  5180. ** explicitly declared [INTEGER PRIMARY KEY] column, then the output
  5181. ** parameters are set as follows:
  5182. **
  5183. ** <pre>
  5184. ** data type: "INTEGER"
  5185. ** collation sequence: "BINARY"
  5186. ** not null: 0
  5187. ** primary key: 1
  5188. ** auto increment: 0
  5189. ** </pre>)^
  5190. **
  5191. ** ^(This function may load one or more schemas from database files. If an
  5192. ** error occurs during this process, or if the requested table or column
  5193. ** cannot be found, an [error code] is returned and an error message left
  5194. ** in the [database connection] (to be retrieved using sqlite3_errmsg()).)^
  5195. **
  5196. ** ^This API is only available if the library was compiled with the
  5197. ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
  5198. */
  5199. SQLITE_API int sqlite3_table_column_metadata(
  5200. sqlite3 *db, /* Connection handle */
  5201. const char *zDbName, /* Database name or NULL */
  5202. const char *zTableName, /* Table name */
  5203. const char *zColumnName, /* Column name */
  5204. char const **pzDataType, /* OUTPUT: Declared data type */
  5205. char const **pzCollSeq, /* OUTPUT: Collation sequence name */
  5206. int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */
  5207. int *pPrimaryKey, /* OUTPUT: True if column part of PK */
  5208. int *pAutoinc /* OUTPUT: True if column is auto-increment */
  5209. );
  5210. /*
  5211. ** CAPI3REF: Load An Extension
  5212. **
  5213. ** ^This interface loads an SQLite extension library from the named file.
  5214. **
  5215. ** ^The sqlite3_load_extension() interface attempts to load an
  5216. ** SQLite extension library contained in the file zFile.
  5217. **
  5218. ** ^The entry point is zProc.
  5219. ** ^zProc may be 0, in which case the name of the entry point
  5220. ** defaults to "sqlite3_extension_init".
  5221. ** ^The sqlite3_load_extension() interface returns
  5222. ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
  5223. ** ^If an error occurs and pzErrMsg is not 0, then the
  5224. ** [sqlite3_load_extension()] interface shall attempt to
  5225. ** fill *pzErrMsg with error message text stored in memory
  5226. ** obtained from [sqlite3_malloc()]. The calling function
  5227. ** should free this memory by calling [sqlite3_free()].
  5228. **
  5229. ** ^Extension loading must be enabled using
  5230. ** [sqlite3_enable_load_extension()] prior to calling this API,
  5231. ** otherwise an error will be returned.
  5232. **
  5233. ** See also the [load_extension() SQL function].
  5234. */
  5235. SQLITE_API int sqlite3_load_extension(
  5236. sqlite3 *db, /* Load the extension into this database connection */
  5237. const char *zFile, /* Name of the shared library containing extension */
  5238. const char *zProc, /* Entry point. Derived from zFile if 0 */
  5239. char **pzErrMsg /* Put error message here if not 0 */
  5240. );
  5241. /*
  5242. ** CAPI3REF: Enable Or Disable Extension Loading
  5243. **
  5244. ** ^So as not to open security holes in older applications that are
  5245. ** unprepared to deal with extension loading, and as a means of disabling
  5246. ** extension loading while evaluating user-entered SQL, the following API
  5247. ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
  5248. **
  5249. ** ^Extension loading is off by default. See ticket #1863.
  5250. ** ^Call the sqlite3_enable_load_extension() routine with onoff==1
  5251. ** to turn extension loading on and call it with onoff==0 to turn
  5252. ** it back off again.
  5253. */
  5254. SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
  5255. /*
  5256. ** CAPI3REF: Automatically Load Statically Linked Extensions
  5257. **
  5258. ** ^This interface causes the xEntryPoint() function to be invoked for
  5259. ** each new [database connection] that is created. The idea here is that
  5260. ** xEntryPoint() is the entry point for a statically linked SQLite extension
  5261. ** that is to be automatically loaded into all new database connections.
  5262. **
  5263. ** ^(Even though the function prototype shows that xEntryPoint() takes
  5264. ** no arguments and returns void, SQLite invokes xEntryPoint() with three
  5265. ** arguments and expects and integer result as if the signature of the
  5266. ** entry point where as follows:
  5267. **
  5268. ** <blockquote><pre>
  5269. ** &nbsp; int xEntryPoint(
  5270. ** &nbsp; sqlite3 *db,
  5271. ** &nbsp; const char **pzErrMsg,
  5272. ** &nbsp; const struct sqlite3_api_routines *pThunk
  5273. ** &nbsp; );
  5274. ** </pre></blockquote>)^
  5275. **
  5276. ** If the xEntryPoint routine encounters an error, it should make *pzErrMsg
  5277. ** point to an appropriate error message (obtained from [sqlite3_mprintf()])
  5278. ** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg
  5279. ** is NULL before calling the xEntryPoint(). ^SQLite will invoke
  5280. ** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any
  5281. ** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()],
  5282. ** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail.
  5283. **
  5284. ** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
  5285. ** on the list of automatic extensions is a harmless no-op. ^No entry point
  5286. ** will be called more than once for each database connection that is opened.
  5287. **
  5288. ** See also: [sqlite3_reset_auto_extension()].
  5289. */
  5290. SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void));
  5291. /*
  5292. ** CAPI3REF: Reset Automatic Extension Loading
  5293. **
  5294. ** ^This interface disables all automatic extensions previously
  5295. ** registered using [sqlite3_auto_extension()].
  5296. */
  5297. SQLITE_API void sqlite3_reset_auto_extension(void);
  5298. /*
  5299. ** The interface to the virtual-table mechanism is currently considered
  5300. ** to be experimental. The interface might change in incompatible ways.
  5301. ** If this is a problem for you, do not use the interface at this time.
  5302. **
  5303. ** When the virtual-table mechanism stabilizes, we will declare the
  5304. ** interface fixed, support it indefinitely, and remove this comment.
  5305. */
  5306. /*
  5307. ** Structures used by the virtual table interface
  5308. */
  5309. typedef struct sqlite3_vtab sqlite3_vtab;
  5310. typedef struct sqlite3_index_info sqlite3_index_info;
  5311. typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;
  5312. typedef struct sqlite3_module sqlite3_module;
  5313. /*
  5314. ** CAPI3REF: Virtual Table Object
  5315. ** KEYWORDS: sqlite3_module {virtual table module}
  5316. **
  5317. ** This structure, sometimes called a "virtual table module",
  5318. ** defines the implementation of a [virtual tables].
  5319. ** This structure consists mostly of methods for the module.
  5320. **
  5321. ** ^A virtual table module is created by filling in a persistent
  5322. ** instance of this structure and passing a pointer to that instance
  5323. ** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].
  5324. ** ^The registration remains valid until it is replaced by a different
  5325. ** module or until the [database connection] closes. The content
  5326. ** of this structure must not change while it is registered with
  5327. ** any database connection.
  5328. */
  5329. struct sqlite3_module {
  5330. int iVersion;
  5331. int (*xCreate)(sqlite3*, void *pAux,
  5332. int argc, const char *const*argv,
  5333. sqlite3_vtab **ppVTab, char**);
  5334. int (*xConnect)(sqlite3*, void *pAux,
  5335. int argc, const char *const*argv,
  5336. sqlite3_vtab **ppVTab, char**);
  5337. int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
  5338. int (*xDisconnect)(sqlite3_vtab *pVTab);
  5339. int (*xDestroy)(sqlite3_vtab *pVTab);
  5340. int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);
  5341. int (*xClose)(sqlite3_vtab_cursor*);
  5342. int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
  5343. int argc, sqlite3_value **argv);
  5344. int (*xNext)(sqlite3_vtab_cursor*);
  5345. int (*xEof)(sqlite3_vtab_cursor*);
  5346. int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int);
  5347. int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid);
  5348. int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *);
  5349. int (*xBegin)(sqlite3_vtab *pVTab);
  5350. int (*xSync)(sqlite3_vtab *pVTab);
  5351. int (*xCommit)(sqlite3_vtab *pVTab);
  5352. int (*xRollback)(sqlite3_vtab *pVTab);
  5353. int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
  5354. void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
  5355. void **ppArg);
  5356. int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
  5357. /* The methods above are in version 1 of the sqlite_module object. Those
  5358. ** below are for version 2 and greater. */
  5359. int (*xSavepoint)(sqlite3_vtab *pVTab, int);
  5360. int (*xRelease)(sqlite3_vtab *pVTab, int);
  5361. int (*xRollbackTo)(sqlite3_vtab *pVTab, int);
  5362. };
  5363. /*
  5364. ** CAPI3REF: Virtual Table Indexing Information
  5365. ** KEYWORDS: sqlite3_index_info
  5366. **
  5367. ** The sqlite3_index_info structure and its substructures is used as part
  5368. ** of the [virtual table] interface to
  5369. ** pass information into and receive the reply from the [xBestIndex]
  5370. ** method of a [virtual table module]. The fields under **Inputs** are the
  5371. ** inputs to xBestIndex and are read-only. xBestIndex inserts its
  5372. ** results into the **Outputs** fields.
  5373. **
  5374. ** ^(The aConstraint[] array records WHERE clause constraints of the form:
  5375. **
  5376. ** <blockquote>column OP expr</blockquote>
  5377. **
  5378. ** where OP is =, &lt;, &lt;=, &gt;, or &gt;=.)^ ^(The particular operator is
  5379. ** stored in aConstraint[].op using one of the
  5380. ** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^
  5381. ** ^(The index of the column is stored in
  5382. ** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the
  5383. ** expr on the right-hand side can be evaluated (and thus the constraint
  5384. ** is usable) and false if it cannot.)^
  5385. **
  5386. ** ^The optimizer automatically inverts terms of the form "expr OP column"
  5387. ** and makes other simplifications to the WHERE clause in an attempt to
  5388. ** get as many WHERE clause terms into the form shown above as possible.
  5389. ** ^The aConstraint[] array only reports WHERE clause terms that are
  5390. ** relevant to the particular virtual table being queried.
  5391. **
  5392. ** ^Information about the ORDER BY clause is stored in aOrderBy[].
  5393. ** ^Each term of aOrderBy records a column of the ORDER BY clause.
  5394. **
  5395. ** The [xBestIndex] method must fill aConstraintUsage[] with information
  5396. ** about what parameters to pass to xFilter. ^If argvIndex>0 then
  5397. ** the right-hand side of the corresponding aConstraint[] is evaluated
  5398. ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
  5399. ** is true, then the constraint is assumed to be fully handled by the
  5400. ** virtual table and is not checked again by SQLite.)^
  5401. **
  5402. ** ^The idxNum and idxPtr values are recorded and passed into the
  5403. ** [xFilter] method.
  5404. ** ^[sqlite3_free()] is used to free idxPtr if and only if
  5405. ** needToFreeIdxPtr is true.
  5406. **
  5407. ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
  5408. ** the correct order to satisfy the ORDER BY clause so that no separate
  5409. ** sorting step is required.
  5410. **
  5411. ** ^The estimatedCost value is an estimate of the cost of doing the
  5412. ** particular lookup. A full scan of a table with N entries should have
  5413. ** a cost of N. A binary search of a table of N entries should have a
  5414. ** cost of approximately log(N).
  5415. */
  5416. struct sqlite3_index_info {
  5417. /* Inputs */
  5418. int nConstraint; /* Number of entries in aConstraint */
  5419. struct sqlite3_index_constraint {
  5420. int iColumn; /* Column on left-hand side of constraint */
  5421. unsigned char op; /* Constraint operator */
  5422. unsigned char usable; /* True if this constraint is usable */
  5423. int iTermOffset; /* Used internally - xBestIndex should ignore */
  5424. } *aConstraint; /* Table of WHERE clause constraints */
  5425. int nOrderBy; /* Number of terms in the ORDER BY clause */
  5426. struct sqlite3_index_orderby {
  5427. int iColumn; /* Column number */
  5428. unsigned char desc; /* True for DESC. False for ASC. */
  5429. } *aOrderBy; /* The ORDER BY clause */
  5430. /* Outputs */
  5431. struct sqlite3_index_constraint_usage {
  5432. int argvIndex; /* if >0, constraint is part of argv to xFilter */
  5433. unsigned char omit; /* Do not code a test for this constraint */
  5434. } *aConstraintUsage;
  5435. int idxNum; /* Number used to identify the index */
  5436. char *idxStr; /* String, possibly obtained from sqlite3_malloc */
  5437. int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
  5438. int orderByConsumed; /* True if output is already ordered */
  5439. double estimatedCost; /* Estimated cost of using this index */
  5440. };
  5441. /*
  5442. ** CAPI3REF: Virtual Table Constraint Operator Codes
  5443. **
  5444. ** These macros defined the allowed values for the
  5445. ** [sqlite3_index_info].aConstraint[].op field. Each value represents
  5446. ** an operator that is part of a constraint term in the wHERE clause of
  5447. ** a query that uses a [virtual table].
  5448. */
  5449. #define SQLITE_INDEX_CONSTRAINT_EQ 2
  5450. #define SQLITE_INDEX_CONSTRAINT_GT 4
  5451. #define SQLITE_INDEX_CONSTRAINT_LE 8
  5452. #define SQLITE_INDEX_CONSTRAINT_LT 16
  5453. #define SQLITE_INDEX_CONSTRAINT_GE 32
  5454. #define SQLITE_INDEX_CONSTRAINT_MATCH 64
  5455. /*
  5456. ** CAPI3REF: Register A Virtual Table Implementation
  5457. **
  5458. ** ^These routines are used to register a new [virtual table module] name.
  5459. ** ^Module names must be registered before
  5460. ** creating a new [virtual table] using the module and before using a
  5461. ** preexisting [virtual table] for the module.
  5462. **
  5463. ** ^The module name is registered on the [database connection] specified
  5464. ** by the first parameter. ^The name of the module is given by the
  5465. ** second parameter. ^The third parameter is a pointer to
  5466. ** the implementation of the [virtual table module]. ^The fourth
  5467. ** parameter is an arbitrary client data pointer that is passed through
  5468. ** into the [xCreate] and [xConnect] methods of the virtual table module
  5469. ** when a new virtual table is be being created or reinitialized.
  5470. **
  5471. ** ^The sqlite3_create_module_v2() interface has a fifth parameter which
  5472. ** is a pointer to a destructor for the pClientData. ^SQLite will
  5473. ** invoke the destructor function (if it is not NULL) when SQLite
  5474. ** no longer needs the pClientData pointer. ^The destructor will also
  5475. ** be invoked if the call to sqlite3_create_module_v2() fails.
  5476. ** ^The sqlite3_create_module()
  5477. ** interface is equivalent to sqlite3_create_module_v2() with a NULL
  5478. ** destructor.
  5479. */
  5480. SQLITE_API int sqlite3_create_module(
  5481. sqlite3 *db, /* SQLite connection to register module with */
  5482. const char *zName, /* Name of the module */
  5483. const sqlite3_module *p, /* Methods for the module */
  5484. void *pClientData /* Client data for xCreate/xConnect */
  5485. );
  5486. SQLITE_API int sqlite3_create_module_v2(
  5487. sqlite3 *db, /* SQLite connection to register module with */
  5488. const char *zName, /* Name of the module */
  5489. const sqlite3_module *p, /* Methods for the module */
  5490. void *pClientData, /* Client data for xCreate/xConnect */
  5491. void(*xDestroy)(void*) /* Module destructor function */
  5492. );
  5493. /*
  5494. ** CAPI3REF: Virtual Table Instance Object
  5495. ** KEYWORDS: sqlite3_vtab
  5496. **
  5497. ** Every [virtual table module] implementation uses a subclass
  5498. ** of this object to describe a particular instance
  5499. ** of the [virtual table]. Each subclass will
  5500. ** be tailored to the specific needs of the module implementation.
  5501. ** The purpose of this superclass is to define certain fields that are
  5502. ** common to all module implementations.
  5503. **
  5504. ** ^Virtual tables methods can set an error message by assigning a
  5505. ** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should
  5506. ** take care that any prior string is freed by a call to [sqlite3_free()]
  5507. ** prior to assigning a new string to zErrMsg. ^After the error message
  5508. ** is delivered up to the client application, the string will be automatically
  5509. ** freed by sqlite3_free() and the zErrMsg field will be zeroed.
  5510. */
  5511. struct sqlite3_vtab {
  5512. const sqlite3_module *pModule; /* The module for this virtual table */
  5513. int nRef; /* NO LONGER USED */
  5514. char *zErrMsg; /* Error message from sqlite3_mprintf() */
  5515. /* Virtual table implementations will typically add additional fields */
  5516. };
  5517. /*
  5518. ** CAPI3REF: Virtual Table Cursor Object
  5519. ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
  5520. **
  5521. ** Every [virtual table module] implementation uses a subclass of the
  5522. ** following structure to describe cursors that point into the
  5523. ** [virtual table] and are used
  5524. ** to loop through the virtual table. Cursors are created using the
  5525. ** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed
  5526. ** by the [sqlite3_module.xClose | xClose] method. Cursors are used
  5527. ** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods
  5528. ** of the module. Each module implementation will define
  5529. ** the content of a cursor structure to suit its own needs.
  5530. **
  5531. ** This superclass exists in order to define fields of the cursor that
  5532. ** are common to all implementations.
  5533. */
  5534. struct sqlite3_vtab_cursor {
  5535. sqlite3_vtab *pVtab; /* Virtual table of this cursor */
  5536. /* Virtual table implementations will typically add additional fields */
  5537. };
  5538. /*
  5539. ** CAPI3REF: Declare The Schema Of A Virtual Table
  5540. **
  5541. ** ^The [xCreate] and [xConnect] methods of a
  5542. ** [virtual table module] call this interface
  5543. ** to declare the format (the names and datatypes of the columns) of
  5544. ** the virtual tables they implement.
  5545. */
  5546. SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
  5547. /*
  5548. ** CAPI3REF: Overload A Function For A Virtual Table
  5549. **
  5550. ** ^(Virtual tables can provide alternative implementations of functions
  5551. ** using the [xFindFunction] method of the [virtual table module].
  5552. ** But global versions of those functions
  5553. ** must exist in order to be overloaded.)^
  5554. **
  5555. ** ^(This API makes sure a global version of a function with a particular
  5556. ** name and number of parameters exists. If no such function exists
  5557. ** before this API is called, a new function is created.)^ ^The implementation
  5558. ** of the new function always causes an exception to be thrown. So
  5559. ** the new function is not good for anything by itself. Its only
  5560. ** purpose is to be a placeholder function that can be overloaded
  5561. ** by a [virtual table].
  5562. */
  5563. SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
  5564. /*
  5565. ** The interface to the virtual-table mechanism defined above (back up
  5566. ** to a comment remarkably similar to this one) is currently considered
  5567. ** to be experimental. The interface might change in incompatible ways.
  5568. ** If this is a problem for you, do not use the interface at this time.
  5569. **
  5570. ** When the virtual-table mechanism stabilizes, we will declare the
  5571. ** interface fixed, support it indefinitely, and remove this comment.
  5572. */
  5573. /*
  5574. ** CAPI3REF: A Handle To An Open BLOB
  5575. ** KEYWORDS: {BLOB handle} {BLOB handles}
  5576. **
  5577. ** An instance of this object represents an open BLOB on which
  5578. ** [sqlite3_blob_open | incremental BLOB I/O] can be performed.
  5579. ** ^Objects of this type are created by [sqlite3_blob_open()]
  5580. ** and destroyed by [sqlite3_blob_close()].
  5581. ** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces
  5582. ** can be used to read or write small subsections of the BLOB.
  5583. ** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes.
  5584. */
  5585. typedef struct sqlite3_blob sqlite3_blob;
  5586. /*
  5587. ** CAPI3REF: Open A BLOB For Incremental I/O
  5588. **
  5589. ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
  5590. ** in row iRow, column zColumn, table zTable in database zDb;
  5591. ** in other words, the same BLOB that would be selected by:
  5592. **
  5593. ** <pre>
  5594. ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
  5595. ** </pre>)^
  5596. **
  5597. ** ^If the flags parameter is non-zero, then the BLOB is opened for read
  5598. ** and write access. ^If it is zero, the BLOB is opened for read access.
  5599. ** ^It is not possible to open a column that is part of an index or primary
  5600. ** key for writing. ^If [foreign key constraints] are enabled, it is
  5601. ** not possible to open a column that is part of a [child key] for writing.
  5602. **
  5603. ** ^Note that the database name is not the filename that contains
  5604. ** the database but rather the symbolic name of the database that
  5605. ** appears after the AS keyword when the database is connected using [ATTACH].
  5606. ** ^For the main database file, the database name is "main".
  5607. ** ^For TEMP tables, the database name is "temp".
  5608. **
  5609. ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written
  5610. ** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set
  5611. ** to be a null pointer.)^
  5612. ** ^This function sets the [database connection] error code and message
  5613. ** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related
  5614. ** functions. ^Note that the *ppBlob variable is always initialized in a
  5615. ** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob
  5616. ** regardless of the success or failure of this routine.
  5617. **
  5618. ** ^(If the row that a BLOB handle points to is modified by an
  5619. ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
  5620. ** then the BLOB handle is marked as "expired".
  5621. ** This is true if any column of the row is changed, even a column
  5622. ** other than the one the BLOB handle is open on.)^
  5623. ** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for
  5624. ** an expired BLOB handle fail with a return code of [SQLITE_ABORT].
  5625. ** ^(Changes written into a BLOB prior to the BLOB expiring are not
  5626. ** rolled back by the expiration of the BLOB. Such changes will eventually
  5627. ** commit if the transaction continues to completion.)^
  5628. **
  5629. ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
  5630. ** the opened blob. ^The size of a blob may not be changed by this
  5631. ** interface. Use the [UPDATE] SQL command to change the size of a
  5632. ** blob.
  5633. **
  5634. ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
  5635. ** and the built-in [zeroblob] SQL function can be used, if desired,
  5636. ** to create an empty, zero-filled blob in which to read or write using
  5637. ** this interface.
  5638. **
  5639. ** To avoid a resource leak, every open [BLOB handle] should eventually
  5640. ** be released by a call to [sqlite3_blob_close()].
  5641. */
  5642. SQLITE_API int sqlite3_blob_open(
  5643. sqlite3*,
  5644. const char *zDb,
  5645. const char *zTable,
  5646. const char *zColumn,
  5647. sqlite3_int64 iRow,
  5648. int flags,
  5649. sqlite3_blob **ppBlob
  5650. );
  5651. /*
  5652. ** CAPI3REF: Move a BLOB Handle to a New Row
  5653. **
  5654. ** ^This function is used to move an existing blob handle so that it points
  5655. ** to a different row of the same database table. ^The new row is identified
  5656. ** by the rowid value passed as the second argument. Only the row can be
  5657. ** changed. ^The database, table and column on which the blob handle is open
  5658. ** remain the same. Moving an existing blob handle to a new row can be
  5659. ** faster than closing the existing handle and opening a new one.
  5660. **
  5661. ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] -
  5662. ** it must exist and there must be either a blob or text value stored in
  5663. ** the nominated column.)^ ^If the new row is not present in the table, or if
  5664. ** it does not contain a blob or text value, or if another error occurs, an
  5665. ** SQLite error code is returned and the blob handle is considered aborted.
  5666. ** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or
  5667. ** [sqlite3_blob_reopen()] on an aborted blob handle immediately return
  5668. ** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle
  5669. ** always returns zero.
  5670. **
  5671. ** ^This function sets the database handle error code and message.
  5672. */
  5673. SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
  5674. /*
  5675. ** CAPI3REF: Close A BLOB Handle
  5676. **
  5677. ** ^Closes an open [BLOB handle].
  5678. **
  5679. ** ^Closing a BLOB shall cause the current transaction to commit
  5680. ** if there are no other BLOBs, no pending prepared statements, and the
  5681. ** database connection is in [autocommit mode].
  5682. ** ^If any writes were made to the BLOB, they might be held in cache
  5683. ** until the close operation if they will fit.
  5684. **
  5685. ** ^(Closing the BLOB often forces the changes
  5686. ** out to disk and so if any I/O errors occur, they will likely occur
  5687. ** at the time when the BLOB is closed. Any errors that occur during
  5688. ** closing are reported as a non-zero return value.)^
  5689. **
  5690. ** ^(The BLOB is closed unconditionally. Even if this routine returns
  5691. ** an error code, the BLOB is still closed.)^
  5692. **
  5693. ** ^Calling this routine with a null pointer (such as would be returned
  5694. ** by a failed call to [sqlite3_blob_open()]) is a harmless no-op.
  5695. */
  5696. SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
  5697. /*
  5698. ** CAPI3REF: Return The Size Of An Open BLOB
  5699. **
  5700. ** ^Returns the size in bytes of the BLOB accessible via the
  5701. ** successfully opened [BLOB handle] in its only argument. ^The
  5702. ** incremental blob I/O routines can only read or overwriting existing
  5703. ** blob content; they cannot change the size of a blob.
  5704. **
  5705. ** This routine only works on a [BLOB handle] which has been created
  5706. ** by a prior successful call to [sqlite3_blob_open()] and which has not
  5707. ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
  5708. ** to this routine results in undefined and probably undesirable behavior.
  5709. */
  5710. SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *);
  5711. /*
  5712. ** CAPI3REF: Read Data From A BLOB Incrementally
  5713. **
  5714. ** ^(This function is used to read data from an open [BLOB handle] into a
  5715. ** caller-supplied buffer. N bytes of data are copied into buffer Z
  5716. ** from the open BLOB, starting at offset iOffset.)^
  5717. **
  5718. ** ^If offset iOffset is less than N bytes from the end of the BLOB,
  5719. ** [SQLITE_ERROR] is returned and no data is read. ^If N or iOffset is
  5720. ** less than zero, [SQLITE_ERROR] is returned and no data is read.
  5721. ** ^The size of the blob (and hence the maximum value of N+iOffset)
  5722. ** can be determined using the [sqlite3_blob_bytes()] interface.
  5723. **
  5724. ** ^An attempt to read from an expired [BLOB handle] fails with an
  5725. ** error code of [SQLITE_ABORT].
  5726. **
  5727. ** ^(On success, sqlite3_blob_read() returns SQLITE_OK.
  5728. ** Otherwise, an [error code] or an [extended error code] is returned.)^
  5729. **
  5730. ** This routine only works on a [BLOB handle] which has been created
  5731. ** by a prior successful call to [sqlite3_blob_open()] and which has not
  5732. ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
  5733. ** to this routine results in undefined and probably undesirable behavior.
  5734. **
  5735. ** See also: [sqlite3_blob_write()].
  5736. */
  5737. SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
  5738. /*
  5739. ** CAPI3REF: Write Data Into A BLOB Incrementally
  5740. **
  5741. ** ^This function is used to write data into an open [BLOB handle] from a
  5742. ** caller-supplied buffer. ^N bytes of data are copied from the buffer Z
  5743. ** into the open BLOB, starting at offset iOffset.
  5744. **
  5745. ** ^If the [BLOB handle] passed as the first argument was not opened for
  5746. ** writing (the flags parameter to [sqlite3_blob_open()] was zero),
  5747. ** this function returns [SQLITE_READONLY].
  5748. **
  5749. ** ^This function may only modify the contents of the BLOB; it is
  5750. ** not possible to increase the size of a BLOB using this API.
  5751. ** ^If offset iOffset is less than N bytes from the end of the BLOB,
  5752. ** [SQLITE_ERROR] is returned and no data is written. ^If N is
  5753. ** less than zero [SQLITE_ERROR] is returned and no data is written.
  5754. ** The size of the BLOB (and hence the maximum value of N+iOffset)
  5755. ** can be determined using the [sqlite3_blob_bytes()] interface.
  5756. **
  5757. ** ^An attempt to write to an expired [BLOB handle] fails with an
  5758. ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred
  5759. ** before the [BLOB handle] expired are not rolled back by the
  5760. ** expiration of the handle, though of course those changes might
  5761. ** have been overwritten by the statement that expired the BLOB handle
  5762. ** or by other independent statements.
  5763. **
  5764. ** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
  5765. ** Otherwise, an [error code] or an [extended error code] is returned.)^
  5766. **
  5767. ** This routine only works on a [BLOB handle] which has been created
  5768. ** by a prior successful call to [sqlite3_blob_open()] and which has not
  5769. ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
  5770. ** to this routine results in undefined and probably undesirable behavior.
  5771. **
  5772. ** See also: [sqlite3_blob_read()].
  5773. */
  5774. SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
  5775. /*
  5776. ** CAPI3REF: Virtual File System Objects
  5777. **
  5778. ** A virtual filesystem (VFS) is an [sqlite3_vfs] object
  5779. ** that SQLite uses to interact
  5780. ** with the underlying operating system. Most SQLite builds come with a
  5781. ** single default VFS that is appropriate for the host computer.
  5782. ** New VFSes can be registered and existing VFSes can be unregistered.
  5783. ** The following interfaces are provided.
  5784. **
  5785. ** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name.
  5786. ** ^Names are case sensitive.
  5787. ** ^Names are zero-terminated UTF-8 strings.
  5788. ** ^If there is no match, a NULL pointer is returned.
  5789. ** ^If zVfsName is NULL then the default VFS is returned.
  5790. **
  5791. ** ^New VFSes are registered with sqlite3_vfs_register().
  5792. ** ^Each new VFS becomes the default VFS if the makeDflt flag is set.
  5793. ** ^The same VFS can be registered multiple times without injury.
  5794. ** ^To make an existing VFS into the default VFS, register it again
  5795. ** with the makeDflt flag set. If two different VFSes with the
  5796. ** same name are registered, the behavior is undefined. If a
  5797. ** VFS is registered with a name that is NULL or an empty string,
  5798. ** then the behavior is undefined.
  5799. **
  5800. ** ^Unregister a VFS with the sqlite3_vfs_unregister() interface.
  5801. ** ^(If the default VFS is unregistered, another VFS is chosen as
  5802. ** the default. The choice for the new VFS is arbitrary.)^
  5803. */
  5804. SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName);
  5805. SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
  5806. SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*);
  5807. /*
  5808. ** CAPI3REF: Mutexes
  5809. **
  5810. ** The SQLite core uses these routines for thread
  5811. ** synchronization. Though they are intended for internal
  5812. ** use by SQLite, code that links against SQLite is
  5813. ** permitted to use any of these routines.
  5814. **
  5815. ** The SQLite source code contains multiple implementations
  5816. ** of these mutex routines. An appropriate implementation
  5817. ** is selected automatically at compile-time. ^(The following
  5818. ** implementations are available in the SQLite core:
  5819. **
  5820. ** <ul>
  5821. ** <li> SQLITE_MUTEX_OS2
  5822. ** <li> SQLITE_MUTEX_PTHREADS
  5823. ** <li> SQLITE_MUTEX_W32
  5824. ** <li> SQLITE_MUTEX_NOOP
  5825. ** </ul>)^
  5826. **
  5827. ** ^The SQLITE_MUTEX_NOOP implementation is a set of routines
  5828. ** that does no real locking and is appropriate for use in
  5829. ** a single-threaded application. ^The SQLITE_MUTEX_OS2,
  5830. ** SQLITE_MUTEX_PTHREADS, and SQLITE_MUTEX_W32 implementations
  5831. ** are appropriate for use on OS/2, Unix, and Windows.
  5832. **
  5833. ** ^(If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
  5834. ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
  5835. ** implementation is included with the library. In this case the
  5836. ** application must supply a custom mutex implementation using the
  5837. ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
  5838. ** before calling sqlite3_initialize() or any other public sqlite3_
  5839. ** function that calls sqlite3_initialize().)^
  5840. **
  5841. ** ^The sqlite3_mutex_alloc() routine allocates a new
  5842. ** mutex and returns a pointer to it. ^If it returns NULL
  5843. ** that means that a mutex could not be allocated. ^SQLite
  5844. ** will unwind its stack and return an error. ^(The argument
  5845. ** to sqlite3_mutex_alloc() is one of these integer constants:
  5846. **
  5847. ** <ul>
  5848. ** <li> SQLITE_MUTEX_FAST
  5849. ** <li> SQLITE_MUTEX_RECURSIVE
  5850. ** <li> SQLITE_MUTEX_STATIC_MASTER
  5851. ** <li> SQLITE_MUTEX_STATIC_MEM
  5852. ** <li> SQLITE_MUTEX_STATIC_MEM2
  5853. ** <li> SQLITE_MUTEX_STATIC_PRNG
  5854. ** <li> SQLITE_MUTEX_STATIC_LRU
  5855. ** <li> SQLITE_MUTEX_STATIC_LRU2
  5856. ** </ul>)^
  5857. **
  5858. ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
  5859. ** cause sqlite3_mutex_alloc() to create
  5860. ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
  5861. ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
  5862. ** The mutex implementation does not need to make a distinction
  5863. ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
  5864. ** not want to. ^SQLite will only request a recursive mutex in
  5865. ** cases where it really needs one. ^If a faster non-recursive mutex
  5866. ** implementation is available on the host platform, the mutex subsystem
  5867. ** might return such a mutex in response to SQLITE_MUTEX_FAST.
  5868. **
  5869. ** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other
  5870. ** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return
  5871. ** a pointer to a static preexisting mutex. ^Six static mutexes are
  5872. ** used by the current version of SQLite. Future versions of SQLite
  5873. ** may add additional static mutexes. Static mutexes are for internal
  5874. ** use by SQLite only. Applications that use SQLite mutexes should
  5875. ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
  5876. ** SQLITE_MUTEX_RECURSIVE.
  5877. **
  5878. ** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
  5879. ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
  5880. ** returns a different mutex on every call. ^But for the static
  5881. ** mutex types, the same mutex is returned on every call that has
  5882. ** the same type number.
  5883. **
  5884. ** ^The sqlite3_mutex_free() routine deallocates a previously
  5885. ** allocated dynamic mutex. ^SQLite is careful to deallocate every
  5886. ** dynamic mutex that it allocates. The dynamic mutexes must not be in
  5887. ** use when they are deallocated. Attempting to deallocate a static
  5888. ** mutex results in undefined behavior. ^SQLite never deallocates
  5889. ** a static mutex.
  5890. **
  5891. ** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
  5892. ** to enter a mutex. ^If another thread is already within the mutex,
  5893. ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
  5894. ** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK]
  5895. ** upon successful entry. ^(Mutexes created using
  5896. ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
  5897. ** In such cases the,
  5898. ** mutex must be exited an equal number of times before another thread
  5899. ** can enter.)^ ^(If the same thread tries to enter any other
  5900. ** kind of mutex more than once, the behavior is undefined.
  5901. ** SQLite will never exhibit
  5902. ** such behavior in its own use of mutexes.)^
  5903. **
  5904. ** ^(Some systems (for example, Windows 95) do not support the operation
  5905. ** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try()
  5906. ** will always return SQLITE_BUSY. The SQLite core only ever uses
  5907. ** sqlite3_mutex_try() as an optimization so this is acceptable behavior.)^
  5908. **
  5909. ** ^The sqlite3_mutex_leave() routine exits a mutex that was
  5910. ** previously entered by the same thread. ^(The behavior
  5911. ** is undefined if the mutex is not currently entered by the
  5912. ** calling thread or is not currently allocated. SQLite will
  5913. ** never do either.)^
  5914. **
  5915. ** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
  5916. ** sqlite3_mutex_leave() is a NULL pointer, then all three routines
  5917. ** behave as no-ops.
  5918. **
  5919. ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].
  5920. */
  5921. SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int);
  5922. SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*);
  5923. SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*);
  5924. SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
  5925. SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
  5926. /*
  5927. ** CAPI3REF: Mutex Methods Object
  5928. **
  5929. ** An instance of this structure defines the low-level routines
  5930. ** used to allocate and use mutexes.
  5931. **
  5932. ** Usually, the default mutex implementations provided by SQLite are
  5933. ** sufficient, however the user has the option of substituting a custom
  5934. ** implementation for specialized deployments or systems for which SQLite
  5935. ** does not provide a suitable implementation. In this case, the user
  5936. ** creates and populates an instance of this structure to pass
  5937. ** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
  5938. ** Additionally, an instance of this structure can be used as an
  5939. ** output variable when querying the system for the current mutex
  5940. ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
  5941. **
  5942. ** ^The xMutexInit method defined by this structure is invoked as
  5943. ** part of system initialization by the sqlite3_initialize() function.
  5944. ** ^The xMutexInit routine is called by SQLite exactly once for each
  5945. ** effective call to [sqlite3_initialize()].
  5946. **
  5947. ** ^The xMutexEnd method defined by this structure is invoked as
  5948. ** part of system shutdown by the sqlite3_shutdown() function. The
  5949. ** implementation of this method is expected to release all outstanding
  5950. ** resources obtained by the mutex methods implementation, especially
  5951. ** those obtained by the xMutexInit method. ^The xMutexEnd()
  5952. ** interface is invoked exactly once for each call to [sqlite3_shutdown()].
  5953. **
  5954. ** ^(The remaining seven methods defined by this structure (xMutexAlloc,
  5955. ** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and
  5956. ** xMutexNotheld) implement the following interfaces (respectively):
  5957. **
  5958. ** <ul>
  5959. ** <li> [sqlite3_mutex_alloc()] </li>
  5960. ** <li> [sqlite3_mutex_free()] </li>
  5961. ** <li> [sqlite3_mutex_enter()] </li>
  5962. ** <li> [sqlite3_mutex_try()] </li>
  5963. ** <li> [sqlite3_mutex_leave()] </li>
  5964. ** <li> [sqlite3_mutex_held()] </li>
  5965. ** <li> [sqlite3_mutex_notheld()] </li>
  5966. ** </ul>)^
  5967. **
  5968. ** The only difference is that the public sqlite3_XXX functions enumerated
  5969. ** above silently ignore any invocations that pass a NULL pointer instead
  5970. ** of a valid mutex handle. The implementations of the methods defined
  5971. ** by this structure are not required to handle this case, the results
  5972. ** of passing a NULL pointer instead of a valid mutex handle are undefined
  5973. ** (i.e. it is acceptable to provide an implementation that segfaults if
  5974. ** it is passed a NULL pointer).
  5975. **
  5976. ** The xMutexInit() method must be threadsafe. ^It must be harmless to
  5977. ** invoke xMutexInit() multiple times within the same process and without
  5978. ** intervening calls to xMutexEnd(). Second and subsequent calls to
  5979. ** xMutexInit() must be no-ops.
  5980. **
  5981. ** ^xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
  5982. ** and its associates). ^Similarly, xMutexAlloc() must not use SQLite memory
  5983. ** allocation for a static mutex. ^However xMutexAlloc() may use SQLite
  5984. ** memory allocation for a fast or recursive mutex.
  5985. **
  5986. ** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is
  5987. ** called, but only if the prior call to xMutexInit returned SQLITE_OK.
  5988. ** If xMutexInit fails in any way, it is expected to clean up after itself
  5989. ** prior to returning.
  5990. */
  5991. typedef struct sqlite3_mutex_methods sqlite3_mutex_methods;
  5992. struct sqlite3_mutex_methods {
  5993. int (*xMutexInit)(void);
  5994. int (*xMutexEnd)(void);
  5995. sqlite3_mutex *(*xMutexAlloc)(int);
  5996. void (*xMutexFree)(sqlite3_mutex *);
  5997. void (*xMutexEnter)(sqlite3_mutex *);
  5998. int (*xMutexTry)(sqlite3_mutex *);
  5999. void (*xMutexLeave)(sqlite3_mutex *);
  6000. int (*xMutexHeld)(sqlite3_mutex *);
  6001. int (*xMutexNotheld)(sqlite3_mutex *);
  6002. };
  6003. /*
  6004. ** CAPI3REF: Mutex Verification Routines
  6005. **
  6006. ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
  6007. ** are intended for use inside assert() statements. ^The SQLite core
  6008. ** never uses these routines except inside an assert() and applications
  6009. ** are advised to follow the lead of the core. ^The SQLite core only
  6010. ** provides implementations for these routines when it is compiled
  6011. ** with the SQLITE_DEBUG flag. ^External mutex implementations
  6012. ** are only required to provide these routines if SQLITE_DEBUG is
  6013. ** defined and if NDEBUG is not defined.
  6014. **
  6015. ** ^These routines should return true if the mutex in their argument
  6016. ** is held or not held, respectively, by the calling thread.
  6017. **
  6018. ** ^The implementation is not required to provide versions of these
  6019. ** routines that actually work. If the implementation does not provide working
  6020. ** versions of these routines, it should at least provide stubs that always
  6021. ** return true so that one does not get spurious assertion failures.
  6022. **
  6023. ** ^If the argument to sqlite3_mutex_held() is a NULL pointer then
  6024. ** the routine should return 1. This seems counter-intuitive since
  6025. ** clearly the mutex cannot be held if it does not exist. But
  6026. ** the reason the mutex does not exist is because the build is not
  6027. ** using mutexes. And we do not want the assert() containing the
  6028. ** call to sqlite3_mutex_held() to fail, so a non-zero return is
  6029. ** the appropriate thing to do. ^The sqlite3_mutex_notheld()
  6030. ** interface should also return 1 when given a NULL pointer.
  6031. */
  6032. #ifndef NDEBUG
  6033. SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);
  6034. SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
  6035. #endif
  6036. /*
  6037. ** CAPI3REF: Mutex Types
  6038. **
  6039. ** The [sqlite3_mutex_alloc()] interface takes a single argument
  6040. ** which is one of these integer constants.
  6041. **
  6042. ** The set of static mutexes may change from one SQLite release to the
  6043. ** next. Applications that override the built-in mutex logic must be
  6044. ** prepared to accommodate additional static mutexes.
  6045. */
  6046. #define SQLITE_MUTEX_FAST 0
  6047. #define SQLITE_MUTEX_RECURSIVE 1
  6048. #define SQLITE_MUTEX_STATIC_MASTER 2
  6049. #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */
  6050. #define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */
  6051. #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */
  6052. #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */
  6053. #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
  6054. #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */
  6055. #define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */
  6056. /*
  6057. ** CAPI3REF: Retrieve the mutex for a database connection
  6058. **
  6059. ** ^This interface returns a pointer the [sqlite3_mutex] object that
  6060. ** serializes access to the [database connection] given in the argument
  6061. ** when the [threading mode] is Serialized.
  6062. ** ^If the [threading mode] is Single-thread or Multi-thread then this
  6063. ** routine returns a NULL pointer.
  6064. */
  6065. SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*);
  6066. /*
  6067. ** CAPI3REF: Low-Level Control Of Database Files
  6068. **
  6069. ** ^The [sqlite3_file_control()] interface makes a direct call to the
  6070. ** xFileControl method for the [sqlite3_io_methods] object associated
  6071. ** with a particular database identified by the second argument. ^The
  6072. ** name of the database is "main" for the main database or "temp" for the
  6073. ** TEMP database, or the name that appears after the AS keyword for
  6074. ** databases that are added using the [ATTACH] SQL command.
  6075. ** ^A NULL pointer can be used in place of "main" to refer to the
  6076. ** main database file.
  6077. ** ^The third and fourth parameters to this routine
  6078. ** are passed directly through to the second and third parameters of
  6079. ** the xFileControl method. ^The return value of the xFileControl
  6080. ** method becomes the return value of this routine.
  6081. **
  6082. ** ^The SQLITE_FCNTL_FILE_POINTER value for the op parameter causes
  6083. ** a pointer to the underlying [sqlite3_file] object to be written into
  6084. ** the space pointed to by the 4th parameter. ^The SQLITE_FCNTL_FILE_POINTER
  6085. ** case is a short-circuit path which does not actually invoke the
  6086. ** underlying sqlite3_io_methods.xFileControl method.
  6087. **
  6088. ** ^If the second parameter (zDbName) does not match the name of any
  6089. ** open database file, then SQLITE_ERROR is returned. ^This error
  6090. ** code is not remembered and will not be recalled by [sqlite3_errcode()]
  6091. ** or [sqlite3_errmsg()]. The underlying xFileControl method might
  6092. ** also return SQLITE_ERROR. There is no way to distinguish between
  6093. ** an incorrect zDbName and an SQLITE_ERROR return from the underlying
  6094. ** xFileControl method.
  6095. **
  6096. ** See also: [SQLITE_FCNTL_LOCKSTATE]
  6097. */
  6098. SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
  6099. /*
  6100. ** CAPI3REF: Testing Interface
  6101. **
  6102. ** ^The sqlite3_test_control() interface is used to read out internal
  6103. ** state of SQLite and to inject faults into SQLite for testing
  6104. ** purposes. ^The first parameter is an operation code that determines
  6105. ** the number, meaning, and operation of all subsequent parameters.
  6106. **
  6107. ** This interface is not for use by applications. It exists solely
  6108. ** for verifying the correct operation of the SQLite library. Depending
  6109. ** on how the SQLite library is compiled, this interface might not exist.
  6110. **
  6111. ** The details of the operation codes, their meanings, the parameters
  6112. ** they take, and what they do are all subject to change without notice.
  6113. ** Unlike most of the SQLite API, this function is not guaranteed to
  6114. ** operate consistently from one release to the next.
  6115. */
  6116. SQLITE_API int sqlite3_test_control(int op, ...);
  6117. /*
  6118. ** CAPI3REF: Testing Interface Operation Codes
  6119. **
  6120. ** These constants are the valid operation code parameters used
  6121. ** as the first argument to [sqlite3_test_control()].
  6122. **
  6123. ** These parameters and their meanings are subject to change
  6124. ** without notice. These values are for testing purposes only.
  6125. ** Applications should not use any of these parameters or the
  6126. ** [sqlite3_test_control()] interface.
  6127. */
  6128. #define SQLITE_TESTCTRL_FIRST 5
  6129. #define SQLITE_TESTCTRL_PRNG_SAVE 5
  6130. #define SQLITE_TESTCTRL_PRNG_RESTORE 6
  6131. #define SQLITE_TESTCTRL_PRNG_RESET 7
  6132. #define SQLITE_TESTCTRL_BITVEC_TEST 8
  6133. #define SQLITE_TESTCTRL_FAULT_INSTALL 9
  6134. #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10
  6135. #define SQLITE_TESTCTRL_PENDING_BYTE 11
  6136. #define SQLITE_TESTCTRL_ASSERT 12
  6137. #define SQLITE_TESTCTRL_ALWAYS 13
  6138. #define SQLITE_TESTCTRL_RESERVE 14
  6139. #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
  6140. #define SQLITE_TESTCTRL_ISKEYWORD 16
  6141. #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
  6142. #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
  6143. #define SQLITE_TESTCTRL_EXPLAIN_STMT 19
  6144. #define SQLITE_TESTCTRL_LAST 19
  6145. /*
  6146. ** CAPI3REF: SQLite Runtime Status
  6147. **
  6148. ** ^This interface is used to retrieve runtime status information
  6149. ** about the performance of SQLite, and optionally to reset various
  6150. ** highwater marks. ^The first argument is an integer code for
  6151. ** the specific parameter to measure. ^(Recognized integer codes
  6152. ** are of the form [status parameters | SQLITE_STATUS_...].)^
  6153. ** ^The current value of the parameter is returned into *pCurrent.
  6154. ** ^The highest recorded value is returned in *pHighwater. ^If the
  6155. ** resetFlag is true, then the highest record value is reset after
  6156. ** *pHighwater is written. ^(Some parameters do not record the highest
  6157. ** value. For those parameters
  6158. ** nothing is written into *pHighwater and the resetFlag is ignored.)^
  6159. ** ^(Other parameters record only the highwater mark and not the current
  6160. ** value. For these latter parameters nothing is written into *pCurrent.)^
  6161. **
  6162. ** ^The sqlite3_status() routine returns SQLITE_OK on success and a
  6163. ** non-zero [error code] on failure.
  6164. **
  6165. ** This routine is threadsafe but is not atomic. This routine can be
  6166. ** called while other threads are running the same or different SQLite
  6167. ** interfaces. However the values returned in *pCurrent and
  6168. ** *pHighwater reflect the status of SQLite at different points in time
  6169. ** and it is possible that another thread might change the parameter
  6170. ** in between the times when *pCurrent and *pHighwater are written.
  6171. **
  6172. ** See also: [sqlite3_db_status()]
  6173. */
  6174. SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
  6175. /*
  6176. ** CAPI3REF: Status Parameters
  6177. ** KEYWORDS: {status parameters}
  6178. **
  6179. ** These integer constants designate various run-time status parameters
  6180. ** that can be returned by [sqlite3_status()].
  6181. **
  6182. ** <dl>
  6183. ** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
  6184. ** <dd>This parameter is the current amount of memory checked out
  6185. ** using [sqlite3_malloc()], either directly or indirectly. The
  6186. ** figure includes calls made to [sqlite3_malloc()] by the application
  6187. ** and internal memory usage by the SQLite library. Scratch memory
  6188. ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
  6189. ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
  6190. ** this parameter. The amount returned is the sum of the allocation
  6191. ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
  6192. **
  6193. ** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
  6194. ** <dd>This parameter records the largest memory allocation request
  6195. ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
  6196. ** internal equivalents). Only the value returned in the
  6197. ** *pHighwater parameter to [sqlite3_status()] is of interest.
  6198. ** The value written into the *pCurrent parameter is undefined.</dd>)^
  6199. **
  6200. ** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
  6201. ** <dd>This parameter records the number of separate memory allocations
  6202. ** currently checked out.</dd>)^
  6203. **
  6204. ** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
  6205. ** <dd>This parameter returns the number of pages used out of the
  6206. ** [pagecache memory allocator] that was configured using
  6207. ** [SQLITE_CONFIG_PAGECACHE]. The
  6208. ** value returned is in pages, not in bytes.</dd>)^
  6209. **
  6210. ** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]]
  6211. ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
  6212. ** <dd>This parameter returns the number of bytes of page cache
  6213. ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
  6214. ** buffer and where forced to overflow to [sqlite3_malloc()]. The
  6215. ** returned value includes allocations that overflowed because they
  6216. ** where too large (they were larger than the "sz" parameter to
  6217. ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
  6218. ** no space was left in the page cache.</dd>)^
  6219. **
  6220. ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
  6221. ** <dd>This parameter records the largest memory allocation request
  6222. ** handed to [pagecache memory allocator]. Only the value returned in the
  6223. ** *pHighwater parameter to [sqlite3_status()] is of interest.
  6224. ** The value written into the *pCurrent parameter is undefined.</dd>)^
  6225. **
  6226. ** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
  6227. ** <dd>This parameter returns the number of allocations used out of the
  6228. ** [scratch memory allocator] configured using
  6229. ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
  6230. ** in bytes. Since a single thread may only have one scratch allocation
  6231. ** outstanding at time, this parameter also reports the number of threads
  6232. ** using scratch memory at the same time.</dd>)^
  6233. **
  6234. ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
  6235. ** <dd>This parameter returns the number of bytes of scratch memory
  6236. ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
  6237. ** buffer and where forced to overflow to [sqlite3_malloc()]. The values
  6238. ** returned include overflows because the requested allocation was too
  6239. ** larger (that is, because the requested allocation was larger than the
  6240. ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
  6241. ** slots were available.
  6242. ** </dd>)^
  6243. **
  6244. ** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
  6245. ** <dd>This parameter records the largest memory allocation request
  6246. ** handed to [scratch memory allocator]. Only the value returned in the
  6247. ** *pHighwater parameter to [sqlite3_status()] is of interest.
  6248. ** The value written into the *pCurrent parameter is undefined.</dd>)^
  6249. **
  6250. ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
  6251. ** <dd>This parameter records the deepest parser stack. It is only
  6252. ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
  6253. ** </dl>
  6254. **
  6255. ** New status parameters may be added from time to time.
  6256. */
  6257. #define SQLITE_STATUS_MEMORY_USED 0
  6258. #define SQLITE_STATUS_PAGECACHE_USED 1
  6259. #define SQLITE_STATUS_PAGECACHE_OVERFLOW 2
  6260. #define SQLITE_STATUS_SCRATCH_USED 3
  6261. #define SQLITE_STATUS_SCRATCH_OVERFLOW 4
  6262. #define SQLITE_STATUS_MALLOC_SIZE 5
  6263. #define SQLITE_STATUS_PARSER_STACK 6
  6264. #define SQLITE_STATUS_PAGECACHE_SIZE 7
  6265. #define SQLITE_STATUS_SCRATCH_SIZE 8
  6266. #define SQLITE_STATUS_MALLOC_COUNT 9
  6267. /*
  6268. ** CAPI3REF: Database Connection Status
  6269. **
  6270. ** ^This interface is used to retrieve runtime status information
  6271. ** about a single [database connection]. ^The first argument is the
  6272. ** database connection object to be interrogated. ^The second argument
  6273. ** is an integer constant, taken from the set of
  6274. ** [SQLITE_DBSTATUS options], that
  6275. ** determines the parameter to interrogate. The set of
  6276. ** [SQLITE_DBSTATUS options] is likely
  6277. ** to grow in future releases of SQLite.
  6278. **
  6279. ** ^The current value of the requested parameter is written into *pCur
  6280. ** and the highest instantaneous value is written into *pHiwtr. ^If
  6281. ** the resetFlg is true, then the highest instantaneous value is
  6282. ** reset back down to the current value.
  6283. **
  6284. ** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
  6285. ** non-zero [error code] on failure.
  6286. **
  6287. ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
  6288. */
  6289. SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
  6290. /*
  6291. ** CAPI3REF: Status Parameters for database connections
  6292. ** KEYWORDS: {SQLITE_DBSTATUS options}
  6293. **
  6294. ** These constants are the available integer "verbs" that can be passed as
  6295. ** the second argument to the [sqlite3_db_status()] interface.
  6296. **
  6297. ** New verbs may be added in future releases of SQLite. Existing verbs
  6298. ** might be discontinued. Applications should check the return code from
  6299. ** [sqlite3_db_status()] to make sure that the call worked.
  6300. ** The [sqlite3_db_status()] interface will return a non-zero error code
  6301. ** if a discontinued or unsupported verb is invoked.
  6302. **
  6303. ** <dl>
  6304. ** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
  6305. ** <dd>This parameter returns the number of lookaside memory slots currently
  6306. ** checked out.</dd>)^
  6307. **
  6308. ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
  6309. ** <dd>This parameter returns the number malloc attempts that were
  6310. ** satisfied using lookaside memory. Only the high-water value is meaningful;
  6311. ** the current value is always zero.)^
  6312. **
  6313. ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
  6314. ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
  6315. ** <dd>This parameter returns the number malloc attempts that might have
  6316. ** been satisfied using lookaside memory but failed due to the amount of
  6317. ** memory requested being larger than the lookaside slot size.
  6318. ** Only the high-water value is meaningful;
  6319. ** the current value is always zero.)^
  6320. **
  6321. ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
  6322. ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
  6323. ** <dd>This parameter returns the number malloc attempts that might have
  6324. ** been satisfied using lookaside memory but failed due to all lookaside
  6325. ** memory already being in use.
  6326. ** Only the high-water value is meaningful;
  6327. ** the current value is always zero.)^
  6328. **
  6329. ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
  6330. ** <dd>This parameter returns the approximate number of of bytes of heap
  6331. ** memory used by all pager caches associated with the database connection.)^
  6332. ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
  6333. **
  6334. ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
  6335. ** <dd>This parameter returns the approximate number of of bytes of heap
  6336. ** memory used to store the schema for all databases associated
  6337. ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
  6338. ** ^The full amount of memory used by the schemas is reported, even if the
  6339. ** schema memory is shared with other database connections due to
  6340. ** [shared cache mode] being enabled.
  6341. ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
  6342. **
  6343. ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
  6344. ** <dd>This parameter returns the approximate number of of bytes of heap
  6345. ** and lookaside memory used by all prepared statements associated with
  6346. ** the database connection.)^
  6347. ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
  6348. ** </dd>
  6349. **
  6350. ** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt>
  6351. ** <dd>This parameter returns the number of pager cache hits that have
  6352. ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT
  6353. ** is always 0.
  6354. ** </dd>
  6355. **
  6356. ** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt>
  6357. ** <dd>This parameter returns the number of pager cache misses that have
  6358. ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS
  6359. ** is always 0.
  6360. ** </dd>
  6361. ** </dl>
  6362. */
  6363. #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
  6364. #define SQLITE_DBSTATUS_CACHE_USED 1
  6365. #define SQLITE_DBSTATUS_SCHEMA_USED 2
  6366. #define SQLITE_DBSTATUS_STMT_USED 3
  6367. #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4
  6368. #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
  6369. #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
  6370. #define SQLITE_DBSTATUS_CACHE_HIT 7
  6371. #define SQLITE_DBSTATUS_CACHE_MISS 8
  6372. #define SQLITE_DBSTATUS_MAX 8 /* Largest defined DBSTATUS */
  6373. /*
  6374. ** CAPI3REF: Prepared Statement Status
  6375. **
  6376. ** ^(Each prepared statement maintains various
  6377. ** [SQLITE_STMTSTATUS counters] that measure the number
  6378. ** of times it has performed specific operations.)^ These counters can
  6379. ** be used to monitor the performance characteristics of the prepared
  6380. ** statements. For example, if the number of table steps greatly exceeds
  6381. ** the number of table searches or result rows, that would tend to indicate
  6382. ** that the prepared statement is using a full table scan rather than
  6383. ** an index.
  6384. **
  6385. ** ^(This interface is used to retrieve and reset counter values from
  6386. ** a [prepared statement]. The first argument is the prepared statement
  6387. ** object to be interrogated. The second argument
  6388. ** is an integer code for a specific [SQLITE_STMTSTATUS counter]
  6389. ** to be interrogated.)^
  6390. ** ^The current value of the requested counter is returned.
  6391. ** ^If the resetFlg is true, then the counter is reset to zero after this
  6392. ** interface call returns.
  6393. **
  6394. ** See also: [sqlite3_status()] and [sqlite3_db_status()].
  6395. */
  6396. SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
  6397. /*
  6398. ** CAPI3REF: Status Parameters for prepared statements
  6399. ** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters}
  6400. **
  6401. ** These preprocessor macros define integer codes that name counter
  6402. ** values associated with the [sqlite3_stmt_status()] interface.
  6403. ** The meanings of the various counters are as follows:
  6404. **
  6405. ** <dl>
  6406. ** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
  6407. ** <dd>^This is the number of times that SQLite has stepped forward in
  6408. ** a table as part of a full table scan. Large numbers for this counter
  6409. ** may indicate opportunities for performance improvement through
  6410. ** careful use of indices.</dd>
  6411. **
  6412. ** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
  6413. ** <dd>^This is the number of sort operations that have occurred.
  6414. ** A non-zero value in this counter may indicate an opportunity to
  6415. ** improvement performance through careful use of indices.</dd>
  6416. **
  6417. ** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
  6418. ** <dd>^This is the number of rows inserted into transient indices that
  6419. ** were created automatically in order to help joins run faster.
  6420. ** A non-zero value in this counter may indicate an opportunity to
  6421. ** improvement performance by adding permanent indices that do not
  6422. ** need to be reinitialized each time the statement is run.</dd>
  6423. ** </dl>
  6424. */
  6425. #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
  6426. #define SQLITE_STMTSTATUS_SORT 2
  6427. #define SQLITE_STMTSTATUS_AUTOINDEX 3
  6428. /*
  6429. ** CAPI3REF: Custom Page Cache Object
  6430. **
  6431. ** The sqlite3_pcache type is opaque. It is implemented by
  6432. ** the pluggable module. The SQLite core has no knowledge of
  6433. ** its size or internal structure and never deals with the
  6434. ** sqlite3_pcache object except by holding and passing pointers
  6435. ** to the object.
  6436. **
  6437. ** See [sqlite3_pcache_methods2] for additional information.
  6438. */
  6439. typedef struct sqlite3_pcache sqlite3_pcache;
  6440. /*
  6441. ** CAPI3REF: Custom Page Cache Object
  6442. **
  6443. ** The sqlite3_pcache_page object represents a single page in the
  6444. ** page cache. The page cache will allocate instances of this
  6445. ** object. Various methods of the page cache use pointers to instances
  6446. ** of this object as parameters or as their return value.
  6447. **
  6448. ** See [sqlite3_pcache_methods2] for additional information.
  6449. */
  6450. typedef struct sqlite3_pcache_page sqlite3_pcache_page;
  6451. struct sqlite3_pcache_page {
  6452. void *pBuf; /* The content of the page */
  6453. void *pExtra; /* Extra information associated with the page */
  6454. };
  6455. /*
  6456. ** CAPI3REF: Application Defined Page Cache.
  6457. ** KEYWORDS: {page cache}
  6458. **
  6459. ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE2], ...) interface can
  6460. ** register an alternative page cache implementation by passing in an
  6461. ** instance of the sqlite3_pcache_methods2 structure.)^
  6462. ** In many applications, most of the heap memory allocated by
  6463. ** SQLite is used for the page cache.
  6464. ** By implementing a
  6465. ** custom page cache using this API, an application can better control
  6466. ** the amount of memory consumed by SQLite, the way in which
  6467. ** that memory is allocated and released, and the policies used to
  6468. ** determine exactly which parts of a database file are cached and for
  6469. ** how long.
  6470. **
  6471. ** The alternative page cache mechanism is an
  6472. ** extreme measure that is only needed by the most demanding applications.
  6473. ** The built-in page cache is recommended for most uses.
  6474. **
  6475. ** ^(The contents of the sqlite3_pcache_methods2 structure are copied to an
  6476. ** internal buffer by SQLite within the call to [sqlite3_config]. Hence
  6477. ** the application may discard the parameter after the call to
  6478. ** [sqlite3_config()] returns.)^
  6479. **
  6480. ** [[the xInit() page cache method]]
  6481. ** ^(The xInit() method is called once for each effective
  6482. ** call to [sqlite3_initialize()])^
  6483. ** (usually only once during the lifetime of the process). ^(The xInit()
  6484. ** method is passed a copy of the sqlite3_pcache_methods2.pArg value.)^
  6485. ** The intent of the xInit() method is to set up global data structures
  6486. ** required by the custom page cache implementation.
  6487. ** ^(If the xInit() method is NULL, then the
  6488. ** built-in default page cache is used instead of the application defined
  6489. ** page cache.)^
  6490. **
  6491. ** [[the xShutdown() page cache method]]
  6492. ** ^The xShutdown() method is called by [sqlite3_shutdown()].
  6493. ** It can be used to clean up
  6494. ** any outstanding resources before process shutdown, if required.
  6495. ** ^The xShutdown() method may be NULL.
  6496. **
  6497. ** ^SQLite automatically serializes calls to the xInit method,
  6498. ** so the xInit method need not be threadsafe. ^The
  6499. ** xShutdown method is only called from [sqlite3_shutdown()] so it does
  6500. ** not need to be threadsafe either. All other methods must be threadsafe
  6501. ** in multithreaded applications.
  6502. **
  6503. ** ^SQLite will never invoke xInit() more than once without an intervening
  6504. ** call to xShutdown().
  6505. **
  6506. ** [[the xCreate() page cache methods]]
  6507. ** ^SQLite invokes the xCreate() method to construct a new cache instance.
  6508. ** SQLite will typically create one cache instance for each open database file,
  6509. ** though this is not guaranteed. ^The
  6510. ** first parameter, szPage, is the size in bytes of the pages that must
  6511. ** be allocated by the cache. ^szPage will always a power of two. ^The
  6512. ** second parameter szExtra is a number of bytes of extra storage
  6513. ** associated with each page cache entry. ^The szExtra parameter will
  6514. ** a number less than 250. SQLite will use the
  6515. ** extra szExtra bytes on each page to store metadata about the underlying
  6516. ** database page on disk. The value passed into szExtra depends
  6517. ** on the SQLite version, the target platform, and how SQLite was compiled.
  6518. ** ^The third argument to xCreate(), bPurgeable, is true if the cache being
  6519. ** created will be used to cache database pages of a file stored on disk, or
  6520. ** false if it is used for an in-memory database. The cache implementation
  6521. ** does not have to do anything special based with the value of bPurgeable;
  6522. ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
  6523. ** never invoke xUnpin() except to deliberately delete a page.
  6524. ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
  6525. ** false will always have the "discard" flag set to true.
  6526. ** ^Hence, a cache created with bPurgeable false will
  6527. ** never contain any unpinned pages.
  6528. **
  6529. ** [[the xCachesize() page cache method]]
  6530. ** ^(The xCachesize() method may be called at any time by SQLite to set the
  6531. ** suggested maximum cache-size (number of pages stored by) the cache
  6532. ** instance passed as the first argument. This is the value configured using
  6533. ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
  6534. ** parameter, the implementation is not required to do anything with this
  6535. ** value; it is advisory only.
  6536. **
  6537. ** [[the xPagecount() page cache methods]]
  6538. ** The xPagecount() method must return the number of pages currently
  6539. ** stored in the cache, both pinned and unpinned.
  6540. **
  6541. ** [[the xFetch() page cache methods]]
  6542. ** The xFetch() method locates a page in the cache and returns a pointer to
  6543. ** an sqlite3_pcache_page object associated with that page, or a NULL pointer.
  6544. ** The pBuf element of the returned sqlite3_pcache_page object will be a
  6545. ** pointer to a buffer of szPage bytes used to store the content of a
  6546. ** single database page. The pExtra element of sqlite3_pcache_page will be
  6547. ** a pointer to the szExtra bytes of extra storage that SQLite has requested
  6548. ** for each entry in the page cache.
  6549. **
  6550. ** The page to be fetched is determined by the key. ^The minimum key value
  6551. ** is 1. After it has been retrieved using xFetch, the page is considered
  6552. ** to be "pinned".
  6553. **
  6554. ** If the requested page is already in the page cache, then the page cache
  6555. ** implementation must return a pointer to the page buffer with its content
  6556. ** intact. If the requested page is not already in the cache, then the
  6557. ** cache implementation should use the value of the createFlag
  6558. ** parameter to help it determined what action to take:
  6559. **
  6560. ** <table border=1 width=85% align=center>
  6561. ** <tr><th> createFlag <th> Behaviour when page is not already in cache
  6562. ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
  6563. ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
  6564. ** Otherwise return NULL.
  6565. ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
  6566. ** NULL if allocating a new page is effectively impossible.
  6567. ** </table>
  6568. **
  6569. ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite
  6570. ** will only use a createFlag of 2 after a prior call with a createFlag of 1
  6571. ** failed.)^ In between the to xFetch() calls, SQLite may
  6572. ** attempt to unpin one or more cache pages by spilling the content of
  6573. ** pinned pages to disk and synching the operating system disk cache.
  6574. **
  6575. ** [[the xUnpin() page cache method]]
  6576. ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
  6577. ** as its second argument. If the third parameter, discard, is non-zero,
  6578. ** then the page must be evicted from the cache.
  6579. ** ^If the discard parameter is
  6580. ** zero, then the page may be discarded or retained at the discretion of
  6581. ** page cache implementation. ^The page cache implementation
  6582. ** may choose to evict unpinned pages at any time.
  6583. **
  6584. ** The cache must not perform any reference counting. A single
  6585. ** call to xUnpin() unpins the page regardless of the number of prior calls
  6586. ** to xFetch().
  6587. **
  6588. ** [[the xRekey() page cache methods]]
  6589. ** The xRekey() method is used to change the key value associated with the
  6590. ** page passed as the second argument. If the cache
  6591. ** previously contains an entry associated with newKey, it must be
  6592. ** discarded. ^Any prior cache entry associated with newKey is guaranteed not
  6593. ** to be pinned.
  6594. **
  6595. ** When SQLite calls the xTruncate() method, the cache must discard all
  6596. ** existing cache entries with page numbers (keys) greater than or equal
  6597. ** to the value of the iLimit parameter passed to xTruncate(). If any
  6598. ** of these pages are pinned, they are implicitly unpinned, meaning that
  6599. ** they can be safely discarded.
  6600. **
  6601. ** [[the xDestroy() page cache method]]
  6602. ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
  6603. ** All resources associated with the specified cache should be freed. ^After
  6604. ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
  6605. ** handle invalid, and will not use it with any other sqlite3_pcache_methods2
  6606. ** functions.
  6607. **
  6608. ** [[the xShrink() page cache method]]
  6609. ** ^SQLite invokes the xShrink() method when it wants the page cache to
  6610. ** free up as much of heap memory as possible. The page cache implementation
  6611. ** is not obligated to free any memory, but well-behaved implementations should
  6612. ** do their best.
  6613. */
  6614. typedef struct sqlite3_pcache_methods2 sqlite3_pcache_methods2;
  6615. struct sqlite3_pcache_methods2 {
  6616. int iVersion;
  6617. void *pArg;
  6618. int (*xInit)(void*);
  6619. void (*xShutdown)(void*);
  6620. sqlite3_pcache *(*xCreate)(int szPage, int szExtra, int bPurgeable);
  6621. void (*xCachesize)(sqlite3_pcache*, int nCachesize);
  6622. int (*xPagecount)(sqlite3_pcache*);
  6623. sqlite3_pcache_page *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
  6624. void (*xUnpin)(sqlite3_pcache*, sqlite3_pcache_page*, int discard);
  6625. void (*xRekey)(sqlite3_pcache*, sqlite3_pcache_page*,
  6626. unsigned oldKey, unsigned newKey);
  6627. void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
  6628. void (*xDestroy)(sqlite3_pcache*);
  6629. void (*xShrink)(sqlite3_pcache*);
  6630. };
  6631. /*
  6632. ** This is the obsolete pcache_methods object that has now been replaced
  6633. ** by sqlite3_pcache_methods2. This object is not used by SQLite. It is
  6634. ** retained in the header file for backwards compatibility only.
  6635. */
  6636. typedef struct sqlite3_pcache_methods sqlite3_pcache_methods;
  6637. struct sqlite3_pcache_methods {
  6638. void *pArg;
  6639. int (*xInit)(void*);
  6640. void (*xShutdown)(void*);
  6641. sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable);
  6642. void (*xCachesize)(sqlite3_pcache*, int nCachesize);
  6643. int (*xPagecount)(sqlite3_pcache*);
  6644. void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
  6645. void (*xUnpin)(sqlite3_pcache*, void*, int discard);
  6646. void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey);
  6647. void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
  6648. void (*xDestroy)(sqlite3_pcache*);
  6649. };
  6650. /*
  6651. ** CAPI3REF: Online Backup Object
  6652. **
  6653. ** The sqlite3_backup object records state information about an ongoing
  6654. ** online backup operation. ^The sqlite3_backup object is created by
  6655. ** a call to [sqlite3_backup_init()] and is destroyed by a call to
  6656. ** [sqlite3_backup_finish()].
  6657. **
  6658. ** See Also: [Using the SQLite Online Backup API]
  6659. */
  6660. typedef struct sqlite3_backup sqlite3_backup;
  6661. /*
  6662. ** CAPI3REF: Online Backup API.
  6663. **
  6664. ** The backup API copies the content of one database into another.
  6665. ** It is useful either for creating backups of databases or
  6666. ** for copying in-memory databases to or from persistent files.
  6667. **
  6668. ** See Also: [Using the SQLite Online Backup API]
  6669. **
  6670. ** ^SQLite holds a write transaction open on the destination database file
  6671. ** for the duration of the backup operation.
  6672. ** ^The source database is read-locked only while it is being read;
  6673. ** it is not locked continuously for the entire backup operation.
  6674. ** ^Thus, the backup may be performed on a live source database without
  6675. ** preventing other database connections from
  6676. ** reading or writing to the source database while the backup is underway.
  6677. **
  6678. ** ^(To perform a backup operation:
  6679. ** <ol>
  6680. ** <li><b>sqlite3_backup_init()</b> is called once to initialize the
  6681. ** backup,
  6682. ** <li><b>sqlite3_backup_step()</b> is called one or more times to transfer
  6683. ** the data between the two databases, and finally
  6684. ** <li><b>sqlite3_backup_finish()</b> is called to release all resources
  6685. ** associated with the backup operation.
  6686. ** </ol>)^
  6687. ** There should be exactly one call to sqlite3_backup_finish() for each
  6688. ** successful call to sqlite3_backup_init().
  6689. **
  6690. ** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b>
  6691. **
  6692. ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the
  6693. ** [database connection] associated with the destination database
  6694. ** and the database name, respectively.
  6695. ** ^The database name is "main" for the main database, "temp" for the
  6696. ** temporary database, or the name specified after the AS keyword in
  6697. ** an [ATTACH] statement for an attached database.
  6698. ** ^The S and M arguments passed to
  6699. ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
  6700. ** and database name of the source database, respectively.
  6701. ** ^The source and destination [database connections] (parameters S and D)
  6702. ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
  6703. ** an error.
  6704. **
  6705. ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
  6706. ** returned and an error code and error message are stored in the
  6707. ** destination [database connection] D.
  6708. ** ^The error code and message for the failed call to sqlite3_backup_init()
  6709. ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
  6710. ** [sqlite3_errmsg16()] functions.
  6711. ** ^A successful call to sqlite3_backup_init() returns a pointer to an
  6712. ** [sqlite3_backup] object.
  6713. ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
  6714. ** sqlite3_backup_finish() functions to perform the specified backup
  6715. ** operation.
  6716. **
  6717. ** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b>
  6718. **
  6719. ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
  6720. ** the source and destination databases specified by [sqlite3_backup] object B.
  6721. ** ^If N is negative, all remaining source pages are copied.
  6722. ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
  6723. ** are still more pages to be copied, then the function returns [SQLITE_OK].
  6724. ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
  6725. ** from source to destination, then it returns [SQLITE_DONE].
  6726. ** ^If an error occurs while running sqlite3_backup_step(B,N),
  6727. ** then an [error code] is returned. ^As well as [SQLITE_OK] and
  6728. ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
  6729. ** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an
  6730. ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code.
  6731. **
  6732. ** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
  6733. ** <ol>
  6734. ** <li> the destination database was opened read-only, or
  6735. ** <li> the destination database is using write-ahead-log journaling
  6736. ** and the destination and source page sizes differ, or
  6737. ** <li> the destination database is an in-memory database and the
  6738. ** destination and source page sizes differ.
  6739. ** </ol>)^
  6740. **
  6741. ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
  6742. ** the [sqlite3_busy_handler | busy-handler function]
  6743. ** is invoked (if one is specified). ^If the
  6744. ** busy-handler returns non-zero before the lock is available, then
  6745. ** [SQLITE_BUSY] is returned to the caller. ^In this case the call to
  6746. ** sqlite3_backup_step() can be retried later. ^If the source
  6747. ** [database connection]
  6748. ** is being used to write to the source database when sqlite3_backup_step()
  6749. ** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this
  6750. ** case the call to sqlite3_backup_step() can be retried later on. ^(If
  6751. ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or
  6752. ** [SQLITE_READONLY] is returned, then
  6753. ** there is no point in retrying the call to sqlite3_backup_step(). These
  6754. ** errors are considered fatal.)^ The application must accept
  6755. ** that the backup operation has failed and pass the backup operation handle
  6756. ** to the sqlite3_backup_finish() to release associated resources.
  6757. **
  6758. ** ^The first call to sqlite3_backup_step() obtains an exclusive lock
  6759. ** on the destination file. ^The exclusive lock is not released until either
  6760. ** sqlite3_backup_finish() is called or the backup operation is complete
  6761. ** and sqlite3_backup_step() returns [SQLITE_DONE]. ^Every call to
  6762. ** sqlite3_backup_step() obtains a [shared lock] on the source database that
  6763. ** lasts for the duration of the sqlite3_backup_step() call.
  6764. ** ^Because the source database is not locked between calls to
  6765. ** sqlite3_backup_step(), the source database may be modified mid-way
  6766. ** through the backup process. ^If the source database is modified by an
  6767. ** external process or via a database connection other than the one being
  6768. ** used by the backup operation, then the backup will be automatically
  6769. ** restarted by the next call to sqlite3_backup_step(). ^If the source
  6770. ** database is modified by the using the same database connection as is used
  6771. ** by the backup operation, then the backup database is automatically
  6772. ** updated at the same time.
  6773. **
  6774. ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
  6775. **
  6776. ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the
  6777. ** application wishes to abandon the backup operation, the application
  6778. ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().
  6779. ** ^The sqlite3_backup_finish() interfaces releases all
  6780. ** resources associated with the [sqlite3_backup] object.
  6781. ** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any
  6782. ** active write-transaction on the destination database is rolled back.
  6783. ** The [sqlite3_backup] object is invalid
  6784. ** and may not be used following a call to sqlite3_backup_finish().
  6785. **
  6786. ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
  6787. ** sqlite3_backup_step() errors occurred, regardless or whether or not
  6788. ** sqlite3_backup_step() completed.
  6789. ** ^If an out-of-memory condition or IO error occurred during any prior
  6790. ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
  6791. ** sqlite3_backup_finish() returns the corresponding [error code].
  6792. **
  6793. ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
  6794. ** is not a permanent error and does not affect the return value of
  6795. ** sqlite3_backup_finish().
  6796. **
  6797. ** [[sqlite3_backup__remaining()]] [[sqlite3_backup_pagecount()]]
  6798. ** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>
  6799. **
  6800. ** ^Each call to sqlite3_backup_step() sets two values inside
  6801. ** the [sqlite3_backup] object: the number of pages still to be backed
  6802. ** up and the total number of pages in the source database file.
  6803. ** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces
  6804. ** retrieve these two values, respectively.
  6805. **
  6806. ** ^The values returned by these functions are only updated by
  6807. ** sqlite3_backup_step(). ^If the source database is modified during a backup
  6808. ** operation, then the values are not updated to account for any extra
  6809. ** pages that need to be updated or the size of the source database file
  6810. ** changing.
  6811. **
  6812. ** <b>Concurrent Usage of Database Handles</b>
  6813. **
  6814. ** ^The source [database connection] may be used by the application for other
  6815. ** purposes while a backup operation is underway or being initialized.
  6816. ** ^If SQLite is compiled and configured to support threadsafe database
  6817. ** connections, then the source database connection may be used concurrently
  6818. ** from within other threads.
  6819. **
  6820. ** However, the application must guarantee that the destination
  6821. ** [database connection] is not passed to any other API (by any thread) after
  6822. ** sqlite3_backup_init() is called and before the corresponding call to
  6823. ** sqlite3_backup_finish(). SQLite does not currently check to see
  6824. ** if the application incorrectly accesses the destination [database connection]
  6825. ** and so no error code is reported, but the operations may malfunction
  6826. ** nevertheless. Use of the destination database connection while a
  6827. ** backup is in progress might also also cause a mutex deadlock.
  6828. **
  6829. ** If running in [shared cache mode], the application must
  6830. ** guarantee that the shared cache used by the destination database
  6831. ** is not accessed while the backup is running. In practice this means
  6832. ** that the application must guarantee that the disk file being
  6833. ** backed up to is not accessed by any connection within the process,
  6834. ** not just the specific connection that was passed to sqlite3_backup_init().
  6835. **
  6836. ** The [sqlite3_backup] object itself is partially threadsafe. Multiple
  6837. ** threads may safely make multiple concurrent calls to sqlite3_backup_step().
  6838. ** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount()
  6839. ** APIs are not strictly speaking threadsafe. If they are invoked at the
  6840. ** same time as another thread is invoking sqlite3_backup_step() it is
  6841. ** possible that they return invalid values.
  6842. */
  6843. SQLITE_API sqlite3_backup *sqlite3_backup_init(
  6844. sqlite3 *pDest, /* Destination database handle */
  6845. const char *zDestName, /* Destination database name */
  6846. sqlite3 *pSource, /* Source database handle */
  6847. const char *zSourceName /* Source database name */
  6848. );
  6849. SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage);
  6850. SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p);
  6851. SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
  6852. SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
  6853. /*
  6854. ** CAPI3REF: Unlock Notification
  6855. **
  6856. ** ^When running in shared-cache mode, a database operation may fail with
  6857. ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
  6858. ** individual tables within the shared-cache cannot be obtained. See
  6859. ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
  6860. ** ^This API may be used to register a callback that SQLite will invoke
  6861. ** when the connection currently holding the required lock relinquishes it.
  6862. ** ^This API is only available if the library was compiled with the
  6863. ** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined.
  6864. **
  6865. ** See Also: [Using the SQLite Unlock Notification Feature].
  6866. **
  6867. ** ^Shared-cache locks are released when a database connection concludes
  6868. ** its current transaction, either by committing it or rolling it back.
  6869. **
  6870. ** ^When a connection (known as the blocked connection) fails to obtain a
  6871. ** shared-cache lock and SQLITE_LOCKED is returned to the caller, the
  6872. ** identity of the database connection (the blocking connection) that
  6873. ** has locked the required resource is stored internally. ^After an
  6874. ** application receives an SQLITE_LOCKED error, it may call the
  6875. ** sqlite3_unlock_notify() method with the blocked connection handle as
  6876. ** the first argument to register for a callback that will be invoked
  6877. ** when the blocking connections current transaction is concluded. ^The
  6878. ** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
  6879. ** call that concludes the blocking connections transaction.
  6880. **
  6881. ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
  6882. ** there is a chance that the blocking connection will have already
  6883. ** concluded its transaction by the time sqlite3_unlock_notify() is invoked.
  6884. ** If this happens, then the specified callback is invoked immediately,
  6885. ** from within the call to sqlite3_unlock_notify().)^
  6886. **
  6887. ** ^If the blocked connection is attempting to obtain a write-lock on a
  6888. ** shared-cache table, and more than one other connection currently holds
  6889. ** a read-lock on the same table, then SQLite arbitrarily selects one of
  6890. ** the other connections to use as the blocking connection.
  6891. **
  6892. ** ^(There may be at most one unlock-notify callback registered by a
  6893. ** blocked connection. If sqlite3_unlock_notify() is called when the
  6894. ** blocked connection already has a registered unlock-notify callback,
  6895. ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
  6896. ** called with a NULL pointer as its second argument, then any existing
  6897. ** unlock-notify callback is canceled. ^The blocked connections
  6898. ** unlock-notify callback may also be canceled by closing the blocked
  6899. ** connection using [sqlite3_close()].
  6900. **
  6901. ** The unlock-notify callback is not reentrant. If an application invokes
  6902. ** any sqlite3_xxx API functions from within an unlock-notify callback, a
  6903. ** crash or deadlock may be the result.
  6904. **
  6905. ** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always
  6906. ** returns SQLITE_OK.
  6907. **
  6908. ** <b>Callback Invocation Details</b>
  6909. **
  6910. ** When an unlock-notify callback is registered, the application provides a
  6911. ** single void* pointer that is passed to the callback when it is invoked.
  6912. ** However, the signature of the callback function allows SQLite to pass
  6913. ** it an array of void* context pointers. The first argument passed to
  6914. ** an unlock-notify callback is a pointer to an array of void* pointers,
  6915. ** and the second is the number of entries in the array.
  6916. **
  6917. ** When a blocking connections transaction is concluded, there may be
  6918. ** more than one blocked connection that has registered for an unlock-notify
  6919. ** callback. ^If two or more such blocked connections have specified the
  6920. ** same callback function, then instead of invoking the callback function
  6921. ** multiple times, it is invoked once with the set of void* context pointers
  6922. ** specified by the blocked connections bundled together into an array.
  6923. ** This gives the application an opportunity to prioritize any actions
  6924. ** related to the set of unblocked database connections.
  6925. **
  6926. ** <b>Deadlock Detection</b>
  6927. **
  6928. ** Assuming that after registering for an unlock-notify callback a
  6929. ** database waits for the callback to be issued before taking any further
  6930. ** action (a reasonable assumption), then using this API may cause the
  6931. ** application to deadlock. For example, if connection X is waiting for
  6932. ** connection Y's transaction to be concluded, and similarly connection
  6933. ** Y is waiting on connection X's transaction, then neither connection
  6934. ** will proceed and the system may remain deadlocked indefinitely.
  6935. **
  6936. ** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock
  6937. ** detection. ^If a given call to sqlite3_unlock_notify() would put the
  6938. ** system in a deadlocked state, then SQLITE_LOCKED is returned and no
  6939. ** unlock-notify callback is registered. The system is said to be in
  6940. ** a deadlocked state if connection A has registered for an unlock-notify
  6941. ** callback on the conclusion of connection B's transaction, and connection
  6942. ** B has itself registered for an unlock-notify callback when connection
  6943. ** A's transaction is concluded. ^Indirect deadlock is also detected, so
  6944. ** the system is also considered to be deadlocked if connection B has
  6945. ** registered for an unlock-notify callback on the conclusion of connection
  6946. ** C's transaction, where connection C is waiting on connection A. ^Any
  6947. ** number of levels of indirection are allowed.
  6948. **
  6949. ** <b>The "DROP TABLE" Exception</b>
  6950. **
  6951. ** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost
  6952. ** always appropriate to call sqlite3_unlock_notify(). There is however,
  6953. ** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement,
  6954. ** SQLite checks if there are any currently executing SELECT statements
  6955. ** that belong to the same connection. If there are, SQLITE_LOCKED is
  6956. ** returned. In this case there is no "blocking connection", so invoking
  6957. ** sqlite3_unlock_notify() results in the unlock-notify callback being
  6958. ** invoked immediately. If the application then re-attempts the "DROP TABLE"
  6959. ** or "DROP INDEX" query, an infinite loop might be the result.
  6960. **
  6961. ** One way around this problem is to check the extended error code returned
  6962. ** by an sqlite3_step() call. ^(If there is a blocking connection, then the
  6963. ** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in
  6964. ** the special "DROP TABLE/INDEX" case, the extended error code is just
  6965. ** SQLITE_LOCKED.)^
  6966. */
  6967. SQLITE_API int sqlite3_unlock_notify(
  6968. sqlite3 *pBlocked, /* Waiting connection */
  6969. void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */
  6970. void *pNotifyArg /* Argument to pass to xNotify */
  6971. );
  6972. /*
  6973. ** CAPI3REF: String Comparison
  6974. **
  6975. ** ^The [sqlite3_stricmp()] and [sqlite3_strnicmp()] APIs allow applications
  6976. ** and extensions to compare the contents of two buffers containing UTF-8
  6977. ** strings in a case-independent fashion, using the same definition of "case
  6978. ** independence" that SQLite uses internally when comparing identifiers.
  6979. */
  6980. SQLITE_API int sqlite3_stricmp(const char *, const char *);
  6981. SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
  6982. /*
  6983. ** CAPI3REF: Error Logging Interface
  6984. **
  6985. ** ^The [sqlite3_log()] interface writes a message into the error log
  6986. ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
  6987. ** ^If logging is enabled, the zFormat string and subsequent arguments are
  6988. ** used with [sqlite3_snprintf()] to generate the final output string.
  6989. **
  6990. ** The sqlite3_log() interface is intended for use by extensions such as
  6991. ** virtual tables, collating functions, and SQL functions. While there is
  6992. ** nothing to prevent an application from calling sqlite3_log(), doing so
  6993. ** is considered bad form.
  6994. **
  6995. ** The zFormat string must not be NULL.
  6996. **
  6997. ** To avoid deadlocks and other threading problems, the sqlite3_log() routine
  6998. ** will not use dynamically allocated memory. The log message is stored in
  6999. ** a fixed-length buffer on the stack. If the log message is longer than
  7000. ** a few hundred characters, it will be truncated to the length of the
  7001. ** buffer.
  7002. */
  7003. SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...);
  7004. /*
  7005. ** CAPI3REF: Write-Ahead Log Commit Hook
  7006. **
  7007. ** ^The [sqlite3_wal_hook()] function is used to register a callback that
  7008. ** will be invoked each time a database connection commits data to a
  7009. ** [write-ahead log] (i.e. whenever a transaction is committed in
  7010. ** [journal_mode | journal_mode=WAL mode]).
  7011. **
  7012. ** ^The callback is invoked by SQLite after the commit has taken place and
  7013. ** the associated write-lock on the database released, so the implementation
  7014. ** may read, write or [checkpoint] the database as required.
  7015. **
  7016. ** ^The first parameter passed to the callback function when it is invoked
  7017. ** is a copy of the third parameter passed to sqlite3_wal_hook() when
  7018. ** registering the callback. ^The second is a copy of the database handle.
  7019. ** ^The third parameter is the name of the database that was written to -
  7020. ** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter
  7021. ** is the number of pages currently in the write-ahead log file,
  7022. ** including those that were just committed.
  7023. **
  7024. ** The callback function should normally return [SQLITE_OK]. ^If an error
  7025. ** code is returned, that error will propagate back up through the
  7026. ** SQLite code base to cause the statement that provoked the callback
  7027. ** to report an error, though the commit will have still occurred. If the
  7028. ** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value
  7029. ** that does not correspond to any valid SQLite error code, the results
  7030. ** are undefined.
  7031. **
  7032. ** A single database handle may have at most a single write-ahead log callback
  7033. ** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any
  7034. ** previously registered write-ahead log callback. ^Note that the
  7035. ** [sqlite3_wal_autocheckpoint()] interface and the
  7036. ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will
  7037. ** those overwrite any prior [sqlite3_wal_hook()] settings.
  7038. */
  7039. SQLITE_API void *sqlite3_wal_hook(
  7040. sqlite3*,
  7041. int(*)(void *,sqlite3*,const char*,int),
  7042. void*
  7043. );
  7044. /*
  7045. ** CAPI3REF: Configure an auto-checkpoint
  7046. **
  7047. ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
  7048. ** [sqlite3_wal_hook()] that causes any database on [database connection] D
  7049. ** to automatically [checkpoint]
  7050. ** after committing a transaction if there are N or
  7051. ** more frames in the [write-ahead log] file. ^Passing zero or
  7052. ** a negative value as the nFrame parameter disables automatic
  7053. ** checkpoints entirely.
  7054. **
  7055. ** ^The callback registered by this function replaces any existing callback
  7056. ** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback
  7057. ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
  7058. ** configured by this function.
  7059. **
  7060. ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
  7061. ** from SQL.
  7062. **
  7063. ** ^Every new [database connection] defaults to having the auto-checkpoint
  7064. ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
  7065. ** pages. The use of this interface
  7066. ** is only necessary if the default setting is found to be suboptimal
  7067. ** for a particular application.
  7068. */
  7069. SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
  7070. /*
  7071. ** CAPI3REF: Checkpoint a database
  7072. **
  7073. ** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X
  7074. ** on [database connection] D to be [checkpointed]. ^If X is NULL or an
  7075. ** empty string, then a checkpoint is run on all databases of
  7076. ** connection D. ^If the database connection D is not in
  7077. ** [WAL | write-ahead log mode] then this interface is a harmless no-op.
  7078. **
  7079. ** ^The [wal_checkpoint pragma] can be used to invoke this interface
  7080. ** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the
  7081. ** [wal_autocheckpoint pragma] can be used to cause this interface to be
  7082. ** run whenever the WAL reaches a certain size threshold.
  7083. **
  7084. ** See also: [sqlite3_wal_checkpoint_v2()]
  7085. */
  7086. SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
  7087. /*
  7088. ** CAPI3REF: Checkpoint a database
  7089. **
  7090. ** Run a checkpoint operation on WAL database zDb attached to database
  7091. ** handle db. The specific operation is determined by the value of the
  7092. ** eMode parameter:
  7093. **
  7094. ** <dl>
  7095. ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
  7096. ** Checkpoint as many frames as possible without waiting for any database
  7097. ** readers or writers to finish. Sync the db file if all frames in the log
  7098. ** are checkpointed. This mode is the same as calling
  7099. ** sqlite3_wal_checkpoint(). The busy-handler callback is never invoked.
  7100. **
  7101. ** <dt>SQLITE_CHECKPOINT_FULL<dd>
  7102. ** This mode blocks (calls the busy-handler callback) until there is no
  7103. ** database writer and all readers are reading from the most recent database
  7104. ** snapshot. It then checkpoints all frames in the log file and syncs the
  7105. ** database file. This call blocks database writers while it is running,
  7106. ** but not database readers.
  7107. **
  7108. ** <dt>SQLITE_CHECKPOINT_RESTART<dd>
  7109. ** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after
  7110. ** checkpointing the log file it blocks (calls the busy-handler callback)
  7111. ** until all readers are reading from the database file only. This ensures
  7112. ** that the next client to write to the database file restarts the log file
  7113. ** from the beginning. This call blocks database writers while it is running,
  7114. ** but not database readers.
  7115. ** </dl>
  7116. **
  7117. ** If pnLog is not NULL, then *pnLog is set to the total number of frames in
  7118. ** the log file before returning. If pnCkpt is not NULL, then *pnCkpt is set to
  7119. ** the total number of checkpointed frames (including any that were already
  7120. ** checkpointed when this function is called). *pnLog and *pnCkpt may be
  7121. ** populated even if sqlite3_wal_checkpoint_v2() returns other than SQLITE_OK.
  7122. ** If no values are available because of an error, they are both set to -1
  7123. ** before returning to communicate this to the caller.
  7124. **
  7125. ** All calls obtain an exclusive "checkpoint" lock on the database file. If
  7126. ** any other process is running a checkpoint operation at the same time, the
  7127. ** lock cannot be obtained and SQLITE_BUSY is returned. Even if there is a
  7128. ** busy-handler configured, it will not be invoked in this case.
  7129. **
  7130. ** The SQLITE_CHECKPOINT_FULL and RESTART modes also obtain the exclusive
  7131. ** "writer" lock on the database file. If the writer lock cannot be obtained
  7132. ** immediately, and a busy-handler is configured, it is invoked and the writer
  7133. ** lock retried until either the busy-handler returns 0 or the lock is
  7134. ** successfully obtained. The busy-handler is also invoked while waiting for
  7135. ** database readers as described above. If the busy-handler returns 0 before
  7136. ** the writer lock is obtained or while waiting for database readers, the
  7137. ** checkpoint operation proceeds from that point in the same way as
  7138. ** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible
  7139. ** without blocking any further. SQLITE_BUSY is returned in this case.
  7140. **
  7141. ** If parameter zDb is NULL or points to a zero length string, then the
  7142. ** specified operation is attempted on all WAL databases. In this case the
  7143. ** values written to output parameters *pnLog and *pnCkpt are undefined. If
  7144. ** an SQLITE_BUSY error is encountered when processing one or more of the
  7145. ** attached WAL databases, the operation is still attempted on any remaining
  7146. ** attached databases and SQLITE_BUSY is returned to the caller. If any other
  7147. ** error occurs while processing an attached database, processing is abandoned
  7148. ** and the error code returned to the caller immediately. If no error
  7149. ** (SQLITE_BUSY or otherwise) is encountered while processing the attached
  7150. ** databases, SQLITE_OK is returned.
  7151. **
  7152. ** If database zDb is the name of an attached database that is not in WAL
  7153. ** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. If
  7154. ** zDb is not NULL (or a zero length string) and is not the name of any
  7155. ** attached database, SQLITE_ERROR is returned to the caller.
  7156. */
  7157. SQLITE_API int sqlite3_wal_checkpoint_v2(
  7158. sqlite3 *db, /* Database handle */
  7159. const char *zDb, /* Name of attached database (or NULL) */
  7160. int eMode, /* SQLITE_CHECKPOINT_* value */
  7161. int *pnLog, /* OUT: Size of WAL log in frames */
  7162. int *pnCkpt /* OUT: Total number of frames checkpointed */
  7163. );
  7164. /*
  7165. ** CAPI3REF: Checkpoint operation parameters
  7166. **
  7167. ** These constants can be used as the 3rd parameter to
  7168. ** [sqlite3_wal_checkpoint_v2()]. See the [sqlite3_wal_checkpoint_v2()]
  7169. ** documentation for additional information about the meaning and use of
  7170. ** each of these values.
  7171. */
  7172. #define SQLITE_CHECKPOINT_PASSIVE 0
  7173. #define SQLITE_CHECKPOINT_FULL 1
  7174. #define SQLITE_CHECKPOINT_RESTART 2
  7175. /*
  7176. ** CAPI3REF: Virtual Table Interface Configuration
  7177. **
  7178. ** This function may be called by either the [xConnect] or [xCreate] method
  7179. ** of a [virtual table] implementation to configure
  7180. ** various facets of the virtual table interface.
  7181. **
  7182. ** If this interface is invoked outside the context of an xConnect or
  7183. ** xCreate virtual table method then the behavior is undefined.
  7184. **
  7185. ** At present, there is only one option that may be configured using
  7186. ** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].) Further options
  7187. ** may be added in the future.
  7188. */
  7189. SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...);
  7190. /*
  7191. ** CAPI3REF: Virtual Table Configuration Options
  7192. **
  7193. ** These macros define the various options to the
  7194. ** [sqlite3_vtab_config()] interface that [virtual table] implementations
  7195. ** can use to customize and optimize their behavior.
  7196. **
  7197. ** <dl>
  7198. ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT
  7199. ** <dd>Calls of the form
  7200. ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
  7201. ** where X is an integer. If X is zero, then the [virtual table] whose
  7202. ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
  7203. ** support constraints. In this configuration (which is the default) if
  7204. ** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire
  7205. ** statement is rolled back as if [ON CONFLICT | OR ABORT] had been
  7206. ** specified as part of the users SQL statement, regardless of the actual
  7207. ** ON CONFLICT mode specified.
  7208. **
  7209. ** If X is non-zero, then the virtual table implementation guarantees
  7210. ** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before
  7211. ** any modifications to internal or persistent data structures have been made.
  7212. ** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite
  7213. ** is able to roll back a statement or database transaction, and abandon
  7214. ** or continue processing the current SQL statement as appropriate.
  7215. ** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns
  7216. ** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode
  7217. ** had been ABORT.
  7218. **
  7219. ** Virtual table implementations that are required to handle OR REPLACE
  7220. ** must do so within the [xUpdate] method. If a call to the
  7221. ** [sqlite3_vtab_on_conflict()] function indicates that the current ON
  7222. ** CONFLICT policy is REPLACE, the virtual table implementation should
  7223. ** silently replace the appropriate rows within the xUpdate callback and
  7224. ** return SQLITE_OK. Or, if this is not possible, it may return
  7225. ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
  7226. ** constraint handling.
  7227. ** </dl>
  7228. */
  7229. #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
  7230. /*
  7231. ** CAPI3REF: Determine The Virtual Table Conflict Policy
  7232. **
  7233. ** This function may only be called from within a call to the [xUpdate] method
  7234. ** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The
  7235. ** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL],
  7236. ** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode
  7237. ** of the SQL statement that triggered the call to the [xUpdate] method of the
  7238. ** [virtual table].
  7239. */
  7240. SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
  7241. /*
  7242. ** CAPI3REF: Conflict resolution modes
  7243. **
  7244. ** These constants are returned by [sqlite3_vtab_on_conflict()] to
  7245. ** inform a [virtual table] implementation what the [ON CONFLICT] mode
  7246. ** is for the SQL statement being evaluated.
  7247. **
  7248. ** Note that the [SQLITE_IGNORE] constant is also used as a potential
  7249. ** return value from the [sqlite3_set_authorizer()] callback and that
  7250. ** [SQLITE_ABORT] is also a [result code].
  7251. */
  7252. #define SQLITE_ROLLBACK 1
  7253. /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
  7254. #define SQLITE_FAIL 3
  7255. /* #define SQLITE_ABORT 4 // Also an error code */
  7256. #define SQLITE_REPLACE 5
  7257. /*
  7258. ** Undo the hack that converts floating point types to integer for
  7259. ** builds on processors without floating point support.
  7260. */
  7261. #ifdef SQLITE_OMIT_FLOATING_POINT
  7262. # undef double
  7263. #endif
  7264. #if 0
  7265. } /* End of the 'extern "C"' block */
  7266. #endif
  7267. #endif
  7268. /*
  7269. ** 2010 August 30
  7270. **
  7271. ** The author disclaims copyright to this source code. In place of
  7272. ** a legal notice, here is a blessing:
  7273. **
  7274. ** May you do good and not evil.
  7275. ** May you find forgiveness for yourself and forgive others.
  7276. ** May you share freely, never taking more than you give.
  7277. **
  7278. *************************************************************************
  7279. */
  7280. #ifndef _SQLITE3RTREE_H_
  7281. #define _SQLITE3RTREE_H_
  7282. #if 0
  7283. extern "C" {
  7284. #endif
  7285. typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry;
  7286. /*
  7287. ** Register a geometry callback named zGeom that can be used as part of an
  7288. ** R-Tree geometry query as follows:
  7289. **
  7290. ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)
  7291. */
  7292. SQLITE_API int sqlite3_rtree_geometry_callback(
  7293. sqlite3 *db,
  7294. const char *zGeom,
  7295. int (*xGeom)(sqlite3_rtree_geometry *, int nCoord, double *aCoord, int *pRes),
  7296. void *pContext
  7297. );
  7298. /*
  7299. ** A pointer to a structure of the following type is passed as the first
  7300. ** argument to callbacks registered using rtree_geometry_callback().
  7301. */
  7302. struct sqlite3_rtree_geometry {
  7303. void *pContext; /* Copy of pContext passed to s_r_g_c() */
  7304. int nParam; /* Size of array aParam[] */
  7305. double *aParam; /* Parameters passed to SQL geom function */
  7306. void *pUser; /* Callback implementation user data */
  7307. void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */
  7308. };
  7309. #if 0
  7310. } /* end of the 'extern "C"' block */
  7311. #endif
  7312. #endif /* ifndef _SQLITE3RTREE_H_ */
  7313. /************** End of sqlite3.h *********************************************/
  7314. /************** Continuing where we left off in sqliteInt.h ******************/
  7315. /************** Include hash.h in the middle of sqliteInt.h ******************/
  7316. /************** Begin file hash.h ********************************************/
  7317. /*
  7318. ** 2001 September 22
  7319. **
  7320. ** The author disclaims copyright to this source code. In place of
  7321. ** a legal notice, here is a blessing:
  7322. **
  7323. ** May you do good and not evil.
  7324. ** May you find forgiveness for yourself and forgive others.
  7325. ** May you share freely, never taking more than you give.
  7326. **
  7327. *************************************************************************
  7328. ** This is the header file for the generic hash-table implemenation
  7329. ** used in SQLite.
  7330. */
  7331. #ifndef _SQLITE_HASH_H_
  7332. #define _SQLITE_HASH_H_
  7333. /* Forward declarations of structures. */
  7334. typedef struct Hash Hash;
  7335. typedef struct HashElem HashElem;
  7336. /* A complete hash table is an instance of the following structure.
  7337. ** The internals of this structure are intended to be opaque -- client
  7338. ** code should not attempt to access or modify the fields of this structure
  7339. ** directly. Change this structure only by using the routines below.
  7340. ** However, some of the "procedures" and "functions" for modifying and
  7341. ** accessing this structure are really macros, so we can't really make
  7342. ** this structure opaque.
  7343. **
  7344. ** All elements of the hash table are on a single doubly-linked list.
  7345. ** Hash.first points to the head of this list.
  7346. **
  7347. ** There are Hash.htsize buckets. Each bucket points to a spot in
  7348. ** the global doubly-linked list. The contents of the bucket are the
  7349. ** element pointed to plus the next _ht.count-1 elements in the list.
  7350. **
  7351. ** Hash.htsize and Hash.ht may be zero. In that case lookup is done
  7352. ** by a linear search of the global list. For small tables, the
  7353. ** Hash.ht table is never allocated because if there are few elements
  7354. ** in the table, it is faster to do a linear search than to manage
  7355. ** the hash table.
  7356. */
  7357. struct Hash {
  7358. unsigned int htsize; /* Number of buckets in the hash table */
  7359. unsigned int count; /* Number of entries in this table */
  7360. HashElem *first; /* The first element of the array */
  7361. struct _ht { /* the hash table */
  7362. int count; /* Number of entries with this hash */
  7363. HashElem *chain; /* Pointer to first entry with this hash */
  7364. } *ht;
  7365. };
  7366. /* Each element in the hash table is an instance of the following
  7367. ** structure. All elements are stored on a single doubly-linked list.
  7368. **
  7369. ** Again, this structure is intended to be opaque, but it can't really
  7370. ** be opaque because it is used by macros.
  7371. */
  7372. struct HashElem {
  7373. HashElem *next, *prev; /* Next and previous elements in the table */
  7374. void *data; /* Data associated with this element */
  7375. const char *pKey; int nKey; /* Key associated with this element */
  7376. };
  7377. /*
  7378. ** Access routines. To delete, insert a NULL pointer.
  7379. */
  7380. SQLITE_PRIVATE void sqlite3HashInit(Hash*);
  7381. SQLITE_PRIVATE void *sqlite3HashInsert(Hash*, const char *pKey, int nKey, void *pData);
  7382. SQLITE_PRIVATE void *sqlite3HashFind(const Hash*, const char *pKey, int nKey);
  7383. SQLITE_PRIVATE void sqlite3HashClear(Hash*);
  7384. /*
  7385. ** Macros for looping over all elements of a hash table. The idiom is
  7386. ** like this:
  7387. **
  7388. ** Hash h;
  7389. ** HashElem *p;
  7390. ** ...
  7391. ** for(p=sqliteHashFirst(&h); p; p=sqliteHashNext(p)){
  7392. ** SomeStructure *pData = sqliteHashData(p);
  7393. ** // do something with pData
  7394. ** }
  7395. */
  7396. #define sqliteHashFirst(H) ((H)->first)
  7397. #define sqliteHashNext(E) ((E)->next)
  7398. #define sqliteHashData(E) ((E)->data)
  7399. /* #define sqliteHashKey(E) ((E)->pKey) // NOT USED */
  7400. /* #define sqliteHashKeysize(E) ((E)->nKey) // NOT USED */
  7401. /*
  7402. ** Number of entries in a hash table
  7403. */
  7404. /* #define sqliteHashCount(H) ((H)->count) // NOT USED */
  7405. #endif /* _SQLITE_HASH_H_ */
  7406. /************** End of hash.h ************************************************/
  7407. /************** Continuing where we left off in sqliteInt.h ******************/
  7408. /************** Include parse.h in the middle of sqliteInt.h *****************/
  7409. /************** Begin file parse.h *******************************************/
  7410. #define TK_SEMI 1
  7411. #define TK_EXPLAIN 2
  7412. #define TK_QUERY 3
  7413. #define TK_PLAN 4
  7414. #define TK_BEGIN 5
  7415. #define TK_TRANSACTION 6
  7416. #define TK_DEFERRED 7
  7417. #define TK_IMMEDIATE 8
  7418. #define TK_EXCLUSIVE 9
  7419. #define TK_COMMIT 10
  7420. #define TK_END 11
  7421. #define TK_ROLLBACK 12
  7422. #define TK_SAVEPOINT 13
  7423. #define TK_RELEASE 14
  7424. #define TK_TO 15
  7425. #define TK_TABLE 16
  7426. #define TK_CREATE 17
  7427. #define TK_IF 18
  7428. #define TK_NOT 19
  7429. #define TK_EXISTS 20
  7430. #define TK_TEMP 21
  7431. #define TK_LP 22
  7432. #define TK_RP 23
  7433. #define TK_AS 24
  7434. #define TK_COMMA 25
  7435. #define TK_ID 26
  7436. #define TK_INDEXED 27
  7437. #define TK_ABORT 28
  7438. #define TK_ACTION 29
  7439. #define TK_AFTER 30
  7440. #define TK_ANALYZE 31
  7441. #define TK_ASC 32
  7442. #define TK_ATTACH 33
  7443. #define TK_BEFORE 34
  7444. #define TK_BY 35
  7445. #define TK_CASCADE 36
  7446. #define TK_CAST 37
  7447. #define TK_COLUMNKW 38
  7448. #define TK_CONFLICT 39
  7449. #define TK_DATABASE 40
  7450. #define TK_DESC 41
  7451. #define TK_DETACH 42
  7452. #define TK_EACH 43
  7453. #define TK_FAIL 44
  7454. #define TK_FOR 45
  7455. #define TK_IGNORE 46
  7456. #define TK_INITIALLY 47
  7457. #define TK_INSTEAD 48
  7458. #define TK_LIKE_KW 49
  7459. #define TK_MATCH 50
  7460. #define TK_NO 51
  7461. #define TK_KEY 52
  7462. #define TK_OF 53
  7463. #define TK_OFFSET 54
  7464. #define TK_PRAGMA 55
  7465. #define TK_RAISE 56
  7466. #define TK_REPLACE 57
  7467. #define TK_RESTRICT 58
  7468. #define TK_ROW 59
  7469. #define TK_TRIGGER 60
  7470. #define TK_VACUUM 61
  7471. #define TK_VIEW 62
  7472. #define TK_VIRTUAL 63
  7473. #define TK_REINDEX 64
  7474. #define TK_RENAME 65
  7475. #define TK_CTIME_KW 66
  7476. #define TK_ANY 67
  7477. #define TK_OR 68
  7478. #define TK_AND 69
  7479. #define TK_IS 70
  7480. #define TK_BETWEEN 71
  7481. #define TK_IN 72
  7482. #define TK_ISNULL 73
  7483. #define TK_NOTNULL 74
  7484. #define TK_NE 75
  7485. #define TK_EQ 76
  7486. #define TK_GT 77
  7487. #define TK_LE 78
  7488. #define TK_LT 79
  7489. #define TK_GE 80
  7490. #define TK_ESCAPE 81
  7491. #define TK_BITAND 82
  7492. #define TK_BITOR 83
  7493. #define TK_LSHIFT 84
  7494. #define TK_RSHIFT 85
  7495. #define TK_PLUS 86
  7496. #define TK_MINUS 87
  7497. #define TK_STAR 88
  7498. #define TK_SLASH 89
  7499. #define TK_REM 90
  7500. #define TK_CONCAT 91
  7501. #define TK_COLLATE 92
  7502. #define TK_BITNOT 93
  7503. #define TK_STRING 94
  7504. #define TK_JOIN_KW 95
  7505. #define TK_CONSTRAINT 96
  7506. #define TK_DEFAULT 97
  7507. #define TK_NULL 98
  7508. #define TK_PRIMARY 99
  7509. #define TK_UNIQUE 100
  7510. #define TK_CHECK 101
  7511. #define TK_REFERENCES 102
  7512. #define TK_AUTOINCR 103
  7513. #define TK_ON 104
  7514. #define TK_INSERT 105
  7515. #define TK_DELETE 106
  7516. #define TK_UPDATE 107
  7517. #define TK_SET 108
  7518. #define TK_DEFERRABLE 109
  7519. #define TK_FOREIGN 110
  7520. #define TK_DROP 111
  7521. #define TK_UNION 112
  7522. #define TK_ALL 113
  7523. #define TK_EXCEPT 114
  7524. #define TK_INTERSECT 115
  7525. #define TK_SELECT 116
  7526. #define TK_DISTINCT 117
  7527. #define TK_DOT 118
  7528. #define TK_FROM 119
  7529. #define TK_JOIN 120
  7530. #define TK_USING 121
  7531. #define TK_ORDER 122
  7532. #define TK_GROUP 123
  7533. #define TK_HAVING 124
  7534. #define TK_LIMIT 125
  7535. #define TK_WHERE 126
  7536. #define TK_INTO 127
  7537. #define TK_VALUES 128
  7538. #define TK_INTEGER 129
  7539. #define TK_FLOAT 130
  7540. #define TK_BLOB 131
  7541. #define TK_REGISTER 132
  7542. #define TK_VARIABLE 133
  7543. #define TK_CASE 134
  7544. #define TK_WHEN 135
  7545. #define TK_THEN 136
  7546. #define TK_ELSE 137
  7547. #define TK_INDEX 138
  7548. #define TK_ALTER 139
  7549. #define TK_ADD 140
  7550. #define TK_TO_TEXT 141
  7551. #define TK_TO_BLOB 142
  7552. #define TK_TO_NUMERIC 143
  7553. #define TK_TO_INT 144
  7554. #define TK_TO_REAL 145
  7555. #define TK_ISNOT 146
  7556. #define TK_END_OF_FILE 147
  7557. #define TK_ILLEGAL 148
  7558. #define TK_SPACE 149
  7559. #define TK_UNCLOSED_STRING 150
  7560. #define TK_FUNCTION 151
  7561. #define TK_COLUMN 152
  7562. #define TK_AGG_FUNCTION 153
  7563. #define TK_AGG_COLUMN 154
  7564. #define TK_CONST_FUNC 155
  7565. #define TK_UMINUS 156
  7566. #define TK_UPLUS 157
  7567. /************** End of parse.h ***********************************************/
  7568. /************** Continuing where we left off in sqliteInt.h ******************/
  7569. #include <stdio.h>
  7570. #include <stdlib.h>
  7571. #include <string.h>
  7572. #include <assert.h>
  7573. #include <stddef.h>
  7574. /*
  7575. ** If compiling for a processor that lacks floating point support,
  7576. ** substitute integer for floating-point
  7577. */
  7578. #ifdef SQLITE_OMIT_FLOATING_POINT
  7579. # define double sqlite_int64
  7580. # define float sqlite_int64
  7581. # define LONGDOUBLE_TYPE sqlite_int64
  7582. # ifndef SQLITE_BIG_DBL
  7583. # define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50)
  7584. # endif
  7585. # define SQLITE_OMIT_DATETIME_FUNCS 1
  7586. # define SQLITE_OMIT_TRACE 1
  7587. # undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
  7588. # undef SQLITE_HAVE_ISNAN
  7589. #endif
  7590. #ifndef SQLITE_BIG_DBL
  7591. # define SQLITE_BIG_DBL (1e99)
  7592. #endif
  7593. /*
  7594. ** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0
  7595. ** afterward. Having this macro allows us to cause the C compiler
  7596. ** to omit code used by TEMP tables without messy #ifndef statements.
  7597. */
  7598. #ifdef SQLITE_OMIT_TEMPDB
  7599. #define OMIT_TEMPDB 1
  7600. #else
  7601. #define OMIT_TEMPDB 0
  7602. #endif
  7603. /*
  7604. ** The "file format" number is an integer that is incremented whenever
  7605. ** the VDBE-level file format changes. The following macros define the
  7606. ** the default file format for new databases and the maximum file format
  7607. ** that the library can read.
  7608. */
  7609. #define SQLITE_MAX_FILE_FORMAT 4
  7610. #ifndef SQLITE_DEFAULT_FILE_FORMAT
  7611. # define SQLITE_DEFAULT_FILE_FORMAT 4
  7612. #endif
  7613. /*
  7614. ** Determine whether triggers are recursive by default. This can be
  7615. ** changed at run-time using a pragma.
  7616. */
  7617. #ifndef SQLITE_DEFAULT_RECURSIVE_TRIGGERS
  7618. # define SQLITE_DEFAULT_RECURSIVE_TRIGGERS 0
  7619. #endif
  7620. /*
  7621. ** Provide a default value for SQLITE_TEMP_STORE in case it is not specified
  7622. ** on the command-line
  7623. */
  7624. #ifndef SQLITE_TEMP_STORE
  7625. # define SQLITE_TEMP_STORE 1
  7626. #endif
  7627. /*
  7628. ** GCC does not define the offsetof() macro so we'll have to do it
  7629. ** ourselves.
  7630. */
  7631. #ifndef offsetof
  7632. #define offsetof(STRUCTURE,FIELD) ((int)((char*)&((STRUCTURE*)0)->FIELD))
  7633. #endif
  7634. /*
  7635. ** Check to see if this machine uses EBCDIC. (Yes, believe it or
  7636. ** not, there are still machines out there that use EBCDIC.)
  7637. */
  7638. #if 'A' == '\301'
  7639. # define SQLITE_EBCDIC 1
  7640. #else
  7641. # define SQLITE_ASCII 1
  7642. #endif
  7643. /*
  7644. ** Integers of known sizes. These typedefs might change for architectures
  7645. ** where the sizes very. Preprocessor macros are available so that the
  7646. ** types can be conveniently redefined at compile-type. Like this:
  7647. **
  7648. ** cc '-DUINTPTR_TYPE=long long int' ...
  7649. */
  7650. #ifndef UINT32_TYPE
  7651. # ifdef HAVE_UINT32_T
  7652. # define UINT32_TYPE uint32_t
  7653. # else
  7654. # define UINT32_TYPE unsigned int
  7655. # endif
  7656. #endif
  7657. #ifndef UINT16_TYPE
  7658. # ifdef HAVE_UINT16_T
  7659. # define UINT16_TYPE uint16_t
  7660. # else
  7661. # define UINT16_TYPE unsigned short int
  7662. # endif
  7663. #endif
  7664. #ifndef INT16_TYPE
  7665. # ifdef HAVE_INT16_T
  7666. # define INT16_TYPE int16_t
  7667. # else
  7668. # define INT16_TYPE short int
  7669. # endif
  7670. #endif
  7671. #ifndef UINT8_TYPE
  7672. # ifdef HAVE_UINT8_T
  7673. # define UINT8_TYPE uint8_t
  7674. # else
  7675. # define UINT8_TYPE unsigned char
  7676. # endif
  7677. #endif
  7678. #ifndef INT8_TYPE
  7679. # ifdef HAVE_INT8_T
  7680. # define INT8_TYPE int8_t
  7681. # else
  7682. # define INT8_TYPE signed char
  7683. # endif
  7684. #endif
  7685. #ifndef LONGDOUBLE_TYPE
  7686. # define LONGDOUBLE_TYPE long double
  7687. #endif
  7688. typedef sqlite_int64 i64; /* 8-byte signed integer */
  7689. typedef sqlite_uint64 u64; /* 8-byte unsigned integer */
  7690. typedef UINT32_TYPE u32; /* 4-byte unsigned integer */
  7691. typedef UINT16_TYPE u16; /* 2-byte unsigned integer */
  7692. typedef INT16_TYPE i16; /* 2-byte signed integer */
  7693. typedef UINT8_TYPE u8; /* 1-byte unsigned integer */
  7694. typedef INT8_TYPE i8; /* 1-byte signed integer */
  7695. /*
  7696. ** SQLITE_MAX_U32 is a u64 constant that is the maximum u64 value
  7697. ** that can be stored in a u32 without loss of data. The value
  7698. ** is 0x00000000ffffffff. But because of quirks of some compilers, we
  7699. ** have to specify the value in the less intuitive manner shown:
  7700. */
  7701. #define SQLITE_MAX_U32 ((((u64)1)<<32)-1)
  7702. /*
  7703. ** The datatype used to store estimates of the number of rows in a
  7704. ** table or index. This is an unsigned integer type. For 99.9% of
  7705. ** the world, a 32-bit integer is sufficient. But a 64-bit integer
  7706. ** can be used at compile-time if desired.
  7707. */
  7708. #ifdef SQLITE_64BIT_STATS
  7709. typedef u64 tRowcnt; /* 64-bit only if requested at compile-time */
  7710. #else
  7711. typedef u32 tRowcnt; /* 32-bit is the default */
  7712. #endif
  7713. /*
  7714. ** Macros to determine whether the machine is big or little endian,
  7715. ** evaluated at runtime.
  7716. */
  7717. #ifdef SQLITE_AMALGAMATION
  7718. SQLITE_PRIVATE const int sqlite3one = 1;
  7719. #else
  7720. SQLITE_PRIVATE const int sqlite3one;
  7721. #endif
  7722. #if defined(i386) || defined(__i386__) || defined(_M_IX86)\
  7723. || defined(__x86_64) || defined(__x86_64__)
  7724. # define SQLITE_BIGENDIAN 0
  7725. # define SQLITE_LITTLEENDIAN 1
  7726. # define SQLITE_UTF16NATIVE SQLITE_UTF16LE
  7727. #else
  7728. # define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0)
  7729. # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
  7730. # define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)
  7731. #endif
  7732. /*
  7733. ** Constants for the largest and smallest possible 64-bit signed integers.
  7734. ** These macros are designed to work correctly on both 32-bit and 64-bit
  7735. ** compilers.
  7736. */
  7737. #define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
  7738. #define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
  7739. /*
  7740. ** Round up a number to the next larger multiple of 8. This is used
  7741. ** to force 8-byte alignment on 64-bit architectures.
  7742. */
  7743. #define ROUND8(x) (((x)+7)&~7)
  7744. /*
  7745. ** Round down to the nearest multiple of 8
  7746. */
  7747. #define ROUNDDOWN8(x) ((x)&~7)
  7748. /*
  7749. ** Assert that the pointer X is aligned to an 8-byte boundary. This
  7750. ** macro is used only within assert() to verify that the code gets
  7751. ** all alignment restrictions correct.
  7752. **
  7753. ** Except, if SQLITE_4_BYTE_ALIGNED_MALLOC is defined, then the
  7754. ** underlying malloc() implemention might return us 4-byte aligned
  7755. ** pointers. In that case, only verify 4-byte alignment.
  7756. */
  7757. #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
  7758. # define EIGHT_BYTE_ALIGNMENT(X) ((((char*)(X) - (char*)0)&3)==0)
  7759. #else
  7760. # define EIGHT_BYTE_ALIGNMENT(X) ((((char*)(X) - (char*)0)&7)==0)
  7761. #endif
  7762. /*
  7763. ** An instance of the following structure is used to store the busy-handler
  7764. ** callback for a given sqlite handle.
  7765. **
  7766. ** The sqlite.busyHandler member of the sqlite struct contains the busy
  7767. ** callback for the database handle. Each pager opened via the sqlite
  7768. ** handle is passed a pointer to sqlite.busyHandler. The busy-handler
  7769. ** callback is currently invoked only from within pager.c.
  7770. */
  7771. typedef struct BusyHandler BusyHandler;
  7772. struct BusyHandler {
  7773. int (*xFunc)(void *,int); /* The busy callback */
  7774. void *pArg; /* First arg to busy callback */
  7775. int nBusy; /* Incremented with each busy call */
  7776. };
  7777. /*
  7778. ** Name of the master database table. The master database table
  7779. ** is a special table that holds the names and attributes of all
  7780. ** user tables and indices.
  7781. */
  7782. #define MASTER_NAME "sqlite_master"
  7783. #define TEMP_MASTER_NAME "sqlite_temp_master"
  7784. /*
  7785. ** The root-page of the master database table.
  7786. */
  7787. #define MASTER_ROOT 1
  7788. /*
  7789. ** The name of the schema table.
  7790. */
  7791. #define SCHEMA_TABLE(x) ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME)
  7792. /*
  7793. ** A convenience macro that returns the number of elements in
  7794. ** an array.
  7795. */
  7796. #define ArraySize(X) ((int)(sizeof(X)/sizeof(X[0])))
  7797. /*
  7798. ** The following value as a destructor means to use sqlite3DbFree().
  7799. ** The sqlite3DbFree() routine requires two parameters instead of the
  7800. ** one parameter that destructors normally want. So we have to introduce
  7801. ** this magic value that the code knows to handle differently. Any
  7802. ** pointer will work here as long as it is distinct from SQLITE_STATIC
  7803. ** and SQLITE_TRANSIENT.
  7804. */
  7805. #define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3MallocSize)
  7806. /*
  7807. ** When SQLITE_OMIT_WSD is defined, it means that the target platform does
  7808. ** not support Writable Static Data (WSD) such as global and static variables.
  7809. ** All variables must either be on the stack or dynamically allocated from
  7810. ** the heap. When WSD is unsupported, the variable declarations scattered
  7811. ** throughout the SQLite code must become constants instead. The SQLITE_WSD
  7812. ** macro is used for this purpose. And instead of referencing the variable
  7813. ** directly, we use its constant as a key to lookup the run-time allocated
  7814. ** buffer that holds real variable. The constant is also the initializer
  7815. ** for the run-time allocated buffer.
  7816. **
  7817. ** In the usual case where WSD is supported, the SQLITE_WSD and GLOBAL
  7818. ** macros become no-ops and have zero performance impact.
  7819. */
  7820. #ifdef SQLITE_OMIT_WSD
  7821. #define SQLITE_WSD const
  7822. #define GLOBAL(t,v) (*(t*)sqlite3_wsd_find((void*)&(v), sizeof(v)))
  7823. #define sqlite3GlobalConfig GLOBAL(struct Sqlite3Config, sqlite3Config)
  7824. SQLITE_API int sqlite3_wsd_init(int N, int J);
  7825. SQLITE_API void *sqlite3_wsd_find(void *K, int L);
  7826. #else
  7827. #define SQLITE_WSD
  7828. #define GLOBAL(t,v) v
  7829. #define sqlite3GlobalConfig sqlite3Config
  7830. #endif
  7831. /*
  7832. ** The following macros are used to suppress compiler warnings and to
  7833. ** make it clear to human readers when a function parameter is deliberately
  7834. ** left unused within the body of a function. This usually happens when
  7835. ** a function is called via a function pointer. For example the
  7836. ** implementation of an SQL aggregate step callback may not use the
  7837. ** parameter indicating the number of arguments passed to the aggregate,
  7838. ** if it knows that this is enforced elsewhere.
  7839. **
  7840. ** When a function parameter is not used at all within the body of a function,
  7841. ** it is generally named "NotUsed" or "NotUsed2" to make things even clearer.
  7842. ** However, these macros may also be used to suppress warnings related to
  7843. ** parameters that may or may not be used depending on compilation options.
  7844. ** For example those parameters only used in assert() statements. In these
  7845. ** cases the parameters are named as per the usual conventions.
  7846. */
  7847. #define UNUSED_PARAMETER(x) (void)(x)
  7848. #define UNUSED_PARAMETER2(x,y) UNUSED_PARAMETER(x),UNUSED_PARAMETER(y)
  7849. /*
  7850. ** Forward references to structures
  7851. */
  7852. typedef struct AggInfo AggInfo;
  7853. typedef struct AuthContext AuthContext;
  7854. typedef struct AutoincInfo AutoincInfo;
  7855. typedef struct Bitvec Bitvec;
  7856. typedef struct CollSeq CollSeq;
  7857. typedef struct Column Column;
  7858. typedef struct Db Db;
  7859. typedef struct Schema Schema;
  7860. typedef struct Expr Expr;
  7861. typedef struct ExprList ExprList;
  7862. typedef struct ExprSpan ExprSpan;
  7863. typedef struct FKey FKey;
  7864. typedef struct FuncDestructor FuncDestructor;
  7865. typedef struct FuncDef FuncDef;
  7866. typedef struct FuncDefHash FuncDefHash;
  7867. typedef struct IdList IdList;
  7868. typedef struct Index Index;
  7869. typedef struct IndexSample IndexSample;
  7870. typedef struct KeyClass KeyClass;
  7871. typedef struct KeyInfo KeyInfo;
  7872. typedef struct Lookaside Lookaside;
  7873. typedef struct LookasideSlot LookasideSlot;
  7874. typedef struct Module Module;
  7875. typedef struct NameContext NameContext;
  7876. typedef struct Parse Parse;
  7877. typedef struct RowSet RowSet;
  7878. typedef struct Savepoint Savepoint;
  7879. typedef struct Select Select;
  7880. typedef struct SrcList SrcList;
  7881. typedef struct StrAccum StrAccum;
  7882. typedef struct Table Table;
  7883. typedef struct TableLock TableLock;
  7884. typedef struct Token Token;
  7885. typedef struct Trigger Trigger;
  7886. typedef struct TriggerPrg TriggerPrg;
  7887. typedef struct TriggerStep TriggerStep;
  7888. typedef struct UnpackedRecord UnpackedRecord;
  7889. typedef struct VTable VTable;
  7890. typedef struct VtabCtx VtabCtx;
  7891. typedef struct Walker Walker;
  7892. typedef struct WherePlan WherePlan;
  7893. typedef struct WhereInfo WhereInfo;
  7894. typedef struct WhereLevel WhereLevel;
  7895. /*
  7896. ** Defer sourcing vdbe.h and btree.h until after the "u8" and
  7897. ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque
  7898. ** pointer types (i.e. FuncDef) defined above.
  7899. */
  7900. /************** Include btree.h in the middle of sqliteInt.h *****************/
  7901. /************** Begin file btree.h *******************************************/
  7902. /*
  7903. ** 2001 September 15
  7904. **
  7905. ** The author disclaims copyright to this source code. In place of
  7906. ** a legal notice, here is a blessing:
  7907. **
  7908. ** May you do good and not evil.
  7909. ** May you find forgiveness for yourself and forgive others.
  7910. ** May you share freely, never taking more than you give.
  7911. **
  7912. *************************************************************************
  7913. ** This header file defines the interface that the sqlite B-Tree file
  7914. ** subsystem. See comments in the source code for a detailed description
  7915. ** of what each interface routine does.
  7916. */
  7917. #ifndef _BTREE_H_
  7918. #define _BTREE_H_
  7919. /* TODO: This definition is just included so other modules compile. It
  7920. ** needs to be revisited.
  7921. */
  7922. #define SQLITE_N_BTREE_META 10
  7923. /*
  7924. ** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
  7925. ** it must be turned on for each database using "PRAGMA auto_vacuum = 1".
  7926. */
  7927. #ifndef SQLITE_DEFAULT_AUTOVACUUM
  7928. #define SQLITE_DEFAULT_AUTOVACUUM 0
  7929. #endif
  7930. #define BTREE_AUTOVACUUM_NONE 0 /* Do not do auto-vacuum */
  7931. #define BTREE_AUTOVACUUM_FULL 1 /* Do full auto-vacuum */
  7932. #define BTREE_AUTOVACUUM_INCR 2 /* Incremental vacuum */
  7933. /*
  7934. ** Forward declarations of structure
  7935. */
  7936. typedef struct Btree Btree;
  7937. typedef struct BtCursor BtCursor;
  7938. typedef struct BtShared BtShared;
  7939. SQLITE_PRIVATE int sqlite3BtreeOpen(
  7940. sqlite3_vfs *pVfs, /* VFS to use with this b-tree */
  7941. const char *zFilename, /* Name of database file to open */
  7942. sqlite3 *db, /* Associated database connection */
  7943. Btree **ppBtree, /* Return open Btree* here */
  7944. int flags, /* Flags */
  7945. int vfsFlags /* Flags passed through to VFS open */
  7946. );
  7947. /* The flags parameter to sqlite3BtreeOpen can be the bitwise or of the
  7948. ** following values.
  7949. **
  7950. ** NOTE: These values must match the corresponding PAGER_ values in
  7951. ** pager.h.
  7952. */
  7953. #define BTREE_OMIT_JOURNAL 1 /* Do not create or use a rollback journal */
  7954. #define BTREE_MEMORY 2 /* This is an in-memory DB */
  7955. #define BTREE_SINGLE 4 /* The file contains at most 1 b-tree */
  7956. #define BTREE_UNORDERED 8 /* Use of a hash implementation is OK */
  7957. SQLITE_PRIVATE int sqlite3BtreeClose(Btree*);
  7958. SQLITE_PRIVATE int sqlite3BtreeSetCacheSize(Btree*,int);
  7959. SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel(Btree*,int,int,int);
  7960. SQLITE_PRIVATE int sqlite3BtreeSyncDisabled(Btree*);
  7961. SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
  7962. SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*);
  7963. SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree*,int);
  7964. SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree*);
  7965. SQLITE_PRIVATE int sqlite3BtreeSecureDelete(Btree*,int);
  7966. SQLITE_PRIVATE int sqlite3BtreeGetReserve(Btree*);
  7967. SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int);
  7968. SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
  7969. SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int);
  7970. SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);
  7971. SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int);
  7972. SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*);
  7973. SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*,int);
  7974. SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int);
  7975. SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, int*, int flags);
  7976. SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree*);
  7977. SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree*);
  7978. SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree*);
  7979. SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
  7980. SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *pBtree);
  7981. SQLITE_PRIVATE int sqlite3BtreeLockTable(Btree *pBtree, int iTab, u8 isWriteLock);
  7982. SQLITE_PRIVATE int sqlite3BtreeSavepoint(Btree *, int, int);
  7983. SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *);
  7984. SQLITE_PRIVATE const char *sqlite3BtreeGetJournalname(Btree *);
  7985. SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *, Btree *);
  7986. SQLITE_PRIVATE int sqlite3BtreeIncrVacuum(Btree *);
  7987. /* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR
  7988. ** of the flags shown below.
  7989. **
  7990. ** Every SQLite table must have either BTREE_INTKEY or BTREE_BLOBKEY set.
  7991. ** With BTREE_INTKEY, the table key is a 64-bit integer and arbitrary data
  7992. ** is stored in the leaves. (BTREE_INTKEY is used for SQL tables.) With
  7993. ** BTREE_BLOBKEY, the key is an arbitrary BLOB and no content is stored
  7994. ** anywhere - the key is the content. (BTREE_BLOBKEY is used for SQL
  7995. ** indices.)
  7996. */
  7997. #define BTREE_INTKEY 1 /* Table has only 64-bit signed integer keys */
  7998. #define BTREE_BLOBKEY 2 /* Table has keys only - no data */
  7999. SQLITE_PRIVATE int sqlite3BtreeDropTable(Btree*, int, int*);
  8000. SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree*, int, int*);
  8001. SQLITE_PRIVATE void sqlite3BtreeTripAllCursors(Btree*, int);
  8002. SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *pBtree, int idx, u32 *pValue);
  8003. SQLITE_PRIVATE int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
  8004. /*
  8005. ** The second parameter to sqlite3BtreeGetMeta or sqlite3BtreeUpdateMeta
  8006. ** should be one of the following values. The integer values are assigned
  8007. ** to constants so that the offset of the corresponding field in an
  8008. ** SQLite database header may be found using the following formula:
  8009. **
  8010. ** offset = 36 + (idx * 4)
  8011. **
  8012. ** For example, the free-page-count field is located at byte offset 36 of
  8013. ** the database file header. The incr-vacuum-flag field is located at
  8014. ** byte offset 64 (== 36+4*7).
  8015. */
  8016. #define BTREE_FREE_PAGE_COUNT 0
  8017. #define BTREE_SCHEMA_VERSION 1
  8018. #define BTREE_FILE_FORMAT 2
  8019. #define BTREE_DEFAULT_CACHE_SIZE 3
  8020. #define BTREE_LARGEST_ROOT_PAGE 4
  8021. #define BTREE_TEXT_ENCODING 5
  8022. #define BTREE_USER_VERSION 6
  8023. #define BTREE_INCR_VACUUM 7
  8024. SQLITE_PRIVATE int sqlite3BtreeCursor(
  8025. Btree*, /* BTree containing table to open */
  8026. int iTable, /* Index of root page */
  8027. int wrFlag, /* 1 for writing. 0 for read-only */
  8028. struct KeyInfo*, /* First argument to compare function */
  8029. BtCursor *pCursor /* Space to write cursor structure */
  8030. );
  8031. SQLITE_PRIVATE int sqlite3BtreeCursorSize(void);
  8032. SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor*);
  8033. SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor*);
  8034. SQLITE_PRIVATE int sqlite3BtreeMovetoUnpacked(
  8035. BtCursor*,
  8036. UnpackedRecord *pUnKey,
  8037. i64 intKey,
  8038. int bias,
  8039. int *pRes
  8040. );
  8041. SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor*, int*);
  8042. SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*);
  8043. SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey,
  8044. const void *pData, int nData,
  8045. int nZero, int bias, int seekResult);
  8046. SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes);
  8047. SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
  8048. SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
  8049. SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
  8050. SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
  8051. SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
  8052. SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
  8053. SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, int *pAmt);
  8054. SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, int *pAmt);
  8055. SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
  8056. SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
  8057. SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor*, sqlite3_int64);
  8058. SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor*);
  8059. SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
  8060. SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
  8061. SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
  8062. SQLITE_PRIVATE void sqlite3BtreeCacheOverflow(BtCursor *);
  8063. SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *);
  8064. SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
  8065. #ifndef NDEBUG
  8066. SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*);
  8067. #endif
  8068. #ifndef SQLITE_OMIT_BTREECOUNT
  8069. SQLITE_PRIVATE int sqlite3BtreeCount(BtCursor *, i64 *);
  8070. #endif
  8071. #ifdef SQLITE_TEST
  8072. SQLITE_PRIVATE int sqlite3BtreeCursorInfo(BtCursor*, int*, int);
  8073. SQLITE_PRIVATE void sqlite3BtreeCursorList(Btree*);
  8074. #endif
  8075. #ifndef SQLITE_OMIT_WAL
  8076. SQLITE_PRIVATE int sqlite3BtreeCheckpoint(Btree*, int, int *, int *);
  8077. #endif
  8078. /*
  8079. ** If we are not using shared cache, then there is no need to
  8080. ** use mutexes to access the BtShared structures. So make the
  8081. ** Enter and Leave procedures no-ops.
  8082. */
  8083. #ifndef SQLITE_OMIT_SHARED_CACHE
  8084. SQLITE_PRIVATE void sqlite3BtreeEnter(Btree*);
  8085. SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3*);
  8086. #else
  8087. # define sqlite3BtreeEnter(X)
  8088. # define sqlite3BtreeEnterAll(X)
  8089. #endif
  8090. #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE
  8091. SQLITE_PRIVATE int sqlite3BtreeSharable(Btree*);
  8092. SQLITE_PRIVATE void sqlite3BtreeLeave(Btree*);
  8093. SQLITE_PRIVATE void sqlite3BtreeEnterCursor(BtCursor*);
  8094. SQLITE_PRIVATE void sqlite3BtreeLeaveCursor(BtCursor*);
  8095. SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3*);
  8096. #ifndef NDEBUG
  8097. /* These routines are used inside assert() statements only. */
  8098. SQLITE_PRIVATE int sqlite3BtreeHoldsMutex(Btree*);
  8099. SQLITE_PRIVATE int sqlite3BtreeHoldsAllMutexes(sqlite3*);
  8100. SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3*,int,Schema*);
  8101. #endif
  8102. #else
  8103. # define sqlite3BtreeSharable(X) 0
  8104. # define sqlite3BtreeLeave(X)
  8105. # define sqlite3BtreeEnterCursor(X)
  8106. # define sqlite3BtreeLeaveCursor(X)
  8107. # define sqlite3BtreeLeaveAll(X)
  8108. # define sqlite3BtreeHoldsMutex(X) 1
  8109. # define sqlite3BtreeHoldsAllMutexes(X) 1
  8110. # define sqlite3SchemaMutexHeld(X,Y,Z) 1
  8111. #endif
  8112. #endif /* _BTREE_H_ */
  8113. /************** End of btree.h ***********************************************/
  8114. /************** Continuing where we left off in sqliteInt.h ******************/
  8115. /************** Include vdbe.h in the middle of sqliteInt.h ******************/
  8116. /************** Begin file vdbe.h ********************************************/
  8117. /*
  8118. ** 2001 September 15
  8119. **
  8120. ** The author disclaims copyright to this source code. In place of
  8121. ** a legal notice, here is a blessing:
  8122. **
  8123. ** May you do good and not evil.
  8124. ** May you find forgiveness for yourself and forgive others.
  8125. ** May you share freely, never taking more than you give.
  8126. **
  8127. *************************************************************************
  8128. ** Header file for the Virtual DataBase Engine (VDBE)
  8129. **
  8130. ** This header defines the interface to the virtual database engine
  8131. ** or VDBE. The VDBE implements an abstract machine that runs a
  8132. ** simple program to access and modify the underlying database.
  8133. */
  8134. #ifndef _SQLITE_VDBE_H_
  8135. #define _SQLITE_VDBE_H_
  8136. /* #include <stdio.h> */
  8137. /*
  8138. ** A single VDBE is an opaque structure named "Vdbe". Only routines
  8139. ** in the source file sqliteVdbe.c are allowed to see the insides
  8140. ** of this structure.
  8141. */
  8142. typedef struct Vdbe Vdbe;
  8143. /*
  8144. ** The names of the following types declared in vdbeInt.h are required
  8145. ** for the VdbeOp definition.
  8146. */
  8147. typedef struct VdbeFunc VdbeFunc;
  8148. typedef struct Mem Mem;
  8149. typedef struct SubProgram SubProgram;
  8150. /*
  8151. ** A single instruction of the virtual machine has an opcode
  8152. ** and as many as three operands. The instruction is recorded
  8153. ** as an instance of the following structure:
  8154. */
  8155. struct VdbeOp {
  8156. u8 opcode; /* What operation to perform */
  8157. signed char p4type; /* One of the P4_xxx constants for p4 */
  8158. u8 opflags; /* Mask of the OPFLG_* flags in opcodes.h */
  8159. u8 p5; /* Fifth parameter is an unsigned character */
  8160. int p1; /* First operand */
  8161. int p2; /* Second parameter (often the jump destination) */
  8162. int p3; /* The third parameter */
  8163. union { /* fourth parameter */
  8164. int i; /* Integer value if p4type==P4_INT32 */
  8165. void *p; /* Generic pointer */
  8166. char *z; /* Pointer to data for string (char array) types */
  8167. i64 *pI64; /* Used when p4type is P4_INT64 */
  8168. double *pReal; /* Used when p4type is P4_REAL */
  8169. FuncDef *pFunc; /* Used when p4type is P4_FUNCDEF */
  8170. VdbeFunc *pVdbeFunc; /* Used when p4type is P4_VDBEFUNC */
  8171. CollSeq *pColl; /* Used when p4type is P4_COLLSEQ */
  8172. Mem *pMem; /* Used when p4type is P4_MEM */
  8173. VTable *pVtab; /* Used when p4type is P4_VTAB */
  8174. KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */
  8175. int *ai; /* Used when p4type is P4_INTARRAY */
  8176. SubProgram *pProgram; /* Used when p4type is P4_SUBPROGRAM */
  8177. int (*xAdvance)(BtCursor *, int *);
  8178. } p4;
  8179. #ifdef SQLITE_DEBUG
  8180. char *zComment; /* Comment to improve readability */
  8181. #endif
  8182. #ifdef VDBE_PROFILE
  8183. int cnt; /* Number of times this instruction was executed */
  8184. u64 cycles; /* Total time spent executing this instruction */
  8185. #endif
  8186. };
  8187. typedef struct VdbeOp VdbeOp;
  8188. /*
  8189. ** A sub-routine used to implement a trigger program.
  8190. */
  8191. struct SubProgram {
  8192. VdbeOp *aOp; /* Array of opcodes for sub-program */
  8193. int nOp; /* Elements in aOp[] */
  8194. int nMem; /* Number of memory cells required */
  8195. int nCsr; /* Number of cursors required */
  8196. int nOnce; /* Number of OP_Once instructions */
  8197. void *token; /* id that may be used to recursive triggers */
  8198. SubProgram *pNext; /* Next sub-program already visited */
  8199. };
  8200. /*
  8201. ** A smaller version of VdbeOp used for the VdbeAddOpList() function because
  8202. ** it takes up less space.
  8203. */
  8204. struct VdbeOpList {
  8205. u8 opcode; /* What operation to perform */
  8206. signed char p1; /* First operand */
  8207. signed char p2; /* Second parameter (often the jump destination) */
  8208. signed char p3; /* Third parameter */
  8209. };
  8210. typedef struct VdbeOpList VdbeOpList;
  8211. /*
  8212. ** Allowed values of VdbeOp.p4type
  8213. */
  8214. #define P4_NOTUSED 0 /* The P4 parameter is not used */
  8215. #define P4_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */
  8216. #define P4_STATIC (-2) /* Pointer to a static string */
  8217. #define P4_COLLSEQ (-4) /* P4 is a pointer to a CollSeq structure */
  8218. #define P4_FUNCDEF (-5) /* P4 is a pointer to a FuncDef structure */
  8219. #define P4_KEYINFO (-6) /* P4 is a pointer to a KeyInfo structure */
  8220. #define P4_VDBEFUNC (-7) /* P4 is a pointer to a VdbeFunc structure */
  8221. #define P4_MEM (-8) /* P4 is a pointer to a Mem* structure */
  8222. #define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */
  8223. #define P4_VTAB (-10) /* P4 is a pointer to an sqlite3_vtab structure */
  8224. #define P4_MPRINTF (-11) /* P4 is a string obtained from sqlite3_mprintf() */
  8225. #define P4_REAL (-12) /* P4 is a 64-bit floating point value */
  8226. #define P4_INT64 (-13) /* P4 is a 64-bit signed integer */
  8227. #define P4_INT32 (-14) /* P4 is a 32-bit signed integer */
  8228. #define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */
  8229. #define P4_SUBPROGRAM (-18) /* P4 is a pointer to a SubProgram structure */
  8230. #define P4_ADVANCE (-19) /* P4 is a pointer to BtreeNext() or BtreePrev() */
  8231. /* When adding a P4 argument using P4_KEYINFO, a copy of the KeyInfo structure
  8232. ** is made. That copy is freed when the Vdbe is finalized. But if the
  8233. ** argument is P4_KEYINFO_HANDOFF, the passed in pointer is used. It still
  8234. ** gets freed when the Vdbe is finalized so it still should be obtained
  8235. ** from a single sqliteMalloc(). But no copy is made and the calling
  8236. ** function should *not* try to free the KeyInfo.
  8237. */
  8238. #define P4_KEYINFO_HANDOFF (-16)
  8239. #define P4_KEYINFO_STATIC (-17)
  8240. /*
  8241. ** The Vdbe.aColName array contains 5n Mem structures, where n is the
  8242. ** number of columns of data returned by the statement.
  8243. */
  8244. #define COLNAME_NAME 0
  8245. #define COLNAME_DECLTYPE 1
  8246. #define COLNAME_DATABASE 2
  8247. #define COLNAME_TABLE 3
  8248. #define COLNAME_COLUMN 4
  8249. #ifdef SQLITE_ENABLE_COLUMN_METADATA
  8250. # define COLNAME_N 5 /* Number of COLNAME_xxx symbols */
  8251. #else
  8252. # ifdef SQLITE_OMIT_DECLTYPE
  8253. # define COLNAME_N 1 /* Store only the name */
  8254. # else
  8255. # define COLNAME_N 2 /* Store the name and decltype */
  8256. # endif
  8257. #endif
  8258. /*
  8259. ** The following macro converts a relative address in the p2 field
  8260. ** of a VdbeOp structure into a negative number so that
  8261. ** sqlite3VdbeAddOpList() knows that the address is relative. Calling
  8262. ** the macro again restores the address.
  8263. */
  8264. #define ADDR(X) (-1-(X))
  8265. /*
  8266. ** The makefile scans the vdbe.c source file and creates the "opcodes.h"
  8267. ** header file that defines a number for each opcode used by the VDBE.
  8268. */
  8269. /************** Include opcodes.h in the middle of vdbe.h ********************/
  8270. /************** Begin file opcodes.h *****************************************/
  8271. /* Automatically generated. Do not edit */
  8272. /* See the mkopcodeh.awk script for details */
  8273. #define OP_Goto 1
  8274. #define OP_Gosub 2
  8275. #define OP_Return 3
  8276. #define OP_Yield 4
  8277. #define OP_HaltIfNull 5
  8278. #define OP_Halt 6
  8279. #define OP_Integer 7
  8280. #define OP_Int64 8
  8281. #define OP_Real 130 /* same as TK_FLOAT */
  8282. #define OP_String8 94 /* same as TK_STRING */
  8283. #define OP_String 9
  8284. #define OP_Null 10
  8285. #define OP_Blob 11
  8286. #define OP_Variable 12
  8287. #define OP_Move 13
  8288. #define OP_Copy 14
  8289. #define OP_SCopy 15
  8290. #define OP_ResultRow 16
  8291. #define OP_Concat 91 /* same as TK_CONCAT */
  8292. #define OP_Add 86 /* same as TK_PLUS */
  8293. #define OP_Subtract 87 /* same as TK_MINUS */
  8294. #define OP_Multiply 88 /* same as TK_STAR */
  8295. #define OP_Divide 89 /* same as TK_SLASH */
  8296. #define OP_Remainder 90 /* same as TK_REM */
  8297. #define OP_CollSeq 17
  8298. #define OP_Function 18
  8299. #define OP_BitAnd 82 /* same as TK_BITAND */
  8300. #define OP_BitOr 83 /* same as TK_BITOR */
  8301. #define OP_ShiftLeft 84 /* same as TK_LSHIFT */
  8302. #define OP_ShiftRight 85 /* same as TK_RSHIFT */
  8303. #define OP_AddImm 20
  8304. #define OP_MustBeInt 21
  8305. #define OP_RealAffinity 22
  8306. #define OP_ToText 141 /* same as TK_TO_TEXT */
  8307. #define OP_ToBlob 142 /* same as TK_TO_BLOB */
  8308. #define OP_ToNumeric 143 /* same as TK_TO_NUMERIC*/
  8309. #define OP_ToInt 144 /* same as TK_TO_INT */
  8310. #define OP_ToReal 145 /* same as TK_TO_REAL */
  8311. #define OP_Eq 76 /* same as TK_EQ */
  8312. #define OP_Ne 75 /* same as TK_NE */
  8313. #define OP_Lt 79 /* same as TK_LT */
  8314. #define OP_Le 78 /* same as TK_LE */
  8315. #define OP_Gt 77 /* same as TK_GT */
  8316. #define OP_Ge 80 /* same as TK_GE */
  8317. #define OP_Permutation 23
  8318. #define OP_Compare 24
  8319. #define OP_Jump 25
  8320. #define OP_And 69 /* same as TK_AND */
  8321. #define OP_Or 68 /* same as TK_OR */
  8322. #define OP_Not 19 /* same as TK_NOT */
  8323. #define OP_BitNot 93 /* same as TK_BITNOT */
  8324. #define OP_Once 26
  8325. #define OP_If 27
  8326. #define OP_IfNot 28
  8327. #define OP_IsNull 73 /* same as TK_ISNULL */
  8328. #define OP_NotNull 74 /* same as TK_NOTNULL */
  8329. #define OP_Column 29
  8330. #define OP_Affinity 30
  8331. #define OP_MakeRecord 31
  8332. #define OP_Count 32
  8333. #define OP_Savepoint 33
  8334. #define OP_AutoCommit 34
  8335. #define OP_Transaction 35
  8336. #define OP_ReadCookie 36
  8337. #define OP_SetCookie 37
  8338. #define OP_VerifyCookie 38
  8339. #define OP_OpenRead 39
  8340. #define OP_OpenWrite 40
  8341. #define OP_OpenAutoindex 41
  8342. #define OP_OpenEphemeral 42
  8343. #define OP_SorterOpen 43
  8344. #define OP_OpenPseudo 44
  8345. #define OP_Close 45
  8346. #define OP_SeekLt 46
  8347. #define OP_SeekLe 47
  8348. #define OP_SeekGe 48
  8349. #define OP_SeekGt 49
  8350. #define OP_Seek 50
  8351. #define OP_NotFound 51
  8352. #define OP_Found 52
  8353. #define OP_IsUnique 53
  8354. #define OP_NotExists 54
  8355. #define OP_Sequence 55
  8356. #define OP_NewRowid 56
  8357. #define OP_Insert 57
  8358. #define OP_InsertInt 58
  8359. #define OP_Delete 59
  8360. #define OP_ResetCount 60
  8361. #define OP_SorterCompare 61
  8362. #define OP_SorterData 62
  8363. #define OP_RowKey 63
  8364. #define OP_RowData 64
  8365. #define OP_Rowid 65
  8366. #define OP_NullRow 66
  8367. #define OP_Last 67
  8368. #define OP_SorterSort 70
  8369. #define OP_Sort 71
  8370. #define OP_Rewind 72
  8371. #define OP_SorterNext 81
  8372. #define OP_Prev 92
  8373. #define OP_Next 95
  8374. #define OP_SorterInsert 96
  8375. #define OP_IdxInsert 97
  8376. #define OP_IdxDelete 98
  8377. #define OP_IdxRowid 99
  8378. #define OP_IdxLT 100
  8379. #define OP_IdxGE 101
  8380. #define OP_Destroy 102
  8381. #define OP_Clear 103
  8382. #define OP_CreateIndex 104
  8383. #define OP_CreateTable 105
  8384. #define OP_ParseSchema 106
  8385. #define OP_LoadAnalysis 107
  8386. #define OP_DropTable 108
  8387. #define OP_DropIndex 109
  8388. #define OP_DropTrigger 110
  8389. #define OP_IntegrityCk 111
  8390. #define OP_RowSetAdd 112
  8391. #define OP_RowSetRead 113
  8392. #define OP_RowSetTest 114
  8393. #define OP_Program 115
  8394. #define OP_Param 116
  8395. #define OP_FkCounter 117
  8396. #define OP_FkIfZero 118
  8397. #define OP_MemMax 119
  8398. #define OP_IfPos 120
  8399. #define OP_IfNeg 121
  8400. #define OP_IfZero 122
  8401. #define OP_AggStep 123
  8402. #define OP_AggFinal 124
  8403. #define OP_Checkpoint 125
  8404. #define OP_JournalMode 126
  8405. #define OP_Vacuum 127
  8406. #define OP_IncrVacuum 128
  8407. #define OP_Expire 129
  8408. #define OP_TableLock 131
  8409. #define OP_VBegin 132
  8410. #define OP_VCreate 133
  8411. #define OP_VDestroy 134
  8412. #define OP_VOpen 135
  8413. #define OP_VFilter 136
  8414. #define OP_VColumn 137
  8415. #define OP_VNext 138
  8416. #define OP_VRename 139
  8417. #define OP_VUpdate 140
  8418. #define OP_Pagecount 146
  8419. #define OP_MaxPgcnt 147
  8420. #define OP_Trace 148
  8421. #define OP_Noop 149
  8422. #define OP_Explain 150
  8423. /* Properties such as "out2" or "jump" that are specified in
  8424. ** comments following the "case" for each opcode in the vdbe.c
  8425. ** are encoded into bitvectors as follows:
  8426. */
  8427. #define OPFLG_JUMP 0x0001 /* jump: P2 holds jmp target */
  8428. #define OPFLG_OUT2_PRERELEASE 0x0002 /* out2-prerelease: */
  8429. #define OPFLG_IN1 0x0004 /* in1: P1 is an input */
  8430. #define OPFLG_IN2 0x0008 /* in2: P2 is an input */
  8431. #define OPFLG_IN3 0x0010 /* in3: P3 is an input */
  8432. #define OPFLG_OUT2 0x0020 /* out2: P2 is an output */
  8433. #define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
  8434. #define OPFLG_INITIALIZER {\
  8435. /* 0 */ 0x00, 0x01, 0x01, 0x04, 0x04, 0x10, 0x00, 0x02,\
  8436. /* 8 */ 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x24, 0x24,\
  8437. /* 16 */ 0x00, 0x00, 0x00, 0x24, 0x04, 0x05, 0x04, 0x00,\
  8438. /* 24 */ 0x00, 0x01, 0x01, 0x05, 0x05, 0x00, 0x00, 0x00,\
  8439. /* 32 */ 0x02, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00,\
  8440. /* 40 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11,\
  8441. /* 48 */ 0x11, 0x11, 0x08, 0x11, 0x11, 0x11, 0x11, 0x02,\
  8442. /* 56 */ 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
  8443. /* 64 */ 0x00, 0x02, 0x00, 0x01, 0x4c, 0x4c, 0x01, 0x01,\
  8444. /* 72 */ 0x01, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15, 0x15,\
  8445. /* 80 */ 0x15, 0x01, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\
  8446. /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x01, 0x24, 0x02, 0x01,\
  8447. /* 96 */ 0x08, 0x08, 0x00, 0x02, 0x01, 0x01, 0x02, 0x00,\
  8448. /* 104 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
  8449. /* 112 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01, 0x08,\
  8450. /* 120 */ 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00,\
  8451. /* 128 */ 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,\
  8452. /* 136 */ 0x01, 0x00, 0x01, 0x00, 0x00, 0x04, 0x04, 0x04,\
  8453. /* 144 */ 0x04, 0x04, 0x02, 0x02, 0x00, 0x00, 0x00,}
  8454. /************** End of opcodes.h *********************************************/
  8455. /************** Continuing where we left off in vdbe.h ***********************/
  8456. /*
  8457. ** Prototypes for the VDBE interface. See comments on the implementation
  8458. ** for a description of what each of these routines does.
  8459. */
  8460. SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(sqlite3*);
  8461. SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe*,int);
  8462. SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int);
  8463. SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
  8464. SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
  8465. SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
  8466. SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
  8467. SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
  8468. SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
  8469. SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
  8470. SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
  8471. SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
  8472. SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
  8473. SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
  8474. SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr);
  8475. SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
  8476. SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
  8477. SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
  8478. SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*);
  8479. SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe*);
  8480. SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe*);
  8481. SQLITE_PRIVATE void sqlite3VdbeDeleteObject(sqlite3*,Vdbe*);
  8482. SQLITE_PRIVATE void sqlite3VdbeMakeReady(Vdbe*,Parse*);
  8483. SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe*);
  8484. SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe*, int);
  8485. SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe*);
  8486. #ifdef SQLITE_DEBUG
  8487. SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *, int);
  8488. SQLITE_PRIVATE void sqlite3VdbeTrace(Vdbe*,FILE*);
  8489. #endif
  8490. SQLITE_PRIVATE void sqlite3VdbeResetStepResult(Vdbe*);
  8491. SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe*);
  8492. SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe*);
  8493. SQLITE_PRIVATE void sqlite3VdbeSetNumCols(Vdbe*,int);
  8494. SQLITE_PRIVATE int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, void(*)(void*));
  8495. SQLITE_PRIVATE void sqlite3VdbeCountChanges(Vdbe*);
  8496. SQLITE_PRIVATE sqlite3 *sqlite3VdbeDb(Vdbe*);
  8497. SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe*, const char *z, int n, int);
  8498. SQLITE_PRIVATE void sqlite3VdbeSwap(Vdbe*,Vdbe*);
  8499. SQLITE_PRIVATE VdbeOp *sqlite3VdbeTakeOpArray(Vdbe*, int*, int*);
  8500. SQLITE_PRIVATE sqlite3_value *sqlite3VdbeGetValue(Vdbe*, int, u8);
  8501. SQLITE_PRIVATE void sqlite3VdbeSetVarmask(Vdbe*, int);
  8502. #ifndef SQLITE_OMIT_TRACE
  8503. SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*);
  8504. #endif
  8505. SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
  8506. SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
  8507. SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
  8508. #ifndef SQLITE_OMIT_TRIGGER
  8509. SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
  8510. #endif
  8511. #ifndef NDEBUG
  8512. SQLITE_PRIVATE void sqlite3VdbeComment(Vdbe*, const char*, ...);
  8513. # define VdbeComment(X) sqlite3VdbeComment X
  8514. SQLITE_PRIVATE void sqlite3VdbeNoopComment(Vdbe*, const char*, ...);
  8515. # define VdbeNoopComment(X) sqlite3VdbeNoopComment X
  8516. #else
  8517. # define VdbeComment(X)
  8518. # define VdbeNoopComment(X)
  8519. #endif
  8520. #endif
  8521. /************** End of vdbe.h ************************************************/
  8522. /************** Continuing where we left off in sqliteInt.h ******************/
  8523. /************** Include pager.h in the middle of sqliteInt.h *****************/
  8524. /************** Begin file pager.h *******************************************/
  8525. /*
  8526. ** 2001 September 15
  8527. **
  8528. ** The author disclaims copyright to this source code. In place of
  8529. ** a legal notice, here is a blessing:
  8530. **
  8531. ** May you do good and not evil.
  8532. ** May you find forgiveness for yourself and forgive others.
  8533. ** May you share freely, never taking more than you give.
  8534. **
  8535. *************************************************************************
  8536. ** This header file defines the interface that the sqlite page cache
  8537. ** subsystem. The page cache subsystem reads and writes a file a page
  8538. ** at a time and provides a journal for rollback.
  8539. */
  8540. #ifndef _PAGER_H_
  8541. #define _PAGER_H_
  8542. /*
  8543. ** Default maximum size for persistent journal files. A negative
  8544. ** value means no limit. This value may be overridden using the
  8545. ** sqlite3PagerJournalSizeLimit() API. See also "PRAGMA journal_size_limit".
  8546. */
  8547. #ifndef SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT
  8548. #define SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT -1
  8549. #endif
  8550. /*
  8551. ** The type used to represent a page number. The first page in a file
  8552. ** is called page 1. 0 is used to represent "not a page".
  8553. */
  8554. typedef u32 Pgno;
  8555. /*
  8556. ** Each open file is managed by a separate instance of the "Pager" structure.
  8557. */
  8558. typedef struct Pager Pager;
  8559. /*
  8560. ** Handle type for pages.
  8561. */
  8562. typedef struct PgHdr DbPage;
  8563. /*
  8564. ** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is
  8565. ** reserved for working around a windows/posix incompatibility). It is
  8566. ** used in the journal to signify that the remainder of the journal file
  8567. ** is devoted to storing a master journal name - there are no more pages to
  8568. ** roll back. See comments for function writeMasterJournal() in pager.c
  8569. ** for details.
  8570. */
  8571. #define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))
  8572. /*
  8573. ** Allowed values for the flags parameter to sqlite3PagerOpen().
  8574. **
  8575. ** NOTE: These values must match the corresponding BTREE_ values in btree.h.
  8576. */
  8577. #define PAGER_OMIT_JOURNAL 0x0001 /* Do not use a rollback journal */
  8578. #define PAGER_MEMORY 0x0002 /* In-memory database */
  8579. /*
  8580. ** Valid values for the second argument to sqlite3PagerLockingMode().
  8581. */
  8582. #define PAGER_LOCKINGMODE_QUERY -1
  8583. #define PAGER_LOCKINGMODE_NORMAL 0
  8584. #define PAGER_LOCKINGMODE_EXCLUSIVE 1
  8585. /*
  8586. ** Numeric constants that encode the journalmode.
  8587. */
  8588. #define PAGER_JOURNALMODE_QUERY (-1) /* Query the value of journalmode */
  8589. #define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */
  8590. #define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */
  8591. #define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */
  8592. #define PAGER_JOURNALMODE_TRUNCATE 3 /* Commit by truncating journal */
  8593. #define PAGER_JOURNALMODE_MEMORY 4 /* In-memory journal file */
  8594. #define PAGER_JOURNALMODE_WAL 5 /* Use write-ahead logging */
  8595. /*
  8596. ** The remainder of this file contains the declarations of the functions
  8597. ** that make up the Pager sub-system API. See source code comments for
  8598. ** a detailed description of each routine.
  8599. */
  8600. /* Open and close a Pager connection. */
  8601. SQLITE_PRIVATE int sqlite3PagerOpen(
  8602. sqlite3_vfs*,
  8603. Pager **ppPager,
  8604. const char*,
  8605. int,
  8606. int,
  8607. int,
  8608. void(*)(DbPage*)
  8609. );
  8610. SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager);
  8611. SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
  8612. /* Functions used to configure a Pager object. */
  8613. SQLITE_PRIVATE void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *);
  8614. SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int);
  8615. SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int);
  8616. SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int);
  8617. SQLITE_PRIVATE void sqlite3PagerShrink(Pager*);
  8618. SQLITE_PRIVATE void sqlite3PagerSetSafetyLevel(Pager*,int,int,int);
  8619. SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int);
  8620. SQLITE_PRIVATE int sqlite3PagerSetJournalMode(Pager *, int);
  8621. SQLITE_PRIVATE int sqlite3PagerGetJournalMode(Pager*);
  8622. SQLITE_PRIVATE int sqlite3PagerOkToChangeJournalMode(Pager*);
  8623. SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *, i64);
  8624. SQLITE_PRIVATE sqlite3_backup **sqlite3PagerBackupPtr(Pager*);
  8625. /* Functions used to obtain and release page references. */
  8626. SQLITE_PRIVATE int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
  8627. #define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0)
  8628. SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
  8629. SQLITE_PRIVATE void sqlite3PagerRef(DbPage*);
  8630. SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*);
  8631. /* Operations on page references. */
  8632. SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
  8633. SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*);
  8634. SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
  8635. SQLITE_PRIVATE int sqlite3PagerPageRefcount(DbPage*);
  8636. SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *);
  8637. SQLITE_PRIVATE void *sqlite3PagerGetExtra(DbPage *);
  8638. /* Functions used to manage pager transactions and savepoints. */
  8639. SQLITE_PRIVATE void sqlite3PagerPagecount(Pager*, int*);
  8640. SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int);
  8641. SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int);
  8642. SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*);
  8643. SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager);
  8644. SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
  8645. SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
  8646. SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
  8647. SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
  8648. SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
  8649. SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, int, int*, int*);
  8650. SQLITE_PRIVATE int sqlite3PagerWalSupported(Pager *pPager);
  8651. SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager);
  8652. SQLITE_PRIVATE int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen);
  8653. SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager);
  8654. #ifdef SQLITE_ENABLE_ZIPVFS
  8655. SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager);
  8656. #endif
  8657. /* Functions used to query pager state and configuration. */
  8658. SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
  8659. SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
  8660. SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
  8661. SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*);
  8662. SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*);
  8663. SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
  8664. SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
  8665. SQLITE_PRIVATE int sqlite3PagerNosync(Pager*);
  8666. SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
  8667. SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*);
  8668. SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *, int, int, int *);
  8669. SQLITE_PRIVATE void sqlite3PagerClearCache(Pager *);
  8670. /* Functions used to truncate the database file. */
  8671. SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
  8672. #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL)
  8673. SQLITE_PRIVATE void *sqlite3PagerCodec(DbPage *);
  8674. #endif
  8675. /* Functions to support testing and debugging. */
  8676. #if !defined(NDEBUG) || defined(SQLITE_TEST)
  8677. SQLITE_PRIVATE Pgno sqlite3PagerPagenumber(DbPage*);
  8678. SQLITE_PRIVATE int sqlite3PagerIswriteable(DbPage*);
  8679. #endif
  8680. #ifdef SQLITE_TEST
  8681. SQLITE_PRIVATE int *sqlite3PagerStats(Pager*);
  8682. SQLITE_PRIVATE void sqlite3PagerRefdump(Pager*);
  8683. void disable_simulated_io_errors(void);
  8684. void enable_simulated_io_errors(void);
  8685. #else
  8686. # define disable_simulated_io_errors()
  8687. # define enable_simulated_io_errors()
  8688. #endif
  8689. #endif /* _PAGER_H_ */
  8690. /************** End of pager.h ***********************************************/
  8691. /************** Continuing where we left off in sqliteInt.h ******************/
  8692. /************** Include pcache.h in the middle of sqliteInt.h ****************/
  8693. /************** Begin file pcache.h ******************************************/
  8694. /*
  8695. ** 2008 August 05
  8696. **
  8697. ** The author disclaims copyright to this source code. In place of
  8698. ** a legal notice, here is a blessing:
  8699. **
  8700. ** May you do good and not evil.
  8701. ** May you find forgiveness for yourself and forgive others.
  8702. ** May you share freely, never taking more than you give.
  8703. **
  8704. *************************************************************************
  8705. ** This header file defines the interface that the sqlite page cache
  8706. ** subsystem.
  8707. */
  8708. #ifndef _PCACHE_H_
  8709. typedef struct PgHdr PgHdr;
  8710. typedef struct PCache PCache;
  8711. /*
  8712. ** Every page in the cache is controlled by an instance of the following
  8713. ** structure.
  8714. */
  8715. struct PgHdr {
  8716. sqlite3_pcache_page *pPage; /* Pcache object page handle */
  8717. void *pData; /* Page data */
  8718. void *pExtra; /* Extra content */
  8719. PgHdr *pDirty; /* Transient list of dirty pages */
  8720. Pager *pPager; /* The pager this page is part of */
  8721. Pgno pgno; /* Page number for this page */
  8722. #ifdef SQLITE_CHECK_PAGES
  8723. u32 pageHash; /* Hash of page content */
  8724. #endif
  8725. u16 flags; /* PGHDR flags defined below */
  8726. /**********************************************************************
  8727. ** Elements above are public. All that follows is private to pcache.c
  8728. ** and should not be accessed by other modules.
  8729. */
  8730. i16 nRef; /* Number of users of this page */
  8731. PCache *pCache; /* Cache that owns this page */
  8732. PgHdr *pDirtyNext; /* Next element in list of dirty pages */
  8733. PgHdr *pDirtyPrev; /* Previous element in list of dirty pages */
  8734. };
  8735. /* Bit values for PgHdr.flags */
  8736. #define PGHDR_DIRTY 0x002 /* Page has changed */
  8737. #define PGHDR_NEED_SYNC 0x004 /* Fsync the rollback journal before
  8738. ** writing this page to the database */
  8739. #define PGHDR_NEED_READ 0x008 /* Content is unread */
  8740. #define PGHDR_REUSE_UNLIKELY 0x010 /* A hint that reuse is unlikely */
  8741. #define PGHDR_DONT_WRITE 0x020 /* Do not write content to disk */
  8742. /* Initialize and shutdown the page cache subsystem */
  8743. SQLITE_PRIVATE int sqlite3PcacheInitialize(void);
  8744. SQLITE_PRIVATE void sqlite3PcacheShutdown(void);
  8745. /* Page cache buffer management:
  8746. ** These routines implement SQLITE_CONFIG_PAGECACHE.
  8747. */
  8748. SQLITE_PRIVATE void sqlite3PCacheBufferSetup(void *, int sz, int n);
  8749. /* Create a new pager cache.
  8750. ** Under memory stress, invoke xStress to try to make pages clean.
  8751. ** Only clean and unpinned pages can be reclaimed.
  8752. */
  8753. SQLITE_PRIVATE void sqlite3PcacheOpen(
  8754. int szPage, /* Size of every page */
  8755. int szExtra, /* Extra space associated with each page */
  8756. int bPurgeable, /* True if pages are on backing store */
  8757. int (*xStress)(void*, PgHdr*), /* Call to try to make pages clean */
  8758. void *pStress, /* Argument to xStress */
  8759. PCache *pToInit /* Preallocated space for the PCache */
  8760. );
  8761. /* Modify the page-size after the cache has been created. */
  8762. SQLITE_PRIVATE void sqlite3PcacheSetPageSize(PCache *, int);
  8763. /* Return the size in bytes of a PCache object. Used to preallocate
  8764. ** storage space.
  8765. */
  8766. SQLITE_PRIVATE int sqlite3PcacheSize(void);
  8767. /* One release per successful fetch. Page is pinned until released.
  8768. ** Reference counted.
  8769. */
  8770. SQLITE_PRIVATE int sqlite3PcacheFetch(PCache*, Pgno, int createFlag, PgHdr**);
  8771. SQLITE_PRIVATE void sqlite3PcacheRelease(PgHdr*);
  8772. SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr*); /* Remove page from cache */
  8773. SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr*); /* Make sure page is marked dirty */
  8774. SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr*); /* Mark a single page as clean */
  8775. SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache*); /* Mark all dirty list pages as clean */
  8776. /* Change a page number. Used by incr-vacuum. */
  8777. SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr*, Pgno);
  8778. /* Remove all pages with pgno>x. Reset the cache if x==0 */
  8779. SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache*, Pgno x);
  8780. /* Get a list of all dirty pages in the cache, sorted by page number */
  8781. SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache*);
  8782. /* Reset and close the cache object */
  8783. SQLITE_PRIVATE void sqlite3PcacheClose(PCache*);
  8784. /* Clear flags from pages of the page cache */
  8785. SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *);
  8786. /* Discard the contents of the cache */
  8787. SQLITE_PRIVATE void sqlite3PcacheClear(PCache*);
  8788. /* Return the total number of outstanding page references */
  8789. SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache*);
  8790. /* Increment the reference count of an existing page */
  8791. SQLITE_PRIVATE void sqlite3PcacheRef(PgHdr*);
  8792. SQLITE_PRIVATE int sqlite3PcachePageRefcount(PgHdr*);
  8793. /* Return the total number of pages stored in the cache */
  8794. SQLITE_PRIVATE int sqlite3PcachePagecount(PCache*);
  8795. #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
  8796. /* Iterate through all dirty pages currently stored in the cache. This
  8797. ** interface is only available if SQLITE_CHECK_PAGES is defined when the
  8798. ** library is built.
  8799. */
  8800. SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
  8801. #endif
  8802. /* Set and get the suggested cache-size for the specified pager-cache.
  8803. **
  8804. ** If no global maximum is configured, then the system attempts to limit
  8805. ** the total number of pages cached by purgeable pager-caches to the sum
  8806. ** of the suggested cache-sizes.
  8807. */
  8808. SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *, int);
  8809. #ifdef SQLITE_TEST
  8810. SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *);
  8811. #endif
  8812. /* Free up as much memory as possible from the page cache */
  8813. SQLITE_PRIVATE void sqlite3PcacheShrink(PCache*);
  8814. #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
  8815. /* Try to return memory used by the pcache module to the main memory heap */
  8816. SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int);
  8817. #endif
  8818. #ifdef SQLITE_TEST
  8819. SQLITE_PRIVATE void sqlite3PcacheStats(int*,int*,int*,int*);
  8820. #endif
  8821. SQLITE_PRIVATE void sqlite3PCacheSetDefault(void);
  8822. #endif /* _PCACHE_H_ */
  8823. /************** End of pcache.h **********************************************/
  8824. /************** Continuing where we left off in sqliteInt.h ******************/
  8825. /************** Include os.h in the middle of sqliteInt.h ********************/
  8826. /************** Begin file os.h **********************************************/
  8827. /*
  8828. ** 2001 September 16
  8829. **
  8830. ** The author disclaims copyright to this source code. In place of
  8831. ** a legal notice, here is a blessing:
  8832. **
  8833. ** May you do good and not evil.
  8834. ** May you find forgiveness for yourself and forgive others.
  8835. ** May you share freely, never taking more than you give.
  8836. **
  8837. ******************************************************************************
  8838. **
  8839. ** This header file (together with is companion C source-code file
  8840. ** "os.c") attempt to abstract the underlying operating system so that
  8841. ** the SQLite library will work on both POSIX and windows systems.
  8842. **
  8843. ** This header file is #include-ed by sqliteInt.h and thus ends up
  8844. ** being included by every source file.
  8845. */
  8846. #ifndef _SQLITE_OS_H_
  8847. #define _SQLITE_OS_H_
  8848. /*
  8849. ** Figure out if we are dealing with Unix, Windows, or some other
  8850. ** operating system. After the following block of preprocess macros,
  8851. ** all of SQLITE_OS_UNIX, SQLITE_OS_WIN, SQLITE_OS_OS2, and SQLITE_OS_OTHER
  8852. ** will defined to either 1 or 0. One of the four will be 1. The other
  8853. ** three will be 0.
  8854. */
  8855. #if defined(SQLITE_OS_OTHER)
  8856. # if SQLITE_OS_OTHER==1
  8857. # undef SQLITE_OS_UNIX
  8858. # define SQLITE_OS_UNIX 0
  8859. # undef SQLITE_OS_WIN
  8860. # define SQLITE_OS_WIN 0
  8861. # undef SQLITE_OS_OS2
  8862. # define SQLITE_OS_OS2 0
  8863. # else
  8864. # undef SQLITE_OS_OTHER
  8865. # endif
  8866. #endif
  8867. #if !defined(SQLITE_OS_UNIX) && !defined(SQLITE_OS_OTHER)
  8868. # define SQLITE_OS_OTHER 0
  8869. # ifndef SQLITE_OS_WIN
  8870. # if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
  8871. # define SQLITE_OS_WIN 1
  8872. # define SQLITE_OS_UNIX 0
  8873. # define SQLITE_OS_OS2 0
  8874. # elif defined(__EMX__) || defined(_OS2) || defined(OS2) || defined(_OS2_) || defined(__OS2__)
  8875. # define SQLITE_OS_WIN 0
  8876. # define SQLITE_OS_UNIX 0
  8877. # define SQLITE_OS_OS2 1
  8878. # else
  8879. # define SQLITE_OS_WIN 0
  8880. # define SQLITE_OS_UNIX 1
  8881. # define SQLITE_OS_OS2 0
  8882. # endif
  8883. # else
  8884. # define SQLITE_OS_UNIX 0
  8885. # define SQLITE_OS_OS2 0
  8886. # endif
  8887. #else
  8888. # ifndef SQLITE_OS_WIN
  8889. # define SQLITE_OS_WIN 0
  8890. # endif
  8891. #endif
  8892. /*
  8893. ** Define the maximum size of a temporary filename
  8894. */
  8895. #if SQLITE_OS_WIN
  8896. # include <windows.h>
  8897. # define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
  8898. #elif SQLITE_OS_OS2
  8899. # if (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3) && defined(OS2_HIGH_MEMORY)
  8900. # include <os2safe.h> /* has to be included before os2.h for linking to work */
  8901. # endif
  8902. # define INCL_DOSDATETIME
  8903. # define INCL_DOSFILEMGR
  8904. # define INCL_DOSERRORS
  8905. # define INCL_DOSMISC
  8906. # define INCL_DOSPROCESS
  8907. # define INCL_DOSMODULEMGR
  8908. # define INCL_DOSSEMAPHORES
  8909. # include <os2.h>
  8910. # include <uconv.h>
  8911. # define SQLITE_TEMPNAME_SIZE (CCHMAXPATHCOMP)
  8912. #else
  8913. # define SQLITE_TEMPNAME_SIZE 200
  8914. #endif
  8915. /*
  8916. ** Determine if we are dealing with Windows NT.
  8917. **
  8918. ** We ought to be able to determine if we are compiling for win98 or winNT
  8919. ** using the _WIN32_WINNT macro as follows:
  8920. **
  8921. ** #if defined(_WIN32_WINNT)
  8922. ** # define SQLITE_OS_WINNT 1
  8923. ** #else
  8924. ** # define SQLITE_OS_WINNT 0
  8925. ** #endif
  8926. **
  8927. ** However, vs2005 does not set _WIN32_WINNT by default, as it ought to,
  8928. ** so the above test does not work. We'll just assume that everything is
  8929. ** winNT unless the programmer explicitly says otherwise by setting
  8930. ** SQLITE_OS_WINNT to 0.
  8931. */
  8932. #if SQLITE_OS_WIN && !defined(SQLITE_OS_WINNT)
  8933. # define SQLITE_OS_WINNT 1
  8934. #endif
  8935. /*
  8936. ** Determine if we are dealing with WindowsCE - which has a much
  8937. ** reduced API.
  8938. */
  8939. #if defined(_WIN32_WCE)
  8940. # define SQLITE_OS_WINCE 1
  8941. #else
  8942. # define SQLITE_OS_WINCE 0
  8943. #endif
  8944. /* If the SET_FULLSYNC macro is not defined above, then make it
  8945. ** a no-op
  8946. */
  8947. #ifndef SET_FULLSYNC
  8948. # define SET_FULLSYNC(x,y)
  8949. #endif
  8950. /*
  8951. ** The default size of a disk sector
  8952. */
  8953. #ifndef SQLITE_DEFAULT_SECTOR_SIZE
  8954. # define SQLITE_DEFAULT_SECTOR_SIZE 4096
  8955. #endif
  8956. /*
  8957. ** Temporary files are named starting with this prefix followed by 16 random
  8958. ** alphanumeric characters, and no file extension. They are stored in the
  8959. ** OS's standard temporary file directory, and are deleted prior to exit.
  8960. ** If sqlite is being embedded in another program, you may wish to change the
  8961. ** prefix to reflect your program's name, so that if your program exits
  8962. ** prematurely, old temporary files can be easily identified. This can be done
  8963. ** using -DSQLITE_TEMP_FILE_PREFIX=myprefix_ on the compiler command line.
  8964. **
  8965. ** 2006-10-31: The default prefix used to be "sqlite_". But then
  8966. ** Mcafee started using SQLite in their anti-virus product and it
  8967. ** started putting files with the "sqlite" name in the c:/temp folder.
  8968. ** This annoyed many windows users. Those users would then do a
  8969. ** Google search for "sqlite", find the telephone numbers of the
  8970. ** developers and call to wake them up at night and complain.
  8971. ** For this reason, the default name prefix is changed to be "sqlite"
  8972. ** spelled backwards. So the temp files are still identified, but
  8973. ** anybody smart enough to figure out the code is also likely smart
  8974. ** enough to know that calling the developer will not help get rid
  8975. ** of the file.
  8976. */
  8977. #ifndef SQLITE_TEMP_FILE_PREFIX
  8978. # define SQLITE_TEMP_FILE_PREFIX "etilqs_"
  8979. #endif
  8980. /*
  8981. ** The following values may be passed as the second argument to
  8982. ** sqlite3OsLock(). The various locks exhibit the following semantics:
  8983. **
  8984. ** SHARED: Any number of processes may hold a SHARED lock simultaneously.
  8985. ** RESERVED: A single process may hold a RESERVED lock on a file at
  8986. ** any time. Other processes may hold and obtain new SHARED locks.
  8987. ** PENDING: A single process may hold a PENDING lock on a file at
  8988. ** any one time. Existing SHARED locks may persist, but no new
  8989. ** SHARED locks may be obtained by other processes.
  8990. ** EXCLUSIVE: An EXCLUSIVE lock precludes all other locks.
  8991. **
  8992. ** PENDING_LOCK may not be passed directly to sqlite3OsLock(). Instead, a
  8993. ** process that requests an EXCLUSIVE lock may actually obtain a PENDING
  8994. ** lock. This can be upgraded to an EXCLUSIVE lock by a subsequent call to
  8995. ** sqlite3OsLock().
  8996. */
  8997. #define NO_LOCK 0
  8998. #define SHARED_LOCK 1
  8999. #define RESERVED_LOCK 2
  9000. #define PENDING_LOCK 3
  9001. #define EXCLUSIVE_LOCK 4
  9002. /*
  9003. ** File Locking Notes: (Mostly about windows but also some info for Unix)
  9004. **
  9005. ** We cannot use LockFileEx() or UnlockFileEx() on Win95/98/ME because
  9006. ** those functions are not available. So we use only LockFile() and
  9007. ** UnlockFile().
  9008. **
  9009. ** LockFile() prevents not just writing but also reading by other processes.
  9010. ** A SHARED_LOCK is obtained by locking a single randomly-chosen
  9011. ** byte out of a specific range of bytes. The lock byte is obtained at
  9012. ** random so two separate readers can probably access the file at the
  9013. ** same time, unless they are unlucky and choose the same lock byte.
  9014. ** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range.
  9015. ** There can only be one writer. A RESERVED_LOCK is obtained by locking
  9016. ** a single byte of the file that is designated as the reserved lock byte.
  9017. ** A PENDING_LOCK is obtained by locking a designated byte different from
  9018. ** the RESERVED_LOCK byte.
  9019. **
  9020. ** On WinNT/2K/XP systems, LockFileEx() and UnlockFileEx() are available,
  9021. ** which means we can use reader/writer locks. When reader/writer locks
  9022. ** are used, the lock is placed on the same range of bytes that is used
  9023. ** for probabilistic locking in Win95/98/ME. Hence, the locking scheme
  9024. ** will support two or more Win95 readers or two or more WinNT readers.
  9025. ** But a single Win95 reader will lock out all WinNT readers and a single
  9026. ** WinNT reader will lock out all other Win95 readers.
  9027. **
  9028. ** The following #defines specify the range of bytes used for locking.
  9029. ** SHARED_SIZE is the number of bytes available in the pool from which
  9030. ** a random byte is selected for a shared lock. The pool of bytes for
  9031. ** shared locks begins at SHARED_FIRST.
  9032. **
  9033. ** The same locking strategy and
  9034. ** byte ranges are used for Unix. This leaves open the possiblity of having
  9035. ** clients on win95, winNT, and unix all talking to the same shared file
  9036. ** and all locking correctly. To do so would require that samba (or whatever
  9037. ** tool is being used for file sharing) implements locks correctly between
  9038. ** windows and unix. I'm guessing that isn't likely to happen, but by
  9039. ** using the same locking range we are at least open to the possibility.
  9040. **
  9041. ** Locking in windows is manditory. For this reason, we cannot store
  9042. ** actual data in the bytes used for locking. The pager never allocates
  9043. ** the pages involved in locking therefore. SHARED_SIZE is selected so
  9044. ** that all locks will fit on a single page even at the minimum page size.
  9045. ** PENDING_BYTE defines the beginning of the locks. By default PENDING_BYTE
  9046. ** is set high so that we don't have to allocate an unused page except
  9047. ** for very large databases. But one should test the page skipping logic
  9048. ** by setting PENDING_BYTE low and running the entire regression suite.
  9049. **
  9050. ** Changing the value of PENDING_BYTE results in a subtly incompatible
  9051. ** file format. Depending on how it is changed, you might not notice
  9052. ** the incompatibility right away, even running a full regression test.
  9053. ** The default location of PENDING_BYTE is the first byte past the
  9054. ** 1GB boundary.
  9055. **
  9056. */
  9057. #ifdef SQLITE_OMIT_WSD
  9058. # define PENDING_BYTE (0x40000000)
  9059. #else
  9060. # define PENDING_BYTE sqlite3PendingByte
  9061. #endif
  9062. #define RESERVED_BYTE (PENDING_BYTE+1)
  9063. #define SHARED_FIRST (PENDING_BYTE+2)
  9064. #define SHARED_SIZE 510
  9065. /*
  9066. ** Wrapper around OS specific sqlite3_os_init() function.
  9067. */
  9068. SQLITE_PRIVATE int sqlite3OsInit(void);
  9069. /*
  9070. ** Functions for accessing sqlite3_file methods
  9071. */
  9072. SQLITE_PRIVATE int sqlite3OsClose(sqlite3_file*);
  9073. SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file*, void*, int amt, i64 offset);
  9074. SQLITE_PRIVATE int sqlite3OsWrite(sqlite3_file*, const void*, int amt, i64 offset);
  9075. SQLITE_PRIVATE int sqlite3OsTruncate(sqlite3_file*, i64 size);
  9076. SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file*, int);
  9077. SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file*, i64 *pSize);
  9078. SQLITE_PRIVATE int sqlite3OsLock(sqlite3_file*, int);
  9079. SQLITE_PRIVATE int sqlite3OsUnlock(sqlite3_file*, int);
  9080. SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut);
  9081. SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file*,int,void*);
  9082. SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file*,int,void*);
  9083. #define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0
  9084. SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id);
  9085. SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id);
  9086. SQLITE_PRIVATE int sqlite3OsShmMap(sqlite3_file *,int,int,int,void volatile **);
  9087. SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int, int, int);
  9088. SQLITE_PRIVATE void sqlite3OsShmBarrier(sqlite3_file *id);
  9089. SQLITE_PRIVATE int sqlite3OsShmUnmap(sqlite3_file *id, int);
  9090. /*
  9091. ** Functions for accessing sqlite3_vfs methods
  9092. */
  9093. SQLITE_PRIVATE int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int, int *);
  9094. SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *, const char *, int);
  9095. SQLITE_PRIVATE int sqlite3OsAccess(sqlite3_vfs *, const char *, int, int *pResOut);
  9096. SQLITE_PRIVATE int sqlite3OsFullPathname(sqlite3_vfs *, const char *, int, char *);
  9097. #ifndef SQLITE_OMIT_LOAD_EXTENSION
  9098. SQLITE_PRIVATE void *sqlite3OsDlOpen(sqlite3_vfs *, const char *);
  9099. SQLITE_PRIVATE void sqlite3OsDlError(sqlite3_vfs *, int, char *);
  9100. SQLITE_PRIVATE void (*sqlite3OsDlSym(sqlite3_vfs *, void *, const char *))(void);
  9101. SQLITE_PRIVATE void sqlite3OsDlClose(sqlite3_vfs *, void *);
  9102. #endif /* SQLITE_OMIT_LOAD_EXTENSION */
  9103. SQLITE_PRIVATE int sqlite3OsRandomness(sqlite3_vfs *, int, char *);
  9104. SQLITE_PRIVATE int sqlite3OsSleep(sqlite3_vfs *, int);
  9105. SQLITE_PRIVATE int sqlite3OsCurrentTimeInt64(sqlite3_vfs *, sqlite3_int64*);
  9106. /*
  9107. ** Convenience functions for opening and closing files using
  9108. ** sqlite3_malloc() to obtain space for the file-handle structure.
  9109. */
  9110. SQLITE_PRIVATE int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int,int*);
  9111. SQLITE_PRIVATE int sqlite3OsCloseFree(sqlite3_file *);
  9112. #endif /* _SQLITE_OS_H_ */
  9113. /************** End of os.h **************************************************/
  9114. /************** Continuing where we left off in sqliteInt.h ******************/
  9115. /************** Include mutex.h in the middle of sqliteInt.h *****************/
  9116. /************** Begin file mutex.h *******************************************/
  9117. /*
  9118. ** 2007 August 28
  9119. **
  9120. ** The author disclaims copyright to this source code. In place of
  9121. ** a legal notice, here is a blessing:
  9122. **
  9123. ** May you do good and not evil.
  9124. ** May you find forgiveness for yourself and forgive others.
  9125. ** May you share freely, never taking more than you give.
  9126. **
  9127. *************************************************************************
  9128. **
  9129. ** This file contains the common header for all mutex implementations.
  9130. ** The sqliteInt.h header #includes this file so that it is available
  9131. ** to all source files. We break it out in an effort to keep the code
  9132. ** better organized.
  9133. **
  9134. ** NOTE: source files should *not* #include this header file directly.
  9135. ** Source files should #include the sqliteInt.h file and let that file
  9136. ** include this one indirectly.
  9137. */
  9138. /*
  9139. ** Figure out what version of the code to use. The choices are
  9140. **
  9141. ** SQLITE_MUTEX_OMIT No mutex logic. Not even stubs. The
  9142. ** mutexes implemention cannot be overridden
  9143. ** at start-time.
  9144. **
  9145. ** SQLITE_MUTEX_NOOP For single-threaded applications. No
  9146. ** mutual exclusion is provided. But this
  9147. ** implementation can be overridden at
  9148. ** start-time.
  9149. **
  9150. ** SQLITE_MUTEX_PTHREADS For multi-threaded applications on Unix.
  9151. **
  9152. ** SQLITE_MUTEX_W32 For multi-threaded applications on Win32.
  9153. **
  9154. ** SQLITE_MUTEX_OS2 For multi-threaded applications on OS/2.
  9155. */
  9156. #if !SQLITE_THREADSAFE
  9157. # define SQLITE_MUTEX_OMIT
  9158. #endif
  9159. #if SQLITE_THREADSAFE && !defined(SQLITE_MUTEX_NOOP)
  9160. # if SQLITE_OS_UNIX
  9161. # define SQLITE_MUTEX_PTHREADS
  9162. # elif SQLITE_OS_WIN
  9163. # define SQLITE_MUTEX_W32
  9164. # elif SQLITE_OS_OS2
  9165. # define SQLITE_MUTEX_OS2
  9166. # else
  9167. # define SQLITE_MUTEX_NOOP
  9168. # endif
  9169. #endif
  9170. #ifdef SQLITE_MUTEX_OMIT
  9171. /*
  9172. ** If this is a no-op implementation, implement everything as macros.
  9173. */
  9174. #define sqlite3_mutex_alloc(X) ((sqlite3_mutex*)8)
  9175. #define sqlite3_mutex_free(X)
  9176. #define sqlite3_mutex_enter(X)
  9177. #define sqlite3_mutex_try(X) SQLITE_OK
  9178. #define sqlite3_mutex_leave(X)
  9179. #define sqlite3_mutex_held(X) ((void)(X),1)
  9180. #define sqlite3_mutex_notheld(X) ((void)(X),1)
  9181. #define sqlite3MutexAlloc(X) ((sqlite3_mutex*)8)
  9182. #define sqlite3MutexInit() SQLITE_OK
  9183. #define sqlite3MutexEnd()
  9184. #define MUTEX_LOGIC(X)
  9185. #else
  9186. #define MUTEX_LOGIC(X) X
  9187. #endif /* defined(SQLITE_MUTEX_OMIT) */
  9188. /************** End of mutex.h ***********************************************/
  9189. /************** Continuing where we left off in sqliteInt.h ******************/
  9190. /*
  9191. ** Each database file to be accessed by the system is an instance
  9192. ** of the following structure. There are normally two of these structures
  9193. ** in the sqlite.aDb[] array. aDb[0] is the main database file and
  9194. ** aDb[1] is the database file used to hold temporary tables. Additional
  9195. ** databases may be attached.
  9196. */
  9197. struct Db {
  9198. char *zName; /* Name of this database */
  9199. Btree *pBt; /* The B*Tree structure for this database file */
  9200. u8 inTrans; /* 0: not writable. 1: Transaction. 2: Checkpoint */
  9201. u8 safety_level; /* How aggressive at syncing data to disk */
  9202. Schema *pSchema; /* Pointer to database schema (possibly shared) */
  9203. };
  9204. /*
  9205. ** An instance of the following structure stores a database schema.
  9206. **
  9207. ** Most Schema objects are associated with a Btree. The exception is
  9208. ** the Schema for the TEMP databaes (sqlite3.aDb[1]) which is free-standing.
  9209. ** In shared cache mode, a single Schema object can be shared by multiple
  9210. ** Btrees that refer to the same underlying BtShared object.
  9211. **
  9212. ** Schema objects are automatically deallocated when the last Btree that
  9213. ** references them is destroyed. The TEMP Schema is manually freed by
  9214. ** sqlite3_close().
  9215. *
  9216. ** A thread must be holding a mutex on the corresponding Btree in order
  9217. ** to access Schema content. This implies that the thread must also be
  9218. ** holding a mutex on the sqlite3 connection pointer that owns the Btree.
  9219. ** For a TEMP Schema, only the connection mutex is required.
  9220. */
  9221. struct Schema {
  9222. int schema_cookie; /* Database schema version number for this file */
  9223. int iGeneration; /* Generation counter. Incremented with each change */
  9224. Hash tblHash; /* All tables indexed by name */
  9225. Hash idxHash; /* All (named) indices indexed by name */
  9226. Hash trigHash; /* All triggers indexed by name */
  9227. Hash fkeyHash; /* All foreign keys by referenced table name */
  9228. Table *pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */
  9229. u8 file_format; /* Schema format version for this file */
  9230. u8 enc; /* Text encoding used by this database */
  9231. u16 flags; /* Flags associated with this schema */
  9232. int cache_size; /* Number of pages to use in the cache */
  9233. };
  9234. /*
  9235. ** These macros can be used to test, set, or clear bits in the
  9236. ** Db.pSchema->flags field.
  9237. */
  9238. #define DbHasProperty(D,I,P) (((D)->aDb[I].pSchema->flags&(P))==(P))
  9239. #define DbHasAnyProperty(D,I,P) (((D)->aDb[I].pSchema->flags&(P))!=0)
  9240. #define DbSetProperty(D,I,P) (D)->aDb[I].pSchema->flags|=(P)
  9241. #define DbClearProperty(D,I,P) (D)->aDb[I].pSchema->flags&=~(P)
  9242. /*
  9243. ** Allowed values for the DB.pSchema->flags field.
  9244. **
  9245. ** The DB_SchemaLoaded flag is set after the database schema has been
  9246. ** read into internal hash tables.
  9247. **
  9248. ** DB_UnresetViews means that one or more views have column names that
  9249. ** have been filled out. If the schema changes, these column names might
  9250. ** changes and so the view will need to be reset.
  9251. */
  9252. #define DB_SchemaLoaded 0x0001 /* The schema has been loaded */
  9253. #define DB_UnresetViews 0x0002 /* Some views have defined column names */
  9254. #define DB_Empty 0x0004 /* The file is empty (length 0 bytes) */
  9255. /*
  9256. ** The number of different kinds of things that can be limited
  9257. ** using the sqlite3_limit() interface.
  9258. */
  9259. #define SQLITE_N_LIMIT (SQLITE_LIMIT_TRIGGER_DEPTH+1)
  9260. /*
  9261. ** Lookaside malloc is a set of fixed-size buffers that can be used
  9262. ** to satisfy small transient memory allocation requests for objects
  9263. ** associated with a particular database connection. The use of
  9264. ** lookaside malloc provides a significant performance enhancement
  9265. ** (approx 10%) by avoiding numerous malloc/free requests while parsing
  9266. ** SQL statements.
  9267. **
  9268. ** The Lookaside structure holds configuration information about the
  9269. ** lookaside malloc subsystem. Each available memory allocation in
  9270. ** the lookaside subsystem is stored on a linked list of LookasideSlot
  9271. ** objects.
  9272. **
  9273. ** Lookaside allocations are only allowed for objects that are associated
  9274. ** with a particular database connection. Hence, schema information cannot
  9275. ** be stored in lookaside because in shared cache mode the schema information
  9276. ** is shared by multiple database connections. Therefore, while parsing
  9277. ** schema information, the Lookaside.bEnabled flag is cleared so that
  9278. ** lookaside allocations are not used to construct the schema objects.
  9279. */
  9280. struct Lookaside {
  9281. u16 sz; /* Size of each buffer in bytes */
  9282. u8 bEnabled; /* False to disable new lookaside allocations */
  9283. u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */
  9284. int nOut; /* Number of buffers currently checked out */
  9285. int mxOut; /* Highwater mark for nOut */
  9286. int anStat[3]; /* 0: hits. 1: size misses. 2: full misses */
  9287. LookasideSlot *pFree; /* List of available buffers */
  9288. void *pStart; /* First byte of available memory space */
  9289. void *pEnd; /* First byte past end of available space */
  9290. };
  9291. struct LookasideSlot {
  9292. LookasideSlot *pNext; /* Next buffer in the list of free buffers */
  9293. };
  9294. /*
  9295. ** A hash table for function definitions.
  9296. **
  9297. ** Hash each FuncDef structure into one of the FuncDefHash.a[] slots.
  9298. ** Collisions are on the FuncDef.pHash chain.
  9299. */
  9300. struct FuncDefHash {
  9301. FuncDef *a[23]; /* Hash table for functions */
  9302. };
  9303. /*
  9304. ** Each database connection is an instance of the following structure.
  9305. */
  9306. struct sqlite3 {
  9307. sqlite3_vfs *pVfs; /* OS Interface */
  9308. struct Vdbe *pVdbe; /* List of active virtual machines */
  9309. CollSeq *pDfltColl; /* The default collating sequence (BINARY) */
  9310. sqlite3_mutex *mutex; /* Connection mutex */
  9311. Db *aDb; /* All backends */
  9312. int nDb; /* Number of backends currently in use */
  9313. int flags; /* Miscellaneous flags. See below */
  9314. i64 lastRowid; /* ROWID of most recent insert (see above) */
  9315. unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
  9316. int errCode; /* Most recent error code (SQLITE_*) */
  9317. int errMask; /* & result codes with this before returning */
  9318. u8 autoCommit; /* The auto-commit flag. */
  9319. u8 temp_store; /* 1: file 2: memory 0: default */
  9320. u8 mallocFailed; /* True if we have seen a malloc failure */
  9321. u8 dfltLockMode; /* Default locking-mode for attached dbs */
  9322. signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
  9323. u8 suppressErr; /* Do not issue error messages if true */
  9324. u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */
  9325. u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */
  9326. int nextPagesize; /* Pagesize after VACUUM if >0 */
  9327. u32 magic; /* Magic number for detect library misuse */
  9328. int nChange; /* Value returned by sqlite3_changes() */
  9329. int nTotalChange; /* Value returned by sqlite3_total_changes() */
  9330. int aLimit[SQLITE_N_LIMIT]; /* Limits */
  9331. struct sqlite3InitInfo { /* Information used during initialization */
  9332. int newTnum; /* Rootpage of table being initialized */
  9333. u8 iDb; /* Which db file is being initialized */
  9334. u8 busy; /* TRUE if currently initializing */
  9335. u8 orphanTrigger; /* Last statement is orphaned TEMP trigger */
  9336. } init;
  9337. int activeVdbeCnt; /* Number of VDBEs currently executing */
  9338. int writeVdbeCnt; /* Number of active VDBEs that are writing */
  9339. int vdbeExecCnt; /* Number of nested calls to VdbeExec() */
  9340. int nExtension; /* Number of loaded extensions */
  9341. void **aExtension; /* Array of shared library handles */
  9342. void (*xTrace)(void*,const char*); /* Trace function */
  9343. void *pTraceArg; /* Argument to the trace function */
  9344. void (*xProfile)(void*,const char*,u64); /* Profiling function */
  9345. void *pProfileArg; /* Argument to profile function */
  9346. void *pCommitArg; /* Argument to xCommitCallback() */
  9347. int (*xCommitCallback)(void*); /* Invoked at every commit. */
  9348. void *pRollbackArg; /* Argument to xRollbackCallback() */
  9349. void (*xRollbackCallback)(void*); /* Invoked at every commit. */
  9350. void *pUpdateArg;
  9351. void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64);
  9352. #ifndef SQLITE_OMIT_WAL
  9353. int (*xWalCallback)(void *, sqlite3 *, const char *, int);
  9354. void *pWalArg;
  9355. #endif
  9356. void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
  9357. void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
  9358. void *pCollNeededArg;
  9359. sqlite3_value *pErr; /* Most recent error message */
  9360. char *zErrMsg; /* Most recent error message (UTF-8 encoded) */
  9361. char *zErrMsg16; /* Most recent error message (UTF-16 encoded) */
  9362. union {
  9363. volatile int isInterrupted; /* True if sqlite3_interrupt has been called */
  9364. double notUsed1; /* Spacer */
  9365. } u1;
  9366. Lookaside lookaside; /* Lookaside malloc configuration */
  9367. #ifndef SQLITE_OMIT_AUTHORIZATION
  9368. int (*xAuth)(void*,int,const char*,const char*,const char*,const char*);
  9369. /* Access authorization function */
  9370. void *pAuthArg; /* 1st argument to the access auth function */
  9371. #endif
  9372. #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
  9373. int (*xProgress)(void *); /* The progress callback */
  9374. void *pProgressArg; /* Argument to the progress callback */
  9375. int nProgressOps; /* Number of opcodes for progress callback */
  9376. #endif
  9377. #ifndef SQLITE_OMIT_VIRTUALTABLE
  9378. int nVTrans; /* Allocated size of aVTrans */
  9379. Hash aModule; /* populated by sqlite3_create_module() */
  9380. VtabCtx *pVtabCtx; /* Context for active vtab connect/create */
  9381. VTable **aVTrans; /* Virtual tables with open transactions */
  9382. VTable *pDisconnect; /* Disconnect these in next sqlite3_prepare() */
  9383. #endif
  9384. FuncDefHash aFunc; /* Hash table of connection functions */
  9385. Hash aCollSeq; /* All collating sequences */
  9386. BusyHandler busyHandler; /* Busy callback */
  9387. Db aDbStatic[2]; /* Static space for the 2 default backends */
  9388. Savepoint *pSavepoint; /* List of active savepoints */
  9389. int busyTimeout; /* Busy handler timeout, in msec */
  9390. int nSavepoint; /* Number of non-transaction savepoints */
  9391. int nStatement; /* Number of nested statement-transactions */
  9392. i64 nDeferredCons; /* Net deferred constraints this transaction. */
  9393. int *pnBytesFreed; /* If not NULL, increment this in DbFree() */
  9394. #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
  9395. /* The following variables are all protected by the STATIC_MASTER
  9396. ** mutex, not by sqlite3.mutex. They are used by code in notify.c.
  9397. **
  9398. ** When X.pUnlockConnection==Y, that means that X is waiting for Y to
  9399. ** unlock so that it can proceed.
  9400. **
  9401. ** When X.pBlockingConnection==Y, that means that something that X tried
  9402. ** tried to do recently failed with an SQLITE_LOCKED error due to locks
  9403. ** held by Y.
  9404. */
  9405. sqlite3 *pBlockingConnection; /* Connection that caused SQLITE_LOCKED */
  9406. sqlite3 *pUnlockConnection; /* Connection to watch for unlock */
  9407. void *pUnlockArg; /* Argument to xUnlockNotify */
  9408. void (*xUnlockNotify)(void **, int); /* Unlock notify callback */
  9409. sqlite3 *pNextBlocked; /* Next in list of all blocked connections */
  9410. #endif
  9411. };
  9412. /*
  9413. ** A macro to discover the encoding of a database.
  9414. */
  9415. #define ENC(db) ((db)->aDb[0].pSchema->enc)
  9416. /*
  9417. ** Possible values for the sqlite3.flags.
  9418. */
  9419. #define SQLITE_VdbeTrace 0x00000100 /* True to trace VDBE execution */
  9420. #define SQLITE_InternChanges 0x00000200 /* Uncommitted Hash table changes */
  9421. #define SQLITE_FullColNames 0x00000400 /* Show full column names on SELECT */
  9422. #define SQLITE_ShortColNames 0x00000800 /* Show short columns names */
  9423. #define SQLITE_CountRows 0x00001000 /* Count rows changed by INSERT, */
  9424. /* DELETE, or UPDATE and return */
  9425. /* the count using a callback. */
  9426. #define SQLITE_NullCallback 0x00002000 /* Invoke the callback once if the */
  9427. /* result set is empty */
  9428. #define SQLITE_SqlTrace 0x00004000 /* Debug print SQL as it executes */
  9429. #define SQLITE_VdbeListing 0x00008000 /* Debug listings of VDBE programs */
  9430. #define SQLITE_WriteSchema 0x00010000 /* OK to update SQLITE_MASTER */
  9431. /* 0x00020000 Unused */
  9432. #define SQLITE_IgnoreChecks 0x00040000 /* Do not enforce check constraints */
  9433. #define SQLITE_ReadUncommitted 0x0080000 /* For shared-cache mode */
  9434. #define SQLITE_LegacyFileFmt 0x00100000 /* Create new databases in format 1 */
  9435. #define SQLITE_FullFSync 0x00200000 /* Use full fsync on the backend */
  9436. #define SQLITE_CkptFullFSync 0x00400000 /* Use full fsync for checkpoint */
  9437. #define SQLITE_RecoveryMode 0x00800000 /* Ignore schema errors */
  9438. #define SQLITE_ReverseOrder 0x01000000 /* Reverse unordered SELECTs */
  9439. #define SQLITE_RecTriggers 0x02000000 /* Enable recursive triggers */
  9440. #define SQLITE_ForeignKeys 0x04000000 /* Enforce foreign key constraints */
  9441. #define SQLITE_AutoIndex 0x08000000 /* Enable automatic indexes */
  9442. #define SQLITE_PreferBuiltin 0x10000000 /* Preference to built-in funcs */
  9443. #define SQLITE_LoadExtension 0x20000000 /* Enable load_extension */
  9444. #define SQLITE_EnableTrigger 0x40000000 /* True to enable triggers */
  9445. /*
  9446. ** Bits of the sqlite3.flags field that are used by the
  9447. ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface.
  9448. ** These must be the low-order bits of the flags field.
  9449. */
  9450. #define SQLITE_QueryFlattener 0x01 /* Disable query flattening */
  9451. #define SQLITE_ColumnCache 0x02 /* Disable the column cache */
  9452. #define SQLITE_IndexSort 0x04 /* Disable indexes for sorting */
  9453. #define SQLITE_IndexSearch 0x08 /* Disable indexes for searching */
  9454. #define SQLITE_IndexCover 0x10 /* Disable index covering table */
  9455. #define SQLITE_GroupByOrder 0x20 /* Disable GROUPBY cover of ORDERBY */
  9456. #define SQLITE_FactorOutConst 0x40 /* Disable factoring out constants */
  9457. #define SQLITE_IdxRealAsInt 0x80 /* Store REAL as INT in indices */
  9458. #define SQLITE_DistinctOpt 0x80 /* DISTINCT using indexes */
  9459. #define SQLITE_OptMask 0xff /* Mask of all disablable opts */
  9460. /*
  9461. ** Possible values for the sqlite.magic field.
  9462. ** The numbers are obtained at random and have no special meaning, other
  9463. ** than being distinct from one another.
  9464. */
  9465. #define SQLITE_MAGIC_OPEN 0xa029a697 /* Database is open */
  9466. #define SQLITE_MAGIC_CLOSED 0x9f3c2d33 /* Database is closed */
  9467. #define SQLITE_MAGIC_SICK 0x4b771290 /* Error and awaiting close */
  9468. #define SQLITE_MAGIC_BUSY 0xf03b7906 /* Database currently in use */
  9469. #define SQLITE_MAGIC_ERROR 0xb5357930 /* An SQLITE_MISUSE error occurred */
  9470. /*
  9471. ** Each SQL function is defined by an instance of the following
  9472. ** structure. A pointer to this structure is stored in the sqlite.aFunc
  9473. ** hash table. When multiple functions have the same name, the hash table
  9474. ** points to a linked list of these structures.
  9475. */
  9476. struct FuncDef {
  9477. i16 nArg; /* Number of arguments. -1 means unlimited */
  9478. u8 iPrefEnc; /* Preferred text encoding (SQLITE_UTF8, 16LE, 16BE) */
  9479. u8 flags; /* Some combination of SQLITE_FUNC_* */
  9480. void *pUserData; /* User data parameter */
  9481. FuncDef *pNext; /* Next function with same name */
  9482. void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */
  9483. void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */
  9484. void (*xFinalize)(sqlite3_context*); /* Aggregate finalizer */
  9485. char *zName; /* SQL name of the function. */
  9486. FuncDef *pHash; /* Next with a different name but the same hash */
  9487. FuncDestructor *pDestructor; /* Reference counted destructor function */
  9488. };
  9489. /*
  9490. ** This structure encapsulates a user-function destructor callback (as
  9491. ** configured using create_function_v2()) and a reference counter. When
  9492. ** create_function_v2() is called to create a function with a destructor,
  9493. ** a single object of this type is allocated. FuncDestructor.nRef is set to
  9494. ** the number of FuncDef objects created (either 1 or 3, depending on whether
  9495. ** or not the specified encoding is SQLITE_ANY). The FuncDef.pDestructor
  9496. ** member of each of the new FuncDef objects is set to point to the allocated
  9497. ** FuncDestructor.
  9498. **
  9499. ** Thereafter, when one of the FuncDef objects is deleted, the reference
  9500. ** count on this object is decremented. When it reaches 0, the destructor
  9501. ** is invoked and the FuncDestructor structure freed.
  9502. */
  9503. struct FuncDestructor {
  9504. int nRef;
  9505. void (*xDestroy)(void *);
  9506. void *pUserData;
  9507. };
  9508. /*
  9509. ** Possible values for FuncDef.flags
  9510. */
  9511. #define SQLITE_FUNC_LIKE 0x01 /* Candidate for the LIKE optimization */
  9512. #define SQLITE_FUNC_CASE 0x02 /* Case-sensitive LIKE-type function */
  9513. #define SQLITE_FUNC_EPHEM 0x04 /* Ephemeral. Delete with VDBE */
  9514. #define SQLITE_FUNC_NEEDCOLL 0x08 /* sqlite3GetFuncCollSeq() might be called */
  9515. #define SQLITE_FUNC_COUNT 0x20 /* Built-in count(*) aggregate */
  9516. #define SQLITE_FUNC_COALESCE 0x40 /* Built-in coalesce() or ifnull() function */
  9517. /*
  9518. ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
  9519. ** used to create the initializers for the FuncDef structures.
  9520. **
  9521. ** FUNCTION(zName, nArg, iArg, bNC, xFunc)
  9522. ** Used to create a scalar function definition of a function zName
  9523. ** implemented by C function xFunc that accepts nArg arguments. The
  9524. ** value passed as iArg is cast to a (void*) and made available
  9525. ** as the user-data (sqlite3_user_data()) for the function. If
  9526. ** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
  9527. **
  9528. ** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
  9529. ** Used to create an aggregate function definition implemented by
  9530. ** the C functions xStep and xFinal. The first four parameters
  9531. ** are interpreted in the same way as the first 4 parameters to
  9532. ** FUNCTION().
  9533. **
  9534. ** LIKEFUNC(zName, nArg, pArg, flags)
  9535. ** Used to create a scalar function definition of a function zName
  9536. ** that accepts nArg arguments and is implemented by a call to C
  9537. ** function likeFunc. Argument pArg is cast to a (void *) and made
  9538. ** available as the function user-data (sqlite3_user_data()). The
  9539. ** FuncDef.flags variable is set to the value passed as the flags
  9540. ** parameter.
  9541. */
  9542. #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
  9543. {nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \
  9544. SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
  9545. #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
  9546. {nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \
  9547. pArg, 0, xFunc, 0, 0, #zName, 0, 0}
  9548. #define LIKEFUNC(zName, nArg, arg, flags) \
  9549. {nArg, SQLITE_UTF8, flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
  9550. #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
  9551. {nArg, SQLITE_UTF8, nc*SQLITE_FUNC_NEEDCOLL, \
  9552. SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
  9553. /*
  9554. ** All current savepoints are stored in a linked list starting at
  9555. ** sqlite3.pSavepoint. The first element in the list is the most recently
  9556. ** opened savepoint. Savepoints are added to the list by the vdbe
  9557. ** OP_Savepoint instruction.
  9558. */
  9559. struct Savepoint {
  9560. char *zName; /* Savepoint name (nul-terminated) */
  9561. i64 nDeferredCons; /* Number of deferred fk violations */
  9562. Savepoint *pNext; /* Parent savepoint (if any) */
  9563. };
  9564. /*
  9565. ** The following are used as the second parameter to sqlite3Savepoint(),
  9566. ** and as the P1 argument to the OP_Savepoint instruction.
  9567. */
  9568. #define SAVEPOINT_BEGIN 0
  9569. #define SAVEPOINT_RELEASE 1
  9570. #define SAVEPOINT_ROLLBACK 2
  9571. /*
  9572. ** Each SQLite module (virtual table definition) is defined by an
  9573. ** instance of the following structure, stored in the sqlite3.aModule
  9574. ** hash table.
  9575. */
  9576. struct Module {
  9577. const sqlite3_module *pModule; /* Callback pointers */
  9578. const char *zName; /* Name passed to create_module() */
  9579. void *pAux; /* pAux passed to create_module() */
  9580. void (*xDestroy)(void *); /* Module destructor function */
  9581. };
  9582. /*
  9583. ** information about each column of an SQL table is held in an instance
  9584. ** of this structure.
  9585. */
  9586. struct Column {
  9587. char *zName; /* Name of this column */
  9588. Expr *pDflt; /* Default value of this column */
  9589. char *zDflt; /* Original text of the default value */
  9590. char *zType; /* Data type for this column */
  9591. char *zColl; /* Collating sequence. If NULL, use the default */
  9592. u8 notNull; /* True if there is a NOT NULL constraint */
  9593. u8 isPrimKey; /* True if this column is part of the PRIMARY KEY */
  9594. char affinity; /* One of the SQLITE_AFF_... values */
  9595. #ifndef SQLITE_OMIT_VIRTUALTABLE
  9596. u8 isHidden; /* True if this column is 'hidden' */
  9597. #endif
  9598. };
  9599. /*
  9600. ** A "Collating Sequence" is defined by an instance of the following
  9601. ** structure. Conceptually, a collating sequence consists of a name and
  9602. ** a comparison routine that defines the order of that sequence.
  9603. **
  9604. ** There may two separate implementations of the collation function, one
  9605. ** that processes text in UTF-8 encoding (CollSeq.xCmp) and another that
  9606. ** processes text encoded in UTF-16 (CollSeq.xCmp16), using the machine
  9607. ** native byte order. When a collation sequence is invoked, SQLite selects
  9608. ** the version that will require the least expensive encoding
  9609. ** translations, if any.
  9610. **
  9611. ** The CollSeq.pUser member variable is an extra parameter that passed in
  9612. ** as the first argument to the UTF-8 comparison function, xCmp.
  9613. ** CollSeq.pUser16 is the equivalent for the UTF-16 comparison function,
  9614. ** xCmp16.
  9615. **
  9616. ** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the
  9617. ** collating sequence is undefined. Indices built on an undefined
  9618. ** collating sequence may not be read or written.
  9619. */
  9620. struct CollSeq {
  9621. char *zName; /* Name of the collating sequence, UTF-8 encoded */
  9622. u8 enc; /* Text encoding handled by xCmp() */
  9623. void *pUser; /* First argument to xCmp() */
  9624. int (*xCmp)(void*,int, const void*, int, const void*);
  9625. void (*xDel)(void*); /* Destructor for pUser */
  9626. };
  9627. /*
  9628. ** A sort order can be either ASC or DESC.
  9629. */
  9630. #define SQLITE_SO_ASC 0 /* Sort in ascending order */
  9631. #define SQLITE_SO_DESC 1 /* Sort in ascending order */
  9632. /*
  9633. ** Column affinity types.
  9634. **
  9635. ** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and
  9636. ** 't' for SQLITE_AFF_TEXT. But we can save a little space and improve
  9637. ** the speed a little by numbering the values consecutively.
  9638. **
  9639. ** But rather than start with 0 or 1, we begin with 'a'. That way,
  9640. ** when multiple affinity types are concatenated into a string and
  9641. ** used as the P4 operand, they will be more readable.
  9642. **
  9643. ** Note also that the numeric types are grouped together so that testing
  9644. ** for a numeric type is a single comparison.
  9645. */
  9646. #define SQLITE_AFF_TEXT 'a'
  9647. #define SQLITE_AFF_NONE 'b'
  9648. #define SQLITE_AFF_NUMERIC 'c'
  9649. #define SQLITE_AFF_INTEGER 'd'
  9650. #define SQLITE_AFF_REAL 'e'
  9651. #define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC)
  9652. /*
  9653. ** The SQLITE_AFF_MASK values masks off the significant bits of an
  9654. ** affinity value.
  9655. */
  9656. #define SQLITE_AFF_MASK 0x67
  9657. /*
  9658. ** Additional bit values that can be ORed with an affinity without
  9659. ** changing the affinity.
  9660. */
  9661. #define SQLITE_JUMPIFNULL 0x08 /* jumps if either operand is NULL */
  9662. #define SQLITE_STOREP2 0x10 /* Store result in reg[P2] rather than jump */
  9663. #define SQLITE_NULLEQ 0x80 /* NULL=NULL */
  9664. /*
  9665. ** An object of this type is created for each virtual table present in
  9666. ** the database schema.
  9667. **
  9668. ** If the database schema is shared, then there is one instance of this
  9669. ** structure for each database connection (sqlite3*) that uses the shared
  9670. ** schema. This is because each database connection requires its own unique
  9671. ** instance of the sqlite3_vtab* handle used to access the virtual table
  9672. ** implementation. sqlite3_vtab* handles can not be shared between
  9673. ** database connections, even when the rest of the in-memory database
  9674. ** schema is shared, as the implementation often stores the database
  9675. ** connection handle passed to it via the xConnect() or xCreate() method
  9676. ** during initialization internally. This database connection handle may
  9677. ** then be used by the virtual table implementation to access real tables
  9678. ** within the database. So that they appear as part of the callers
  9679. ** transaction, these accesses need to be made via the same database
  9680. ** connection as that used to execute SQL operations on the virtual table.
  9681. **
  9682. ** All VTable objects that correspond to a single table in a shared
  9683. ** database schema are initially stored in a linked-list pointed to by
  9684. ** the Table.pVTable member variable of the corresponding Table object.
  9685. ** When an sqlite3_prepare() operation is required to access the virtual
  9686. ** table, it searches the list for the VTable that corresponds to the
  9687. ** database connection doing the preparing so as to use the correct
  9688. ** sqlite3_vtab* handle in the compiled query.
  9689. **
  9690. ** When an in-memory Table object is deleted (for example when the
  9691. ** schema is being reloaded for some reason), the VTable objects are not
  9692. ** deleted and the sqlite3_vtab* handles are not xDisconnect()ed
  9693. ** immediately. Instead, they are moved from the Table.pVTable list to
  9694. ** another linked list headed by the sqlite3.pDisconnect member of the
  9695. ** corresponding sqlite3 structure. They are then deleted/xDisconnected
  9696. ** next time a statement is prepared using said sqlite3*. This is done
  9697. ** to avoid deadlock issues involving multiple sqlite3.mutex mutexes.
  9698. ** Refer to comments above function sqlite3VtabUnlockList() for an
  9699. ** explanation as to why it is safe to add an entry to an sqlite3.pDisconnect
  9700. ** list without holding the corresponding sqlite3.mutex mutex.
  9701. **
  9702. ** The memory for objects of this type is always allocated by
  9703. ** sqlite3DbMalloc(), using the connection handle stored in VTable.db as
  9704. ** the first argument.
  9705. */
  9706. struct VTable {
  9707. sqlite3 *db; /* Database connection associated with this table */
  9708. Module *pMod; /* Pointer to module implementation */
  9709. sqlite3_vtab *pVtab; /* Pointer to vtab instance */
  9710. int nRef; /* Number of pointers to this structure */
  9711. u8 bConstraint; /* True if constraints are supported */
  9712. int iSavepoint; /* Depth of the SAVEPOINT stack */
  9713. VTable *pNext; /* Next in linked list (see above) */
  9714. };
  9715. /*
  9716. ** Each SQL table is represented in memory by an instance of the
  9717. ** following structure.
  9718. **
  9719. ** Table.zName is the name of the table. The case of the original
  9720. ** CREATE TABLE statement is stored, but case is not significant for
  9721. ** comparisons.
  9722. **
  9723. ** Table.nCol is the number of columns in this table. Table.aCol is a
  9724. ** pointer to an array of Column structures, one for each column.
  9725. **
  9726. ** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of
  9727. ** the column that is that key. Otherwise Table.iPKey is negative. Note
  9728. ** that the datatype of the PRIMARY KEY must be INTEGER for this field to
  9729. ** be set. An INTEGER PRIMARY KEY is used as the rowid for each row of
  9730. ** the table. If a table has no INTEGER PRIMARY KEY, then a random rowid
  9731. ** is generated for each row of the table. TF_HasPrimaryKey is set if
  9732. ** the table has any PRIMARY KEY, INTEGER or otherwise.
  9733. **
  9734. ** Table.tnum is the page number for the root BTree page of the table in the
  9735. ** database file. If Table.iDb is the index of the database table backend
  9736. ** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that
  9737. ** holds temporary tables and indices. If TF_Ephemeral is set
  9738. ** then the table is stored in a file that is automatically deleted
  9739. ** when the VDBE cursor to the table is closed. In this case Table.tnum
  9740. ** refers VDBE cursor number that holds the table open, not to the root
  9741. ** page number. Transient tables are used to hold the results of a
  9742. ** sub-query that appears instead of a real table name in the FROM clause
  9743. ** of a SELECT statement.
  9744. */
  9745. struct Table {
  9746. char *zName; /* Name of the table or view */
  9747. int iPKey; /* If not negative, use aCol[iPKey] as the primary key */
  9748. int nCol; /* Number of columns in this table */
  9749. Column *aCol; /* Information about each column */
  9750. Index *pIndex; /* List of SQL indexes on this table. */
  9751. int tnum; /* Root BTree node for this table (see note above) */
  9752. tRowcnt nRowEst; /* Estimated rows in table - from sqlite_stat1 table */
  9753. Select *pSelect; /* NULL for tables. Points to definition if a view. */
  9754. u16 nRef; /* Number of pointers to this Table */
  9755. u8 tabFlags; /* Mask of TF_* values */
  9756. u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
  9757. FKey *pFKey; /* Linked list of all foreign keys in this table */
  9758. char *zColAff; /* String defining the affinity of each column */
  9759. #ifndef SQLITE_OMIT_CHECK
  9760. Expr *pCheck; /* The AND of all CHECK constraints */
  9761. #endif
  9762. #ifndef SQLITE_OMIT_ALTERTABLE
  9763. int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
  9764. #endif
  9765. #ifndef SQLITE_OMIT_VIRTUALTABLE
  9766. VTable *pVTable; /* List of VTable objects. */
  9767. int nModuleArg; /* Number of arguments to the module */
  9768. char **azModuleArg; /* Text of all module args. [0] is module name */
  9769. #endif
  9770. Trigger *pTrigger; /* List of triggers stored in pSchema */
  9771. Schema *pSchema; /* Schema that contains this table */
  9772. Table *pNextZombie; /* Next on the Parse.pZombieTab list */
  9773. };
  9774. /*
  9775. ** Allowed values for Tabe.tabFlags.
  9776. */
  9777. #define TF_Readonly 0x01 /* Read-only system table */
  9778. #define TF_Ephemeral 0x02 /* An ephemeral table */
  9779. #define TF_HasPrimaryKey 0x04 /* Table has a primary key */
  9780. #define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */
  9781. #define TF_Virtual 0x10 /* Is a virtual table */
  9782. /*
  9783. ** Test to see whether or not a table is a virtual table. This is
  9784. ** done as a macro so that it will be optimized out when virtual
  9785. ** table support is omitted from the build.
  9786. */
  9787. #ifndef SQLITE_OMIT_VIRTUALTABLE
  9788. # define IsVirtual(X) (((X)->tabFlags & TF_Virtual)!=0)
  9789. # define IsHiddenColumn(X) ((X)->isHidden)
  9790. #else
  9791. # define IsVirtual(X) 0
  9792. # define IsHiddenColumn(X) 0
  9793. #endif
  9794. /*
  9795. ** Each foreign key constraint is an instance of the following structure.
  9796. **
  9797. ** A foreign key is associated with two tables. The "from" table is
  9798. ** the table that contains the REFERENCES clause that creates the foreign
  9799. ** key. The "to" table is the table that is named in the REFERENCES clause.
  9800. ** Consider this example:
  9801. **
  9802. ** CREATE TABLE ex1(
  9803. ** a INTEGER PRIMARY KEY,
  9804. ** b INTEGER CONSTRAINT fk1 REFERENCES ex2(x)
  9805. ** );
  9806. **
  9807. ** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2".
  9808. **
  9809. ** Each REFERENCES clause generates an instance of the following structure
  9810. ** which is attached to the from-table. The to-table need not exist when
  9811. ** the from-table is created. The existence of the to-table is not checked.
  9812. */
  9813. struct FKey {
  9814. Table *pFrom; /* Table containing the REFERENCES clause (aka: Child) */
  9815. FKey *pNextFrom; /* Next foreign key in pFrom */
  9816. char *zTo; /* Name of table that the key points to (aka: Parent) */
  9817. FKey *pNextTo; /* Next foreign key on table named zTo */
  9818. FKey *pPrevTo; /* Previous foreign key on table named zTo */
  9819. int nCol; /* Number of columns in this key */
  9820. /* EV: R-30323-21917 */
  9821. u8 isDeferred; /* True if constraint checking is deferred till COMMIT */
  9822. u8 aAction[2]; /* ON DELETE and ON UPDATE actions, respectively */
  9823. Trigger *apTrigger[2]; /* Triggers for aAction[] actions */
  9824. struct sColMap { /* Mapping of columns in pFrom to columns in zTo */
  9825. int iFrom; /* Index of column in pFrom */
  9826. char *zCol; /* Name of column in zTo. If 0 use PRIMARY KEY */
  9827. } aCol[1]; /* One entry for each of nCol column s */
  9828. };
  9829. /*
  9830. ** SQLite supports many different ways to resolve a constraint
  9831. ** error. ROLLBACK processing means that a constraint violation
  9832. ** causes the operation in process to fail and for the current transaction
  9833. ** to be rolled back. ABORT processing means the operation in process
  9834. ** fails and any prior changes from that one operation are backed out,
  9835. ** but the transaction is not rolled back. FAIL processing means that
  9836. ** the operation in progress stops and returns an error code. But prior
  9837. ** changes due to the same operation are not backed out and no rollback
  9838. ** occurs. IGNORE means that the particular row that caused the constraint
  9839. ** error is not inserted or updated. Processing continues and no error
  9840. ** is returned. REPLACE means that preexisting database rows that caused
  9841. ** a UNIQUE constraint violation are removed so that the new insert or
  9842. ** update can proceed. Processing continues and no error is reported.
  9843. **
  9844. ** RESTRICT, SETNULL, and CASCADE actions apply only to foreign keys.
  9845. ** RESTRICT is the same as ABORT for IMMEDIATE foreign keys and the
  9846. ** same as ROLLBACK for DEFERRED keys. SETNULL means that the foreign
  9847. ** key is set to NULL. CASCADE means that a DELETE or UPDATE of the
  9848. ** referenced table row is propagated into the row that holds the
  9849. ** foreign key.
  9850. **
  9851. ** The following symbolic values are used to record which type
  9852. ** of action to take.
  9853. */
  9854. #define OE_None 0 /* There is no constraint to check */
  9855. #define OE_Rollback 1 /* Fail the operation and rollback the transaction */
  9856. #define OE_Abort 2 /* Back out changes but do no rollback transaction */
  9857. #define OE_Fail 3 /* Stop the operation but leave all prior changes */
  9858. #define OE_Ignore 4 /* Ignore the error. Do not do the INSERT or UPDATE */
  9859. #define OE_Replace 5 /* Delete existing record, then do INSERT or UPDATE */
  9860. #define OE_Restrict 6 /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */
  9861. #define OE_SetNull 7 /* Set the foreign key value to NULL */
  9862. #define OE_SetDflt 8 /* Set the foreign key value to its default */
  9863. #define OE_Cascade 9 /* Cascade the changes */
  9864. #define OE_Default 99 /* Do whatever the default action is */
  9865. /*
  9866. ** An instance of the following structure is passed as the first
  9867. ** argument to sqlite3VdbeKeyCompare and is used to control the
  9868. ** comparison of the two index keys.
  9869. */
  9870. struct KeyInfo {
  9871. sqlite3 *db; /* The database connection */
  9872. u8 enc; /* Text encoding - one of the SQLITE_UTF* values */
  9873. u16 nField; /* Number of entries in aColl[] */
  9874. u8 *aSortOrder; /* Sort order for each column. May be NULL */
  9875. CollSeq *aColl[1]; /* Collating sequence for each term of the key */
  9876. };
  9877. /*
  9878. ** An instance of the following structure holds information about a
  9879. ** single index record that has already been parsed out into individual
  9880. ** values.
  9881. **
  9882. ** A record is an object that contains one or more fields of data.
  9883. ** Records are used to store the content of a table row and to store
  9884. ** the key of an index. A blob encoding of a record is created by
  9885. ** the OP_MakeRecord opcode of the VDBE and is disassembled by the
  9886. ** OP_Column opcode.
  9887. **
  9888. ** This structure holds a record that has already been disassembled
  9889. ** into its constituent fields.
  9890. */
  9891. struct UnpackedRecord {
  9892. KeyInfo *pKeyInfo; /* Collation and sort-order information */
  9893. u16 nField; /* Number of entries in apMem[] */
  9894. u8 flags; /* Boolean settings. UNPACKED_... below */
  9895. i64 rowid; /* Used by UNPACKED_PREFIX_SEARCH */
  9896. Mem *aMem; /* Values */
  9897. };
  9898. /*
  9899. ** Allowed values of UnpackedRecord.flags
  9900. */
  9901. #define UNPACKED_INCRKEY 0x01 /* Make this key an epsilon larger */
  9902. #define UNPACKED_PREFIX_MATCH 0x02 /* A prefix match is considered OK */
  9903. #define UNPACKED_PREFIX_SEARCH 0x04 /* Ignore final (rowid) field */
  9904. /*
  9905. ** Each SQL index is represented in memory by an
  9906. ** instance of the following structure.
  9907. **
  9908. ** The columns of the table that are to be indexed are described
  9909. ** by the aiColumn[] field of this structure. For example, suppose
  9910. ** we have the following table and index:
  9911. **
  9912. ** CREATE TABLE Ex1(c1 int, c2 int, c3 text);
  9913. ** CREATE INDEX Ex2 ON Ex1(c3,c1);
  9914. **
  9915. ** In the Table structure describing Ex1, nCol==3 because there are
  9916. ** three columns in the table. In the Index structure describing
  9917. ** Ex2, nColumn==2 since 2 of the 3 columns of Ex1 are indexed.
  9918. ** The value of aiColumn is {2, 0}. aiColumn[0]==2 because the
  9919. ** first column to be indexed (c3) has an index of 2 in Ex1.aCol[].
  9920. ** The second column to be indexed (c1) has an index of 0 in
  9921. ** Ex1.aCol[], hence Ex2.aiColumn[1]==0.
  9922. **
  9923. ** The Index.onError field determines whether or not the indexed columns
  9924. ** must be unique and what to do if they are not. When Index.onError=OE_None,
  9925. ** it means this is not a unique index. Otherwise it is a unique index
  9926. ** and the value of Index.onError indicate the which conflict resolution
  9927. ** algorithm to employ whenever an attempt is made to insert a non-unique
  9928. ** element.
  9929. */
  9930. struct Index {
  9931. char *zName; /* Name of this index */
  9932. int *aiColumn; /* Which columns are used by this index. 1st is 0 */
  9933. tRowcnt *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */
  9934. Table *pTable; /* The SQL table being indexed */
  9935. char *zColAff; /* String defining the affinity of each column */
  9936. Index *pNext; /* The next index associated with the same table */
  9937. Schema *pSchema; /* Schema containing this index */
  9938. u8 *aSortOrder; /* Array of size Index.nColumn. True==DESC, False==ASC */
  9939. char **azColl; /* Array of collation sequence names for index */
  9940. int nColumn; /* Number of columns in the table used by this index */
  9941. int tnum; /* Page containing root of this index in database file */
  9942. u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
  9943. u8 autoIndex; /* True if is automatically created (ex: by UNIQUE) */
  9944. u8 bUnordered; /* Use this index for == or IN queries only */
  9945. #ifdef SQLITE_ENABLE_STAT3
  9946. int nSample; /* Number of elements in aSample[] */
  9947. tRowcnt avgEq; /* Average nEq value for key values not in aSample */
  9948. IndexSample *aSample; /* Samples of the left-most key */
  9949. #endif
  9950. };
  9951. /*
  9952. ** Each sample stored in the sqlite_stat3 table is represented in memory
  9953. ** using a structure of this type. See documentation at the top of the
  9954. ** analyze.c source file for additional information.
  9955. */
  9956. struct IndexSample {
  9957. union {
  9958. char *z; /* Value if eType is SQLITE_TEXT or SQLITE_BLOB */
  9959. double r; /* Value if eType is SQLITE_FLOAT */
  9960. i64 i; /* Value if eType is SQLITE_INTEGER */
  9961. } u;
  9962. u8 eType; /* SQLITE_NULL, SQLITE_INTEGER ... etc. */
  9963. int nByte; /* Size in byte of text or blob. */
  9964. tRowcnt nEq; /* Est. number of rows where the key equals this sample */
  9965. tRowcnt nLt; /* Est. number of rows where key is less than this sample */
  9966. tRowcnt nDLt; /* Est. number of distinct keys less than this sample */
  9967. };
  9968. /*
  9969. ** Each token coming out of the lexer is an instance of
  9970. ** this structure. Tokens are also used as part of an expression.
  9971. **
  9972. ** Note if Token.z==0 then Token.dyn and Token.n are undefined and
  9973. ** may contain random values. Do not make any assumptions about Token.dyn
  9974. ** and Token.n when Token.z==0.
  9975. */
  9976. struct Token {
  9977. const char *z; /* Text of the token. Not NULL-terminated! */
  9978. unsigned int n; /* Number of characters in this token */
  9979. };
  9980. /*
  9981. ** An instance of this structure contains information needed to generate
  9982. ** code for a SELECT that contains aggregate functions.
  9983. **
  9984. ** If Expr.op==TK_AGG_COLUMN or TK_AGG_FUNCTION then Expr.pAggInfo is a
  9985. ** pointer to this structure. The Expr.iColumn field is the index in
  9986. ** AggInfo.aCol[] or AggInfo.aFunc[] of information needed to generate
  9987. ** code for that node.
  9988. **
  9989. ** AggInfo.pGroupBy and AggInfo.aFunc.pExpr point to fields within the
  9990. ** original Select structure that describes the SELECT statement. These
  9991. ** fields do not need to be freed when deallocating the AggInfo structure.
  9992. */
  9993. struct AggInfo {
  9994. u8 directMode; /* Direct rendering mode means take data directly
  9995. ** from source tables rather than from accumulators */
  9996. u8 useSortingIdx; /* In direct mode, reference the sorting index rather
  9997. ** than the source table */
  9998. int sortingIdx; /* Cursor number of the sorting index */
  9999. int sortingIdxPTab; /* Cursor number of pseudo-table */
  10000. int nSortingColumn; /* Number of columns in the sorting index */
  10001. ExprList *pGroupBy; /* The group by clause */
  10002. struct AggInfo_col { /* For each column used in source tables */
  10003. Table *pTab; /* Source table */
  10004. int iTable; /* Cursor number of the source table */
  10005. int iColumn; /* Column number within the source table */
  10006. int iSorterColumn; /* Column number in the sorting index */
  10007. int iMem; /* Memory location that acts as accumulator */
  10008. Expr *pExpr; /* The original expression */
  10009. } *aCol;
  10010. int nColumn; /* Number of used entries in aCol[] */
  10011. int nAccumulator; /* Number of columns that show through to the output.
  10012. ** Additional columns are used only as parameters to
  10013. ** aggregate functions */
  10014. struct AggInfo_func { /* For each aggregate function */
  10015. Expr *pExpr; /* Expression encoding the function */
  10016. FuncDef *pFunc; /* The aggregate function implementation */
  10017. int iMem; /* Memory location that acts as accumulator */
  10018. int iDistinct; /* Ephemeral table used to enforce DISTINCT */
  10019. } *aFunc;
  10020. int nFunc; /* Number of entries in aFunc[] */
  10021. };
  10022. /*
  10023. ** The datatype ynVar is a signed integer, either 16-bit or 32-bit.
  10024. ** Usually it is 16-bits. But if SQLITE_MAX_VARIABLE_NUMBER is greater
  10025. ** than 32767 we have to make it 32-bit. 16-bit is preferred because
  10026. ** it uses less memory in the Expr object, which is a big memory user
  10027. ** in systems with lots of prepared statements. And few applications
  10028. ** need more than about 10 or 20 variables. But some extreme users want
  10029. ** to have prepared statements with over 32767 variables, and for them
  10030. ** the option is available (at compile-time).
  10031. */
  10032. #if SQLITE_MAX_VARIABLE_NUMBER<=32767
  10033. typedef i16 ynVar;
  10034. #else
  10035. typedef int ynVar;
  10036. #endif
  10037. /*
  10038. ** Each node of an expression in the parse tree is an instance
  10039. ** of this structure.
  10040. **
  10041. ** Expr.op is the opcode. The integer parser token codes are reused
  10042. ** as opcodes here. For example, the parser defines TK_GE to be an integer
  10043. ** code representing the ">=" operator. This same integer code is reused
  10044. ** to represent the greater-than-or-equal-to operator in the expression
  10045. ** tree.
  10046. **
  10047. ** If the expression is an SQL literal (TK_INTEGER, TK_FLOAT, TK_BLOB,
  10048. ** or TK_STRING), then Expr.token contains the text of the SQL literal. If
  10049. ** the expression is a variable (TK_VARIABLE), then Expr.token contains the
  10050. ** variable name. Finally, if the expression is an SQL function (TK_FUNCTION),
  10051. ** then Expr.token contains the name of the function.
  10052. **
  10053. ** Expr.pRight and Expr.pLeft are the left and right subexpressions of a
  10054. ** binary operator. Either or both may be NULL.
  10055. **
  10056. ** Expr.x.pList is a list of arguments if the expression is an SQL function,
  10057. ** a CASE expression or an IN expression of the form "<lhs> IN (<y>, <z>...)".
  10058. ** Expr.x.pSelect is used if the expression is a sub-select or an expression of
  10059. ** the form "<lhs> IN (SELECT ...)". If the EP_xIsSelect bit is set in the
  10060. ** Expr.flags mask, then Expr.x.pSelect is valid. Otherwise, Expr.x.pList is
  10061. ** valid.
  10062. **
  10063. ** An expression of the form ID or ID.ID refers to a column in a table.
  10064. ** For such expressions, Expr.op is set to TK_COLUMN and Expr.iTable is
  10065. ** the integer cursor number of a VDBE cursor pointing to that table and
  10066. ** Expr.iColumn is the column number for the specific column. If the
  10067. ** expression is used as a result in an aggregate SELECT, then the
  10068. ** value is also stored in the Expr.iAgg column in the aggregate so that
  10069. ** it can be accessed after all aggregates are computed.
  10070. **
  10071. ** If the expression is an unbound variable marker (a question mark
  10072. ** character '?' in the original SQL) then the Expr.iTable holds the index
  10073. ** number for that variable.
  10074. **
  10075. ** If the expression is a subquery then Expr.iColumn holds an integer
  10076. ** register number containing the result of the subquery. If the
  10077. ** subquery gives a constant result, then iTable is -1. If the subquery
  10078. ** gives a different answer at different times during statement processing
  10079. ** then iTable is the address of a subroutine that computes the subquery.
  10080. **
  10081. ** If the Expr is of type OP_Column, and the table it is selecting from
  10082. ** is a disk table or the "old.*" pseudo-table, then pTab points to the
  10083. ** corresponding table definition.
  10084. **
  10085. ** ALLOCATION NOTES:
  10086. **
  10087. ** Expr objects can use a lot of memory space in database schema. To
  10088. ** help reduce memory requirements, sometimes an Expr object will be
  10089. ** truncated. And to reduce the number of memory allocations, sometimes
  10090. ** two or more Expr objects will be stored in a single memory allocation,
  10091. ** together with Expr.zToken strings.
  10092. **
  10093. ** If the EP_Reduced and EP_TokenOnly flags are set when
  10094. ** an Expr object is truncated. When EP_Reduced is set, then all
  10095. ** the child Expr objects in the Expr.pLeft and Expr.pRight subtrees
  10096. ** are contained within the same memory allocation. Note, however, that
  10097. ** the subtrees in Expr.x.pList or Expr.x.pSelect are always separately
  10098. ** allocated, regardless of whether or not EP_Reduced is set.
  10099. */
  10100. struct Expr {
  10101. u8 op; /* Operation performed by this node */
  10102. char affinity; /* The affinity of the column or 0 if not a column */
  10103. u16 flags; /* Various flags. EP_* See below */
  10104. union {
  10105. char *zToken; /* Token value. Zero terminated and dequoted */
  10106. int iValue; /* Non-negative integer value if EP_IntValue */
  10107. } u;
  10108. /* If the EP_TokenOnly flag is set in the Expr.flags mask, then no
  10109. ** space is allocated for the fields below this point. An attempt to
  10110. ** access them will result in a segfault or malfunction.
  10111. *********************************************************************/
  10112. Expr *pLeft; /* Left subnode */
  10113. Expr *pRight; /* Right subnode */
  10114. union {
  10115. ExprList *pList; /* Function arguments or in "<expr> IN (<expr-list)" */
  10116. Select *pSelect; /* Used for sub-selects and "<expr> IN (<select>)" */
  10117. } x;
  10118. CollSeq *pColl; /* The collation type of the column or 0 */
  10119. /* If the EP_Reduced flag is set in the Expr.flags mask, then no
  10120. ** space is allocated for the fields below this point. An attempt to
  10121. ** access them will result in a segfault or malfunction.
  10122. *********************************************************************/
  10123. int iTable; /* TK_COLUMN: cursor number of table holding column
  10124. ** TK_REGISTER: register number
  10125. ** TK_TRIGGER: 1 -> new, 0 -> old */
  10126. ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
  10127. ** TK_VARIABLE: variable number (always >= 1). */
  10128. i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
  10129. i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
  10130. u8 flags2; /* Second set of flags. EP2_... */
  10131. u8 op2; /* If a TK_REGISTER, the original value of Expr.op */
  10132. AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
  10133. Table *pTab; /* Table for TK_COLUMN expressions. */
  10134. #if SQLITE_MAX_EXPR_DEPTH>0
  10135. int nHeight; /* Height of the tree headed by this node */
  10136. #endif
  10137. };
  10138. /*
  10139. ** The following are the meanings of bits in the Expr.flags field.
  10140. */
  10141. #define EP_FromJoin 0x0001 /* Originated in ON or USING clause of a join */
  10142. #define EP_Agg 0x0002 /* Contains one or more aggregate functions */
  10143. #define EP_Resolved 0x0004 /* IDs have been resolved to COLUMNs */
  10144. #define EP_Error 0x0008 /* Expression contains one or more errors */
  10145. #define EP_Distinct 0x0010 /* Aggregate function with DISTINCT keyword */
  10146. #define EP_VarSelect 0x0020 /* pSelect is correlated, not constant */
  10147. #define EP_DblQuoted 0x0040 /* token.z was originally in "..." */
  10148. #define EP_InfixFunc 0x0080 /* True for an infix function: LIKE, GLOB, etc */
  10149. #define EP_ExpCollate 0x0100 /* Collating sequence specified explicitly */
  10150. #define EP_FixedDest 0x0200 /* Result needed in a specific register */
  10151. #define EP_IntValue 0x0400 /* Integer value contained in u.iValue */
  10152. #define EP_xIsSelect 0x0800 /* x.pSelect is valid (otherwise x.pList is) */
  10153. #define EP_Hint 0x1000 /* Optimizer hint. Not required for correctness */
  10154. #define EP_Reduced 0x2000 /* Expr struct is EXPR_REDUCEDSIZE bytes only */
  10155. #define EP_TokenOnly 0x4000 /* Expr struct is EXPR_TOKENONLYSIZE bytes only */
  10156. #define EP_Static 0x8000 /* Held in memory not obtained from malloc() */
  10157. /*
  10158. ** The following are the meanings of bits in the Expr.flags2 field.
  10159. */
  10160. #define EP2_MallocedToken 0x0001 /* Need to sqlite3DbFree() Expr.zToken */
  10161. #define EP2_Irreducible 0x0002 /* Cannot EXPRDUP_REDUCE this Expr */
  10162. /*
  10163. ** The pseudo-routine sqlite3ExprSetIrreducible sets the EP2_Irreducible
  10164. ** flag on an expression structure. This flag is used for VV&A only. The
  10165. ** routine is implemented as a macro that only works when in debugging mode,
  10166. ** so as not to burden production code.
  10167. */
  10168. #ifdef SQLITE_DEBUG
  10169. # define ExprSetIrreducible(X) (X)->flags2 |= EP2_Irreducible
  10170. #else
  10171. # define ExprSetIrreducible(X)
  10172. #endif
  10173. /*
  10174. ** These macros can be used to test, set, or clear bits in the
  10175. ** Expr.flags field.
  10176. */
  10177. #define ExprHasProperty(E,P) (((E)->flags&(P))==(P))
  10178. #define ExprHasAnyProperty(E,P) (((E)->flags&(P))!=0)
  10179. #define ExprSetProperty(E,P) (E)->flags|=(P)
  10180. #define ExprClearProperty(E,P) (E)->flags&=~(P)
  10181. /*
  10182. ** Macros to determine the number of bytes required by a normal Expr
  10183. ** struct, an Expr struct with the EP_Reduced flag set in Expr.flags
  10184. ** and an Expr struct with the EP_TokenOnly flag set.
  10185. */
  10186. #define EXPR_FULLSIZE sizeof(Expr) /* Full size */
  10187. #define EXPR_REDUCEDSIZE offsetof(Expr,iTable) /* Common features */
  10188. #define EXPR_TOKENONLYSIZE offsetof(Expr,pLeft) /* Fewer features */
  10189. /*
  10190. ** Flags passed to the sqlite3ExprDup() function. See the header comment
  10191. ** above sqlite3ExprDup() for details.
  10192. */
  10193. #define EXPRDUP_REDUCE 0x0001 /* Used reduced-size Expr nodes */
  10194. /*
  10195. ** A list of expressions. Each expression may optionally have a
  10196. ** name. An expr/name combination can be used in several ways, such
  10197. ** as the list of "expr AS ID" fields following a "SELECT" or in the
  10198. ** list of "ID = expr" items in an UPDATE. A list of expressions can
  10199. ** also be used as the argument to a function, in which case the a.zName
  10200. ** field is not used.
  10201. */
  10202. struct ExprList {
  10203. int nExpr; /* Number of expressions on the list */
  10204. int iECursor; /* VDBE Cursor associated with this ExprList */
  10205. struct ExprList_item { /* For each expression in the list */
  10206. Expr *pExpr; /* The list of expressions */
  10207. char *zName; /* Token associated with this expression */
  10208. char *zSpan; /* Original text of the expression */
  10209. u8 sortOrder; /* 1 for DESC or 0 for ASC */
  10210. u8 done; /* A flag to indicate when processing is finished */
  10211. u16 iOrderByCol; /* For ORDER BY, column number in result set */
  10212. u16 iAlias; /* Index into Parse.aAlias[] for zName */
  10213. } *a; /* Alloc a power of two greater or equal to nExpr */
  10214. };
  10215. /*
  10216. ** An instance of this structure is used by the parser to record both
  10217. ** the parse tree for an expression and the span of input text for an
  10218. ** expression.
  10219. */
  10220. struct ExprSpan {
  10221. Expr *pExpr; /* The expression parse tree */
  10222. const char *zStart; /* First character of input text */
  10223. const char *zEnd; /* One character past the end of input text */
  10224. };
  10225. /*
  10226. ** An instance of this structure can hold a simple list of identifiers,
  10227. ** such as the list "a,b,c" in the following statements:
  10228. **
  10229. ** INSERT INTO t(a,b,c) VALUES ...;
  10230. ** CREATE INDEX idx ON t(a,b,c);
  10231. ** CREATE TRIGGER trig BEFORE UPDATE ON t(a,b,c) ...;
  10232. **
  10233. ** The IdList.a.idx field is used when the IdList represents the list of
  10234. ** column names after a table name in an INSERT statement. In the statement
  10235. **
  10236. ** INSERT INTO t(a,b,c) ...
  10237. **
  10238. ** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
  10239. */
  10240. struct IdList {
  10241. struct IdList_item {
  10242. char *zName; /* Name of the identifier */
  10243. int idx; /* Index in some Table.aCol[] of a column named zName */
  10244. } *a;
  10245. int nId; /* Number of identifiers on the list */
  10246. };
  10247. /*
  10248. ** The bitmask datatype defined below is used for various optimizations.
  10249. **
  10250. ** Changing this from a 64-bit to a 32-bit type limits the number of
  10251. ** tables in a join to 32 instead of 64. But it also reduces the size
  10252. ** of the library by 738 bytes on ix86.
  10253. */
  10254. typedef u64 Bitmask;
  10255. /*
  10256. ** The number of bits in a Bitmask. "BMS" means "BitMask Size".
  10257. */
  10258. #define BMS ((int)(sizeof(Bitmask)*8))
  10259. /*
  10260. ** The following structure describes the FROM clause of a SELECT statement.
  10261. ** Each table or subquery in the FROM clause is a separate element of
  10262. ** the SrcList.a[] array.
  10263. **
  10264. ** With the addition of multiple database support, the following structure
  10265. ** can also be used to describe a particular table such as the table that
  10266. ** is modified by an INSERT, DELETE, or UPDATE statement. In standard SQL,
  10267. ** such a table must be a simple name: ID. But in SQLite, the table can
  10268. ** now be identified by a database name, a dot, then the table name: ID.ID.
  10269. **
  10270. ** The jointype starts out showing the join type between the current table
  10271. ** and the next table on the list. The parser builds the list this way.
  10272. ** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each
  10273. ** jointype expresses the join between the table and the previous table.
  10274. **
  10275. ** In the colUsed field, the high-order bit (bit 63) is set if the table
  10276. ** contains more than 63 columns and the 64-th or later column is used.
  10277. */
  10278. struct SrcList {
  10279. i16 nSrc; /* Number of tables or subqueries in the FROM clause */
  10280. i16 nAlloc; /* Number of entries allocated in a[] below */
  10281. struct SrcList_item {
  10282. char *zDatabase; /* Name of database holding this table */
  10283. char *zName; /* Name of the table */
  10284. char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */
  10285. Table *pTab; /* An SQL table corresponding to zName */
  10286. Select *pSelect; /* A SELECT statement used in place of a table name */
  10287. int addrFillSub; /* Address of subroutine to manifest a subquery */
  10288. int regReturn; /* Register holding return address of addrFillSub */
  10289. u8 jointype; /* Type of join between this able and the previous */
  10290. u8 notIndexed; /* True if there is a NOT INDEXED clause */
  10291. u8 isCorrelated; /* True if sub-query is correlated */
  10292. #ifndef SQLITE_OMIT_EXPLAIN
  10293. u8 iSelectId; /* If pSelect!=0, the id of the sub-select in EQP */
  10294. #endif
  10295. int iCursor; /* The VDBE cursor number used to access this table */
  10296. Expr *pOn; /* The ON clause of a join */
  10297. IdList *pUsing; /* The USING clause of a join */
  10298. Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
  10299. char *zIndex; /* Identifier from "INDEXED BY <zIndex>" clause */
  10300. Index *pIndex; /* Index structure corresponding to zIndex, if any */
  10301. } a[1]; /* One entry for each identifier on the list */
  10302. };
  10303. /*
  10304. ** Permitted values of the SrcList.a.jointype field
  10305. */
  10306. #define JT_INNER 0x0001 /* Any kind of inner or cross join */
  10307. #define JT_CROSS 0x0002 /* Explicit use of the CROSS keyword */
  10308. #define JT_NATURAL 0x0004 /* True for a "natural" join */
  10309. #define JT_LEFT 0x0008 /* Left outer join */
  10310. #define JT_RIGHT 0x0010 /* Right outer join */
  10311. #define JT_OUTER 0x0020 /* The "OUTER" keyword is present */
  10312. #define JT_ERROR 0x0040 /* unknown or unsupported join type */
  10313. /*
  10314. ** A WherePlan object holds information that describes a lookup
  10315. ** strategy.
  10316. **
  10317. ** This object is intended to be opaque outside of the where.c module.
  10318. ** It is included here only so that that compiler will know how big it
  10319. ** is. None of the fields in this object should be used outside of
  10320. ** the where.c module.
  10321. **
  10322. ** Within the union, pIdx is only used when wsFlags&WHERE_INDEXED is true.
  10323. ** pTerm is only used when wsFlags&WHERE_MULTI_OR is true. And pVtabIdx
  10324. ** is only used when wsFlags&WHERE_VIRTUALTABLE is true. It is never the
  10325. ** case that more than one of these conditions is true.
  10326. */
  10327. struct WherePlan {
  10328. u32 wsFlags; /* WHERE_* flags that describe the strategy */
  10329. u32 nEq; /* Number of == constraints */
  10330. double nRow; /* Estimated number of rows (for EQP) */
  10331. union {
  10332. Index *pIdx; /* Index when WHERE_INDEXED is true */
  10333. struct WhereTerm *pTerm; /* WHERE clause term for OR-search */
  10334. sqlite3_index_info *pVtabIdx; /* Virtual table index to use */
  10335. } u;
  10336. };
  10337. /*
  10338. ** For each nested loop in a WHERE clause implementation, the WhereInfo
  10339. ** structure contains a single instance of this structure. This structure
  10340. ** is intended to be private the the where.c module and should not be
  10341. ** access or modified by other modules.
  10342. **
  10343. ** The pIdxInfo field is used to help pick the best index on a
  10344. ** virtual table. The pIdxInfo pointer contains indexing
  10345. ** information for the i-th table in the FROM clause before reordering.
  10346. ** All the pIdxInfo pointers are freed by whereInfoFree() in where.c.
  10347. ** All other information in the i-th WhereLevel object for the i-th table
  10348. ** after FROM clause ordering.
  10349. */
  10350. struct WhereLevel {
  10351. WherePlan plan; /* query plan for this element of the FROM clause */
  10352. int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
  10353. int iTabCur; /* The VDBE cursor used to access the table */
  10354. int iIdxCur; /* The VDBE cursor used to access pIdx */
  10355. int addrBrk; /* Jump here to break out of the loop */
  10356. int addrNxt; /* Jump here to start the next IN combination */
  10357. int addrCont; /* Jump here to continue with the next loop cycle */
  10358. int addrFirst; /* First instruction of interior of the loop */
  10359. u8 iFrom; /* Which entry in the FROM clause */
  10360. u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */
  10361. int p1, p2; /* Operands of the opcode used to ends the loop */
  10362. union { /* Information that depends on plan.wsFlags */
  10363. struct {
  10364. int nIn; /* Number of entries in aInLoop[] */
  10365. struct InLoop {
  10366. int iCur; /* The VDBE cursor used by this IN operator */
  10367. int addrInTop; /* Top of the IN loop */
  10368. } *aInLoop; /* Information about each nested IN operator */
  10369. } in; /* Used when plan.wsFlags&WHERE_IN_ABLE */
  10370. } u;
  10371. /* The following field is really not part of the current level. But
  10372. ** we need a place to cache virtual table index information for each
  10373. ** virtual table in the FROM clause and the WhereLevel structure is
  10374. ** a convenient place since there is one WhereLevel for each FROM clause
  10375. ** element.
  10376. */
  10377. sqlite3_index_info *pIdxInfo; /* Index info for n-th source table */
  10378. };
  10379. /*
  10380. ** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin()
  10381. ** and the WhereInfo.wctrlFlags member.
  10382. */
  10383. #define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
  10384. #define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
  10385. #define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
  10386. #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
  10387. #define WHERE_DUPLICATES_OK 0x0008 /* Ok to return a row more than once */
  10388. #define WHERE_OMIT_OPEN_CLOSE 0x0010 /* Table cursors are already open */
  10389. #define WHERE_FORCE_TABLE 0x0020 /* Do not use an index-only search */
  10390. #define WHERE_ONETABLE_ONLY 0x0040 /* Only code the 1st table in pTabList */
  10391. #define WHERE_AND_ONLY 0x0080 /* Don't use indices for OR terms */
  10392. /*
  10393. ** The WHERE clause processing routine has two halves. The
  10394. ** first part does the start of the WHERE loop and the second
  10395. ** half does the tail of the WHERE loop. An instance of
  10396. ** this structure is returned by the first half and passed
  10397. ** into the second half to give some continuity.
  10398. */
  10399. struct WhereInfo {
  10400. Parse *pParse; /* Parsing and code generating context */
  10401. u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
  10402. u8 okOnePass; /* Ok to use one-pass algorithm for UPDATE or DELETE */
  10403. u8 untestedTerms; /* Not all WHERE terms resolved by outer loop */
  10404. u8 eDistinct;
  10405. SrcList *pTabList; /* List of tables in the join */
  10406. int iTop; /* The very beginning of the WHERE loop */
  10407. int iContinue; /* Jump here to continue with next record */
  10408. int iBreak; /* Jump here to break out of the loop */
  10409. int nLevel; /* Number of nested loop */
  10410. struct WhereClause *pWC; /* Decomposition of the WHERE clause */
  10411. double savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
  10412. double nRowOut; /* Estimated number of output rows */
  10413. WhereLevel a[1]; /* Information about each nest loop in WHERE */
  10414. };
  10415. #define WHERE_DISTINCT_UNIQUE 1
  10416. #define WHERE_DISTINCT_ORDERED 2
  10417. /*
  10418. ** A NameContext defines a context in which to resolve table and column
  10419. ** names. The context consists of a list of tables (the pSrcList) field and
  10420. ** a list of named expression (pEList). The named expression list may
  10421. ** be NULL. The pSrc corresponds to the FROM clause of a SELECT or