PageRenderTime 85ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 1ms

/db/sqlite3/src/sqlite3.c

https://bitbucket.org/mkato/mozilla-1.9.0-win64
C | 10964 lines | 2990 code | 425 blank | 7549 comment | 40 complexity | d8171ee7d693017778d52b17b26a1b22 MD5 | raw file
Possible License(s): LGPL-3.0, MIT, BSD-3-Clause, MPL-2.0-no-copyleft-exception, GPL-2.0, LGPL-2.1

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.10. By combining all the individual C code files into this
  4. ** single large file, the entire code can be compiled as a one translation
  5. ** unit. This allows many compilers to do optimizations that would not be
  6. ** possible if the files were compiled separately. Performance improvements
  7. ** of 5% are more are commonly seen when SQLite is compiled as a single
  8. ** translation unit.
  9. **
  10. ** This file is all you need to compile SQLite. To use SQLite in other
  11. ** programs, you need this file and the "sqlite3.h" header file that defines
  12. ** the programming interface to the SQLite library. (If you do not have
  13. ** the "sqlite3.h" header file at hand, you will find a copy in the first
  14. ** 6736 lines past this header comment.) Additional code files may be
  15. ** needed if you want a wrapper to interface SQLite with your choice of
  16. ** programming language. The code for the "sqlite3" command-line shell
  17. ** is also in a separate file. This file contains only code for the core
  18. ** SQLite library.
  19. **
  20. ** This amalgamation was generated on 2009-01-15 16:00:39 UTC.
  21. */
  22. #define SQLITE_CORE 1
  23. #define SQLITE_AMALGAMATION 1
  24. #ifndef SQLITE_PRIVATE
  25. # define SQLITE_PRIVATE static
  26. #endif
  27. #ifndef SQLITE_API
  28. # define SQLITE_API
  29. #endif
  30. /************** Begin file sqliteInt.h ***************************************/
  31. /*
  32. ** 2001 September 15
  33. **
  34. ** The author disclaims copyright to this source code. In place of
  35. ** a legal notice, here is a blessing:
  36. **
  37. ** May you do good and not evil.
  38. ** May you find forgiveness for yourself and forgive others.
  39. ** May you share freely, never taking more than you give.
  40. **
  41. *************************************************************************
  42. ** Internal interface definitions for SQLite.
  43. **
  44. ** @(#) $Id: sqliteInt.h,v 1.824 2009/01/14 23:03:41 drh Exp $
  45. */
  46. #ifndef _SQLITEINT_H_
  47. #define _SQLITEINT_H_
  48. /*
  49. ** Include the configuration header output by 'configure' if we're using the
  50. ** autoconf-based build
  51. */
  52. #ifdef _HAVE_SQLITE_CONFIG_H
  53. #include "config.h"
  54. #endif
  55. /************** Include sqliteLimit.h in the middle of sqliteInt.h ***********/
  56. /************** Begin file sqliteLimit.h *************************************/
  57. /*
  58. ** 2007 May 7
  59. **
  60. ** The author disclaims copyright to this source code. In place of
  61. ** a legal notice, here is a blessing:
  62. **
  63. ** May you do good and not evil.
  64. ** May you find forgiveness for yourself and forgive others.
  65. ** May you share freely, never taking more than you give.
  66. **
  67. *************************************************************************
  68. **
  69. ** This file defines various limits of what SQLite can process.
  70. **
  71. ** @(#) $Id: sqliteLimit.h,v 1.10 2009/01/10 16:15:09 danielk1977 Exp $
  72. */
  73. /*
  74. ** The maximum length of a TEXT or BLOB in bytes. This also
  75. ** limits the size of a row in a table or index.
  76. **
  77. ** The hard limit is the ability of a 32-bit signed integer
  78. ** to count the size: 2^31-1 or 2147483647.
  79. */
  80. #ifndef SQLITE_MAX_LENGTH
  81. # define SQLITE_MAX_LENGTH 1000000000
  82. #endif
  83. /*
  84. ** This is the maximum number of
  85. **
  86. ** * Columns in a table
  87. ** * Columns in an index
  88. ** * Columns in a view
  89. ** * Terms in the SET clause of an UPDATE statement
  90. ** * Terms in the result set of a SELECT statement
  91. ** * Terms in the GROUP BY or ORDER BY clauses of a SELECT statement.
  92. ** * Terms in the VALUES clause of an INSERT statement
  93. **
  94. ** The hard upper limit here is 32676. Most database people will
  95. ** tell you that in a well-normalized database, you usually should
  96. ** not have more than a dozen or so columns in any table. And if
  97. ** that is the case, there is no point in having more than a few
  98. ** dozen values in any of the other situations described above.
  99. */
  100. #ifndef SQLITE_MAX_COLUMN
  101. # define SQLITE_MAX_COLUMN 2000
  102. #endif
  103. /*
  104. ** The maximum length of a single SQL statement in bytes.
  105. **
  106. ** It used to be the case that setting this value to zero would
  107. ** turn the limit off. That is no longer true. It is not possible
  108. ** to turn this limit off.
  109. */
  110. #ifndef SQLITE_MAX_SQL_LENGTH
  111. # define SQLITE_MAX_SQL_LENGTH 1000000000
  112. #endif
  113. /*
  114. ** The maximum depth of an expression tree. This is limited to
  115. ** some extent by SQLITE_MAX_SQL_LENGTH. But sometime you might
  116. ** want to place more severe limits on the complexity of an
  117. ** expression.
  118. **
  119. ** A value of 0 used to mean that the limit was not enforced.
  120. ** But that is no longer true. The limit is now strictly enforced
  121. ** at all times.
  122. */
  123. #ifndef SQLITE_MAX_EXPR_DEPTH
  124. # define SQLITE_MAX_EXPR_DEPTH 1000
  125. #endif
  126. /*
  127. ** The maximum number of terms in a compound SELECT statement.
  128. ** The code generator for compound SELECT statements does one
  129. ** level of recursion for each term. A stack overflow can result
  130. ** if the number of terms is too large. In practice, most SQL
  131. ** never has more than 3 or 4 terms. Use a value of 0 to disable
  132. ** any limit on the number of terms in a compount SELECT.
  133. */
  134. #ifndef SQLITE_MAX_COMPOUND_SELECT
  135. # define SQLITE_MAX_COMPOUND_SELECT 500
  136. #endif
  137. /*
  138. ** The maximum number of opcodes in a VDBE program.
  139. ** Not currently enforced.
  140. */
  141. #ifndef SQLITE_MAX_VDBE_OP
  142. # define SQLITE_MAX_VDBE_OP 25000
  143. #endif
  144. /*
  145. ** The maximum number of arguments to an SQL function.
  146. */
  147. #ifndef SQLITE_MAX_FUNCTION_ARG
  148. # define SQLITE_MAX_FUNCTION_ARG 127
  149. #endif
  150. /*
  151. ** The maximum number of in-memory pages to use for the main database
  152. ** table and for temporary tables. The SQLITE_DEFAULT_CACHE_SIZE
  153. */
  154. #ifndef SQLITE_DEFAULT_CACHE_SIZE
  155. # define SQLITE_DEFAULT_CACHE_SIZE 2000
  156. #endif
  157. #ifndef SQLITE_DEFAULT_TEMP_CACHE_SIZE
  158. # define SQLITE_DEFAULT_TEMP_CACHE_SIZE 500
  159. #endif
  160. /*
  161. ** The maximum number of attached databases. This must be between 0
  162. ** and 30. The upper bound on 30 is because a 32-bit integer bitmap
  163. ** is used internally to track attached databases.
  164. */
  165. #ifndef SQLITE_MAX_ATTACHED
  166. # define SQLITE_MAX_ATTACHED 10
  167. #endif
  168. /*
  169. ** The maximum value of a ?nnn wildcard that the parser will accept.
  170. */
  171. #ifndef SQLITE_MAX_VARIABLE_NUMBER
  172. # define SQLITE_MAX_VARIABLE_NUMBER 999
  173. #endif
  174. /* Maximum page size. The upper bound on this value is 32768. This a limit
  175. ** imposed by the necessity of storing the value in a 2-byte unsigned integer
  176. ** and the fact that the page size must be a power of 2.
  177. **
  178. ** If this limit is changed, then the compiled library is technically
  179. ** incompatible with an SQLite library compiled with a different limit. If
  180. ** a process operating on a database with a page-size of 65536 bytes
  181. ** crashes, then an instance of SQLite compiled with the default page-size
  182. ** limit will not be able to rollback the aborted transaction. This could
  183. ** lead to database corruption.
  184. */
  185. #ifndef SQLITE_MAX_PAGE_SIZE
  186. # define SQLITE_MAX_PAGE_SIZE 32768
  187. #endif
  188. /*
  189. ** The default size of a database page.
  190. */
  191. #ifndef SQLITE_DEFAULT_PAGE_SIZE
  192. # define SQLITE_DEFAULT_PAGE_SIZE 1024
  193. #endif
  194. #if SQLITE_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE
  195. # undef SQLITE_DEFAULT_PAGE_SIZE
  196. # define SQLITE_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE
  197. #endif
  198. /*
  199. ** Ordinarily, if no value is explicitly provided, SQLite creates databases
  200. ** with page size SQLITE_DEFAULT_PAGE_SIZE. However, based on certain
  201. ** device characteristics (sector-size and atomic write() support),
  202. ** SQLite may choose a larger value. This constant is the maximum value
  203. ** SQLite will choose on its own.
  204. */
  205. #ifndef SQLITE_MAX_DEFAULT_PAGE_SIZE
  206. # define SQLITE_MAX_DEFAULT_PAGE_SIZE 8192
  207. #endif
  208. #if SQLITE_MAX_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE
  209. # undef SQLITE_MAX_DEFAULT_PAGE_SIZE
  210. # define SQLITE_MAX_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE
  211. #endif
  212. /*
  213. ** Maximum number of pages in one database file.
  214. **
  215. ** This is really just the default value for the max_page_count pragma.
  216. ** This value can be lowered (or raised) at run-time using that the
  217. ** max_page_count macro.
  218. */
  219. #ifndef SQLITE_MAX_PAGE_COUNT
  220. # define SQLITE_MAX_PAGE_COUNT 1073741823
  221. #endif
  222. /*
  223. ** Maximum length (in bytes) of the pattern in a LIKE or GLOB
  224. ** operator.
  225. */
  226. #ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH
  227. # define SQLITE_MAX_LIKE_PATTERN_LENGTH 50000
  228. #endif
  229. /************** End of sqliteLimit.h *****************************************/
  230. /************** Continuing where we left off in sqliteInt.h ******************/
  231. /* Disable nuisance warnings on Borland compilers */
  232. #if defined(__BORLANDC__)
  233. #pragma warn -rch /* unreachable code */
  234. #pragma warn -ccc /* Condition is always true or false */
  235. #pragma warn -aus /* Assigned value is never used */
  236. #pragma warn -csu /* Comparing signed and unsigned */
  237. #pragma warn -spa /* Suspicious pointer arithmetic */
  238. #endif
  239. /* Needed for various definitions... */
  240. #ifndef _GNU_SOURCE
  241. # define _GNU_SOURCE
  242. #endif
  243. /*
  244. ** Include standard header files as necessary
  245. */
  246. #ifdef HAVE_STDINT_H
  247. #include <stdint.h>
  248. #endif
  249. #ifdef HAVE_INTTYPES_H
  250. #include <inttypes.h>
  251. #endif
  252. /*
  253. * This macro is used to "hide" some ugliness in casting an int
  254. * value to a ptr value under the MSVC 64-bit compiler. Casting
  255. * non 64-bit values to ptr types results in a "hard" error with
  256. * the MSVC 64-bit compiler which this attempts to avoid.
  257. *
  258. * A simple compiler pragma or casting sequence could not be found
  259. * to correct this in all situations, so this macro was introduced.
  260. *
  261. * It could be argued that the intptr_t type could be used in this
  262. * case, but that type is not available on all compilers, or
  263. * requires the #include of specific headers which differs between
  264. * platforms.
  265. */
  266. #define SQLITE_INT_TO_PTR(X) ((void*)&((char*)0)[X])
  267. #define SQLITE_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0))
  268. /*
  269. ** These #defines should enable >2GB file support on POSIX if the
  270. ** underlying operating system supports it. If the OS lacks
  271. ** large file support, or if the OS is windows, these should be no-ops.
  272. **
  273. ** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any
  274. ** system #includes. Hence, this block of code must be the very first
  275. ** code in all source files.
  276. **
  277. ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
  278. ** on the compiler command line. This is necessary if you are compiling
  279. ** on a recent machine (ex: Red Hat 7.2) but you want your code to work
  280. ** on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2
  281. ** without this option, LFS is enable. But LFS does not exist in the kernel
  282. ** in Red Hat 6.0, so the code won't work. Hence, for maximum binary
  283. ** portability you should omit LFS.
  284. **
  285. ** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later.
  286. */
  287. #ifndef SQLITE_DISABLE_LFS
  288. # define _LARGE_FILE 1
  289. # ifndef _FILE_OFFSET_BITS
  290. # define _FILE_OFFSET_BITS 64
  291. # endif
  292. # define _LARGEFILE_SOURCE 1
  293. #endif
  294. /*
  295. ** The SQLITE_THREADSAFE macro must be defined as either 0 or 1.
  296. ** Older versions of SQLite used an optional THREADSAFE macro.
  297. ** We support that for legacy
  298. */
  299. #if !defined(SQLITE_THREADSAFE)
  300. #if defined(THREADSAFE)
  301. # define SQLITE_THREADSAFE THREADSAFE
  302. #else
  303. # define SQLITE_THREADSAFE 1
  304. #endif
  305. #endif
  306. /*
  307. ** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1.
  308. ** It determines whether or not the features related to
  309. ** SQLITE_CONFIG_MEMSTATUS are available by default or not. This value can
  310. ** be overridden at runtime using the sqlite3_config() API.
  311. */
  312. #if !defined(SQLITE_DEFAULT_MEMSTATUS)
  313. # define SQLITE_DEFAULT_MEMSTATUS 1
  314. #endif
  315. /*
  316. ** Exactly one of the following macros must be defined in order to
  317. ** specify which memory allocation subsystem to use.
  318. **
  319. ** SQLITE_SYSTEM_MALLOC // Use normal system malloc()
  320. ** SQLITE_MEMDEBUG // Debugging version of system malloc()
  321. ** SQLITE_MEMORY_SIZE // internal allocator #1
  322. ** SQLITE_MMAP_HEAP_SIZE // internal mmap() allocator
  323. ** SQLITE_POW2_MEMORY_SIZE // internal power-of-two allocator
  324. **
  325. ** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as
  326. ** the default.
  327. */
  328. #if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)+\
  329. defined(SQLITE_MEMORY_SIZE)+defined(SQLITE_MMAP_HEAP_SIZE)+\
  330. defined(SQLITE_POW2_MEMORY_SIZE)>1
  331. # error "At most one of the following compile-time configuration options\
  332. is allows: SQLITE_SYSTEM_MALLOC, SQLITE_MEMDEBUG, SQLITE_MEMORY_SIZE,\
  333. SQLITE_MMAP_HEAP_SIZE, SQLITE_POW2_MEMORY_SIZE"
  334. #endif
  335. #if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)+\
  336. defined(SQLITE_MEMORY_SIZE)+defined(SQLITE_MMAP_HEAP_SIZE)+\
  337. defined(SQLITE_POW2_MEMORY_SIZE)==0
  338. # define SQLITE_SYSTEM_MALLOC 1
  339. #endif
  340. /*
  341. ** If SQLITE_MALLOC_SOFT_LIMIT is defined, then try to keep the
  342. ** sizes of memory allocations below this value where possible.
  343. */
  344. #if defined(SQLITE_POW2_MEMORY_SIZE) && !defined(SQLITE_MALLOC_SOFT_LIMIT)
  345. # define SQLITE_MALLOC_SOFT_LIMIT 1024
  346. #endif
  347. /*
  348. ** We need to define _XOPEN_SOURCE as follows in order to enable
  349. ** recursive mutexes on most Unix systems. But Mac OS X is different.
  350. ** The _XOPEN_SOURCE define causes problems for Mac OS X we are told,
  351. ** so it is omitted there. See ticket #2673.
  352. **
  353. ** Later we learn that _XOPEN_SOURCE is poorly or incorrectly
  354. ** implemented on some systems. So we avoid defining it at all
  355. ** if it is already defined or if it is unneeded because we are
  356. ** not doing a threadsafe build. Ticket #2681.
  357. **
  358. ** See also ticket #2741.
  359. */
  360. #if !defined(_XOPEN_SOURCE) && !defined(__DARWIN__) && !defined(__APPLE__) && SQLITE_THREADSAFE
  361. # define _XOPEN_SOURCE 500 /* Needed to enable pthread recursive mutexes */
  362. #endif
  363. /*
  364. ** The TCL headers are only needed when compiling the TCL bindings.
  365. */
  366. #if defined(SQLITE_TCL) || defined(TCLSH)
  367. # include <tcl.h>
  368. #endif
  369. /*
  370. ** Many people are failing to set -DNDEBUG=1 when compiling SQLite.
  371. ** Setting NDEBUG makes the code smaller and run faster. So the following
  372. ** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1
  373. ** option is set. Thus NDEBUG becomes an opt-in rather than an opt-out
  374. ** feature.
  375. */
  376. #if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
  377. # define NDEBUG 1
  378. #endif
  379. /*
  380. ** The testcase() macro is used to aid in coverage testing. When
  381. ** doing coverage testing, the condition inside the argument to
  382. ** testcase() must be evaluated both true and false in order to
  383. ** get full branch coverage. The testcase() macro is inserted
  384. ** to help ensure adequate test coverage in places where simple
  385. ** condition/decision coverage is inadequate. For example, testcase()
  386. ** can be used to make sure boundary values are tested. For
  387. ** bitmask tests, testcase() can be used to make sure each bit
  388. ** is significant and used at least once. On switch statements
  389. ** where multiple cases go to the same block of code, testcase()
  390. ** can insure that all cases are evaluated.
  391. **
  392. */
  393. #ifdef SQLITE_COVERAGE_TEST
  394. SQLITE_PRIVATE void sqlite3Coverage(int);
  395. # define testcase(X) if( X ){ sqlite3Coverage(__LINE__); }
  396. #else
  397. # define testcase(X)
  398. #endif
  399. /*
  400. ** The TESTONLY macro is used to enclose variable declarations or
  401. ** other bits of code that are needed to support the arguments
  402. ** within testcase() and assert() macros.
  403. */
  404. #if !defined(NDEBUG) || defined(SQLITE_COVERAGE_TEST)
  405. # define TESTONLY(X) X
  406. #else
  407. # define TESTONLY(X)
  408. #endif
  409. /*
  410. ** The ALWAYS and NEVER macros surround boolean expressions which
  411. ** are intended to always be true or false, respectively. Such
  412. ** expressions could be omitted from the code completely. But they
  413. ** are included in a few cases in order to enhance the resilience
  414. ** of SQLite to unexpected behavior - to make the code "self-healing"
  415. ** or "ductile" rather than being "brittle" and crashing at the first
  416. ** hint of unplanned behavior.
  417. **
  418. ** In other words, ALWAYS and NEVER are added for defensive code.
  419. **
  420. ** When doing coverage testing ALWAYS and NEVER are hard-coded to
  421. ** be true and false so that the unreachable code then specify will
  422. ** not be counted as untested code.
  423. */
  424. #if defined(SQLITE_COVERAGE_TEST)
  425. # define ALWAYS(X) (1)
  426. # define NEVER(X) (0)
  427. #elif !defined(NDEBUG)
  428. SQLITE_PRIVATE int sqlite3Assert(void);
  429. # define ALWAYS(X) ((X)?1:sqlite3Assert())
  430. # define NEVER(X) ((X)?sqlite3Assert():0)
  431. #else
  432. # define ALWAYS(X) (X)
  433. # define NEVER(X) (X)
  434. #endif
  435. /*
  436. ** The macro unlikely() is a hint that surrounds a boolean
  437. ** expression that is usually false. Macro likely() surrounds
  438. ** a boolean expression that is usually true. GCC is able to
  439. ** use these hints to generate better code, sometimes.
  440. */
  441. #if defined(__GNUC__) && 0
  442. # define likely(X) __builtin_expect((X),1)
  443. # define unlikely(X) __builtin_expect((X),0)
  444. #else
  445. # define likely(X) !!(X)
  446. # define unlikely(X) !!(X)
  447. #endif
  448. /*
  449. ** Sometimes we need a small amount of code such as a variable initialization
  450. ** to setup for a later assert() statement. We do not want this code to
  451. ** appear when assert() is disabled. The following macro is therefore
  452. ** used to contain that setup code. The "VVA" acronym stands for
  453. ** "Verification, Validation, and Accreditation". In other words, the
  454. ** code within VVA_ONLY() will only run during verification processes.
  455. */
  456. #ifndef NDEBUG
  457. # define VVA_ONLY(X) X
  458. #else
  459. # define VVA_ONLY(X)
  460. #endif
  461. /************** Include sqlite3.h in the middle of sqliteInt.h ***************/
  462. /************** Begin file sqlite3.h *****************************************/
  463. /*
  464. ** 2001 September 15
  465. **
  466. ** The author disclaims copyright to this source code. In place of
  467. ** a legal notice, here is a blessing:
  468. **
  469. ** May you do good and not evil.
  470. ** May you find forgiveness for yourself and forgive others.
  471. ** May you share freely, never taking more than you give.
  472. **
  473. *************************************************************************
  474. ** This header file defines the interface that the SQLite library
  475. ** presents to client programs. If a C-function, structure, datatype,
  476. ** or constant definition does not appear in this file, then it is
  477. ** not a published API of SQLite, is subject to change without
  478. ** notice, and should not be referenced by programs that use SQLite.
  479. **
  480. ** Some of the definitions that are in this file are marked as
  481. ** "experimental". Experimental interfaces are normally new
  482. ** features recently added to SQLite. We do not anticipate changes
  483. ** to experimental interfaces but reserve to make minor changes if
  484. ** experience from use "in the wild" suggest such changes are prudent.
  485. **
  486. ** The official C-language API documentation for SQLite is derived
  487. ** from comments in this file. This file is the authoritative source
  488. ** on how SQLite interfaces are suppose to operate.
  489. **
  490. ** The name of this file under configuration management is "sqlite.h.in".
  491. ** The makefile makes some minor changes to this file (such as inserting
  492. ** the version number) and changes its name to "sqlite3.h" as
  493. ** part of the build process.
  494. **
  495. ** @(#) $Id: sqlite.h.in,v 1.421 2008/12/30 06:24:58 danielk1977 Exp $
  496. */
  497. #ifndef _SQLITE3_H_
  498. #define _SQLITE3_H_
  499. #include <stdarg.h> /* Needed for the definition of va_list */
  500. /*
  501. ** Make sure we can call this stuff from C++.
  502. */
  503. #if 0
  504. extern "C" {
  505. #endif
  506. /*
  507. ** Add the ability to override 'extern'
  508. */
  509. #ifndef SQLITE_EXTERN
  510. # define SQLITE_EXTERN extern
  511. #endif
  512. /*
  513. ** These no-op macros are used in front of interfaces to mark those
  514. ** interfaces as either deprecated or experimental. New applications
  515. ** should not use deprecated intrfaces - they are support for backwards
  516. ** compatibility only. Application writers should be aware that
  517. ** experimental interfaces are subject to change in point releases.
  518. **
  519. ** These macros used to resolve to various kinds of compiler magic that
  520. ** would generate warning messages when they were used. But that
  521. ** compiler magic ended up generating such a flurry of bug reports
  522. ** that we have taken it all out and gone back to using simple
  523. ** noop macros.
  524. */
  525. #define SQLITE_DEPRECATED
  526. #define SQLITE_EXPERIMENTAL
  527. /*
  528. ** Ensure these symbols were not defined by some previous header file.
  529. */
  530. #ifdef SQLITE_VERSION
  531. # undef SQLITE_VERSION
  532. #endif
  533. #ifdef SQLITE_VERSION_NUMBER
  534. # undef SQLITE_VERSION_NUMBER
  535. #endif
  536. /*
  537. ** CAPI3REF: Compile-Time Library Version Numbers {H10010} <S60100>
  538. **
  539. ** The SQLITE_VERSION and SQLITE_VERSION_NUMBER #defines in
  540. ** the sqlite3.h file specify the version of SQLite with which
  541. ** that header file is associated.
  542. **
  543. ** The "version" of SQLite is a string of the form "X.Y.Z".
  544. ** The phrase "alpha" or "beta" might be appended after the Z.
  545. ** The X value is major version number always 3 in SQLite3.
  546. ** The X value only changes when backwards compatibility is
  547. ** broken and we intend to never break backwards compatibility.
  548. ** The Y value is the minor version number and only changes when
  549. ** there are major feature enhancements that are forwards compatible
  550. ** but not backwards compatible.
  551. ** The Z value is the release number and is incremented with
  552. ** each release but resets back to 0 whenever Y is incremented.
  553. **
  554. ** See also: [sqlite3_libversion()] and [sqlite3_libversion_number()].
  555. **
  556. ** INVARIANTS:
  557. **
  558. ** {H10011} The SQLITE_VERSION #define in the sqlite3.h header file shall
  559. ** evaluate to a string literal that is the SQLite version
  560. ** with which the header file is associated.
  561. **
  562. ** {H10014} The SQLITE_VERSION_NUMBER #define shall resolve to an integer
  563. ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z
  564. ** are the major version, minor version, and release number.
  565. */
  566. #define SQLITE_VERSION "3.6.10"
  567. #define SQLITE_VERSION_NUMBER 3006010
  568. /*
  569. ** CAPI3REF: Run-Time Library Version Numbers {H10020} <S60100>
  570. ** KEYWORDS: sqlite3_version
  571. **
  572. ** These features provide the same information as the [SQLITE_VERSION]
  573. ** and [SQLITE_VERSION_NUMBER] #defines in the header, but are associated
  574. ** with the library instead of the header file. Cautious programmers might
  575. ** include a check in their application to verify that
  576. ** sqlite3_libversion_number() always returns the value
  577. ** [SQLITE_VERSION_NUMBER].
  578. **
  579. ** The sqlite3_libversion() function returns the same information as is
  580. ** in the sqlite3_version[] string constant. The function is provided
  581. ** for use in DLLs since DLL users usually do not have direct access to string
  582. ** constants within the DLL.
  583. **
  584. ** INVARIANTS:
  585. **
  586. ** {H10021} The [sqlite3_libversion_number()] interface shall return
  587. ** an integer equal to [SQLITE_VERSION_NUMBER].
  588. **
  589. ** {H10022} The [sqlite3_version] string constant shall contain
  590. ** the text of the [SQLITE_VERSION] string.
  591. **
  592. ** {H10023} The [sqlite3_libversion()] function shall return
  593. ** a pointer to the [sqlite3_version] string constant.
  594. */
  595. SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
  596. SQLITE_API const char *sqlite3_libversion(void);
  597. SQLITE_API int sqlite3_libversion_number(void);
  598. /*
  599. ** CAPI3REF: Test To See If The Library Is Threadsafe {H10100} <S60100>
  600. **
  601. ** SQLite can be compiled with or without mutexes. When
  602. ** the [SQLITE_THREADSAFE] C preprocessor macro 1 or 2, mutexes
  603. ** are enabled and SQLite is threadsafe. When the
  604. ** [SQLITE_THREADSAFE] macro is 0,
  605. ** the mutexes are omitted. Without the mutexes, it is not safe
  606. ** to use SQLite concurrently from more than one thread.
  607. **
  608. ** Enabling mutexes incurs a measurable performance penalty.
  609. ** So if speed is of utmost importance, it makes sense to disable
  610. ** the mutexes. But for maximum safety, mutexes should be enabled.
  611. ** The default behavior is for mutexes to be enabled.
  612. **
  613. ** This interface can be used by a program to make sure that the
  614. ** version of SQLite that it is linking against was compiled with
  615. ** the desired setting of the [SQLITE_THREADSAFE] macro.
  616. **
  617. ** This interface only reports on the compile-time mutex setting
  618. ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
  619. ** SQLITE_THREADSAFE=1 then mutexes are enabled by default but
  620. ** can be fully or partially disabled using a call to [sqlite3_config()]
  621. ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
  622. ** or [SQLITE_CONFIG_MUTEX]. The return value of this function shows
  623. ** only the default compile-time setting, not any run-time changes
  624. ** to that setting.
  625. **
  626. ** See the [threading mode] documentation for additional information.
  627. **
  628. ** INVARIANTS:
  629. **
  630. ** {H10101} The [sqlite3_threadsafe()] function shall return zero if
  631. ** and only if SQLite was compiled with mutexing code omitted.
  632. **
  633. ** {H10102} The value returned by the [sqlite3_threadsafe()] function
  634. ** shall remain the same across calls to [sqlite3_config()].
  635. */
  636. SQLITE_API int sqlite3_threadsafe(void);
  637. /*
  638. ** CAPI3REF: Database Connection Handle {H12000} <S40200>
  639. ** KEYWORDS: {database connection} {database connections}
  640. **
  641. ** Each open SQLite database is represented by a pointer to an instance of
  642. ** the opaque structure named "sqlite3". It is useful to think of an sqlite3
  643. ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and
  644. ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
  645. ** is its destructor. There are many other interfaces (such as
  646. ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
  647. ** [sqlite3_busy_timeout()] to name but three) that are methods on an
  648. ** sqlite3 object.
  649. */
  650. typedef struct sqlite3 sqlite3;
  651. /*
  652. ** CAPI3REF: 64-Bit Integer Types {H10200} <S10110>
  653. ** KEYWORDS: sqlite_int64 sqlite_uint64
  654. **
  655. ** Because there is no cross-platform way to specify 64-bit integer types
  656. ** SQLite includes typedefs for 64-bit signed and unsigned integers.
  657. **
  658. ** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
  659. ** The sqlite_int64 and sqlite_uint64 types are supported for backwards
  660. ** compatibility only.
  661. **
  662. ** INVARIANTS:
  663. **
  664. ** {H10201} The [sqlite_int64] and [sqlite3_int64] type shall specify
  665. ** a 64-bit signed integer.
  666. **
  667. ** {H10202} The [sqlite_uint64] and [sqlite3_uint64] type shall specify
  668. ** a 64-bit unsigned integer.
  669. */
  670. #ifdef SQLITE_INT64_TYPE
  671. typedef SQLITE_INT64_TYPE sqlite_int64;
  672. typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
  673. #elif defined(_MSC_VER) || defined(__BORLANDC__)
  674. typedef __int64 sqlite_int64;
  675. typedef unsigned __int64 sqlite_uint64;
  676. #else
  677. typedef long long int sqlite_int64;
  678. typedef unsigned long long int sqlite_uint64;
  679. #endif
  680. typedef sqlite_int64 sqlite3_int64;
  681. typedef sqlite_uint64 sqlite3_uint64;
  682. /*
  683. ** If compiling for a processor that lacks floating point support,
  684. ** substitute integer for floating-point.
  685. */
  686. #ifdef SQLITE_OMIT_FLOATING_POINT
  687. # define double sqlite3_int64
  688. #endif
  689. /*
  690. ** CAPI3REF: Closing A Database Connection {H12010} <S30100><S40200>
  691. **
  692. ** This routine is the destructor for the [sqlite3] object.
  693. **
  694. ** Applications should [sqlite3_finalize | finalize] all [prepared statements]
  695. ** and [sqlite3_blob_close | close] all [BLOB handles] associated with
  696. ** the [sqlite3] object prior to attempting to close the object.
  697. ** The [sqlite3_next_stmt()] interface can be used to locate all
  698. ** [prepared statements] associated with a [database connection] if desired.
  699. ** Typical code might look like this:
  700. **
  701. ** <blockquote><pre>
  702. ** sqlite3_stmt *pStmt;
  703. ** while( (pStmt = sqlite3_next_stmt(db, 0))!=0 ){
  704. ** &nbsp; sqlite3_finalize(pStmt);
  705. ** }
  706. ** </pre></blockquote>
  707. **
  708. ** If [sqlite3_close()] is invoked while a transaction is open,
  709. ** the transaction is automatically rolled back.
  710. **
  711. ** INVARIANTS:
  712. **
  713. ** {H12011} A successful call to [sqlite3_close(C)] shall destroy the
  714. ** [database connection] object C.
  715. **
  716. ** {H12012} A successful call to [sqlite3_close(C)] shall return SQLITE_OK.
  717. **
  718. ** {H12013} A successful call to [sqlite3_close(C)] shall release all
  719. ** memory and system resources associated with [database connection]
  720. ** C.
  721. **
  722. ** {H12014} A call to [sqlite3_close(C)] on a [database connection] C that
  723. ** has one or more open [prepared statements] shall fail with
  724. ** an [SQLITE_BUSY] error code.
  725. **
  726. ** {H12015} A call to [sqlite3_close(C)] where C is a NULL pointer shall
  727. ** be a harmless no-op returning SQLITE_OK.
  728. **
  729. ** {H12019} When [sqlite3_close(C)] is invoked on a [database connection] C
  730. ** that has a pending transaction, the transaction shall be
  731. ** rolled back.
  732. **
  733. ** ASSUMPTIONS:
  734. **
  735. ** {A12016} The C parameter to [sqlite3_close(C)] must be either a NULL
  736. ** pointer or an [sqlite3] object pointer obtained
  737. ** from [sqlite3_open()], [sqlite3_open16()], or
  738. ** [sqlite3_open_v2()], and not previously closed.
  739. */
  740. SQLITE_API int sqlite3_close(sqlite3 *);
  741. /*
  742. ** The type for a callback function.
  743. ** This is legacy and deprecated. It is included for historical
  744. ** compatibility and is not documented.
  745. */
  746. typedef int (*sqlite3_callback)(void*,int,char**, char**);
  747. /*
  748. ** CAPI3REF: One-Step Query Execution Interface {H12100} <S10000>
  749. **
  750. ** The sqlite3_exec() interface is a convenient way of running one or more
  751. ** SQL statements without having to write a lot of C code. The UTF-8 encoded
  752. ** SQL statements are passed in as the second parameter to sqlite3_exec().
  753. ** The statements are evaluated one by one until either an error or
  754. ** an interrupt is encountered, or until they are all done. The 3rd parameter
  755. ** is an optional callback that is invoked once for each row of any query
  756. ** results produced by the SQL statements. The 5th parameter tells where
  757. ** to write any error messages.
  758. **
  759. ** The error message passed back through the 5th parameter is held
  760. ** in memory obtained from [sqlite3_malloc()]. To avoid a memory leak,
  761. ** the calling application should call [sqlite3_free()] on any error
  762. ** message returned through the 5th parameter when it has finished using
  763. ** the error message.
  764. **
  765. ** If the SQL statement in the 2nd parameter is NULL or an empty string
  766. ** or a string containing only whitespace and comments, then no SQL
  767. ** statements are evaluated and the database is not changed.
  768. **
  769. ** The sqlite3_exec() interface is implemented in terms of
  770. ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()].
  771. ** The sqlite3_exec() routine does nothing to the database that cannot be done
  772. ** by [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()].
  773. **
  774. ** INVARIANTS:
  775. **
  776. ** {H12101} A successful invocation of [sqlite3_exec(D,S,C,A,E)]
  777. ** shall sequentially evaluate all of the UTF-8 encoded,
  778. ** semicolon-separated SQL statements in the zero-terminated
  779. ** string S within the context of the [database connection] D.
  780. **
  781. ** {H12102} If the S parameter to [sqlite3_exec(D,S,C,A,E)] is NULL then
  782. ** the actions of the interface shall be the same as if the
  783. ** S parameter were an empty string.
  784. **
  785. ** {H12104} The return value of [sqlite3_exec()] shall be [SQLITE_OK] if all
  786. ** SQL statements run successfully and to completion.
  787. **
  788. ** {H12105} The return value of [sqlite3_exec()] shall be an appropriate
  789. ** non-zero [error code] if any SQL statement fails.
  790. **
  791. ** {H12107} If one or more of the SQL statements handed to [sqlite3_exec()]
  792. ** return results and the 3rd parameter is not NULL, then
  793. ** the callback function specified by the 3rd parameter shall be
  794. ** invoked once for each row of result.
  795. **
  796. ** {H12110} If the callback returns a non-zero value then [sqlite3_exec()]
  797. ** shall abort the SQL statement it is currently evaluating,
  798. ** skip all subsequent SQL statements, and return [SQLITE_ABORT].
  799. **
  800. ** {H12113} The [sqlite3_exec()] routine shall pass its 4th parameter through
  801. ** as the 1st parameter of the callback.
  802. **
  803. ** {H12116} The [sqlite3_exec()] routine shall set the 2nd parameter of its
  804. ** callback to be the number of columns in the current row of
  805. ** result.
  806. **
  807. ** {H12119} The [sqlite3_exec()] routine shall set the 3rd parameter of its
  808. ** callback to be an array of pointers to strings holding the
  809. ** values for each column in the current result set row as
  810. ** obtained from [sqlite3_column_text()].
  811. **
  812. ** {H12122} The [sqlite3_exec()] routine shall set the 4th parameter of its
  813. ** callback to be an array of pointers to strings holding the
  814. ** names of result columns as obtained from [sqlite3_column_name()].
  815. **
  816. ** {H12125} If the 3rd parameter to [sqlite3_exec()] is NULL then
  817. ** [sqlite3_exec()] shall silently discard query results.
  818. **
  819. ** {H12131} If an error occurs while parsing or evaluating any of the SQL
  820. ** statements in the S parameter of [sqlite3_exec(D,S,C,A,E)] and if
  821. ** the E parameter is not NULL, then [sqlite3_exec()] shall store
  822. ** in *E an appropriate error message written into memory obtained
  823. ** from [sqlite3_malloc()].
  824. **
  825. ** {H12134} The [sqlite3_exec(D,S,C,A,E)] routine shall set the value of
  826. ** *E to NULL if E is not NULL and there are no errors.
  827. **
  828. ** {H12137} The [sqlite3_exec(D,S,C,A,E)] function shall set the [error code]
  829. ** and message accessible via [sqlite3_errcode()],
  830. ** [sqlite3_extended_errcode()],
  831. ** [sqlite3_errmsg()], and [sqlite3_errmsg16()].
  832. **
  833. ** {H12138} If the S parameter to [sqlite3_exec(D,S,C,A,E)] is NULL or an
  834. ** empty string or contains nothing other than whitespace, comments,
  835. ** and/or semicolons, then results of [sqlite3_errcode()],
  836. ** [sqlite3_extended_errcode()],
  837. ** [sqlite3_errmsg()], and [sqlite3_errmsg16()]
  838. ** shall reset to indicate no errors.
  839. **
  840. ** ASSUMPTIONS:
  841. **
  842. ** {A12141} The first parameter to [sqlite3_exec()] must be an valid and open
  843. ** [database connection].
  844. **
  845. ** {A12142} The database connection must not be closed while
  846. ** [sqlite3_exec()] is running.
  847. **
  848. ** {A12143} The calling function should use [sqlite3_free()] to free
  849. ** the memory that *errmsg is left pointing at once the error
  850. ** message is no longer needed.
  851. **
  852. ** {A12145} The SQL statement text in the 2nd parameter to [sqlite3_exec()]
  853. ** must remain unchanged while [sqlite3_exec()] is running.
  854. */
  855. SQLITE_API int sqlite3_exec(
  856. sqlite3*, /* An open database */
  857. const char *sql, /* SQL to be evaluated */
  858. int (*callback)(void*,int,char**,char**), /* Callback function */
  859. void *, /* 1st argument to callback */
  860. char **errmsg /* Error msg written here */
  861. );
  862. /*
  863. ** CAPI3REF: Result Codes {H10210} <S10700>
  864. ** KEYWORDS: SQLITE_OK {error code} {error codes}
  865. ** KEYWORDS: {result code} {result codes}
  866. **
  867. ** Many SQLite functions return an integer result code from the set shown
  868. ** here in order to indicates success or failure.
  869. **
  870. ** New error codes may be added in future versions of SQLite.
  871. **
  872. ** See also: [SQLITE_IOERR_READ | extended result codes]
  873. */
  874. #define SQLITE_OK 0 /* Successful result */
  875. /* beginning-of-error-codes */
  876. #define SQLITE_ERROR 1 /* SQL error or missing database */
  877. #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
  878. #define SQLITE_PERM 3 /* Access permission denied */
  879. #define SQLITE_ABORT 4 /* Callback routine requested an abort */
  880. #define SQLITE_BUSY 5 /* The database file is locked */
  881. #define SQLITE_LOCKED 6 /* A table in the database is locked */
  882. #define SQLITE_NOMEM 7 /* A malloc() failed */
  883. #define SQLITE_READONLY 8 /* Attempt to write a readonly database */
  884. #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
  885. #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
  886. #define SQLITE_CORRUPT 11 /* The database disk image is malformed */
  887. #define SQLITE_NOTFOUND 12 /* NOT USED. Table or record not found */
  888. #define SQLITE_FULL 13 /* Insertion failed because database is full */
  889. #define SQLITE_CANTOPEN 14 /* Unable to open the database file */
  890. #define SQLITE_PROTOCOL 15 /* NOT USED. Database lock protocol error */
  891. #define SQLITE_EMPTY 16 /* Database is empty */
  892. #define SQLITE_SCHEMA 17 /* The database schema changed */
  893. #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
  894. #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
  895. #define SQLITE_MISMATCH 20 /* Data type mismatch */
  896. #define SQLITE_MISUSE 21 /* Library used incorrectly */
  897. #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
  898. #define SQLITE_AUTH 23 /* Authorization denied */
  899. #define SQLITE_FORMAT 24 /* Auxiliary database format error */
  900. #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
  901. #define SQLITE_NOTADB 26 /* File opened that is not a database file */
  902. #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
  903. #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
  904. /* end-of-error-codes */
  905. /*
  906. ** CAPI3REF: Extended Result Codes {H10220} <S10700>
  907. ** KEYWORDS: {extended error code} {extended error codes}
  908. ** KEYWORDS: {extended result code} {extended result codes}
  909. **
  910. ** In its default configuration, SQLite API routines return one of 26 integer
  911. ** [SQLITE_OK | result codes]. However, experience has shown that many of
  912. ** these result codes are too coarse-grained. They do not provide as
  913. ** much information about problems as programmers might like. In an effort to
  914. ** address this, newer versions of SQLite (version 3.3.8 and later) include
  915. ** support for additional result codes that provide more detailed information
  916. ** about errors. The extended result codes are enabled or disabled
  917. ** on a per database connection basis using the
  918. ** [sqlite3_extended_result_codes()] API.
  919. **
  920. ** Some of the available extended result codes are listed here.
  921. ** One may expect the number of extended result codes will be expand
  922. ** over time. Software that uses extended result codes should expect
  923. ** to see new result codes in future releases of SQLite.
  924. **
  925. ** The SQLITE_OK result code will never be extended. It will always
  926. ** be exactly zero.
  927. **
  928. ** INVARIANTS:
  929. **
  930. ** {H10223} The symbolic name for an extended result code shall contains
  931. ** a related primary result code as a prefix.
  932. **
  933. ** {H10224} Primary result code names shall contain a single "_" character.
  934. **
  935. ** {H10225} Extended result code names shall contain two or more "_" characters.
  936. **
  937. ** {H10226} The numeric value of an extended result code shall contain the
  938. ** numeric value of its corresponding primary result code in
  939. ** its least significant 8 bits.
  940. */
  941. #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))
  942. #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))
  943. #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8))
  944. #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8))
  945. #define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8))
  946. #define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8))
  947. #define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8))
  948. #define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8))
  949. #define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8))
  950. #define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8))
  951. #define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8))
  952. #define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8))
  953. #define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8))
  954. #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
  955. #define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8))
  956. #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8))
  957. #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8))
  958. /*
  959. ** CAPI3REF: Flags For File Open Operations {H10230} <H11120> <H12700>
  960. **
  961. ** These bit values are intended for use in the
  962. ** 3rd parameter to the [sqlite3_open_v2()] interface and
  963. ** in the 4th parameter to the xOpen method of the
  964. ** [sqlite3_vfs] object.
  965. */
  966. #define SQLITE_OPEN_READONLY 0x00000001
  967. #define SQLITE_OPEN_READWRITE 0x00000002
  968. #define SQLITE_OPEN_CREATE 0x00000004
  969. #define SQLITE_OPEN_DELETEONCLOSE 0x00000008
  970. #define SQLITE_OPEN_EXCLUSIVE 0x00000010
  971. #define SQLITE_OPEN_MAIN_DB 0x00000100
  972. #define SQLITE_OPEN_TEMP_DB 0x00000200
  973. #define SQLITE_OPEN_TRANSIENT_DB 0x00000400
  974. #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800
  975. #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000
  976. #define SQLITE_OPEN_SUBJOURNAL 0x00002000
  977. #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000
  978. #define SQLITE_OPEN_NOMUTEX 0x00008000
  979. #define SQLITE_OPEN_FULLMUTEX 0x00010000
  980. /*
  981. ** CAPI3REF: Device Characteristics {H10240} <H11120>
  982. **
  983. ** The xDeviceCapabilities method of the [sqlite3_io_methods]
  984. ** object returns an integer which is a vector of the these
  985. ** bit values expressing I/O characteristics of the mass storage
  986. ** device that holds the file that the [sqlite3_io_methods]
  987. ** refers to.
  988. **
  989. ** The SQLITE_IOCAP_ATOMIC property means that all writes of
  990. ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
  991. ** mean that writes of blocks that are nnn bytes in size and
  992. ** are aligned to an address which is an integer multiple of
  993. ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
  994. ** that when data is appended to a file, the data is appended
  995. ** first then the size of the file is extended, never the other
  996. ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
  997. ** information is written to disk in the same order as calls
  998. ** to xWrite().
  999. */
  1000. #define SQLITE_IOCAP_ATOMIC 0x00000001
  1001. #define SQLITE_IOCAP_ATOMIC512 0x00000002
  1002. #define SQLITE_IOCAP_ATOMIC1K 0x00000004
  1003. #define SQLITE_IOCAP_ATOMIC2K 0x00000008
  1004. #define SQLITE_IOCAP_ATOMIC4K 0x00000010
  1005. #define SQLITE_IOCAP_ATOMIC8K 0x00000020
  1006. #define SQLITE_IOCAP_ATOMIC16K 0x00000040
  1007. #define SQLITE_IOCAP_ATOMIC32K 0x00000080
  1008. #define SQLITE_IOCAP_ATOMIC64K 0x00000100
  1009. #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
  1010. #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
  1011. /*
  1012. ** CAPI3REF: File Locking Levels {H10250} <H11120> <H11310>
  1013. **
  1014. ** SQLite uses one of these integer values as the second
  1015. ** argument to calls it makes to the xLock() and xUnlock() methods
  1016. ** of an [sqlite3_io_methods] object.
  1017. */
  1018. #define SQLITE_LOCK_NONE 0
  1019. #define SQLITE_LOCK_SHARED 1
  1020. #define SQLITE_LOCK_RESERVED 2
  1021. #define SQLITE_LOCK_PENDING 3
  1022. #define SQLITE_LOCK_EXCLUSIVE 4
  1023. /*
  1024. ** CAPI3REF: Synchronization Type Flags {H10260} <H11120>
  1025. **
  1026. ** When SQLite invokes the xSync() method of an
  1027. ** [sqlite3_io_methods] object it uses a combination of
  1028. ** these integer values as the second argument.
  1029. **
  1030. ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
  1031. ** sync operation only needs to flush data to mass storage. Inode
  1032. ** information need not be flushed. The SQLITE_SYNC_NORMAL flag means
  1033. ** to use normal fsync() semantics. The SQLITE_SYNC_FULL flag means
  1034. ** to use Mac OS X style fullsync instead of fsync().
  1035. */
  1036. #define SQLITE_SYNC_NORMAL 0x00002
  1037. #define SQLITE_SYNC_FULL 0x00003
  1038. #define SQLITE_SYNC_DATAONLY 0x00010
  1039. /*
  1040. ** CAPI3REF: OS Interface Open File Handle {H11110} <S20110>
  1041. **
  1042. ** An [sqlite3_file] object represents an open file in the OS
  1043. ** interface layer. Individual OS interface implementations will
  1044. ** want to subclass this object by appending additional fields
  1045. ** for their own use. The pMethods entry is a pointer to an
  1046. ** [sqlite3_io_methods] object that defines methods for performing
  1047. ** I/O operations on the open file.
  1048. */
  1049. typedef struct sqlite3_file sqlite3_file;
  1050. struct sqlite3_file {
  1051. const struct sqlite3_io_methods *pMethods; /* Methods for an open file */
  1052. };
  1053. /*
  1054. ** CAPI3REF: OS Interface File Virtual Methods Object {H11120} <S20110>
  1055. **
  1056. ** Every file opened by the [sqlite3_vfs] xOpen method populates an
  1057. ** [sqlite3_file] object (or, more commonly, a subclass of the
  1058. ** [sqlite3_file] object) with a pointer to an instance of this object.
  1059. ** This object defines the methods used to perform various operations
  1060. ** against the open file represented by the [sqlite3_file] object.
  1061. **
  1062. ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
  1063. ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
  1064. ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]
  1065. ** flag may be ORed in to indicate that only the data of the file
  1066. ** and not its inode needs to be synced.
  1067. **
  1068. ** The integer values to xLock() and xUnlock() are one of
  1069. ** <ul>
  1070. ** <li> [SQLITE_LOCK_NONE],
  1071. ** <li> [SQLITE_LOCK_SHARED],
  1072. ** <li> [SQLITE_LOCK_RESERVED],
  1073. ** <li> [SQLITE_LOCK_PENDING], or
  1074. ** <li> [SQLITE_LOCK_EXCLUSIVE].
  1075. ** </ul>
  1076. ** xLock() increases the lock. xUnlock() decreases the lock.
  1077. ** The xCheckReservedLock() method checks whether any database connection,
  1078. ** either in this process or in some other process, is holding a RESERVED,
  1079. ** PENDING, or EXCLUSIVE lock on the file. It returns true
  1080. ** if such a lock exists and false otherwise.
  1081. **
  1082. ** The xFileControl() method is a generic interface that allows custom
  1083. ** VFS implementations to directly control an open file using the
  1084. ** [sqlite3_file_control()] interface. The second "op" argument is an
  1085. ** integer opcode. The third argument is a generic pointer intended to
  1086. ** point to a structure that may contain arguments or space in which to
  1087. ** write return values. Potential uses for xFileControl() might be
  1088. ** functions to enable blocking locks with timeouts, to change the
  1089. ** locking strategy (for example to use dot-file locks), to inquire
  1090. ** about the status of a lock, or to break stale locks. The SQLite
  1091. ** core reserves all opcodes less than 100 for its own use.
  1092. ** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available.
  1093. ** Applications that define a custom xFileControl method should use opcodes
  1094. ** greater than 100 to avoid conflicts.
  1095. **
  1096. ** The xSectorSize() method returns the sector size of the
  1097. ** device that underlies the file. The sector size is the
  1098. ** minimum write that can be performed without disturbing
  1099. ** other bytes in the file. The xDeviceCharacteristics()
  1100. ** method returns a bit vector describing behaviors of the
  1101. ** underlying device:
  1102. **
  1103. ** <ul>
  1104. ** <li> [SQLITE_IOCAP_ATOMIC]
  1105. ** <li> [SQLITE_IOCAP_ATOMIC512]
  1106. ** <li> [SQLITE_IOCAP_ATOMIC1K]
  1107. ** <li> [SQLITE_IOCAP_ATOMIC2K]
  1108. ** <li> [SQLITE_IOCAP_ATOMIC4K]
  1109. ** <li> [SQLITE_IOCAP_ATOMIC8K]
  1110. ** <li> [SQLITE_IOCAP_ATOMIC16K]
  1111. ** <li> [SQLITE_IOCAP_ATOMIC32K]
  1112. ** <li> [SQLITE_IOCAP_ATOMIC64K]
  1113. ** <li> [SQLITE_IOCAP_SAFE_APPEND]
  1114. ** <li> [SQLITE_IOCAP_SEQUENTIAL]
  1115. ** </ul>
  1116. **
  1117. ** The SQLITE_IOCAP_ATOMIC property means that all writes of
  1118. ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
  1119. ** mean that writes of blocks that are nnn bytes in size and
  1120. ** are aligned to an address which is an integer multiple of
  1121. ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
  1122. ** that when data is appended to a file, the data is appended
  1123. ** first then the size of the file is extended, never the other
  1124. ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
  1125. ** information is written to disk in the same order as calls
  1126. ** to xWrite().
  1127. **
  1128. ** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
  1129. ** in the unread portions of the buffer with zeros. A VFS that
  1130. ** fails to zero-fill short reads might seem to work. However,
  1131. ** failure to zero-fill short reads will eventually lead to
  1132. ** database corruption.
  1133. */
  1134. typedef struct sqlite3_io_methods sqlite3_io_methods;
  1135. struct sqlite3_io_methods {
  1136. int iVersion;
  1137. int (*xClose)(sqlite3_file*);
  1138. int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
  1139. int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
  1140. int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
  1141. int (*xSync)(sqlite3_file*, int flags);
  1142. int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
  1143. int (*xLock)(sqlite3_file*, int);
  1144. int (*xUnlock)(sqlite3_file*, int);
  1145. int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);
  1146. int (*xFileControl)(sqlite3_file*, int op, void *pArg);
  1147. int (*xSectorSize)(sqlite3_file*);
  1148. int (*xDeviceCharacteristics)(sqlite3_file*);
  1149. /* Additional methods may be added in future releases */
  1150. };
  1151. /*
  1152. ** CAPI3REF: Standard File Control Opcodes {H11310} <S30800>
  1153. **
  1154. ** These integer constants are opcodes for the xFileControl method
  1155. ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
  1156. ** interface.
  1157. **
  1158. ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This
  1159. ** opcode causes the xFileControl method to write the current state of
  1160. ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
  1161. ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
  1162. ** into an integer that the pArg argument points to. This capability
  1163. ** is used during testing and only needs to be supported when SQLITE_TEST
  1164. ** is defined.
  1165. */
  1166. #define SQLITE_FCNTL_LOCKSTATE 1
  1167. #define SQLITE_GET_LOCKPROXYFILE 2
  1168. #define SQLITE_SET_LOCKPROXYFILE 3
  1169. #define SQLITE_LAST_ERRNO 4
  1170. /*
  1171. ** CAPI3REF: Mutex Handle {H17110} <S20130>
  1172. **
  1173. ** The mutex module within SQLite defines [sqlite3_mutex] to be an
  1174. ** abstract type for a mutex object. The SQLite core never looks
  1175. ** at the internal representation of an [sqlite3_mutex]. It only
  1176. ** deals with pointers to the [sqlite3_mutex] object.
  1177. **
  1178. ** Mutexes are created using [sqlite3_mutex_alloc()].
  1179. */
  1180. typedef struct sqlite3_mutex sqlite3_mutex;
  1181. /*
  1182. ** CAPI3REF: OS Interface Object {H11140} <S20100>
  1183. **
  1184. ** An instance of the sqlite3_vfs object defines the interface between
  1185. ** the SQLite core and the underlying operating system. The "vfs"
  1186. ** in the name of the object stands for "virtual file system".
  1187. **
  1188. ** The value of the iVersion field is initially 1 but may be larger in
  1189. ** future versions of SQLite. Additional fields may be appended to this
  1190. ** object when the iVersion value is increased. Note that the structure
  1191. ** of the sqlite3_vfs object changes in the transaction between
  1192. ** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not
  1193. ** modified.
  1194. **
  1195. ** The szOsFile field is the size of the subclassed [sqlite3_file]
  1196. ** structure used by this VFS. mxPathname is t…

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