PageRenderTime 109ms CodeModel.GetById 54ms RepoModel.GetById 0ms app.codeStats 2ms

/db/sqlite3/src/sqlite3.c

https://bitbucket.org/soko/mozilla-central
C | 10892 lines | 2863 code | 471 blank | 7558 comment | 37 complexity | f34bca82efdadb1451d829710755bce9 MD5 | raw file
Possible License(s): GPL-2.0, JSON, 0BSD, LGPL-3.0, AGPL-1.0, MIT, MPL-2.0-no-copyleft-exception, BSD-3-Clause, LGPL-2.1, Apache-2.0

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

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