PageRenderTime 114ms CodeModel.GetById 35ms RepoModel.GetById 3ms app.codeStats 2ms

/security/nss/lib/sqlite/sqlite3.c

http://github.com/zpao/v8monkey
C | 10962 lines | 3602 code | 518 blank | 6842 comment | 55 complexity | 53baa8167f00ffeea2662d0515f72037 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, AGPL-1.0, LGPL-2.1, BSD-3-Clause, GPL-2.0, JSON, Apache-2.0, 0BSD

Large files files are truncated, but you can click here to view the full file

  1. /******************************************************************************
  2. ** This file is an amalgamation of many separate C source files from SQLite
  3. ** version 3.6.22. By combining all the individual C code files into this
  4. ** single large file, the entire code can be compiled as a one translation
  5. ** unit. This allows many compilers to do optimizations that would not be
  6. ** possible if the files were compiled separately. Performance improvements
  7. ** of 5% are more are commonly seen when SQLite is compiled as a single
  8. ** translation unit.
  9. **
  10. ** This file is all you need to compile SQLite. To use SQLite in other
  11. ** programs, you need this file and the "sqlite3.h" header file that defines
  12. ** the programming interface to the SQLite library. (If you do not have
  13. ** the "sqlite3.h" header file at hand, you will find a copy 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 maximum number of attached databases. This must be between 0
  183. ** and 30. The upper bound on 30 is because a 32-bit integer bitmap
  184. ** is used internally to track attached databases.
  185. */
  186. #ifndef SQLITE_MAX_ATTACHED
  187. # define SQLITE_MAX_ATTACHED 10
  188. #endif
  189. /*
  190. ** The maximum value of a ?nnn wildcard that the parser will accept.
  191. */
  192. #ifndef SQLITE_MAX_VARIABLE_NUMBER
  193. # define SQLITE_MAX_VARIABLE_NUMBER 999
  194. #endif
  195. /* Maximum page size. The upper bound on this value is 32768. This a limit
  196. ** imposed by the necessity of storing the value in a 2-byte unsigned integer
  197. ** and the fact that the page size must be a power of 2.
  198. **
  199. ** If this limit is changed, then the compiled library is technically
  200. ** incompatible with an SQLite library compiled with a different limit. If
  201. ** a process operating on a database with a page-size of 65536 bytes
  202. ** crashes, then an instance of SQLite compiled with the default page-size
  203. ** limit will not be able to rollback the aborted transaction. This could
  204. ** lead to database corruption.
  205. */
  206. #ifndef SQLITE_MAX_PAGE_SIZE
  207. # define SQLITE_MAX_PAGE_SIZE 32768
  208. #endif
  209. /*
  210. ** The default size of a database page.
  211. */
  212. #ifndef SQLITE_DEFAULT_PAGE_SIZE
  213. # define SQLITE_DEFAULT_PAGE_SIZE 1024
  214. #endif
  215. #if SQLITE_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE
  216. # undef SQLITE_DEFAULT_PAGE_SIZE
  217. # define SQLITE_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE
  218. #endif
  219. /*
  220. ** Ordinarily, if no value is explicitly provided, SQLite creates databases
  221. ** with page size SQLITE_DEFAULT_PAGE_SIZE. However, based on certain
  222. ** device characteristics (sector-size and atomic write() support),
  223. ** SQLite may choose a larger value. This constant is the maximum value
  224. ** SQLite will choose on its own.
  225. */
  226. #ifndef SQLITE_MAX_DEFAULT_PAGE_SIZE
  227. # define SQLITE_MAX_DEFAULT_PAGE_SIZE 8192
  228. #endif
  229. #if SQLITE_MAX_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE
  230. # undef SQLITE_MAX_DEFAULT_PAGE_SIZE
  231. # define SQLITE_MAX_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE
  232. #endif
  233. /*
  234. ** Maximum number of pages in one database file.
  235. **
  236. ** This is really just the default value for the max_page_count pragma.
  237. ** This value can be lowered (or raised) at run-time using that the
  238. ** max_page_count macro.
  239. */
  240. #ifndef SQLITE_MAX_PAGE_COUNT
  241. # define SQLITE_MAX_PAGE_COUNT 1073741823
  242. #endif
  243. /*
  244. ** Maximum length (in bytes) of the pattern in a LIKE or GLOB
  245. ** operator.
  246. */
  247. #ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH
  248. # define SQLITE_MAX_LIKE_PATTERN_LENGTH 50000
  249. #endif
  250. /*
  251. ** Maximum depth of recursion for triggers.
  252. **
  253. ** A value of 1 means that a trigger program will not be able to itself
  254. ** fire any triggers. A value of 0 means that no trigger programs at all
  255. ** may be executed.
  256. */
  257. #ifndef SQLITE_MAX_TRIGGER_DEPTH
  258. # define SQLITE_MAX_TRIGGER_DEPTH 1000
  259. #endif
  260. /************** End of sqliteLimit.h *****************************************/
  261. /************** Continuing where we left off in sqliteInt.h ******************/
  262. /* Disable nuisance warnings on Borland compilers */
  263. #if defined(__BORLANDC__)
  264. #pragma warn -rch /* unreachable code */
  265. #pragma warn -ccc /* Condition is always true or false */
  266. #pragma warn -aus /* Assigned value is never used */
  267. #pragma warn -csu /* Comparing signed and unsigned */
  268. #pragma warn -spa /* Suspicious pointer arithmetic */
  269. #endif
  270. /* Needed for various definitions... */
  271. #ifndef _GNU_SOURCE
  272. # define _GNU_SOURCE
  273. #endif
  274. /*
  275. ** Include standard header files as necessary
  276. */
  277. #ifdef HAVE_STDINT_H
  278. #include <stdint.h>
  279. #endif
  280. #ifdef HAVE_INTTYPES_H
  281. #include <inttypes.h>
  282. #endif
  283. #define SQLITE_INDEX_SAMPLES 10
  284. /*
  285. ** This macro is used to "hide" some ugliness in casting an int
  286. ** value to a ptr value under the MSVC 64-bit compiler. Casting
  287. ** non 64-bit values to ptr types results in a "hard" error with
  288. ** the MSVC 64-bit compiler which this attempts to avoid.
  289. **
  290. ** A simple compiler pragma or casting sequence could not be found
  291. ** to correct this in all situations, so this macro was introduced.
  292. **
  293. ** It could be argued that the intptr_t type could be used in this
  294. ** case, but that type is not available on all compilers, or
  295. ** requires the #include of specific headers which differs between
  296. ** platforms.
  297. **
  298. ** Ticket #3860: The llvm-gcc-4.2 compiler from Apple chokes on
  299. ** the ((void*)&((char*)0)[X]) construct. But MSVC chokes on ((void*)(X)).
  300. ** So we have to define the macros in different ways depending on the
  301. ** compiler.
  302. */
  303. #if defined(__GNUC__)
  304. # if defined(HAVE_STDINT_H)
  305. # define SQLITE_INT_TO_PTR(X) ((void*)(intptr_t)(X))
  306. # define SQLITE_PTR_TO_INT(X) ((int)(intptr_t)(X))
  307. # else
  308. # define SQLITE_INT_TO_PTR(X) ((void*)(X))
  309. # define SQLITE_PTR_TO_INT(X) ((int)(X))
  310. # endif
  311. #else
  312. # define SQLITE_INT_TO_PTR(X) ((void*)&((char*)0)[X])
  313. # define SQLITE_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0))
  314. #endif
  315. /*
  316. ** The SQLITE_THREADSAFE macro must be defined as either 0 or 1.
  317. ** Older versions of SQLite used an optional THREADSAFE macro.
  318. ** We support that for legacy
  319. */
  320. #if !defined(SQLITE_THREADSAFE)
  321. #if defined(THREADSAFE)
  322. # define SQLITE_THREADSAFE THREADSAFE
  323. #else
  324. # define SQLITE_THREADSAFE 1
  325. #endif
  326. #endif
  327. /*
  328. ** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1.
  329. ** It determines whether or not the features related to
  330. ** SQLITE_CONFIG_MEMSTATUS are available by default or not. This value can
  331. ** be overridden at runtime using the sqlite3_config() API.
  332. */
  333. #if !defined(SQLITE_DEFAULT_MEMSTATUS)
  334. # define SQLITE_DEFAULT_MEMSTATUS 1
  335. #endif
  336. /*
  337. ** Exactly one of the following macros must be defined in order to
  338. ** specify which memory allocation subsystem to use.
  339. **
  340. ** SQLITE_SYSTEM_MALLOC // Use normal system malloc()
  341. ** SQLITE_MEMDEBUG // Debugging version of system malloc()
  342. ** SQLITE_MEMORY_SIZE // internal allocator #1
  343. ** SQLITE_MMAP_HEAP_SIZE // internal mmap() allocator
  344. ** SQLITE_POW2_MEMORY_SIZE // internal power-of-two allocator
  345. **
  346. ** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as
  347. ** the default.
  348. */
  349. #if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)+\
  350. defined(SQLITE_MEMORY_SIZE)+defined(SQLITE_MMAP_HEAP_SIZE)+\
  351. defined(SQLITE_POW2_MEMORY_SIZE)>1
  352. # error "At most one of the following compile-time configuration options\
  353. is allows: SQLITE_SYSTEM_MALLOC, SQLITE_MEMDEBUG, SQLITE_MEMORY_SIZE,\
  354. SQLITE_MMAP_HEAP_SIZE, SQLITE_POW2_MEMORY_SIZE"
  355. #endif
  356. #if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)+\
  357. defined(SQLITE_MEMORY_SIZE)+defined(SQLITE_MMAP_HEAP_SIZE)+\
  358. defined(SQLITE_POW2_MEMORY_SIZE)==0
  359. # define SQLITE_SYSTEM_MALLOC 1
  360. #endif
  361. /*
  362. ** If SQLITE_MALLOC_SOFT_LIMIT is not zero, then try to keep the
  363. ** sizes of memory allocations below this value where possible.
  364. */
  365. #if !defined(SQLITE_MALLOC_SOFT_LIMIT)
  366. # define SQLITE_MALLOC_SOFT_LIMIT 1024
  367. #endif
  368. /*
  369. ** We need to define _XOPEN_SOURCE as follows in order to enable
  370. ** recursive mutexes on most Unix systems. But Mac OS X is different.
  371. ** The _XOPEN_SOURCE define causes problems for Mac OS X we are told,
  372. ** so it is omitted there. See ticket #2673.
  373. **
  374. ** Later we learn that _XOPEN_SOURCE is poorly or incorrectly
  375. ** implemented on some systems. So we avoid defining it at all
  376. ** if it is already defined or if it is unneeded because we are
  377. ** not doing a threadsafe build. Ticket #2681.
  378. **
  379. ** See also ticket #2741.
  380. */
  381. #if !defined(_XOPEN_SOURCE) && !defined(__DARWIN__) && !defined(__APPLE__) && SQLITE_THREADSAFE
  382. # define _XOPEN_SOURCE 500 /* Needed to enable pthread recursive mutexes */
  383. #endif
  384. /*
  385. ** The TCL headers are only needed when compiling the TCL bindings.
  386. */
  387. #if defined(SQLITE_TCL) || defined(TCLSH)
  388. # include <tcl.h>
  389. #endif
  390. /*
  391. ** Many people are failing to set -DNDEBUG=1 when compiling SQLite.
  392. ** Setting NDEBUG makes the code smaller and run faster. So the following
  393. ** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1
  394. ** option is set. Thus NDEBUG becomes an opt-in rather than an opt-out
  395. ** feature.
  396. */
  397. #if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
  398. # define NDEBUG 1
  399. #endif
  400. /*
  401. ** The testcase() macro is used to aid in coverage testing. When
  402. ** doing coverage testing, the condition inside the argument to
  403. ** testcase() must be evaluated both true and false in order to
  404. ** get full branch coverage. The testcase() macro is inserted
  405. ** to help ensure adequate test coverage in places where simple
  406. ** condition/decision coverage is inadequate. For example, testcase()
  407. ** can be used to make sure boundary values are tested. For
  408. ** bitmask tests, testcase() can be used to make sure each bit
  409. ** is significant and used at least once. On switch statements
  410. ** where multiple cases go to the same block of code, testcase()
  411. ** can insure that all cases are evaluated.
  412. **
  413. */
  414. #ifdef SQLITE_COVERAGE_TEST
  415. SQLITE_PRIVATE void sqlite3Coverage(int);
  416. # define testcase(X) if( X ){ sqlite3Coverage(__LINE__); }
  417. #else
  418. # define testcase(X)
  419. #endif
  420. /*
  421. ** The TESTONLY macro is used to enclose variable declarations or
  422. ** other bits of code that are needed to support the arguments
  423. ** within testcase() and assert() macros.
  424. */
  425. #if !defined(NDEBUG) || defined(SQLITE_COVERAGE_TEST)
  426. # define TESTONLY(X) X
  427. #else
  428. # define TESTONLY(X)
  429. #endif
  430. /*
  431. ** Sometimes we need a small amount of code such as a variable initialization
  432. ** to setup for a later assert() statement. We do not want this code to
  433. ** appear when assert() is disabled. The following macro is therefore
  434. ** used to contain that setup code. The "VVA" acronym stands for
  435. ** "Verification, Validation, and Accreditation". In other words, the
  436. ** code within VVA_ONLY() will only run during verification processes.
  437. */
  438. #ifndef NDEBUG
  439. # define VVA_ONLY(X) X
  440. #else
  441. # define VVA_ONLY(X)
  442. #endif
  443. /*
  444. ** The ALWAYS and NEVER macros surround boolean expressions which
  445. ** are intended to always be true or false, respectively. Such
  446. ** expressions could be omitted from the code completely. But they
  447. ** are included in a few cases in order to enhance the resilience
  448. ** of SQLite to unexpected behavior - to make the code "self-healing"
  449. ** or "ductile" rather than being "brittle" and crashing at the first
  450. ** hint of unplanned behavior.
  451. **
  452. ** In other words, ALWAYS and NEVER are added for defensive code.
  453. **
  454. ** When doing coverage testing ALWAYS and NEVER are hard-coded to
  455. ** be true and false so that the unreachable code then specify will
  456. ** not be counted as untested code.
  457. */
  458. #if defined(SQLITE_COVERAGE_TEST)
  459. # define ALWAYS(X) (1)
  460. # define NEVER(X) (0)
  461. #elif !defined(NDEBUG)
  462. # define ALWAYS(X) ((X)?1:(assert(0),0))
  463. # define NEVER(X) ((X)?(assert(0),1):0)
  464. #else
  465. # define ALWAYS(X) (X)
  466. # define NEVER(X) (X)
  467. #endif
  468. /*
  469. ** The macro unlikely() is a hint that surrounds a boolean
  470. ** expression that is usually false. Macro likely() surrounds
  471. ** a boolean expression that is usually true. GCC is able to
  472. ** use these hints to generate better code, sometimes.
  473. */
  474. #if defined(__GNUC__) && 0
  475. # define likely(X) __builtin_expect((X),1)
  476. # define unlikely(X) __builtin_expect((X),0)
  477. #else
  478. # define likely(X) !!(X)
  479. # define unlikely(X) !!(X)
  480. #endif
  481. /************** Include sqlite3.h in the middle of sqliteInt.h ***************/
  482. /************** Begin file sqlite3.h *****************************************/
  483. /*
  484. ** 2001 September 15
  485. **
  486. ** The author disclaims copyright to this source code. In place of
  487. ** a legal notice, here is a blessing:
  488. **
  489. ** May you do good and not evil.
  490. ** May you find forgiveness for yourself and forgive others.
  491. ** May you share freely, never taking more than you give.
  492. **
  493. *************************************************************************
  494. ** This header file defines the interface that the SQLite library
  495. ** presents to client programs. If a C-function, structure, datatype,
  496. ** or constant definition does not appear in this file, then it is
  497. ** not a published API of SQLite, is subject to change without
  498. ** notice, and should not be referenced by programs that use SQLite.
  499. **
  500. ** Some of the definitions that are in this file are marked as
  501. ** "experimental". Experimental interfaces are normally new
  502. ** features recently added to SQLite. We do not anticipate changes
  503. ** to experimental interfaces but reserve the right to make minor changes
  504. ** if experience from use "in the wild" suggest such changes are prudent.
  505. **
  506. ** The official C-language API documentation for SQLite is derived
  507. ** from comments in this file. This file is the authoritative source
  508. ** on how SQLite interfaces are suppose to operate.
  509. **
  510. ** The name of this file under configuration management is "sqlite.h.in".
  511. ** The makefile makes some minor changes to this file (such as inserting
  512. ** the version number) and changes its name to "sqlite3.h" as
  513. ** part of the build process.
  514. */
  515. #ifndef _SQLITE3_H_
  516. #define _SQLITE3_H_
  517. #include <stdarg.h> /* Needed for the definition of va_list */
  518. /*
  519. ** Make sure we can call this stuff from C++.
  520. */
  521. #if 0
  522. extern "C" {
  523. #endif
  524. /*
  525. ** Add the ability to override 'extern'
  526. */
  527. #ifndef SQLITE_EXTERN
  528. # define SQLITE_EXTERN extern
  529. #endif
  530. #ifndef SQLITE_API
  531. # define SQLITE_API
  532. #endif
  533. /*
  534. ** These no-op macros are used in front of interfaces to mark those
  535. ** interfaces as either deprecated or experimental. New applications
  536. ** should not use deprecated interfaces - they are support for backwards
  537. ** compatibility only. Application writers should be aware that
  538. ** experimental interfaces are subject to change in point releases.
  539. **
  540. ** These macros used to resolve to various kinds of compiler magic that
  541. ** would generate warning messages when they were used. But that
  542. ** compiler magic ended up generating such a flurry of bug reports
  543. ** that we have taken it all out and gone back to using simple
  544. ** noop macros.
  545. */
  546. #define SQLITE_DEPRECATED
  547. #define SQLITE_EXPERIMENTAL
  548. /*
  549. ** Ensure these symbols were not defined by some previous header file.
  550. */
  551. #ifdef SQLITE_VERSION
  552. # undef SQLITE_VERSION
  553. #endif
  554. #ifdef SQLITE_VERSION_NUMBER
  555. # undef SQLITE_VERSION_NUMBER
  556. #endif
  557. /*
  558. ** CAPI3REF: Compile-Time Library Version Numbers
  559. **
  560. ** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header
  561. ** evaluates to a string literal that is the SQLite version in the
  562. ** format "X.Y.Z" where X is the major version number (always 3 for
  563. ** SQLite3) and Y is the minor version number and Z is the release number.)^
  564. ** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer
  565. ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
  566. ** numbers used in [SQLITE_VERSION].)^
  567. ** The SQLITE_VERSION_NUMBER for any given release of SQLite will also
  568. ** be larger than the release from which it is derived. Either Y will
  569. ** be held constant and Z will be incremented or else Y will be incremented
  570. ** and Z will be reset to zero.
  571. **
  572. ** Since version 3.6.18, SQLite source code has been stored in the
  573. ** <a href="http://www.fossil-scm.org/">Fossil configuration management
  574. ** system</a>. ^The SQLITE_SOURCE_ID macro evalutes to
  575. ** a string which identifies a particular check-in of SQLite
  576. ** within its configuration management system. ^The SQLITE_SOURCE_ID
  577. ** string contains the date and time of the check-in (UTC) and an SHA1
  578. ** hash of the entire source tree.
  579. **
  580. ** See also: [sqlite3_libversion()],
  581. ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
  582. ** [sqlite_version()] and [sqlite_source_id()].
  583. */
  584. #define SQLITE_VERSION "3.6.22"
  585. #define SQLITE_VERSION_NUMBER 3006022
  586. #define SQLITE_SOURCE_ID "2010-01-05 15:30:36 28d0d7710761114a44a1a3a425a6883c661f06e7"
  587. /*
  588. ** CAPI3REF: Run-Time Library Version Numbers
  589. ** KEYWORDS: sqlite3_version
  590. **
  591. ** These interfaces provide the same information as the [SQLITE_VERSION],
  592. ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
  593. ** but are associated with the library instead of the header file. ^(Cautious
  594. ** programmers might include assert() statements in their application to
  595. ** verify that values returned by these interfaces match the macros in
  596. ** the header, and thus insure that the application is
  597. ** compiled with matching library and header files.
  598. **
  599. ** <blockquote><pre>
  600. ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
  601. ** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 );
  602. ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
  603. ** </pre></blockquote>)^
  604. **
  605. ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
  606. ** macro. ^The sqlite3_libversion() function returns a pointer to the
  607. ** to the sqlite3_version[] string constant. The sqlite3_libversion()
  608. ** function is provided for use in DLLs since DLL users usually do not have
  609. ** direct access to string constants within the DLL. ^The
  610. ** sqlite3_libversion_number() function returns an integer equal to
  611. ** [SQLITE_VERSION_NUMBER]. ^The sqlite3_sourceid() function a pointer
  612. ** to a string constant whose value is the same as the [SQLITE_SOURCE_ID]
  613. ** C preprocessor macro.
  614. **
  615. ** See also: [sqlite_version()] and [sqlite_source_id()].
  616. */
  617. SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
  618. SQLITE_API const char *sqlite3_libversion(void);
  619. SQLITE_API const char *sqlite3_sourceid(void);
  620. SQLITE_API int sqlite3_libversion_number(void);
  621. /*
  622. ** CAPI3REF: Test To See If The Library Is Threadsafe
  623. **
  624. ** ^The sqlite3_threadsafe() function returns zero if and only if
  625. ** SQLite was compiled mutexing code omitted due to the
  626. ** [SQLITE_THREADSAFE] compile-time option being set to 0.
  627. **
  628. ** SQLite can be compiled with or without mutexes. When
  629. ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes
  630. ** are enabled and SQLite is threadsafe. When the
  631. ** [SQLITE_THREADSAFE] macro is 0,
  632. ** the mutexes are omitted. Without the mutexes, it is not safe
  633. ** to use SQLite concurrently from more than one thread.
  634. **
  635. ** Enabling mutexes incurs a measurable performance penalty.
  636. ** So if speed is of utmost importance, it makes sense to disable
  637. ** the mutexes. But for maximum safety, mutexes should be enabled.
  638. ** ^The default behavior is for mutexes to be enabled.
  639. **
  640. ** This interface can be used by an application to make sure that the
  641. ** version of SQLite that it is linking against was compiled with
  642. ** the desired setting of the [SQLITE_THREADSAFE] macro.
  643. **
  644. ** This interface only reports on the compile-time mutex setting
  645. ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
  646. ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
  647. ** can be fully or partially disabled using a call to [sqlite3_config()]
  648. ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
  649. ** or [SQLITE_CONFIG_MUTEX]. ^(The return value of the
  650. ** sqlite3_threadsafe() function shows only the compile-time setting of
  651. ** thread safety, not any run-time changes to that setting made by
  652. ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
  653. ** is unchanged by calls to sqlite3_config().)^
  654. **
  655. ** See the [threading mode] documentation for additional information.
  656. */
  657. SQLITE_API int sqlite3_threadsafe(void);
  658. /*
  659. ** CAPI3REF: Database Connection Handle
  660. ** KEYWORDS: {database connection} {database connections}
  661. **
  662. ** Each open SQLite database is represented by a pointer to an instance of
  663. ** the opaque structure named "sqlite3". It is useful to think of an sqlite3
  664. ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and
  665. ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
  666. ** is its destructor. There are many other interfaces (such as
  667. ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
  668. ** [sqlite3_busy_timeout()] to name but three) that are methods on an
  669. ** sqlite3 object.
  670. */
  671. typedef struct sqlite3 sqlite3;
  672. /*
  673. ** CAPI3REF: 64-Bit Integer Types
  674. ** KEYWORDS: sqlite_int64 sqlite_uint64
  675. **
  676. ** Because there is no cross-platform way to specify 64-bit integer types
  677. ** SQLite includes typedefs for 64-bit signed and unsigned integers.
  678. **
  679. ** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
  680. ** The sqlite_int64 and sqlite_uint64 types are supported for backwards
  681. ** compatibility only.
  682. **
  683. ** ^The sqlite3_int64 and sqlite_int64 types can store integer values
  684. ** between -9223372036854775808 and +9223372036854775807 inclusive. ^The
  685. ** sqlite3_uint64 and sqlite_uint64 types can store integer values
  686. ** between 0 and +18446744073709551615 inclusive.
  687. */
  688. #ifdef SQLITE_INT64_TYPE
  689. typedef SQLITE_INT64_TYPE sqlite_int64;
  690. typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
  691. #elif defined(_MSC_VER) || defined(__BORLANDC__)
  692. typedef __int64 sqlite_int64;
  693. typedef unsigned __int64 sqlite_uint64;
  694. #else
  695. typedef long long int sqlite_int64;
  696. typedef unsigned long long int sqlite_uint64;
  697. #endif
  698. typedef sqlite_int64 sqlite3_int64;
  699. typedef sqlite_uint64 sqlite3_uint64;
  700. /*
  701. ** If compiling for a processor that lacks floating point support,
  702. ** substitute integer for floating-point.
  703. */
  704. #ifdef SQLITE_OMIT_FLOATING_POINT
  705. # define double sqlite3_int64
  706. #endif
  707. /*
  708. ** CAPI3REF: Closing A Database Connection
  709. **
  710. ** ^The sqlite3_close() routine is the destructor for the [sqlite3] object.
  711. ** ^Calls to sqlite3_close() return SQLITE_OK if the [sqlite3] object is
  712. ** successfullly destroyed and all associated resources are deallocated.
  713. **
  714. ** Applications must [sqlite3_finalize | finalize] all [prepared statements]
  715. ** and [sqlite3_blob_close | close] all [BLOB handles] associated with
  716. ** the [sqlite3] object prior to attempting to close the object. ^If
  717. ** sqlite3_close() is called on a [database connection] that still has
  718. ** outstanding [prepared statements] or [BLOB handles], then it returns
  719. ** SQLITE_BUSY.
  720. **
  721. ** ^If [sqlite3_close()] is invoked while a transaction is open,
  722. ** the transaction is automatically rolled back.
  723. **
  724. ** The C parameter to [sqlite3_close(C)] must be either a NULL
  725. ** pointer or an [sqlite3] object pointer obtained
  726. ** from [sqlite3_open()], [sqlite3_open16()], or
  727. ** [sqlite3_open_v2()], and not previously closed.
  728. ** ^Calling sqlite3_close() with a NULL pointer argument is a
  729. ** harmless no-op.
  730. */
  731. SQLITE_API int sqlite3_close(sqlite3 *);
  732. /*
  733. ** The type for a callback function.
  734. ** This is legacy and deprecated. It is included for historical
  735. ** compatibility and is not documented.
  736. */
  737. typedef int (*sqlite3_callback)(void*,int,char**, char**);
  738. /*
  739. ** CAPI3REF: One-Step Query Execution Interface
  740. **
  741. ** The sqlite3_exec() interface is a convenience wrapper around
  742. ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
  743. ** that allows an application to run multiple statements of SQL
  744. ** without having to use a lot of C code.
  745. **
  746. ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
  747. ** semicolon-separate SQL statements passed into its 2nd argument,
  748. ** in the context of the [database connection] passed in as its 1st
  749. ** argument. ^If the callback function of the 3rd argument to
  750. ** sqlite3_exec() is not NULL, then it is invoked for each result row
  751. ** coming out of the evaluated SQL statements. ^The 4th argument to
  752. ** to sqlite3_exec() is relayed through to the 1st argument of each
  753. ** callback invocation. ^If the callback pointer to sqlite3_exec()
  754. ** is NULL, then no callback is ever invoked and result rows are
  755. ** ignored.
  756. **
  757. ** ^If an error occurs while evaluating the SQL statements passed into
  758. ** sqlite3_exec(), then execution of the current statement stops and
  759. ** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec()
  760. ** is not NULL then any error message is written into memory obtained
  761. ** from [sqlite3_malloc()] and passed back through the 5th parameter.
  762. ** To avoid memory leaks, the application should invoke [sqlite3_free()]
  763. ** on error message strings returned through the 5th parameter of
  764. ** of sqlite3_exec() after the error message string is no longer needed.
  765. ** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors
  766. ** occur, then sqlite3_exec() sets the pointer in its 5th parameter to
  767. ** NULL before returning.
  768. **
  769. ** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec()
  770. ** routine returns SQLITE_ABORT without invoking the callback again and
  771. ** without running any subsequent SQL statements.
  772. **
  773. ** ^The 2nd argument to the sqlite3_exec() callback function is the
  774. ** number of columns in the result. ^The 3rd argument to the sqlite3_exec()
  775. ** callback is an array of pointers to strings obtained as if from
  776. ** [sqlite3_column_text()], one for each column. ^If an element of a
  777. ** result row is NULL then the corresponding string pointer for the
  778. ** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the
  779. ** sqlite3_exec() callback is an array of pointers to strings where each
  780. ** entry represents the name of corresponding result column as obtained
  781. ** from [sqlite3_column_name()].
  782. **
  783. ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
  784. ** to an empty string, or a pointer that contains only whitespace and/or
  785. ** SQL comments, then no SQL statements are evaluated and the database
  786. ** is not changed.
  787. **
  788. ** Restrictions:
  789. **
  790. ** <ul>
  791. ** <li> The application must insure that the 1st parameter to sqlite3_exec()
  792. ** is a valid and open [database connection].
  793. ** <li> The application must not close [database connection] specified by
  794. ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
  795. ** <li> The application must not modify the SQL statement text passed into
  796. ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
  797. ** </ul>
  798. */
  799. SQLITE_API int sqlite3_exec(
  800. sqlite3*, /* An open database */
  801. const char *sql, /* SQL to be evaluated */
  802. int (*callback)(void*,int,char**,char**), /* Callback function */
  803. void *, /* 1st argument to callback */
  804. char **errmsg /* Error msg written here */
  805. );
  806. /*
  807. ** CAPI3REF: Result Codes
  808. ** KEYWORDS: SQLITE_OK {error code} {error codes}
  809. ** KEYWORDS: {result code} {result codes}
  810. **
  811. ** Many SQLite functions return an integer result code from the set shown
  812. ** here in order to indicates success or failure.
  813. **
  814. ** New error codes may be added in future versions of SQLite.
  815. **
  816. ** See also: [SQLITE_IOERR_READ | extended result codes]
  817. */
  818. #define SQLITE_OK 0 /* Successful result */
  819. /* beginning-of-error-codes */
  820. #define SQLITE_ERROR 1 /* SQL error or missing database */
  821. #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
  822. #define SQLITE_PERM 3 /* Access permission denied */
  823. #define SQLITE_ABORT 4 /* Callback routine requested an abort */
  824. #define SQLITE_BUSY 5 /* The database file is locked */
  825. #define SQLITE_LOCKED 6 /* A table in the database is locked */
  826. #define SQLITE_NOMEM 7 /* A malloc() failed */
  827. #define SQLITE_READONLY 8 /* Attempt to write a readonly database */
  828. #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
  829. #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
  830. #define SQLITE_CORRUPT 11 /* The database disk image is malformed */
  831. #define SQLITE_NOTFOUND 12 /* NOT USED. Table or record not found */
  832. #define SQLITE_FULL 13 /* Insertion failed because database is full */
  833. #define SQLITE_CANTOPEN 14 /* Unable to open the database file */
  834. #define SQLITE_PROTOCOL 15 /* NOT USED. Database lock protocol error */
  835. #define SQLITE_EMPTY 16 /* Database is empty */
  836. #define SQLITE_SCHEMA 17 /* The database schema changed */
  837. #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
  838. #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
  839. #define SQLITE_MISMATCH 20 /* Data type mismatch */
  840. #define SQLITE_MISUSE 21 /* Library used incorrectly */
  841. #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
  842. #define SQLITE_AUTH 23 /* Authorization denied */
  843. #define SQLITE_FORMAT 24 /* Auxiliary database format error */
  844. #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
  845. #define SQLITE_NOTADB 26 /* File opened that is not a database file */
  846. #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
  847. #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
  848. /* end-of-error-codes */
  849. /*
  850. ** CAPI3REF: Extended Result Codes
  851. ** KEYWORDS: {extended error code} {extended error codes}
  852. ** KEYWORDS: {extended result code} {extended result codes}
  853. **
  854. ** In its default configuration, SQLite API routines return one of 26 integer
  855. ** [SQLITE_OK | result codes]. However, experience has shown that many of
  856. ** these result codes are too coarse-grained. They do not provide as
  857. ** much information about problems as programmers might like. In an effort to
  858. ** address this, newer versions of SQLite (version 3.3.8 and later) include
  859. ** support for additional result codes that provide more detailed information
  860. ** about errors. The extended result codes are enabled or disabled
  861. ** on a per database connection basis using the
  862. ** [sqlite3_extended_result_codes()] API.
  863. **
  864. ** Some of the available extended result codes are listed here.
  865. ** One may expect the number of extended result codes will be expand
  866. ** over time. Software that uses extended result codes should expect
  867. ** to see new result codes in future releases of SQLite.
  868. **
  869. ** The SQLITE_OK result code will never be extended. It will always
  870. ** be exactly zero.
  871. */
  872. #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))
  873. #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))
  874. #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8))
  875. #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8))
  876. #define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8))
  877. #define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8))
  878. #define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8))
  879. #define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8))
  880. #define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8))
  881. #define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8))
  882. #define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8))
  883. #define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8))
  884. #define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8))
  885. #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
  886. #define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8))
  887. #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8))
  888. #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8))
  889. #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8) )
  890. /*
  891. ** CAPI3REF: Flags For File Open Operations
  892. **
  893. ** These bit values are intended for use in the
  894. ** 3rd parameter to the [sqlite3_open_v2()] interface and
  895. ** in the 4th parameter to the xOpen method of the
  896. ** [sqlite3_vfs] object.
  897. */
  898. #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
  899. #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
  900. #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
  901. #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
  902. #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
  903. #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
  904. #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
  905. #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
  906. #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
  907. #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
  908. #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */
  909. #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */
  910. #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
  911. #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
  912. #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
  913. #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
  914. /*
  915. ** CAPI3REF: Device Characteristics
  916. **
  917. ** The xDeviceCapabilities method of the [sqlite3_io_methods]
  918. ** object returns an integer which is a vector of the these
  919. ** bit values expressing I/O characteristics of the mass storage
  920. ** device that holds the file that the [sqlite3_io_methods]
  921. ** refers to.
  922. **
  923. ** The SQLITE_IOCAP_ATOMIC property means that all writes of
  924. ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
  925. ** mean that writes of blocks that are nnn bytes in size and
  926. ** are aligned to an address which is an integer multiple of
  927. ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
  928. ** that when data is appended to a file, the data is appended
  929. ** first then the size of the file is extended, never the other
  930. ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
  931. ** information is written to disk in the same order as calls
  932. ** to xWrite().
  933. */
  934. #define SQLITE_IOCAP_ATOMIC 0x00000001
  935. #define SQLITE_IOCAP_ATOMIC512 0x00000002
  936. #define SQLITE_IOCAP_ATOMIC1K 0x00000004
  937. #define SQLITE_IOCAP_ATOMIC2K 0x00000008
  938. #define SQLITE_IOCAP_ATOMIC4K 0x00000010
  939. #define SQLITE_IOCAP_ATOMIC8K 0x00000020
  940. #define SQLITE_IOCAP_ATOMIC16K 0x00000040
  941. #define SQLITE_IOCAP_ATOMIC32K 0x00000080
  942. #define SQLITE_IOCAP_ATOMIC64K 0x00000100
  943. #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
  944. #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
  945. /*
  946. ** CAPI3REF: File Locking Levels
  947. **
  948. ** SQLite uses one of these integer values as the second
  949. ** argument to calls it makes to the xLock() and xUnlock() methods
  950. ** of an [sqlite3_io_methods] object.
  951. */
  952. #define SQLITE_LOCK_NONE 0
  953. #define SQLITE_LOCK_SHARED 1
  954. #define SQLITE_LOCK_RESERVED 2
  955. #define SQLITE_LOCK_PENDING 3
  956. #define SQLITE_LOCK_EXCLUSIVE 4
  957. /*
  958. ** CAPI3REF: Synchronization Type Flags
  959. **
  960. ** When SQLite invokes the xSync() method of an
  961. ** [sqlite3_io_methods] object it uses a combination of
  962. ** these integer values as the second argument.
  963. **
  964. ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
  965. ** sync operation only needs to flush data to mass storage. Inode
  966. ** information need not be flushed. If the lower four bits of the flag
  967. ** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics.
  968. ** If the lower four bits equal SQLITE_SYNC_FULL, that means
  969. ** to use Mac OS X style fullsync instead of fsync().
  970. */
  971. #define SQLITE_SYNC_NORMAL 0x00002
  972. #define SQLITE_SYNC_FULL 0x00003
  973. #define SQLITE_SYNC_DATAONLY 0x00010
  974. /*
  975. ** CAPI3REF: OS Interface Open File Handle
  976. **
  977. ** An [sqlite3_file] object represents an open file in the
  978. ** [sqlite3_vfs | OS interface layer]. Individual OS interface
  979. ** implementations will
  980. ** want to subclass this object by appending additional fields
  981. ** for their own use. The pMethods entry is a pointer to an
  982. ** [sqlite3_io_methods] object that defines methods for performing
  983. ** I/O operations on the open file.
  984. */
  985. typedef struct sqlite3_file sqlite3_file;
  986. struct sqlite3_file {
  987. const struct sqlite3_io_methods *pMethods; /* Methods for an open file */
  988. };
  989. /*
  990. ** CAPI3REF: OS Interface File Virtual Methods Object
  991. **
  992. ** Every file opened by the [sqlite3_vfs] xOpen method populates an
  993. ** [sqlite3_file] object (or, more commonly, a subclass of the
  994. ** [sqlite3_file] object) with a pointer to an instance of this object.
  995. ** This object defines the methods used to perform various operations
  996. ** against the open file represented by the [sqlite3_file] object.
  997. **
  998. ** If the xOpen method sets the sqlite3_file.pMethods element
  999. ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
  1000. ** may be invoked even if the xOpen reported that it failed. The
  1001. ** only way to prevent a call to xClose following a failed xOpen
  1002. ** is for the xOpen to set the sqlite3_file.pMethods element to NULL.
  1003. **
  1004. ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
  1005. ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
  1006. ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]
  1007. ** flag may be ORed in to indicate that only the data of the file
  1008. ** and not its inode needs to be synced.
  1009. **
  1010. ** The integer values to xLock() and xUnlock() are one of
  1011. ** <ul>
  1012. ** <li> [SQLITE_LOCK_NONE],
  1013. ** <li> [SQLITE_LOCK_SHARED],
  1014. ** <li> [SQLITE_LOCK_RESERVED],
  1015. ** <li> [SQLITE_LOCK_PENDING], or
  1016. ** <li> [SQLITE_LOCK_EXCLUSIVE].
  1017. ** </ul>
  1018. ** xLock() increases the lock. xUnlock() decreases the lock.
  1019. ** The xCheckReservedLock() method checks whether any database connection,
  1020. ** either in this process or in some other process, is holding a RESERVED,
  1021. ** PENDING, or EXCLUSIVE lock on the file. It returns true
  1022. ** if such a lock exists and false otherwise.
  1023. **
  1024. ** The xFileControl() method is a generic interface that allows custom
  1025. ** VFS implementations to directly control an open file using the
  1026. ** [sqlite3_file_control()] interface. The second "op" argument is an
  1027. ** integer opcode. The third argument is a generic pointer intended to
  1028. ** point to a structure that may contain arguments or space in which to
  1029. ** write return values. Potential uses for xFileControl() might be
  1030. ** functions to enable blocking locks with timeouts, to change the
  1031. ** locking strategy (for example to use dot-file locks), to inquire
  1032. ** about the status of a lock, or to break stale locks. The SQLite
  1033. ** core reserves all opcodes less than 100 for its own use.
  1034. ** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available.
  1035. ** Applications that define a custom xFileControl method should use opcodes
  1036. ** greater than 100 to avoid conflicts.
  1037. **
  1038. ** The xSectorSize() method returns the sector size of the
  1039. ** device that underlies the file. The sector size is the
  1040. ** minimum write that can be performed without disturbing
  1041. ** other bytes in the file. The xDeviceCharacteristics()
  1042. ** method returns a bit vector describing behaviors of the
  1043. ** underlying device:
  1044. **
  1045. ** <ul>
  1046. ** <li> [SQLITE_IOCAP_ATOMIC]
  1047. ** <li> [SQLITE_IOCAP_ATOMIC512]
  1048. ** <li> [SQLITE_IOCAP_ATOMIC1K]
  1049. ** <li> [SQLITE_IOCAP_ATOMIC2K]
  1050. ** <li> [SQLITE_IOCAP_ATOMIC4K]
  1051. ** <li> [SQLITE_IOCAP_ATOMIC8K]
  1052. ** <li> [SQLITE_IOCAP_ATOMIC16K]
  1053. ** <li> [SQLITE_IOCAP_ATOMIC32K]
  1054. ** <li> [SQLITE_IOCAP_ATOMIC64K]
  1055. ** <li> [SQLITE_IOCAP_SAFE_APPEND]
  1056. ** <li> [SQLITE_IOCAP_SEQUENTIAL]
  1057. ** </ul>
  1058. **
  1059. ** The SQLITE_IOCAP_ATOMIC property means that all writes of
  1060. ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
  1061. ** mean that writes of blocks that are nnn bytes in size and
  1062. ** are aligned to an address which is an integer multiple of
  1063. ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
  1064. ** that when data is appended to a file, the data is appended
  1065. ** first then the size of the file is extended, never the other
  1066. ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
  1067. ** information is written to disk in the same order as calls
  1068. ** to xWrite().
  1069. **
  1070. ** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
  1071. ** in the unread portions of the buffer with zeros. A VFS that
  1072. ** fails to zero-fill short reads might seem to work. However,
  1073. ** failure to zero-fill short reads will eventually lead to
  1074. ** database corruption.
  1075. */
  1076. typedef struct sqlite3_io_methods sqlite3_io_methods;
  1077. struct sqlite3_io_methods {
  1078. int iVersion;
  1079. int (*xClose)(sqlite3_file*);
  1080. int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
  1081. int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
  1082. int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
  1083. int (*xSync)(sqlite3_file*, int flags);
  1084. int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
  1085. int (*xLock)(sqlite3_file*, int);
  1086. int (*xUnlock)(sqlite3_file*, int);
  1087. int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);
  1088. int (*xFileControl)(sqlite3_file*, int op, void *pArg);
  1089. int (*xSectorSize)(sqlite3_file*);
  1090. int (*xDeviceCharacteristics)(sqlite3_file*);
  1091. /* Additional methods may be added in future releases */
  1092. };
  1093. /*
  1094. ** CAPI3REF: Standard File Control Opcodes
  1095. **
  1096. ** These integer constants are opcodes for the xFileControl method
  1097. ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
  1098. ** interface.
  1099. **
  1100. ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This
  1101. ** opcode causes the xFileControl method to write the current state of
  1102. ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
  1103. ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
  1104. ** into an integer that the pArg argument points to. This capability
  1105. ** is used during testing and only needs to be supported when SQLITE_TEST
  1106. ** is defined.
  1107. */
  1108. #define SQLITE_FCNTL_LOCKSTATE 1
  1109. #define SQLITE_GET_LOCKPROXYFILE 2
  1110. #define SQLITE_SET_LOCKPROXYFILE 3
  1111. #define SQLITE_LAST_ERRNO 4
  1112. /*
  1113. ** CAPI3REF: Mutex Handle
  1114. **
  1115. ** The mutex module within SQLite defines [sqlite3_mutex] to be an
  1116. ** abstract type for a mutex object. The SQLite core never looks
  1117. ** at the internal representation of an [sqlite3_mutex]. It only
  1118. ** deals with pointers to the [sqlite3_mutex] object.
  1119. **
  1120. ** Mutexes are created using [sqlite3_mutex_alloc()].
  1121. */
  1122. typedef struct sqlite3_mutex sqlite3_mutex;
  1123. /*
  1124. ** CAPI3REF: OS Interface Object
  1125. **
  1126. ** An instance of the sqlite3_vfs object defines the interface between
  1127. ** the SQLite core and the underlying operating system. The "vfs"
  1128. ** in the name of the object stands for "virtual file system".
  1129. **
  1130. ** The value of the iVersion field is initially 1 but may be larger in
  1131. ** future versions of SQLite. Additional fields may be appended to this
  1132. ** object when the iVersion value is increased. Note that the structure
  1133. ** of the sqlite3_vfs object changes in the transaction between
  1134. ** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not
  1135. ** modified.
  1136. **
  1137. ** The szOsFile field is the size of the subclassed [sqlite3_file]
  1138. ** structure used by this VFS. mxPathname is the maximum length of
  1139. ** a pathname in this VFS.
  1140. **
  1141. ** Registered sqlite3_vfs objects are kept on a linked list formed by
  1142. ** the pNext pointer. The [sqlite3_vfs_register()]
  1143. ** and [sqlite3_vfs_unregister()] interfaces manage this list
  1144. ** in a thread-safe way. The [sqlite3_vfs_find()] interface
  1145. ** searches the list. Neither the application code nor the VFS
  1146. ** implementation should use the pNext pointer.
  1147. **
  1148. ** The pNext field is the only field in the sqlite3_vfs
  1149. ** structure that SQLite will ever modify. SQLite will only access
  1150. ** or modify this field while holding a particular static mutex.
  1151. ** The application should never modify anything within the sqlite3_vfs
  1152. ** object once the object has been registered.
  1153. **
  1154. ** The zName field holds the name of the VFS module. The name must
  1155. ** be unique across all VFS modules.
  1156. **
  1157. ** SQLite will guarantee that the zFilename parameter to xOpen
  1158. ** is either a NULL pointer or string obtained
  1159. ** from xFullPathname(). SQLite further guarantees that
  1160. ** the string will be valid and unchanged until xClose() is
  1161. ** called. Because of the previous sentence,
  1162. ** the [sqlite3_file] can safely store a pointer to the
  1163. ** filename if it needs to remember the filename for some reason.
  1164. ** If the zFilename parameter is xOpen is a NULL pointer then xOpen
  1165. ** must invent its own temporary name for the file. Whenever the
  1166. ** xFilename parameter is NULL it will also be the case that the
  1167. ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
  1168. **
  1169. ** The flags argument to xOpen() includes all bits set in
  1170. ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]
  1171. ** or [sqlite3_…

Large files files are truncated, but you can click here to view the full file