1/******************************************************************************
2** This file is an amalgamation of many separate C source files from SQLite
3** version 3.7.6.3.  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/*
47** These #defines should enable >2GB file support on POSIX if the
48** underlying operating system supports it.  If the OS lacks
49** large file support, or if the OS is windows, these should be no-ops.
50**
51** Ticket #2739:  The _LARGEFILE_SOURCE macro must appear before any
52** system #includes.  Hence, this block of code must be the very first
53** code in all source files.
54**
55** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
56** on the compiler command line.  This is necessary if you are compiling
57** on a recent machine (ex: Red Hat 7.2) but you want your code to work
58** on an older machine (ex: Red Hat 6.0).  If you compile on Red Hat 7.2
59** without this option, LFS is enable.  But LFS does not exist in the kernel
60** in Red Hat 6.0, so the code won't work.  Hence, for maximum binary
61** portability you should omit LFS.
62**
63** Similar is true for Mac OS X.  LFS is only supported on Mac OS X 9 and later.
64*/
65#ifndef SQLITE_DISABLE_LFS
66# define _LARGE_FILE       1
67# ifndef _FILE_OFFSET_BITS
68#   define _FILE_OFFSET_BITS 64
69# endif
70# define _LARGEFILE_SOURCE 1
71#endif
72
73/*
74** Include the configuration header output by 'configure' if we're using the
75** autoconf-based build
76*/
77#ifdef _HAVE_SQLITE_CONFIG_H
78#include "config.h"
79#endif
80
81/************** Include sqliteLimit.h in the middle of sqliteInt.h ***********/
82/************** Begin file sqliteLimit.h *************************************/
83/*
84** 2007 May 7
85**
86** The author disclaims copyright to this source code.  In place of
87** a legal notice, here is a blessing:
88**
89**    May you do good and not evil.
90**    May you find forgiveness for yourself and forgive others.
91**    May you share freely, never taking more than you give.
92**
93*************************************************************************
94**
95** This file defines various limits of what SQLite can process.
96*/
97
98/*
99** The maximum length of a TEXT or BLOB in bytes.   This also
100** limits the size of a row in a table or index.
101**
102** The hard limit is the ability of a 32-bit signed integer
103** to count the size: 2^31-1 or 2147483647.
104*/
105#ifndef SQLITE_MAX_LENGTH
106# define SQLITE_MAX_LENGTH 1000000000
107#endif
108
109/*
110** This is the maximum number of
111**
112**    * Columns in a table
113**    * Columns in an index
114**    * Columns in a view
115**    * Terms in the SET clause of an UPDATE statement
116**    * Terms in the result set of a SELECT statement
117**    * Terms in the GROUP BY or ORDER BY clauses of a SELECT statement.
118**    * Terms in the VALUES clause of an INSERT statement
119**
120** The hard upper limit here is 32676.  Most database people will
121** tell you that in a well-normalized database, you usually should
122** not have more than a dozen or so columns in any table.  And if
123** that is the case, there is no point in having more than a few
124** dozen values in any of the other situations described above.
125*/
126#ifndef SQLITE_MAX_COLUMN
127# define SQLITE_MAX_COLUMN 2000
128#endif
129
130/*
131** The maximum length of a single SQL statement in bytes.
132**
133** It used to be the case that setting this value to zero would
134** turn the limit off.  That is no longer true.  It is not possible
135** to turn this limit off.
136*/
137#ifndef SQLITE_MAX_SQL_LENGTH
138# define SQLITE_MAX_SQL_LENGTH 1000000000
139#endif
140
141/*
142** The maximum depth of an expression tree. This is limited to
143** some extent by SQLITE_MAX_SQL_LENGTH. But sometime you might
144** want to place more severe limits on the complexity of an
145** expression.
146**
147** A value of 0 used to mean that the limit was not enforced.
148** But that is no longer true.  The limit is now strictly enforced
149** at all times.
150*/
151#ifndef SQLITE_MAX_EXPR_DEPTH
152# define SQLITE_MAX_EXPR_DEPTH 1000
153#endif
154
155/*
156** The maximum number of terms in a compound SELECT statement.
157** The code generator for compound SELECT statements does one
158** level of recursion for each term.  A stack overflow can result
159** if the number of terms is too large.  In practice, most SQL
160** never has more than 3 or 4 terms.  Use a value of 0 to disable
161** any limit on the number of terms in a compount SELECT.
162*/
163#ifndef SQLITE_MAX_COMPOUND_SELECT
164# define SQLITE_MAX_COMPOUND_SELECT 500
165#endif
166
167/*
168** The maximum number of opcodes in a VDBE program.
169** Not currently enforced.
170*/
171#ifndef SQLITE_MAX_VDBE_OP
172# define SQLITE_MAX_VDBE_OP 25000
173#endif
174
175/*
176** The maximum number of arguments to an SQL function.
177*/
178#ifndef SQLITE_MAX_FUNCTION_ARG
179# define SQLITE_MAX_FUNCTION_ARG 127
180#endif
181
182/*
183** The maximum number of in-memory pages to use for the main database
184** table and for temporary tables.  The SQLITE_DEFAULT_CACHE_SIZE
185*/
186#ifndef SQLITE_DEFAULT_CACHE_SIZE
187# define SQLITE_DEFAULT_CACHE_SIZE  2000
188#endif
189#ifndef SQLITE_DEFAULT_TEMP_CACHE_SIZE
190# define SQLITE_DEFAULT_TEMP_CACHE_SIZE  500
191#endif
192
193/*
194** The default number of frames to accumulate in the log file before
195** checkpointing the database in WAL mode.
196*/
197#ifndef SQLITE_DEFAULT_WAL_AUTOCHECKPOINT
198# define SQLITE_DEFAULT_WAL_AUTOCHECKPOINT  1000
199#endif
200
201/*
202** The maximum number of attached databases.  This must be between 0
203** and 62.  The upper bound on 62 is because a 64-bit integer bitmap
204** is used internally to track attached databases.
205*/
206#ifndef SQLITE_MAX_ATTACHED
207# define SQLITE_MAX_ATTACHED 10
208#endif
209
210
211/*
212** The maximum value of a ?nnn wildcard that the parser will accept.
213*/
214#ifndef SQLITE_MAX_VARIABLE_NUMBER
215# define SQLITE_MAX_VARIABLE_NUMBER 999
216#endif
217
218/* Maximum page size.  The upper bound on this value is 65536.  This a limit
219** imposed by the use of 16-bit offsets within each page.
220**
221** Earlier versions of SQLite allowed the user to change this value at
222** compile time. This is no longer permitted, on the grounds that it creates
223** a library that is technically incompatible with an SQLite library
224** compiled with a different limit. If a process operating on a database
225** with a page-size of 65536 bytes crashes, then an instance of SQLite
226** compiled with the default page-size limit will not be able to rollback
227** the aborted transaction. This could lead to database corruption.
228*/
229#ifdef SQLITE_MAX_PAGE_SIZE
230# undef SQLITE_MAX_PAGE_SIZE
231#endif
232#define SQLITE_MAX_PAGE_SIZE 65536
233
234
235/*
236** The default size of a database page.
237*/
238#ifndef SQLITE_DEFAULT_PAGE_SIZE
239# define SQLITE_DEFAULT_PAGE_SIZE 1024
240#endif
241#if SQLITE_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE
242# undef SQLITE_DEFAULT_PAGE_SIZE
243# define SQLITE_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE
244#endif
245
246/*
247** Ordinarily, if no value is explicitly provided, SQLite creates databases
248** with page size SQLITE_DEFAULT_PAGE_SIZE. However, based on certain
249** device characteristics (sector-size and atomic write() support),
250** SQLite may choose a larger value. This constant is the maximum value
251** SQLite will choose on its own.
252*/
253#ifndef SQLITE_MAX_DEFAULT_PAGE_SIZE
254# define SQLITE_MAX_DEFAULT_PAGE_SIZE 8192
255#endif
256#if SQLITE_MAX_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE
257# undef SQLITE_MAX_DEFAULT_PAGE_SIZE
258# define SQLITE_MAX_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE
259#endif
260
261
262/*
263** Maximum number of pages in one database file.
264**
265** This is really just the default value for the max_page_count pragma.
266** This value can be lowered (or raised) at run-time using that the
267** max_page_count macro.
268*/
269#ifndef SQLITE_MAX_PAGE_COUNT
270# define SQLITE_MAX_PAGE_COUNT 1073741823
271#endif
272
273/*
274** Maximum length (in bytes) of the pattern in a LIKE or GLOB
275** operator.
276*/
277#ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH
278# define SQLITE_MAX_LIKE_PATTERN_LENGTH 50000
279#endif
280
281/*
282** Maximum depth of recursion for triggers.
283**
284** A value of 1 means that a trigger program will not be able to itself
285** fire any triggers. A value of 0 means that no trigger programs at all
286** may be executed.
287*/
288#ifndef SQLITE_MAX_TRIGGER_DEPTH
289# define SQLITE_MAX_TRIGGER_DEPTH 1000
290#endif
291
292/************** End of sqliteLimit.h *****************************************/
293/************** Continuing where we left off in sqliteInt.h ******************/
294
295/* Disable nuisance warnings on Borland compilers */
296#if defined(__BORLANDC__)
297#pragma warn -rch /* unreachable code */
298#pragma warn -ccc /* Condition is always true or false */
299#pragma warn -aus /* Assigned value is never used */
300#pragma warn -csu /* Comparing signed and unsigned */
301#pragma warn -spa /* Suspicious pointer arithmetic */
302#endif
303
304/* Needed for various definitions... */
305#ifndef _GNU_SOURCE
306# define _GNU_SOURCE
307#endif
308
309/*
310** Include standard header files as necessary
311*/
312#ifdef HAVE_STDINT_H
313#include <stdint.h>
314#endif
315#ifdef HAVE_INTTYPES_H
316#include <inttypes.h>
317#endif
318
319/*
320** The number of samples of an index that SQLite takes in order to
321** construct a histogram of the table content when running ANALYZE
322** and with SQLITE_ENABLE_STAT2
323*/
324#define SQLITE_INDEX_SAMPLES 10
325
326/*
327** The following macros are used to cast pointers to integers and
328** integers to pointers.  The way you do this varies from one compiler
329** to the next, so we have developed the following set of #if statements
330** to generate appropriate macros for a wide range of compilers.
331**
332** The correct "ANSI" way to do this is to use the intptr_t type.
333** Unfortunately, that typedef is not available on all compilers, or
334** if it is available, it requires an #include of specific headers
335** that vary from one machine to the next.
336**
337** Ticket #3860:  The llvm-gcc-4.2 compiler from Apple chokes on
338** the ((void*)&((char*)0)[X]) construct.  But MSVC chokes on ((void*)(X)).
339** So we have to define the macros in different ways depending on the
340** compiler.
341*/
342#if defined(__PTRDIFF_TYPE__)  /* This case should work for GCC */
343# define SQLITE_INT_TO_PTR(X)  ((void*)(__PTRDIFF_TYPE__)(X))
344# define SQLITE_PTR_TO_INT(X)  ((int)(__PTRDIFF_TYPE__)(X))
345#elif !defined(__GNUC__)       /* Works for compilers other than LLVM */
346# define SQLITE_INT_TO_PTR(X)  ((void*)&((char*)0)[X])
347# define SQLITE_PTR_TO_INT(X)  ((int)(((char*)X)-(char*)0))
348#elif defined(HAVE_STDINT_H)   /* Use this case if we have ANSI headers */
349# define SQLITE_INT_TO_PTR(X)  ((void*)(intptr_t)(X))
350# define SQLITE_PTR_TO_INT(X)  ((int)(intptr_t)(X))
351#else                          /* Generates a warning - but it always works */
352# define SQLITE_INT_TO_PTR(X)  ((void*)(X))
353# define SQLITE_PTR_TO_INT(X)  ((int)(X))
354#endif
355
356/*
357** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
358** 0 means mutexes are permanently disable and the library is never
359** threadsafe.  1 means the library is serialized which is the highest
360** level of threadsafety.  2 means the libary is multithreaded - multiple
361** threads can use SQLite as long as no two threads try to use the same
362** database connection at the same time.
363**
364** Older versions of SQLite used an optional THREADSAFE macro.
365** We support that for legacy.
366*/
367#if !defined(SQLITE_THREADSAFE)
368#if defined(THREADSAFE)
369# define SQLITE_THREADSAFE THREADSAFE
370#else
371# define SQLITE_THREADSAFE 1 /* IMP: R-07272-22309 */
372#endif
373#endif
374
375/*
376** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1.
377** It determines whether or not the features related to
378** SQLITE_CONFIG_MEMSTATUS are available by default or not. This value can
379** be overridden at runtime using the sqlite3_config() API.
380*/
381#if !defined(SQLITE_DEFAULT_MEMSTATUS)
382# define SQLITE_DEFAULT_MEMSTATUS 1
383#endif
384
385/*
386** Exactly one of the following macros must be defined in order to
387** specify which memory allocation subsystem to use.
388**
389**     SQLITE_SYSTEM_MALLOC          // Use normal system malloc()
390**     SQLITE_MEMDEBUG               // Debugging version of system malloc()
391**
392** (Historical note:  There used to be several other options, but we've
393** pared it down to just these two.)
394**
395** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as
396** the default.
397*/
398#if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)>1
399# error "At most one of the following compile-time configuration options\
400 is allows: SQLITE_SYSTEM_MALLOC, SQLITE_MEMDEBUG"
401#endif
402#if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)==0
403# define SQLITE_SYSTEM_MALLOC 1
404#endif
405
406/*
407** If SQLITE_MALLOC_SOFT_LIMIT is not zero, then try to keep the
408** sizes of memory allocations below this value where possible.
409*/
410#if !defined(SQLITE_MALLOC_SOFT_LIMIT)
411# define SQLITE_MALLOC_SOFT_LIMIT 1024
412#endif
413
414/*
415** We need to define _XOPEN_SOURCE as follows in order to enable
416** recursive mutexes on most Unix systems.  But Mac OS X is different.
417** The _XOPEN_SOURCE define causes problems for Mac OS X we are told,
418** so it is omitted there.  See ticket #2673.
419**
420** Later we learn that _XOPEN_SOURCE is poorly or incorrectly
421** implemented on some systems.  So we avoid defining it at all
422** if it is already defined or if it is unneeded because we are
423** not doing a threadsafe build.  Ticket #2681.
424**
425** See also ticket #2741.
426*/
427#if !defined(_XOPEN_SOURCE) && !defined(__DARWIN__) && !defined(__APPLE__) && SQLITE_THREADSAFE
428#  define _XOPEN_SOURCE 500  /* Needed to enable pthread recursive mutexes */
429#endif
430
431/*
432** The TCL headers are only needed when compiling the TCL bindings.
433*/
434#if defined(SQLITE_TCL) || defined(TCLSH)
435# include <tcl.h>
436#endif
437
438/*
439** Many people are failing to set -DNDEBUG=1 when compiling SQLite.
440** Setting NDEBUG makes the code smaller and run faster.  So the following
441** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1
442** option is set.  Thus NDEBUG becomes an opt-in rather than an opt-out
443** feature.
444*/
445#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
446# define NDEBUG 1
447#endif
448
449/*
450** The testcase() macro is used to aid in coverage testing.  When
451** doing coverage testing, the condition inside the argument to
452** testcase() must be evaluated both true and false in order to
453** get full branch coverage.  The testcase() macro is inserted
454** to help ensure adequate test coverage in places where simple
455** condition/decision coverage is inadequate.  For example, testcase()
456** can be used to make sure boundary values are tested.  For
457** bitmask tests, testcase() can be used to make sure each bit
458** is significant and used at least once.  On switch statements
459** where multiple cases go to the same block of code, testcase()
460** can insure that all cases are evaluated.
461**
462*/
463#ifdef SQLITE_COVERAGE_TEST
464SQLITE_PRIVATE   void sqlite3Coverage(int);
465# define testcase(X)  if( X ){ sqlite3Coverage(__LINE__); }
466#else
467# define testcase(X)
468#endif
469
470/*
471** The TESTONLY macro is used to enclose variable declarations or
472** other bits of code that are needed to support the arguments
473** within testcase() and assert() macros.
474*/
475#if !defined(NDEBUG) || defined(SQLITE_COVERAGE_TEST)
476# define TESTONLY(X)  X
477#else
478# define TESTONLY(X)
479#endif
480
481/*
482** Sometimes we need a small amount of code such as a variable initialization
483** to setup for a later assert() statement.  We do not want this code to
484** appear when assert() is disabled.  The following macro is therefore
485** used to contain that setup code.  The "VVA" acronym stands for
486** "Verification, Validation, and Accreditation".  In other words, the
487** code within VVA_ONLY() will only run during verification processes.
488*/
489#ifndef NDEBUG
490# define VVA_ONLY(X)  X
491#else
492# define VVA_ONLY(X)
493#endif
494
495/*
496** The ALWAYS and NEVER macros surround boolean expressions which
497** are intended to always be true or false, respectively.  Such
498** expressions could be omitted from the code completely.  But they
499** are included in a few cases in order to enhance the resilience
500** of SQLite to unexpected behavior - to make the code "self-healing"
501** or "ductile" rather than being "brittle" and crashing at the first
502** hint of unplanned behavior.
503**
504** In other words, ALWAYS and NEVER are added for defensive code.
505**
506** When doing coverage testing ALWAYS and NEVER are hard-coded to
507** be true and false so that the unreachable code then specify will
508** not be counted as untested code.
509*/
510#if defined(SQLITE_COVERAGE_TEST)
511# define ALWAYS(X)      (1)
512# define NEVER(X)       (0)
513#elif !defined(NDEBUG)
514# define ALWAYS(X)      ((X)?1:(assert(0),0))
515# define NEVER(X)       ((X)?(assert(0),1):0)
516#else
517# define ALWAYS(X)      (X)
518# define NEVER(X)       (X)
519#endif
520
521/*
522** Return true (non-zero) if the input is a integer that is too large
523** to fit in 32-bits.  This macro is used inside of various testcase()
524** macros to verify that we have tested SQLite for large-file support.
525*/
526#define IS_BIG_INT(X)  (((X)&~(i64)0xffffffff)!=0)
527
528/*
529** The macro unlikely() is a hint that surrounds a boolean
530** expression that is usually false.  Macro likely() surrounds
531** a boolean expression that is usually true.  GCC is able to
532** use these hints to generate better code, sometimes.
533*/
534#if defined(__GNUC__) && 0
535# define likely(X)    __builtin_expect((X),1)
536# define unlikely(X)  __builtin_expect((X),0)
537#else
538# define likely(X)    !!(X)
539# define unlikely(X)  !!(X)
540#endif
541
542/************** Include sqlite3.h in the middle of sqliteInt.h ***************/
543/************** Begin file sqlite3.h *****************************************/
544/*
545** 2001 September 15
546**
547** The author disclaims copyright to this source code.  In place of
548** a legal notice, here is a blessing:
549**
550**    May you do good and not evil.
551**    May you find forgiveness for yourself and forgive others.
552**    May you share freely, never taking more than you give.
553**
554*************************************************************************
555** This header file defines the interface that the SQLite library
556** presents to client programs.  If a C-function, structure, datatype,
557** or constant definition does not appear in this file, then it is
558** not a published API of SQLite, is subject to change without
559** notice, and should not be referenced by programs that use SQLite.
560**
561** Some of the definitions that are in this file are marked as
562** "experimental".  Experimental interfaces are normally new
563** features recently added to SQLite.  We do not anticipate changes
564** to experimental interfaces but reserve the right to make minor changes
565** if experience from use "in the wild" suggest such changes are prudent.
566**
567** The official C-language API documentation for SQLite is derived
568** from comments in this file.  This file is the authoritative source
569** on how SQLite interfaces are suppose to operate.
570**
571** The name of this file under configuration management is "sqlite.h.in".
572** The makefile makes some minor changes to this file (such as inserting
573** the version number) and changes its name to "sqlite3.h" as
574** part of the build process.
575*/
576#ifndef _SQLITE3_H_
577#define _SQLITE3_H_
578#include <stdarg.h>     /* Needed for the definition of va_list */
579
580/*
581** Make sure we can call this stuff from C++.
582*/
583#if 0
584extern "C" {
585#endif
586
587
588/*
589** Add the ability to override 'extern'
590*/
591#ifndef SQLITE_EXTERN
592# define SQLITE_EXTERN extern
593#endif
594
595#ifndef SQLITE_API
596# define SQLITE_API
597#endif
598
599
600/*
601** These no-op macros are used in front of interfaces to mark those
602** interfaces as either deprecated or experimental.  New applications
603** should not use deprecated interfaces - they are support for backwards
604** compatibility only.  Application writers should be aware that
605** experimental interfaces are subject to change in point releases.
606**
607** These macros used to resolve to various kinds of compiler magic that
608** would generate warning messages when they were used.  But that
609** compiler magic ended up generating such a flurry of bug reports
610** that we have taken it all out and gone back to using simple
611** noop macros.
612*/
613#define SQLITE_DEPRECATED
614#define SQLITE_EXPERIMENTAL
615
616/*
617** Ensure these symbols were not defined by some previous header file.
618*/
619#ifdef SQLITE_VERSION
620# undef SQLITE_VERSION
621#endif
622#ifdef SQLITE_VERSION_NUMBER
623# undef SQLITE_VERSION_NUMBER
624#endif
625
626/*
627** CAPI3REF: Compile-Time Library Version Numbers
628**
629** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header
630** evaluates to a string literal that is the SQLite version in the
631** format "X.Y.Z" where X is the major version number (always 3 for
632** SQLite3) and Y is the minor version number and Z is the release number.)^
633** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer
634** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
635** numbers used in [SQLITE_VERSION].)^
636** The SQLITE_VERSION_NUMBER for any given release of SQLite will also
637** be larger than the release from which it is derived.  Either Y will
638** be held constant and Z will be incremented or else Y will be incremented
639** and Z will be reset to zero.
640**
641** Since version 3.6.18, SQLite source code has been stored in the
642** <a href="http://www.fossil-scm.org/">Fossil configuration management
643** system</a>.  ^The SQLITE_SOURCE_ID macro evaluates to
644** a string which identifies a particular check-in of SQLite
645** within its configuration management system.  ^The SQLITE_SOURCE_ID
646** string contains the date and time of the check-in (UTC) and an SHA1
647** hash of the entire source tree.
648**
649** See also: [sqlite3_libversion()],
650** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651** [sqlite_version()] and [sqlite_source_id()].
652*/
653#define SQLITE_VERSION        "3.7.6.3"
654#define SQLITE_VERSION_NUMBER 3007006
655#define SQLITE_SOURCE_ID      "2011-05-19 13:26:54 ed1da510a239ea767a01dc332b667119fa3c908e"
656
657/*
658** CAPI3REF: Run-Time Library Version Numbers
659** KEYWORDS: sqlite3_version, sqlite3_sourceid
660**
661** These interfaces provide the same information as the [SQLITE_VERSION],
662** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
663** but are associated with the library instead of the header file.  ^(Cautious
664** programmers might include assert() statements in their application to
665** verify that values returned by these interfaces match the macros in
666** the header, and thus insure that the application is
667** compiled with matching library and header files.
668**
669** <blockquote><pre>
670** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
671** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 );
672** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
673** </pre></blockquote>)^
674**
675** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
676** macro.  ^The sqlite3_libversion() function returns a pointer to the
677** to the sqlite3_version[] string constant.  The sqlite3_libversion()
678** function is provided for use in DLLs since DLL users usually do not have
679** direct access to string constants within the DLL.  ^The
680** sqlite3_libversion_number() function returns an integer equal to
681** [SQLITE_VERSION_NUMBER].  ^The sqlite3_sourceid() function returns
682** a pointer to a string constant whose value is the same as the
683** [SQLITE_SOURCE_ID] C preprocessor macro.
684**
685** See also: [sqlite_version()] and [sqlite_source_id()].
686*/
687SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
688SQLITE_API const char *sqlite3_libversion(void);
689SQLITE_API const char *sqlite3_sourceid(void);
690SQLITE_API int sqlite3_libversion_number(void);
691
692/*
693** CAPI3REF: Run-Time Library Compilation Options Diagnostics
694**
695** ^The sqlite3_compileoption_used() function returns 0 or 1
696** indicating whether the specified option was defined at
697** compile time.  ^The SQLITE_ prefix may be omitted from the
698** option name passed to sqlite3_compileoption_used().
699**
700** ^The sqlite3_compileoption_get() function allows iterating
701** over the list of options that were defined at compile time by
702** returning the N-th compile time option string.  ^If N is out of range,
703** sqlite3_compileoption_get() returns a NULL pointer.  ^The SQLITE_
704** prefix is omitted from any strings returned by
705** sqlite3_compileoption_get().
706**
707** ^Support for the diagnostic functions sqlite3_compileoption_used()
708** and sqlite3_compileoption_get() may be omitted by specifying the
709** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
710**
711** See also: SQL functions [sqlite_compileoption_used()] and
712** [sqlite_compileoption_get()] and the [compile_options pragma].
713*/
714#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
715SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
716SQLITE_API const char *sqlite3_compileoption_get(int N);
717#endif
718
719/*
720** CAPI3REF: Test To See If The Library Is Threadsafe
721**
722** ^The sqlite3_threadsafe() function returns zero if and only if
723** SQLite was compiled mutexing code omitted due to the
724** [SQLITE_THREADSAFE] compile-time option being set to 0.
725**
726** SQLite can be compiled with or without mutexes.  When
727** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes
728** are enabled and SQLite is threadsafe.  When the
729** [SQLITE_THREADSAFE] macro is 0,
730** the mutexes are omitted.  Without the mutexes, it is not safe
731** to use SQLite concurrently from more than one thread.
732**
733** Enabling mutexes incurs a measurable performance penalty.
734** So if speed is of utmost importance, it makes sense to disable
735** the mutexes.  But for maximum safety, mutexes should be enabled.
736** ^The default behavior is for mutexes to be enabled.
737**
738** This interface can be used by an application to make sure that the
739** version of SQLite that it is linking against was compiled with
740** the desired setting of the [SQLITE_THREADSAFE] macro.
741**
742** This interface only reports on the compile-time mutex setting
743** of the [SQLITE_THREADSAFE] flag.  If SQLite is compiled with
744** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
745** can be fully or partially disabled using a call to [sqlite3_config()]
746** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
747** or [SQLITE_CONFIG_MUTEX].  ^(The return value of the
748** sqlite3_threadsafe() function shows only the compile-time setting of
749** thread safety, not any run-time changes to that setting made by
750** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
751** is unchanged by calls to sqlite3_config().)^
752**
753** See the [threading mode] documentation for additional information.
754*/
755SQLITE_API int sqlite3_threadsafe(void);
756
757/*
758** CAPI3REF: Database Connection Handle
759** KEYWORDS: {database connection} {database connections}
760**
761** Each open SQLite database is represented by a pointer to an instance of
762** the opaque structure named "sqlite3".  It is useful to think of an sqlite3
763** pointer as an object.  The [sqlite3_open()], [sqlite3_open16()], and
764** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
765** is its destructor.  There are many other interfaces (such as
766** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
767** [sqlite3_busy_timeout()] to name but three) that are methods on an
768** sqlite3 object.
769*/
770typedef struct sqlite3 sqlite3;
771
772/*
773** CAPI3REF: 64-Bit Integer Types
774** KEYWORDS: sqlite_int64 sqlite_uint64
775**
776** Because there is no cross-platform way to specify 64-bit integer types
777** SQLite includes typedefs for 64-bit signed and unsigned integers.
778**
779** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
780** The sqlite_int64 and sqlite_uint64 types are supported for backwards
781** compatibility only.
782**
783** ^The sqlite3_int64 and sqlite_int64 types can store integer values
784** between -9223372036854775808 and +9223372036854775807 inclusive.  ^The
785** sqlite3_uint64 and sqlite_uint64 types can store integer values
786** between 0 and +18446744073709551615 inclusive.
787*/
788#ifdef SQLITE_INT64_TYPE
789  typedef SQLITE_INT64_TYPE sqlite_int64;
790  typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
791#elif defined(_MSC_VER) || defined(__BORLANDC__)
792  typedef __int64 sqlite_int64;
793  typedef unsigned __int64 sqlite_uint64;
794#else
795  typedef long long int sqlite_int64;
796  typedef unsigned long long int sqlite_uint64;
797#endif
798typedef sqlite_int64 sqlite3_int64;
799typedef sqlite_uint64 sqlite3_uint64;
800
801/*
802** If compiling for a processor that lacks floating point support,
803** substitute integer for floating-point.
804*/
805#ifdef SQLITE_OMIT_FLOATING_POINT
806# define double sqlite3_int64
807#endif
808
809/*
810** CAPI3REF: Closing A Database Connection
811**
812** ^The sqlite3_close() routine is the destructor for the [sqlite3] object.
813** ^Calls to sqlite3_close() return SQLITE_OK if the [sqlite3] object is
814** successfully destroyed and all associated resources are deallocated.
815**
816** Applications must [sqlite3_finalize | finalize] all [prepared statements]
817** and [sqlite3_blob_close | close] all [BLOB handles] associated with
818** the [sqlite3] object prior to attempting to close the object.  ^If
819** sqlite3_close() is called on a [database connection] that still has
820** outstanding [prepared statements] or [BLOB handles], then it returns
821** SQLITE_BUSY.
822**
823** ^If [sqlite3_close()] is invoked while a transaction is open,
824** the transaction is automatically rolled back.
825**
826** The C parameter to [sqlite3_close(C)] must be either a NULL
827** pointer or an [sqlite3] object pointer obtained
828** from [sqlite3_open()], [sqlite3_open16()], or
829** [sqlite3_open_v2()], and not previously closed.
830** ^Calling sqlite3_close() with a NULL pointer argument is a
831** harmless no-op.
832*/
833SQLITE_API int sqlite3_close(sqlite3 *);
834
835/*
836** The type for a callback function.
837** This is legacy and deprecated.  It is included for historical
838** compatibility and is not documented.
839*/
840typedef int (*sqlite3_callback)(void*,int,char**, char**);
841
842/*
843** CAPI3REF: One-Step Query Execution Interface
844**
845** The sqlite3_exec() interface is a convenience wrapper around
846** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
847** that allows an application to run multiple statements of SQL
848** without having to use a lot of C code.
849**
850** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
851** semicolon-separate SQL statements passed into its 2nd argument,
852** in the context of the [database connection] passed in as its 1st
853** argument.  ^If the callback function of the 3rd argument to
854** sqlite3_exec() is not NULL, then it is invoked for each result row
855** coming out of the evaluated SQL statements.  ^The 4th argument to
856** to sqlite3_exec() is relayed through to the 1st argument of each
857** callback invocation.  ^If the callback pointer to sqlite3_exec()
858** is NULL, then no callback is ever invoked and result rows are
859** ignored.
860**
861** ^If an error occurs while evaluating the SQL statements passed into
862** sqlite3_exec(), then execution of the current statement stops and
863** subsequent statements are skipped.  ^If the 5th parameter to sqlite3_exec()
864** is not NULL then any error message is written into memory obtained
865** from [sqlite3_malloc()] and passed back through the 5th parameter.
866** To avoid memory leaks, the application should invoke [sqlite3_free()]
867** on error message strings returned through the 5th parameter of
868** of sqlite3_exec() after the error message string is no longer needed.
869** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors
870** occur, then sqlite3_exec() sets the pointer in its 5th parameter to
871** NULL before returning.
872**
873** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec()
874** routine returns SQLITE_ABORT without invoking the callback again and
875** without running any subsequent SQL statements.
876**
877** ^The 2nd argument to the sqlite3_exec() callback function is the
878** number of columns in the result.  ^The 3rd argument to the sqlite3_exec()
879** callback is an array of pointers to strings obtained as if from
880** [sqlite3_column_text()], one for each column.  ^If an element of a
881** result row is NULL then the corresponding string pointer for the
882** sqlite3_exec() callback is a NULL pointer.  ^The 4th argument to the
883** sqlite3_exec() callback is an array of pointers to strings where each
884** entry represents the name of corresponding result column as obtained
885** from [sqlite3_column_name()].
886**
887** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
888** to an empty string, or a pointer that contains only whitespace and/or
889** SQL comments, then no SQL statements are evaluated and the database
890** is not changed.
891**
892** Restrictions:
893**
894** <ul>
895** <li> The application must insure that the 1st parameter to sqlite3_exec()
896**      is a valid and open [database connection].
897** <li> The application must not close [database connection] specified by
898**      the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
899** <li> The application must not modify the SQL statement text passed into
900**      the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
901** </ul>
902*/
903SQLITE_API int sqlite3_exec(
904  sqlite3*,                                  /* An open database */
905  const char *sql,                           /* SQL to be evaluated */
906  int (*callback)(void*,int,char**,char**),  /* Callback function */
907  void *,                                    /* 1st argument to callback */
908  char **errmsg                              /* Error msg written here */
909);
910
911/*
912** CAPI3REF: Result Codes
913** KEYWORDS: SQLITE_OK {error code} {error codes}
914** KEYWORDS: {result code} {result codes}
915**
916** Many SQLite functions return an integer result code from the set shown
917** here in order to indicates success or failure.
918**
919** New error codes may be added in future versions of SQLite.
920**
921** See also: [SQLITE_IOERR_READ | extended result codes]
922*/
923#define SQLITE_OK           0   /* Successful result */
924/* beginning-of-error-codes */
925#define SQLITE_ERROR        1   /* SQL error or missing database */
926#define SQLITE_INTERNAL     2   /* Internal logic error in SQLite */
927#define SQLITE_PERM         3   /* Access permission denied */
928#define SQLITE_ABORT        4   /* Callback routine requested an abort */
929#define SQLITE_BUSY         5   /* The database file is locked */
930#define SQLITE_LOCKED       6   /* A table in the database is locked */
931#define SQLITE_NOMEM        7   /* A malloc() failed */
932#define SQLITE_READONLY     8   /* Attempt to write a readonly database */
933#define SQLITE_INTERRUPT    9   /* Operation terminated by sqlite3_interrupt()*/
934#define SQLITE_IOERR       10   /* Some kind of disk I/O error occurred */
935#define SQLITE_CORRUPT     11   /* The database disk image is malformed */
936#define SQLITE_NOTFOUND    12   /* Unknown opcode in sqlite3_file_control() */
937#define SQLITE_FULL        13   /* Insertion failed because database is full */
938#define SQLITE_CANTOPEN    14   /* Unable to open the database file */
939#define SQLITE_PROTOCOL    15   /* Database lock protocol error */
940#define SQLITE_EMPTY       16   /* Database is empty */
941#define SQLITE_SCHEMA      17   /* The database schema changed */
942#define SQLITE_TOOBIG      18   /* String or BLOB exceeds size limit */
943#define SQLITE_CONSTRAINT  19   /* Abort due to constraint violation */
944#define SQLITE_MISMATCH    20   /* Data type mismatch */
945#define SQLITE_MISUSE      21   /* Library used incorrectly */
946#define SQLITE_NOLFS       22   /* Uses OS features not supported on host */
947#define SQLITE_AUTH        23   /* Authorization denied */
948#define SQLITE_FORMAT      24   /* Auxiliary database format error */
949#define SQLITE_RANGE       25   /* 2nd parameter to sqlite3_bind out of range */
950#define SQLITE_NOTADB      26   /* File opened that is not a database file */
951#define SQLITE_ROW         100  /* sqlite3_step() has another row ready */
952#define SQLITE_DONE        101  /* sqlite3_step() has finished executing */
953/* end-of-error-codes */
954
955/*
956** CAPI3REF: Extended Result Codes
957** KEYWORDS: {extended error code} {extended error codes}
958** KEYWORDS: {extended result code} {extended result codes}
959**
960** In its default configuration, SQLite API routines return one of 26 integer
961** [SQLITE_OK | result codes].  However, experience has shown that many of
962** these result codes are too coarse-grained.  They do not provide as
963** much information about problems as programmers might like.  In an effort to
964** address this, newer versions of SQLite (version 3.3.8 and later) include
965** support for additional result codes that provide more detailed information
966** about errors. The extended result codes are enabled or disabled
967** on a per database connection basis using the
968** [sqlite3_extended_result_codes()] API.
969**
970** Some of the available extended result codes are listed here.
971** One may expect the number of extended result codes will be expand
972** over time.  Software that uses extended result codes should expect
973** to see new result codes in future releases of SQLite.
974**
975** The SQLITE_OK result code will never be extended.  It will always
976** be exactly zero.
977*/
978#define SQLITE_IOERR_READ              (SQLITE_IOERR | (1<<8))
979#define SQLITE_IOERR_SHORT_READ        (SQLITE_IOERR | (2<<8))
980#define SQLITE_IOERR_WRITE             (SQLITE_IOERR | (3<<8))
981#define SQLITE_IOERR_FSYNC             (SQLITE_IOERR | (4<<8))
982#define SQLITE_IOERR_DIR_FSYNC         (SQLITE_IOERR | (5<<8))
983#define SQLITE_IOERR_TRUNCATE          (SQLITE_IOERR | (6<<8))
984#define SQLITE_IOERR_FSTAT             (SQLITE_IOERR | (7<<8))
985#define SQLITE_IOERR_UNLOCK            (SQLITE_IOERR | (8<<8))
986#define SQLITE_IOERR_RDLOCK            (SQLITE_IOERR | (9<<8))
987#define SQLITE_IOERR_DELETE            (SQLITE_IOERR | (10<<8))
988#define SQLITE_IOERR_BLOCKED           (SQLITE_IOERR | (11<<8))
989#define SQLITE_IOERR_NOMEM             (SQLITE_IOERR | (12<<8))
990#define SQLITE_IOERR_ACCESS            (SQLITE_IOERR | (13<<8))
991#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
992#define SQLITE_IOERR_LOCK              (SQLITE_IOERR | (15<<8))
993#define SQLITE_IOERR_CLOSE             (SQLITE_IOERR | (16<<8))
994#define SQLITE_IOERR_DIR_CLOSE         (SQLITE_IOERR | (17<<8))
995#define SQLITE_IOERR_SHMOPEN           (SQLITE_IOERR | (18<<8))
996#define SQLITE_IOERR_SHMSIZE           (SQLITE_IOERR | (19<<8))
997#define SQLITE_IOERR_SHMLOCK           (SQLITE_IOERR | (20<<8))
998#define SQLITE_LOCKED_SHAREDCACHE      (SQLITE_LOCKED |  (1<<8))
999#define SQLITE_BUSY_RECOVERY           (SQLITE_BUSY   |  (1<<8))
1000#define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
1001
1002/*
1003** CAPI3REF: Flags For File Open Operations
1004**
1005** These bit values are intended for use in the
1006** 3rd parameter to the [sqlite3_open_v2()] interface and
1007** in the 4th parameter to the xOpen method of the
1008** [sqlite3_vfs] object.
1009*/
1010#define SQLITE_OPEN_READONLY         0x00000001  /* Ok for sqlite3_open_v2() */
1011#define SQLITE_OPEN_READWRITE        0x00000002  /* Ok for sqlite3_open_v2() */
1012#define SQLITE_OPEN_CREATE           0x00000004  /* Ok for sqlite3_open_v2() */
1013#define SQLITE_OPEN_DELETEONCLOSE    0x00000008  /* VFS only */
1014#define SQLITE_OPEN_EXCLUSIVE        0x00000010  /* VFS only */
1015#define SQLITE_OPEN_AUTOPROXY        0x00000020  /* VFS only */
1016#define SQLITE_OPEN_MAIN_DB          0x00000100  /* VFS only */
1017#define SQLITE_OPEN_TEMP_DB          0x00000200  /* VFS only */
1018#define SQLITE_OPEN_TRANSIENT_DB     0x00000400  /* VFS only */
1019#define SQLITE_OPEN_MAIN_JOURNAL     0x00000800  /* VFS only */
1020#define SQLITE_OPEN_TEMP_JOURNAL     0x00001000  /* VFS only */
1021#define SQLITE_OPEN_SUBJOURNAL       0x00002000  /* VFS only */
1022#define SQLITE_OPEN_MASTER_JOURNAL   0x00004000  /* VFS only */
1023#define SQLITE_OPEN_NOMUTEX          0x00008000  /* Ok for sqlite3_open_v2() */
1024#define SQLITE_OPEN_FULLMUTEX        0x00010000  /* Ok for sqlite3_open_v2() */
1025#define SQLITE_OPEN_SHAREDCACHE      0x00020000  /* Ok for sqlite3_open_v2() */
1026#define SQLITE_OPEN_PRIVATECACHE     0x00040000  /* Ok for sqlite3_open_v2() */
1027#define SQLITE_OPEN_WAL              0x00080000  /* VFS only */
1028
1029/* Reserved:                         0x00F00000 */
1030
1031/*
1032** CAPI3REF: Device Characteristics
1033**
1034** The xDeviceCharacteristics method of the [sqlite3_io_methods]
1035** object returns an integer which is a vector of the these
1036** bit values expressing I/O characteristics of the mass storage
1037** device that holds the file that the [sqlite3_io_methods]
1038** refers to.
1039**
1040** The SQLITE_IOCAP_ATOMIC property means that all writes of
1041** any size are atomic.  The SQLITE_IOCAP_ATOMICnnn values
1042** mean that writes of blocks that are nnn bytes in size and
1043** are aligned to an address which is an integer multiple of
1044** nnn are atomic.  The SQLITE_IOCAP_SAFE_APPEND value means
1045** that when data is appended to a file, the data is appended
1046** first then the size of the file is extended, never the other
1047** way around.  The SQLITE_IOCAP_SEQUENTIAL property means that
1048** information is written to disk in the same order as calls
1049** to xWrite().
1050*/
1051#define SQLITE_IOCAP_ATOMIC                 0x00000001
1052#define SQLITE_IOCAP_ATOMIC512              0x00000002
1053#define SQLITE_IOCAP_ATOMIC1K               0x00000004
1054#define SQLITE_IOCAP_ATOMIC2K               0x00000008
1055#define SQLITE_IOCAP_ATOMIC4K               0x00000010
1056#define SQLITE_IOCAP_ATOMIC8K               0x00000020
1057#define SQLITE_IOCAP_ATOMIC16K              0x00000040
1058#define SQLITE_IOCAP_ATOMIC32K              0x00000080
1059#define SQLITE_IOCAP_ATOMIC64K              0x00000100
1060#define SQLITE_IOCAP_SAFE_APPEND            0x00000200
1061#define SQLITE_IOCAP_SEQUENTIAL             0x00000400
1062#define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN  0x00000800
1063
1064/*
1065** CAPI3REF: File Locking Levels
1066**
1067** SQLite uses one of these integer values as the second
1068** argument to calls it makes to the xLock() and xUnlock() methods
1069** of an [sqlite3_io_methods] object.
1070*/
1071#define SQLITE_LOCK_NONE          0
1072#define SQLITE_LOCK_SHARED        1
1073#define SQLITE_LOCK_RESERVED      2
1074#define SQLITE_LOCK_PENDING       3
1075#define SQLITE_LOCK_EXCLUSIVE     4
1076
1077/*
1078** CAPI3REF: Synchronization Type Flags
1079**
1080** When SQLite invokes the xSync() method of an
1081** [sqlite3_io_methods] object it uses a combination of
1082** these integer values as the second argument.
1083**
1084** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
1085** sync operation only needs to flush data to mass storage.  Inode
1086** information need not be flushed. If the lower four bits of the flag
1087** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics.
1088** If the lower four bits equal SQLITE_SYNC_FULL, that means
1089** to use Mac OS X style fullsync instead of fsync().
1090**
1091** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags
1092** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL
1093** settings.  The [synchronous pragma] determines when calls to the
1094** xSync VFS method occur and applies uniformly across all platforms.
1095** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how
1096** energetic or rigorous or forceful the sync operations are and
1097** only make a difference on Mac OSX for the default SQLite code.
1098** (Third-party VFS implementations might also make the distinction
1099** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the
1100** operating systems natively supported by SQLite, only Mac OSX
1101** cares about the difference.)
1102*/
1103#define SQLITE_SYNC_NORMAL        0x00002
1104#define SQLITE_SYNC_FULL          0x00003
1105#define SQLITE_SYNC_DATAONLY      0x00010
1106
1107/*
1108** CAPI3REF: OS Interface Open File Handle
1109**
1110** An [sqlite3_file] object represents an open file in the
1111** [sqlite3_vfs | OS interface layer].  Individual OS interface
1112** implementations will
1113** want to subclass this object by appending additional fields
1114** for their own use.  The pMethods entry is a pointer to an
1115** [sqlite3_io_methods] object that defines methods for performing
1116** I/O operations on the open file.
1117*/
1118typedef struct sqlite3_file sqlite3_file;
1119struct sqlite3_file {
1120  const struct sqlite3_io_methods *pMethods;  /* Methods for an open file */
1121};
1122
1123/*
1124** CAPI3REF: OS Interface File Virtual Methods Object
1125**
1126** Every file opened by the [sqlite3_vfs] xOpen method populates an
1127** [sqlite3_file] object (or, more commonly, a subclass of the
1128** [sqlite3_file] object) with a pointer to an instance of this object.
1129** This object defines the methods used to perform various operations
1130** against the open file represented by the [sqlite3_file] object.
1131**
1132** If the xOpen method sets the sqlite3_file.pMethods element
1133** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
1134** may be invoked even if the xOpen reported that it failed.  The
1135** only way to prevent a call to xClose following a failed xOpen
1136** is for the xOpen to set the sqlite3_file.pMethods element to NULL.
1137**
1138** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
1139** [SQLITE_SYNC_FULL].  The first choice is the normal fsync().
1140** The second choice is a Mac OS X style fullsync.  The [SQLITE_SYNC_DATAONLY]
1141** flag may be ORed in to indicate that only the data of the file
1142** and not its inode needs to be synced.
1143**
1144** The integer values to xLock() and xUnlock() are one of
1145** <ul>
1146** <li> [SQLITE_LOCK_NONE],
1147** <li> [SQLITE_LOCK_SHARED],
1148** <li> [SQLITE_LOCK_RESERVED],
1149** <li> [SQLITE_LOCK_PENDING], or
1150** <li> [SQLITE_LOCK_EXCLUSIVE].
1151** </ul>
1152** xLock() increases the lock. xUnlock() decreases the lock.
1153** The xCheckReservedLock() method checks whether any database connection,
1154** either in this process or in some other process, is holding a RESERVED,
1155** PENDING, or EXCLUSIVE lock on the file.  It returns true
1156** if such a lock exists and false otherwise.
1157**
1158** The xFileControl() method is a generic interface that allows custom
1159** VFS implementations to directly control an open file using the
1160** [sqlite3_file_control()] interface.  The second "op" argument is an
1161** integer opcode.  The third argument is a generic pointer intended to
1162** point to a structure that may contain arguments or space in which to
1163** write return values.  Potential uses for xFileControl() might be
1164** functions to enable blocking locks with timeouts, to change the
1165** locking strategy (for example to use dot-file locks), to inquire
1166** about the status of a lock, or to break stale locks.  The SQLite
1167** core reserves all opcodes less than 100 for its own use.
1168** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available.
1169** Applications that define a custom xFileControl method should use opcodes
1170** greater than 100 to avoid conflicts.  VFS implementations should
1171** return [SQLITE_NOTFOUND] for file control opcodes that they do not
1172** recognize.
1173**
1174** The xSectorSize() method returns the sector size of the
1175** device that underlies the file.  The sector size is the
1176** minimum write that can be performed without disturbing
1177** other bytes in the file.  The xDeviceCharacteristics()
1178** method returns a bit vector describing behaviors of the
1179** underlying device:
1180**
1181** <ul>
1182** <li> [SQLITE_IOCAP_ATOMIC]
1183** <li> [SQLITE_IOCAP_ATOMIC512]
1184** <li> [SQLITE_IOCAP_ATOMIC1K]
1185** <li> [SQLITE_IOCAP_ATOMIC2K]
1186** <li> [SQLITE_IOCAP_ATOMIC4K]
1187** <li> [SQLITE_IOCAP_ATOMIC8K]
1188** <li> [SQLITE_IOCAP_ATOMIC16K]
1189** <li> [SQLITE_IOCAP_ATOMIC32K]
1190** <li> [SQLITE_IOCAP_ATOMIC64K]
1191** <li> [SQLITE_IOCAP_SAFE_APPEND]
1192** <li> [SQLITE_IOCAP_SEQUENTIAL]
1193** </ul>
1194**
1195** The SQLITE_IOCAP_ATOMIC property means that all writes of
1196** any size are atomic.  The SQLITE_IOCAP_ATOMICnnn values
1197** mean that writes of blocks that are nnn bytes in size and
1198** are aligned to an address which is an integer multiple of
1199** nnn are atomic.  The SQLITE_IOCAP_SAFE_APPEND value means
1200** that when data is appended to a file, the data is appended
1201** first then the size of the file is extended, never the other
1202** way around.  The SQLITE_IOCAP_SEQUENTIAL property means that
1203** information is written to disk in the same order as calls
1204** to xWrite().
1205**
1206** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
1207** in the unread portions of the buffer with zeros.  A VFS that
1208** fails to zero-fill short reads might seem to work.  However,
1209** failure to zero-fill short reads will eventually lead to
1210** database corruption.
1211*/
1212typedef struct sqlite3_io_methods sqlite3_io_methods;
1213struct sqlite3_io_methods {
1214  int iVersion;
1215  int (*xClose)(sqlite3_file*);
1216  int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
1217  int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
1218  int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
1219  int (*xSync)(sqlite3_file*, int flags);
1220  int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
1221  int (*xLock)(sqlite3_file*, int);
1222  int (*xUnlock)(sqlite3_file*, int);
1223  int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);
1224  int (*xFileControl)(sqlite3_file*, int op, void *pArg);
1225  int (*xSectorSize)(sqlite3_file*);
1226  int (*xDeviceCharacteristics)(sqlite3_file*);
1227  /* Methods above are valid for version 1 */
1228  int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
1229  int (*xShmLock)(sqlite3_file*, int offset, int n, int flags);
1230  void (*xShmBarrier)(sqlite3_file*);
1231  int (*xShmUnmap)(sqlite3_file*, int deleteFlag);
1232  /* Methods above are valid for version 2 */
1233  /* Additional methods may be added in future releases */
1234};
1235
1236/*
1237** CAPI3REF: Standard File Control Opcodes
1238**
1239** These integer constants are opcodes for the xFileControl method
1240** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
1241** interface.
1242**
1243** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging.  This
1244** opcode causes the xFileControl method to write the current state of
1245** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
1246** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
1247** into an integer that the pArg argument points to. This capability
1248** is used during testing and only needs to be supported when SQLITE_TEST
1249** is defined.
1250**
1251** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
1252** layer a hint of how large the database file will grow to be during the
1253** current transaction.  This hint is not guaranteed to be accurate but it
1254** is often close.  The underlying VFS might choose to preallocate database
1255** file space based on this hint in order to help writes to the database
1256** file run faster.
1257**
1258** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
1259** extends and truncates the database file in chunks of a size specified
1260** by the user. The fourth argument to [sqlite3_file_control()] should
1261** point to an integer (type int) containing the new chunk-size to use
1262** for the nominated database. Allocating database file space in large
1263** chunks (say 1MB at a time), may reduce file-system fragmentation and
1264** improve performance on some systems.
1265**
1266** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
1267** to the [sqlite3_file] object associated with a particular database
1268** connection.  See the [sqlite3_file_control()] documentation for
1269** additional information.
1270**
1271** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by
1272** SQLite and sent to all VFSes in place of a call to the xSync method
1273** when the database connection has [PRAGMA synchronous] set to OFF.)^
1274** Some specialized VFSes need this signal in order to operate correctly
1275** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most
1276** VFSes do not need this signal and should silently ignore this opcode.
1277** Applications should not call [sqlite3_file_control()] with this
1278** opcode as doing so may disrupt the operation of the specialized VFSes
1279** that do require it.
1280*/
1281#define SQLITE_FCNTL_LOCKSTATE        1
1282#define SQLITE_GET_LOCKPROXYFILE      2
1283#define SQLITE_SET_LOCKPROXYFILE      3
1284#define SQLITE_LAST_ERRNO             4
1285#define SQLITE_FCNTL_SIZE_HINT        5
1286#define SQLITE_FCNTL_CHUNK_SIZE       6
1287#define SQLITE_FCNTL_FILE_POINTER     7
1288#define SQLITE_FCNTL_SYNC_OMITTED     8
1289
1290
1291/*
1292** CAPI3REF: Mutex Handle
1293**
1294** The mutex module within SQLite defines [sqlite3_mutex] to be an
1295** abstract type for a mutex object.  The SQLite core never looks
1296** at the internal representation of an [sqlite3_mutex].  It only
1297** deals with pointers to the [sqlite3_mutex] object.
1298**
1299** Mutexes are created using [sqlite3_mutex_alloc()].
1300*/
1301typedef struct sqlite3_mutex sqlite3_mutex;
1302
1303/*
1304** CAPI3REF: OS Interface Object
1305**
1306** An instance of the sqlite3_vfs object defines the interface between
1307** the SQLite core and the underlying operating system.  The "vfs"
1308** in the name of the object stands for "virtual file system".
1309**
1310** The value of the iVersion field is initially 1 but may be larger in
1311** future versions of SQLite.  Additional fields may be appended to this
1312** object when the iVersion value is increased.  Note that the structure
1313** of the sqlite3_vfs object changes in the transaction between
1314** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not
1315** modified.
1316**
1317** The szOsFile field is the size of the subclassed [sqlite3_file]
1318** structure used by this VFS.  mxPathname is the maximum length of
1319** a pathname in this VFS.
1320**
1321** Registered sqlite3_vfs objects are kept on a linked list formed by
1322** the pNext pointer.  The [sqlite3_vfs_register()]
1323** and [sqlite3_vfs_unregister()] interfaces manage this list
1324** in a thread-safe way.  The [sqlite3_vfs_find()] interface
1325** searches the list.  Neither the application code nor the VFS
1326** implementation should use the pNext pointer.
1327**
1328** The pNext field is the only field in the sqlite3_vfs
1329** structure that SQLite will ever modify.  SQLite will only access
1330** or modify this field while holding a particular static mutex.
1331** The application should never modify anything within the sqlite3_vfs
1332** object once the object has been registered.
1333**
1334** The zName field holds the name of the VFS module.  The name must
1335** be unique across all VFS modules.
1336**
1337** ^SQLite guarantees that the zFilename parameter to xOpen
1338** is either a NULL pointer or string obtained
1339** from xFullPathname() with an optional suffix added.
1340** ^If a suffix is added to the zFilename parameter, it will
1341** consist of a single "-" character followed by no more than
1342** 10 alphanumeric and/or "-" characters.
1343** ^SQLite further guarantees that
1344** the string will be valid and unchanged until xClose() is
1345** called. Because of the previous sentence,
1346** the [sqlite3_file] can safely store a pointer to the
1347** filename if it needs to remember the filename for some reason.
1348** If the zFilename parameter to xOpen is a NULL pointer then xOpen
1349** must invent its own temporary name for the file.  ^Whenever the
1350** xFilename parameter is NULL it will also be the case that the
1351** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
1352**
1353** The flags argument to xOpen() includes all bits set in
1354** the flags argument to [sqlite3_open_v2()].  Or if [sqlite3_open()]
1355** or [sqlite3_open16()] is used, then flags includes at least
1356** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
1357** If xOpen() opens a file read-only then it sets *pOutFlags to
1358** include [SQLITE_OPEN_READONLY].  Other bits in *pOutFlags may be set.
1359**
1360** ^(SQLite will also add one of the following flags to the xOpen()
1361** call, depending on the object being opened:
1362**
1363** <ul>
1364** <li>  [SQLITE_OPEN_MAIN_DB]
1365** <li>  [SQLITE_OPEN_MAIN_JOURNAL]
1366** <li>  [SQLITE_OPEN_TEMP_DB]
1367** <li>  [SQLITE_OPEN_TEMP_JOURNAL]
1368** <li>  [SQLITE_OPEN_TRANSIENT_DB]
1369** <li>  [SQLITE_OPEN_SUBJOURNAL]
1370** <li>  [SQLITE_OPEN_MASTER_JOURNAL]
1371** <li>  [SQLITE_OPEN_WAL]
1372** </ul>)^
1373**
1374** The file I/O implementation can use the object type flags to
1375** change the way it deals with files.  For example, an application
1376** that does not care about crash recovery or rollback might make
1377** the open of a journal file a no-op.  Writes to this journal would
1378** also be no-ops, and any attempt to read the journal would return
1379** SQLITE_IOERR.  Or the implementation might recognize that a database
1380** file will be doing page-aligned sector reads and writes in a random
1381** order and set up its I/O subsystem accordingly.
1382**
1383** SQLite might also add one of the following flags to the xOpen method:
1384**
1385** <ul>
1386** <li> [SQLITE_OPEN_DELETEONCLOSE]
1387** <li> [SQLITE_OPEN_EXCLUSIVE]
1388** </ul>
1389**
1390** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
1391** deleted when it is closed.  ^The [SQLITE_OPEN_DELETEONCLOSE]
1392** will be set for TEMP databases and their journals, transient
1393** databases, and subjournals.
1394**
1395** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
1396** with the [SQLITE_OPEN_CREATE] flag, which are both directly
1397** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
1398** API.  The SQLITE_OPEN_EXCLUSIVE flag, when paired with the
1399** SQLITE_OPEN_CREATE, is used to indicate that file should always
1400** be created, and that it is an error if it already exists.
1401** It is <i>not</i> used to indicate the file should be opened
1402** for exclusive access.
1403**
1404** ^At least szOsFile bytes of memory are allocated by SQLite
1405** to hold the  [sqlite3_file] structure passed as the third
1406** argument to xOpen.  The xOpen method does not have to
1407** allocate the structure; it should just fill it in.  Note that
1408** the xOpen method must set the sqlite3_file.pMethods to either
1409** a valid [sqlite3_io_methods] object or to NULL.  xOpen must do
1410** this even if the open fails.  SQLite expects that the sqlite3_file.pMethods
1411** element will be valid after xOpen returns regardless of the success
1412** or failure of the xOpen call.
1413**
1414** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
1415** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
1416** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
1417** to test whether a file is at least readable.   The file can be a
1418** directory.
1419**
1420** ^SQLite will always allocate at least mxPathname+1 bytes for the
1421** output buffer xFullPathname.  The exact size of the output buffer
1422** is also passed as a parameter to both  methods. If the output buffer
1423** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
1424** handled as a fatal error by SQLite, vfs implementations should endeavor
1425** to prevent this by setting mxPathname to a sufficiently large value.
1426**
1427** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
1428** interfaces are not strictly a part of the filesystem, but they are
1429** included in the VFS structure for completeness.
1430** The xRandomness() function attempts to return nBytes bytes
1431** of good-quality randomness into zOut.  The return value is
1432** the actual number of bytes of randomness obtained.
1433** The xSleep() method causes the calling thread to sleep for at
1434** least the number of microseconds given.  ^The xCurrentTime()
1435** method returns a Julian Day Number for the current date and time as
1436** a floating point value.
1437** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
1438** Day Number multipled by 86400000 (the number of milliseconds in
1439** a 24-hour day).
1440** ^SQLite will use the xCurrentTimeInt64() method to get the current
1441** date and time if that method is available (if iVersion is 2 or
1442** greater and the function pointer is not NULL) and will fall back
1443** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
1444**
1445** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
1446** are not used by the SQLite core.  These optional interfaces are provided
1447** by some VFSes to facilitate testing of the VFS code. By overriding
1448** system calls with functions under its control, a test program can
1449** simulate faults and error conditions that would otherwise be difficult
1450** or impossible to induce.  The set of system calls that can be overridden
1451** varies from one VFS to another, and from one version of the same VFS to the
1452** next.  Applications that use these interfaces must be prepared for any
1453** or all of these interfaces to be NULL or for their behavior to change
1454** from one release to the next.  Applications must not attempt to access
1455** any of these methods if the iVersion of the VFS is less than 3.
1456*/
1457typedef struct sqlite3_vfs sqlite3_vfs;
1458typedef void (*sqlite3_syscall_ptr)(void);
1459struct sqlite3_vfs {
1460  int iVersion;            /* Structure version number (currently 3) */
1461  int szOsFile;            /* Size of subclassed sqlite3_file */
1462  int mxPathname;          /* Maximum file pathname length */
1463  sqlite3_vfs *pNext;      /* Next registered VFS */
1464  const char *zName;       /* Name of this virtual file system */
1465  void *pAppData;          /* Pointer to application-specific data */
1466  int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*,
1467               int flags, int *pOutFlags);
1468  int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
1469  int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
1470  int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
1471  void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
1472  void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
1473  void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
1474  void (*xDlClose)(sqlite3_vfs*, void*);
1475  int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
1476  int (*xSleep)(sqlite3_vfs*, int microseconds);
1477  int (*xCurrentTime)(sqlite3_vfs*, double*);
1478  int (*xGetLastError)(sqlite3_vfs*, int, char *);
1479  /*
1480  ** The methods above are in version 1 of the sqlite_vfs object
1481  ** definition.  Those that follow are added in version 2 or later
1482  */
1483  int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
1484  /*
1485  ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
1486  ** Those below are for version 3 and greater.
1487  */
1488  int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);
1489  sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);
1490  const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
1491  /*
1492  ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
1493  ** New fields may be appended in figure versions.  The iVersion
1494  ** value will increment whenever this happens.
1495  */
1496};
1497
1498/*
1499** CAPI3REF: Flags for the xAccess VFS method
1500**
1501** These integer constants can be used as the third parameter to
1502** the xAccess method of an [sqlite3_vfs] object.  They determine
1503** what kind of permissions the xAccess method is looking for.
1504** With SQLITE_ACCESS_EXISTS, the xAccess method
1505** simply checks whether the file exists.
1506** With SQLITE_ACCESS_READWRITE, the xAccess method
1507** checks whether the named directory is both readable and writable
1508** (in other words, if files can be added, removed, and renamed within
1509** the directory).
1510** The SQLITE_ACCESS_READWRITE constant is currently used only by the
1511** [temp_store_directory pragma], though this could change in a future
1512** release of SQLite.
1513** With SQLITE_ACCESS_READ, the xAccess method
1514** checks whether the file is readable.  The SQLITE_ACCESS_READ constant is
1515** currently unused, though it might be used in a future release of
1516** SQLite.
1517*/
1518#define SQLITE_ACCESS_EXISTS    0
1519#define SQLITE_ACCESS_READWRITE 1   /* Used by PRAGMA temp_store_directory */
1520#define SQLITE_ACCESS_READ      2   /* Unused */
1521
1522/*
1523** CAPI3REF: Flags for the xShmLock VFS method
1524**
1525** These integer constants define the various locking operations
1526** allowed by the xShmLock method of [sqlite3_io_methods].  The
1527** following are the only legal combinations of flags to the
1528** xShmLock method:
1529**
1530** <ul>
1531** <li>  SQLITE_SHM_LOCK | SQLITE_SHM_SHARED
1532** <li>  SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE
1533** <li>  SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
1534** <li>  SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
1535** </ul>
1536**
1537** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as
1538** was given no the corresponding lock.
1539**
1540** The xShmLock method can transition between unlocked and SHARED or
1541** between unlocked and EXCLUSIVE.  It cannot transition between SHARED
1542** and EXCLUSIVE.
1543*/
1544#define SQLITE_SHM_UNLOCK       1
1545#define SQLITE_SHM_LOCK         2
1546#define SQLITE_SHM_SHARED       4
1547#define SQLITE_SHM_EXCLUSIVE    8
1548
1549/*
1550** CAPI3REF: Maximum xShmLock index
1551**
1552** The xShmLock method on [sqlite3_io_methods] may use values
1553** between 0 and this upper bound as its "offset" argument.
1554** The SQLite core will never attempt to acquire or release a
1555** lock outside of this range
1556*/
1557#define SQLITE_SHM_NLOCK        8
1558
1559
1560/*
1561** CAPI3REF: Initialize The SQLite Library
1562**
1563** ^The sqlite3_initialize() routine initializes the
1564** SQLite library.  ^The sqlite3_shutdown() routine
1565** deallocates any resources that were allocated by sqlite3_initialize().
1566** These routines are designed to aid in process initialization and
1567** shutdown on embedded systems.  Workstation applications using
1568** SQLite normally do not need to invoke either of these routines.
1569**
1570** A call to sqlite3_initialize() is an "effective" call if it is
1571** the first time sqlite3_initialize() is invoked during the lifetime of
1572** the process, or if it is the first time sqlite3_initialize() is invoked
1573** following a call to sqlite3_shutdown().  ^(Only an effective call
1574** of sqlite3_initialize() does any initialization.  All other calls
1575** are harmless no-ops.)^
1576**
1577** A call to sqlite3_shutdown() is an "effective" call if it is the first
1578** call to sqlite3_shutdown() since the last sqlite3_initialize().  ^(Only
1579** an effective call to sqlite3_shutdown() does any deinitialization.
1580** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^
1581**
1582** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown()
1583** is not.  The sqlite3_shutdown() interface must only be called from a
1584** single thread.  All open [database connections] must be closed and all
1585** other SQLite resources must be deallocated prior to invoking
1586** sqlite3_shutdown().
1587**
1588** Among other things, ^sqlite3_initialize() will invoke
1589** sqlite3_os_init().  Similarly, ^sqlite3_shutdown()
1590** will invoke sqlite3_os_end().
1591**
1592** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success.
1593** ^If for some reason, sqlite3_initialize() is unable to initialize
1594** the library (perhaps it is unable to allocate a needed resource such
1595** as a mutex) it returns an [error code] other than [SQLITE_OK].
1596**
1597** ^The sqlite3_initialize() routine is called internally by many other
1598** SQLite interfaces so that an application usually does not need to
1599** invoke sqlite3_initialize() directly.  For example, [sqlite3_open()]
1600** calls sqlite3_initialize() so the SQLite library will be automatically
1601** initialized when [sqlite3_open()] is called if it has not be initialized
1602** already.  ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
1603** compile-time option, then the automatic calls to sqlite3_initialize()
1604** are omitted and the application must call sqlite3_initialize() directly
1605** prior to using any other SQLite interface.  For maximum portability,
1606** it is recommended that applications always invoke sqlite3_initialize()
1607** directly prior to using any other SQLite interface.  Future releases
1608** of SQLite may require this.  In other words, the behavior exhibited
1609** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the
1610** default behavior in some future release of SQLite.
1611**
1612** The sqlite3_os_init() routine does operating-system specific
1613** initialization of the SQLite library.  The sqlite3_os_end()
1614** routine undoes the effect of sqlite3_os_init().  Typical tasks
1615** performed by these routines include allocation or deallocation
1616** of static resources, initialization of global variables,
1617** setting up a default [sqlite3_vfs] module, or setting up
1618** a default configuration using [sqlite3_config()].
1619**
1620** The application should never invoke either sqlite3_os_init()
1621** or sqlite3_os_end() directly.  The application should only invoke
1622** sqlite3_initialize() and sqlite3_shutdown().  The sqlite3_os_init()
1623** interface is called automatically by sqlite3_initialize() and
1624** sqlite3_os_end() is called by sqlite3_shutdown().  Appropriate
1625** implementations for sqlite3_os_init() and sqlite3_os_end()
1626** are built into SQLite when it is compiled for Unix, Windows, or OS/2.
1627** When [custom builds | built for other platforms]
1628** (using the [SQLITE_OS_OTHER=1] compile-time
1629** option) the application must supply a suitable implementation for
1630** sqlite3_os_init() and sqlite3_os_end().  An application-supplied
1631** implementation of sqlite3_os_init() or sqlite3_os_end()
1632** must return [SQLITE_OK] on success and some other [error code] upon
1633** failure.
1634*/
1635SQLITE_API int sqlite3_initialize(void);
1636SQLITE_API int sqlite3_shutdown(void);
1637SQLITE_API int sqlite3_os_init(void);
1638SQLITE_API int sqlite3_os_end(void);
1639
1640/*
1641** CAPI3REF: Configuring The SQLite Library
1642**
1643** The sqlite3_config() interface is used to make global configuration
1644** changes to SQLite in order to tune SQLite to the specific needs of
1645** the application.  The default configuration is recommended for most
1646** applications and so this routine is usually not necessary.  It is
1647** provided to support rare applications with unusual needs.
1648**
1649** The sqlite3_config() interface is not threadsafe.  The application
1650** must insure that no other SQLite interfaces are invoked by other
1651** threads while sqlite3_config() is running.  Furthermore, sqlite3_config()
1652** may only be invoked prior to library initialization using
1653** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
1654** ^If sqlite3_config() is called after [sqlite3_initialize()] and before
1655** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
1656** Note, however, that ^sqlite3_config() can be called as part of the
1657** implementation of an application-defined [sqlite3_os_init()].
1658**
1659** The first argument to sqlite3_config() is an integer
1660** [SQLITE_CONFIG_SINGLETHREAD | configuration option] that determines
1661** what property of SQLite is to be configured.  Subsequent arguments
1662** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option]
1663** in the first argument.
1664**
1665** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
1666** ^If the option is unknown or SQLite is unable to set the option
1667** then this routine returns a non-zero [error code].
1668*/
1669SQLITE_API int sqlite3_config(int, ...);
1670
1671/*
1672** CAPI3REF: Configure database connections
1673**
1674** The sqlite3_db_config() interface is used to make configuration
1675** changes to a [database connection].  The interface is similar to
1676** [sqlite3_config()] except that the changes apply to a single
1677** [database connection] (specified in the first argument).
1678**
1679** The second argument to sqlite3_db_config(D,V,...)  is the
1680** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code
1681** that indicates what aspect of the [database connection] is being configured.
1682** Subsequent arguments vary depending on the configuration verb.
1683**
1684** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
1685** the call is considered successful.
1686*/
1687SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
1688
1689/*
1690** CAPI3REF: Memory Allocation Routines
1691**
1692** An instance of this object defines the interface between SQLite
1693** and low-level memory allocation routines.
1694**
1695** This object is used in only one place in the SQLite interface.
1696** A pointer to an instance of this object is the argument to
1697** [sqlite3_config()] when the configuration option is
1698** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC].
1699** By creating an instance of this object
1700** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC])
1701** during configuration, an application can specify an alternative
1702** memory allocation subsystem for SQLite to use for all of its
1703** dynamic memory needs.
1704**
1705** Note that SQLite comes with several [built-in memory allocators]
1706** that are perfectly adequate for the overwhelming majority of applications
1707** and that this object is only useful to a tiny minority of applications
1708** with specialized memory allocation requirements.  This object is
1709** also used during testing of SQLite in order to specify an alternative
1710** memory allocator that simulates memory out-of-memory conditions in
1711** order to verify that SQLite recovers gracefully from such
1712** conditions.
1713**
1714** The xMalloc and xFree methods must work like the
1715** malloc() and free() functions from the standard C library.
1716** The xRealloc method must work like realloc() from the standard C library
1717** with the exception that if the second argument to xRealloc is zero,
1718** xRealloc must be a no-op - it must not perform any allocation or
1719** deallocation.  ^SQLite guarantees that the second argument to
1720** xRealloc is always a value returned by a prior call to xRoundup.
1721** And so in cases where xRoundup always returns a positive number,
1722** xRealloc can perform exactly as the standard library realloc() and
1723** still be in compliance with this specification.
1724**
1725** xSize should return the allocated size of a memory allocation
1726** previously obtained from xMalloc or xRealloc.  The allocated size
1727** is always at least as big as the requested size but may be larger.
1728**
1729** The xRoundup method returns what would be the allocated size of
1730** a memory allocation given a particular requested size.  Most memory
1731** allocators round up memory allocations at least to the next multiple
1732** of 8.  Some allocators round up to a larger multiple or to a power of 2.
1733** Every memory allocation request coming in through [sqlite3_malloc()]
1734** or [sqlite3_realloc()] first calls xRoundup.  If xRoundup returns 0,
1735** that causes the corresponding memory allocation to fail.
1736**
1737** The xInit method initializes the memory allocator.  (For example,
1738** it might allocate any require mutexes or initialize internal data
1739** structures.  The xShutdown method is invoked (indirectly) by
1740** [sqlite3_shutdown()] and should deallocate any resources acquired
1741** by xInit.  The pAppData pointer is used as the only parameter to
1742** xInit and xShutdown.
1743**
1744** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes
1745** the xInit method, so the xInit method need not be threadsafe.  The
1746** xShutdown method is only called from [sqlite3_shutdown()] so it does
1747** not need to be threadsafe either.  For all other methods, SQLite
1748** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
1749** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
1750** it is by default) and so the methods are automatically serialized.
1751** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other
1752** methods must be threadsafe or else make their own arrangements for
1753** serialization.
1754**
1755** SQLite will never invoke xInit() more than once without an intervening
1756** call to xShutdown().
1757*/
1758typedef struct sqlite3_mem_methods sqlite3_mem_methods;
1759struct sqlite3_mem_methods {
1760  void *(*xMalloc)(int);         /* Memory allocation function */
1761  void (*xFree)(void*);          /* Free a prior allocation */
1762  void *(*xRealloc)(void*,int);  /* Resize an allocation */
1763  int (*xSize)(void*);           /* Return the size of an allocation */
1764  int (*xRoundup)(int);          /* Round up request size to allocation size */
1765  int (*xInit)(void*);           /* Initialize the memory allocator */
1766  void (*xShutdown)(void*);      /* Deinitialize the memory allocator */
1767  void *pAppData;                /* Argument to xInit() and xShutdown() */
1768};
1769
1770/*
1771** CAPI3REF: Configuration Options
1772**
1773** These constants are the available integer configuration options that
1774** can be passed as the first argument to the [sqlite3_config()] interface.
1775**
1776** New configuration options may be added in future releases of SQLite.
1777** Existing configuration options might be discontinued.  Applications
1778** should check the return code from [sqlite3_config()] to make sure that
1779** the call worked.  The [sqlite3_config()] interface will return a
1780** non-zero [error code] if a discontinued or unsupported configuration option
1781** is invoked.
1782**
1783** <dl>
1784** <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
1785** <dd>There are no arguments to this option.  ^This option sets the
1786** [threading mode] to Single-thread.  In other words, it disables
1787** all mutexing and puts SQLite into a mode where it can only be used
1788** by a single thread.   ^If SQLite is compiled with
1789** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1790** it is not possible to change the [threading mode] from its default
1791** value of Single-thread and so [sqlite3_config()] will return
1792** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
1793** configuration option.</dd>
1794**
1795** <dt>SQLITE_CONFIG_MULTITHREAD</dt>
1796** <dd>There are no arguments to this option.  ^This option sets the
1797** [threading mode] to Multi-thread.  In other words, it disables
1798** mutexing on [database connection] and [prepared statement] objects.
1799** The application is responsible for serializing access to
1800** [database connections] and [prepared statements].  But other mutexes
1801** are enabled so that SQLite will be safe to use in a multi-threaded
1802** environment as long as no two threads attempt to use the same
1803** [database connection] at the same time.  ^If SQLite is compiled with
1804** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1805** it is not possible to set the Multi-thread [threading mode] and
1806** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1807** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
1808**
1809** <dt>SQLITE_CONFIG_SERIALIZED</dt>
1810** <dd>There are no arguments to this option.  ^This option sets the
1811** [threading mode] to Serialized. In other words, this option enables
1812** all mutexes including the recursive
1813** mutexes on [database connection] and [prepared statement] objects.
1814** In this mode (which is the default when SQLite is compiled with
1815** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access
1816** to [database connections] and [prepared statements] so that the
1817** application is free to use the same [database connection] or the
1818** same [prepared statement] in different threads at the same time.
1819** ^If SQLite is compiled with
1820** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1821** it is not possible to set the Serialized [threading mode] and
1822** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1823** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
1824**
1825** <dt>SQLITE_CONFIG_MALLOC</dt>
1826** <dd> ^(This option takes a single argument which is a pointer to an
1827** instance of the [sqlite3_mem_methods] structure.  The argument specifies
1828** alternative low-level memory allocation routines to be used in place of
1829** the memory allocation routines built into SQLite.)^ ^SQLite makes
1830** its own private copy of the content of the [sqlite3_mem_methods] structure
1831** before the [sqlite3_config()] call returns.</dd>
1832**
1833** <dt>SQLITE_CONFIG_GETMALLOC</dt>
1834** <dd> ^(This option takes a single argument which is a pointer to an
1835** instance of the [sqlite3_mem_methods] structure.  The [sqlite3_mem_methods]
1836** structure is filled with the currently defined memory allocation routines.)^
1837** This option can be used to overload the default memory allocation
1838** routines with a wrapper that simulations memory allocation failure or
1839** tracks memory usage, for example. </dd>
1840**
1841** <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1842** <dd> ^This option takes single argument of type int, interpreted as a
1843** boolean, which enables or disables the collection of memory allocation
1844** statistics. ^(When memory allocation statistics are disabled, the
1845** following SQLite interfaces become non-operational:
1846**   <ul>
1847**   <li> [sqlite3_memory_used()]
1848**   <li> [sqlite3_memory_highwater()]
1849**   <li> [sqlite3_soft_heap_limit64()]
1850**   <li> [sqlite3_status()]
1851**   </ul>)^
1852** ^Memory allocation statistics are enabled by default unless SQLite is
1853** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1854** allocation statistics are disabled by default.
1855** </dd>
1856**
1857** <dt>SQLITE_CONFIG_SCRATCH</dt>
1858** <dd> ^This option specifies a static memory buffer that SQLite can use for
1859** scratch memory.  There are three arguments:  A pointer an 8-byte
1860** aligned memory buffer from which the scratch allocations will be
1861** drawn, the size of each scratch allocation (sz),
1862** and the maximum number of scratch allocations (N).  The sz
1863** argument must be a multiple of 16.
1864** The first argument must be a pointer to an 8-byte aligned buffer
1865** of at least sz*N bytes of memory.
1866** ^SQLite will use no more than two scratch buffers per thread.  So
1867** N should be set to twice the expected maximum number of threads.
1868** ^SQLite will never require a scratch buffer that is more than 6
1869** times the database page size. ^If SQLite needs needs additional
1870** scratch memory beyond what is provided by this configuration option, then
1871** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
1872**
1873** <dt>SQLITE_CONFIG_PAGECACHE</dt>
1874** <dd> ^This option specifies a static memory buffer that SQLite can use for
1875** the database page cache with the default page cache implemenation.
1876** This configuration should not be used if an application-define page
1877** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option.
1878** There are three arguments to this option: A pointer to 8-byte aligned
1879** memory, the size of each page buffer (sz), and the number of pages (N).
1880** The sz argument should be the size of the largest database page
1881** (a power of two between 512 and 32768) plus a little extra for each
1882** page header.  ^The page header size is 20 to 40 bytes depending on
1883** the host architecture.  ^It is harmless, apart from the wasted memory,
1884** to make sz a little too large.  The first
1885** argument should point to an allocation of at least sz*N bytes of memory.
1886** ^SQLite will use the memory provided by the first argument to satisfy its
1887** memory needs for the first N pages that it adds to cache.  ^If additional
1888** page cache memory is needed beyond what is provided by this option, then
1889** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1890** The pointer in the first argument must
1891** be aligned to an 8-byte boundary or subsequent behavior of SQLite
1892** will be undefined.</dd>
1893**
1894** <dt>SQLITE_CONFIG_HEAP</dt>
1895** <dd> ^This option specifies a static memory buffer that SQLite will use
1896** for all of its dynamic memory allocation needs beyond those provided
1897** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
1898** There are three arguments: An 8-byte aligned pointer to the memory,
1899** the number of bytes in the memory buffer, and the minimum allocation size.
1900** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
1901** to using its default memory allocator (the system malloc() implementation),
1902** undoing any prior invocation of [SQLITE_CONFIG_MALLOC].  ^If the
1903** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
1904** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
1905** allocator is engaged to handle all of SQLites memory allocation needs.
1906** The first pointer (the memory pointer) must be aligned to an 8-byte
1907** boundary or subsequent behavior of SQLite will be undefined.
1908** The minimum allocation size is capped at 2^12. Reasonable values
1909** for the minimum allocation size are 2^5 through 2^8.</dd>
1910**
1911** <dt>SQLITE_CONFIG_MUTEX</dt>
1912** <dd> ^(This option takes a single argument which is a pointer to an
1913** instance of the [sqlite3_mutex_methods] structure.  The argument specifies
1914** alternative low-level mutex routines to be used in place
1915** the mutex routines built into SQLite.)^  ^SQLite makes a copy of the
1916** content of the [sqlite3_mutex_methods] structure before the call to
1917** [sqlite3_config()] returns. ^If SQLite is compiled with
1918** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1919** the entire mutexing subsystem is omitted from the build and hence calls to
1920** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
1921** return [SQLITE_ERROR].</dd>
1922**
1923** <dt>SQLITE_CONFIG_GETMUTEX</dt>
1924** <dd> ^(This option takes a single argument which is a pointer to an
1925** instance of the [sqlite3_mutex_methods] structure.  The
1926** [sqlite3_mutex_methods]
1927** structure is filled with the currently defined mutex routines.)^
1928** This option can be used to overload the default mutex allocation
1929** routines with a wrapper used to track mutex usage for performance
1930** profiling or testing, for example.   ^If SQLite is compiled with
1931** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1932** the entire mutexing subsystem is omitted from the build and hence calls to
1933** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
1934** return [SQLITE_ERROR].</dd>
1935**
1936** <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1937** <dd> ^(This option takes two arguments that determine the default
1938** memory allocation for the lookaside memory allocator on each
1939** [database connection].  The first argument is the
1940** size of each lookaside buffer slot and the second is the number of
1941** slots allocated to each database connection.)^  ^(This option sets the
1942** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1943** verb to [sqlite3_db_config()] can be used to change the lookaside
1944** configuration on individual connections.)^ </dd>
1945**
1946** <dt>SQLITE_CONFIG_PCACHE</dt>
1947** <dd> ^(This option takes a single argument which is a pointer to
1948** an [sqlite3_pcache_methods] object.  This object specifies the interface
1949** to a custom page cache implementation.)^  ^SQLite makes a copy of the
1950** object and uses it for page cache memory allocations.</dd>
1951**
1952** <dt>SQLITE_CONFIG_GETPCACHE</dt>
1953** <dd> ^(This option takes a single argument which is a pointer to an
1954** [sqlite3_pcache_methods] object.  SQLite copies of the current
1955** page cache implementation into that object.)^ </dd>
1956**
1957** <dt>SQLITE_CONFIG_LOG</dt>
1958** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
1959** function with a call signature of void(*)(void*,int,const char*),
1960** and a pointer to void. ^If the function pointer is not NULL, it is
1961** invoked by [sqlite3_log()] to process each logging event.  ^If the
1962** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
1963** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
1964** passed through as the first parameter to the application-defined logger
1965** function whenever that function is invoked.  ^The second parameter to
1966** the logger function is a copy of the first parameter to the corresponding
1967** [sqlite3_log()] call and is intended to be a [result code] or an
1968** [extended result code].  ^The third parameter passed to the logger is
1969** log message after formatting via [sqlite3_snprintf()].
1970** The SQLite logging interface is not reentrant; the logger function
1971** supplied by the application must not invoke any SQLite interface.
1972** In a multi-threaded application, the application-defined logger
1973** function must be threadsafe. </dd>
1974**
1975** </dl>
1976*/
1977#define SQLITE_CONFIG_SINGLETHREAD  1  /* nil */
1978#define SQLITE_CONFIG_MULTITHREAD   2  /* nil */
1979#define SQLITE_CONFIG_SERIALIZED    3  /* nil */
1980#define SQLITE_CONFIG_MALLOC        4  /* sqlite3_mem_methods* */
1981#define SQLITE_CONFIG_GETMALLOC     5  /* sqlite3_mem_methods* */
1982#define SQLITE_CONFIG_SCRATCH       6  /* void*, int sz, int N */
1983#define SQLITE_CONFIG_PAGECACHE     7  /* void*, int sz, int N */
1984#define SQLITE_CONFIG_HEAP          8  /* void*, int nByte, int min */
1985#define SQLITE_CONFIG_MEMSTATUS     9  /* boolean */
1986#define SQLITE_CONFIG_MUTEX        10  /* sqlite3_mutex_methods* */
1987#define SQLITE_CONFIG_GETMUTEX     11  /* sqlite3_mutex_methods* */
1988/* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
1989#define SQLITE_CONFIG_LOOKASIDE    13  /* int int */
1990#define SQLITE_CONFIG_PCACHE       14  /* sqlite3_pcache_methods* */
1991#define SQLITE_CONFIG_GETPCACHE    15  /* sqlite3_pcache_methods* */
1992#define SQLITE_CONFIG_LOG          16  /* xFunc, void* */
1993
1994/*
1995** CAPI3REF: Database Connection Configuration Options
1996**
1997** These constants are the available integer configuration options that
1998** can be passed as the second argument to the [sqlite3_db_config()] interface.
1999**
2000** New configuration options may be added in future releases of SQLite.
2001** Existing configuration options might be discontinued.  Applications
2002** should check the return code from [sqlite3_db_config()] to make sure that
2003** the call worked.  ^The [sqlite3_db_config()] interface will return a
2004** non-zero [error code] if a discontinued or unsupported configuration option
2005** is invoked.
2006**
2007** <dl>
2008** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
2009** <dd> ^This option takes three additional arguments that determine the
2010** [lookaside memory allocator] configuration for the [database connection].
2011** ^The first argument (the third parameter to [sqlite3_db_config()] is a
2012** pointer to a memory buffer to use for lookaside memory.
2013** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
2014** may be NULL in which case SQLite will allocate the
2015** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the
2016** size of each lookaside buffer slot.  ^The third argument is the number of
2017** slots.  The size of the buffer in the first argument must be greater than
2018** or equal to the product of the second and third arguments.  The buffer
2019** must be aligned to an 8-byte boundary.  ^If the second argument to
2020** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
2021** rounded down to the next smaller multiple of 8.  ^(The lookaside memory
2022** configuration for a database connection can only be changed when that
2023** connection is not currently using lookaside memory, or in other words
2024** when the "current value" returned by
2025** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
2026** Any attempt to change the lookaside memory configuration when lookaside
2027** memory is in use leaves the configuration unchanged and returns
2028** [SQLITE_BUSY].)^</dd>
2029**
2030** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
2031** <dd> ^This option is used to enable or disable the enforcement of
2032** [foreign key constraints].  There should be two additional arguments.
2033** The first argument is an integer which is 0 to disable FK enforcement,
2034** positive to enable FK enforcement or negative to leave FK enforcement
2035** unchanged.  The second parameter is a pointer to an integer into which
2036** is written 0 or 1 to indicate whether FK enforcement is off or on
2037** following this call.  The second parameter may be a NULL pointer, in
2038** which case the FK enforcement setting is not reported back. </dd>
2039**
2040** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
2041** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
2042** There should be two additional arguments.
2043** The first argument is an integer which is 0 to disable triggers,
2044** positive to enable triggers or negative to leave the setting unchanged.
2045** The second parameter is a pointer to an integer into which
2046** is written 0 or 1 to indicate whether triggers are disabled or enabled
2047** following this call.  The second parameter may be a NULL pointer, in
2048** which case the trigger setting is not reported back. </dd>
2049**
2050** </dl>
2051*/
2052#define SQLITE_DBCONFIG_LOOKASIDE       1001  /* void* int int */
2053#define SQLITE_DBCONFIG_ENABLE_FKEY     1002  /* int int* */
2054#define SQLITE_DBCONFIG_ENABLE_TRIGGER  1003  /* int int* */
2055
2056
2057/*
2058** CAPI3REF: Enable Or Disable Extended Result Codes
2059**
2060** ^The sqlite3_extended_result_codes() routine enables or disables the
2061** [extended result codes] feature of SQLite. ^The extended result
2062** codes are disabled by default for historical compatibility.
2063*/
2064SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
2065
2066/*
2067** CAPI3REF: Last Insert Rowid
2068**
2069** ^Each entry in an SQLite table has a unique 64-bit signed
2070** integer key called the [ROWID | "rowid"]. ^The rowid is always available
2071** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
2072** names are not also used by explicitly declared columns. ^If
2073** the table has a column of type [INTEGER PRIMARY KEY] then that column
2074** is another alias for the rowid.
2075**
2076** ^This routine returns the [rowid] of the most recent
2077** successful [INSERT] into the database from the [database connection]
2078** in the first argument.  ^If no successful [INSERT]s
2079** have ever occurred on that database connection, zero is returned.
2080**
2081** ^(If an [INSERT] occurs within a trigger, then the [rowid] of the inserted
2082** row is returned by this routine as long as the trigger is running.
2083** But once the trigger terminates, the value returned by this routine
2084** reverts to the last value inserted before the trigger fired.)^
2085**
2086** ^An [INSERT] that fails due to a constraint violation is not a
2087** successful [INSERT] and does not change the value returned by this
2088** routine.  ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
2089** and INSERT OR ABORT make no changes to the return value of this
2090** routine when their insertion fails.  ^(When INSERT OR REPLACE
2091** encounters a constraint violation, it does not fail.  The
2092** INSERT continues to completion after deleting rows that caused
2093** the constraint problem so INSERT OR REPLACE will always change
2094** the return value of this interface.)^
2095**
2096** ^For the purposes of this routine, an [INSERT] is considered to
2097** be successful even if it is subsequently rolled back.
2098**
2099** This function is accessible to SQL statements via the
2100** [last_insert_rowid() SQL function].
2101**
2102** If a separate thread performs a new [INSERT] on the same
2103** database connection while the [sqlite3_last_insert_rowid()]
2104** function is running and thus changes the last insert [rowid],
2105** then the value returned by [sqlite3_last_insert_rowid()] is
2106** unpredictable and might not equal either the old or the new
2107** last insert [rowid].
2108*/
2109SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
2110
2111/*
2112** CAPI3REF: Count The Number Of Rows Modified
2113**
2114** ^This function returns the number of database rows that were changed
2115** or inserted or deleted by the most recently completed SQL statement
2116** on the [database connection] specified by the first parameter.
2117** ^(Only changes that are directly specified by the [INSERT], [UPDATE],
2118** or [DELETE] statement are counted.  Auxiliary changes caused by
2119** triggers or [foreign key actions] are not counted.)^ Use the
2120** [sqlite3_total_changes()] function to find the total number of changes
2121** including changes caused by triggers and foreign key actions.
2122**
2123** ^Changes to a view that are simulated by an [INSTEAD OF trigger]
2124** are not counted.  Only real table changes are counted.
2125**
2126** ^(A "row change" is a change to a single row of a single table
2127** caused by an INSERT, DELETE, or UPDATE statement.  Rows that
2128** are changed as side effects of [REPLACE] constraint resolution,
2129** rollback, ABORT processing, [DROP TABLE], or by any other
2130** mechanisms do not count as direct row changes.)^
2131**
2132** A "trigger context" is a scope of execution that begins and
2133** ends with the script of a [CREATE TRIGGER | trigger].
2134** Most SQL statements are
2135** evaluated outside of any trigger.  This is the "top level"
2136** trigger context.  If a trigger fires from the top level, a
2137** new trigger context is entered for the duration of that one
2138** trigger.  Subtriggers create subcontexts for their duration.
2139**
2140** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does
2141** not create a new trigger context.
2142**
2143** ^This function returns the number of direct row changes in the
2144** most recent INSERT, UPDATE, or DELETE statement within the same
2145** trigger context.
2146**
2147** ^Thus, when called from the top level, this function returns the
2148** number of changes in the most recent INSERT, UPDATE, or DELETE
2149** that also occurred at the top level.  ^(Within the body of a trigger,
2150** the sqlite3_changes() interface can be called to find the number of
2151** changes in the most recently completed INSERT, UPDATE, or DELETE
2152** statement within the body of the same trigger.
2153** However, the number returned does not include changes
2154** caused by subtriggers since those have their own context.)^
2155**
2156** See also the [sqlite3_total_changes()] interface, the
2157** [count_changes pragma], and the [changes() SQL function].
2158**
2159** If a separate thread makes changes on the same database connection
2160** while [sqlite3_changes()] is running then the value returned
2161** is unpredictable and not meaningful.
2162*/
2163SQLITE_API int sqlite3_changes(sqlite3*);
2164
2165/*
2166** CAPI3REF: Total Number Of Rows Modified
2167**
2168** ^This function returns the number of row changes caused by [INSERT],
2169** [UPDATE] or [DELETE] statements since the [database connection] was opened.
2170** ^(The count returned by sqlite3_total_changes() includes all changes
2171** from all [CREATE TRIGGER | trigger] contexts and changes made by
2172** [foreign key actions]. However,
2173** the count does not include changes used to implement [REPLACE] constraints,
2174** do rollbacks or ABORT processing, or [DROP TABLE] processing.  The
2175** count does not include rows of views that fire an [INSTEAD OF trigger],
2176** though if the INSTEAD OF trigger makes changes of its own, those changes
2177** are counted.)^
2178** ^The sqlite3_total_changes() function counts the changes as soon as
2179** the statement that makes them is completed (when the statement handle
2180** is passed to [sqlite3_reset()] or [sqlite3_finalize()]).
2181**
2182** See also the [sqlite3_changes()] interface, the
2183** [count_changes pragma], and the [total_changes() SQL function].
2184**
2185** If a separate thread makes changes on the same database connection
2186** while [sqlite3_total_changes()] is running then the value
2187** returned is unpredictable and not meaningful.
2188*/
2189SQLITE_API int sqlite3_total_changes(sqlite3*);
2190
2191/*
2192** CAPI3REF: Interrupt A Long-Running Query
2193**
2194** ^This function causes any pending database operation to abort and
2195** return at its earliest opportunity. This routine is typically
2196** called in response to a user action such as pressing "Cancel"
2197** or Ctrl-C where the user wants a long query operation to halt
2198** immediately.
2199**
2200** ^It is safe to call this routine from a thread different from the
2201** thread that is currently running the database operation.  But it
2202** is not safe to call this routine with a [database connection] that
2203** is closed or might close before sqlite3_interrupt() returns.
2204**
2205** ^If an SQL operation is very nearly finished at the time when
2206** sqlite3_interrupt() is called, then it might not have an opportunity
2207** to be interrupted and might continue to completion.
2208**
2209** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT].
2210** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
2211** that is inside an explicit transaction, then the entire transaction
2212** will be rolled back automatically.
2213**
2214** ^The sqlite3_interrupt(D) call is in effect until all currently running
2215** SQL statements on [database connection] D complete.  ^Any new SQL statements
2216** that are started after the sqlite3_interrupt() call and before the
2217** running statements reaches zero are interrupted as if they had been
2218** running prior to the sqlite3_interrupt() call.  ^New SQL statements
2219** that are started after the running statement count reaches zero are
2220** not effected by the sqlite3_interrupt().
2221** ^A call to sqlite3_interrupt(D) that occurs when there are no running
2222** SQL statements is a no-op and has no effect on SQL statements
2223** that are started after the sqlite3_interrupt() call returns.
2224**
2225** If the database connection closes while [sqlite3_interrupt()]
2226** is running then bad things will likely happen.
2227*/
2228SQLITE_API void sqlite3_interrupt(sqlite3*);
2229
2230/*
2231** CAPI3REF: Determine If An SQL Statement Is Complete
2232**
2233** These routines are useful during command-line input to determine if the
2234** currently entered text seems to form a complete SQL statement or
2235** if additional input is needed before sending the text into
2236** SQLite for parsing.  ^These routines return 1 if the input string
2237** appears to be a complete SQL statement.  ^A statement is judged to be
2238** complete if it ends with a semicolon token and is not a prefix of a
2239** well-formed CREATE TRIGGER statement.  ^Semicolons that are embedded within
2240** string literals or quoted identifier names or comments are not
2241** independent tokens (they are part of the token in which they are
2242** embedded) and thus do not count as a statement terminator.  ^Whitespace
2243** and comments that follow the final semicolon are ignored.
2244**
2245** ^These routines return 0 if the statement is incomplete.  ^If a
2246** memory allocation fails, then SQLITE_NOMEM is returned.
2247**
2248** ^These routines do not parse the SQL statements thus
2249** will not detect syntactically incorrect SQL.
2250**
2251** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior
2252** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
2253** automatically by sqlite3_complete16().  If that initialization fails,
2254** then the return value from sqlite3_complete16() will be non-zero
2255** regardless of whether or not the input SQL is complete.)^
2256**
2257** The input to [sqlite3_complete()] must be a zero-terminated
2258** UTF-8 string.
2259**
2260** The input to [sqlite3_complete16()] must be a zero-terminated
2261** UTF-16 string in native byte order.
2262*/
2263SQLITE_API int sqlite3_complete(const char *sql);
2264SQLITE_API int sqlite3_complete16(const void *sql);
2265
2266/*
2267** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2268**
2269** ^This routine sets a callback function that might be invoked whenever
2270** an attempt is made to open a database table that another thread
2271** or process has locked.
2272**
2273** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]
2274** is returned immediately upon encountering the lock.  ^If the busy callback
2275** is not NULL, then the callback might be invoked with two arguments.
2276**
2277** ^The first argument to the busy handler is a copy of the void* pointer which
2278** is the third argument to sqlite3_busy_handler().  ^The second argument to
2279** the busy handler callback is the number of times that the busy handler has
2280** been invoked for this locking event.  ^If the
2281** busy callback returns 0, then no additional attempts are made to
2282** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned.
2283** ^If the callback returns non-zero, then another attempt
2284** is made to open the database for reading and the cycle repeats.
2285**
2286** The presence of a busy handler does not guarantee that it will be invoked
2287** when there is lock contention. ^If SQLite determines that invoking the busy
2288** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
2289** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler.
2290** Consider a scenario where one process is holding a read lock that
2291** it is trying to promote to a reserved lock and
2292** a second process is holding a reserved lock that it is trying
2293** to promote to an exclusive lock.  The first process cannot proceed
2294** because it is blocked by the second and the second process cannot
2295** proceed because it is blocked by the first.  If both processes
2296** invoke the busy handlers, neither will make any progress.  Therefore,
2297** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
2298** will induce the first process to release its read lock and allow
2299** the second process to proceed.
2300**
2301** ^The default busy callback is NULL.
2302**
2303** ^The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED]
2304** when SQLite is in the middle of a large transaction where all the
2305** changes will not fit into the in-memory cache.  SQLite will
2306** already hold a RESERVED lock on the database file, but it needs
2307** to promote this lock to EXCLUSIVE so that it can spill cache
2308** pages into the database file without harm to concurrent
2309** readers.  ^If it is unable to promote the lock, then the in-memory
2310** cache will be left in an inconsistent state and so the error
2311** code is promoted from the relatively benign [SQLITE_BUSY] to
2312** the more severe [SQLITE_IOERR_BLOCKED].  ^This error code promotion
2313** forces an automatic rollback of the changes.  See the
2314** <a href="/cvstrac/wiki?p=CorruptionFollowingBusyError">
2315** CorruptionFollowingBusyError</a> wiki page for a discussion of why
2316** this is important.
2317**
2318** ^(There can only be a single busy handler defined for each
2319** [database connection].  Setting a new busy handler clears any
2320** previously set handler.)^  ^Note that calling [sqlite3_busy_timeout()]
2321** will also set or clear the busy handler.
2322**
2323** The busy callback should not take any actions which modify the
2324** database connection that invoked the busy handler.  Any such actions
2325** result in undefined behavior.
2326**
2327** A busy handler must not close the database connection
2328** or [prepared statement] that invoked the busy handler.
2329*/
2330SQLITE_API int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
2331
2332/*
2333** CAPI3REF: Set A Busy Timeout
2334**
2335** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
2336** for a specified amount of time when a table is locked.  ^The handler
2337** will sleep multiple times until at least "ms" milliseconds of sleeping
2338** have accumulated.  ^After at least "ms" milliseconds of sleeping,
2339** the handler returns 0 which causes [sqlite3_step()] to return
2340** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED].
2341**
2342** ^Calling this routine with an argument less than or equal to zero
2343** turns off all busy handlers.
2344**
2345** ^(There can only be a single busy handler for a particular
2346** [database connection] any any given moment.  If another busy handler
2347** was defined  (using [sqlite3_busy_handler()]) prior to calling
2348** this routine, that other busy handler is cleared.)^
2349*/
2350SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
2351
2352/*
2353** CAPI3REF: Convenience Routines For Running Queries
2354**
2355** This is a legacy interface that is preserved for backwards compatibility.
2356** Use of this interface is not recommended.
2357**
2358** Definition: A <b>result table</b> is memory data structure created by the
2359** [sqlite3_get_table()] interface.  A result table records the
2360** complete query results from one or more queries.
2361**
2362** The table conceptually has a number of rows and columns.  But
2363** these numbers are not part of the result table itself.  These
2364** numbers are obtained separately.  Let N be the number of rows
2365** and M be the number of columns.
2366**
2367** A result table is an array of pointers to zero-terminated UTF-8 strings.
2368** There are (N+1)*M elements in the array.  The first M pointers point
2369** to zero-terminated strings that  contain the names of the columns.
2370** The remaining entries all point to query results.  NULL values result
2371** in NULL pointers.  All other values are in their UTF-8 zero-terminated
2372** string representation as returned by [sqlite3_column_text()].
2373**
2374** A result table might consist of one or more memory allocations.
2375** It is not safe to pass a result table directly to [sqlite3_free()].
2376** A result table should be deallocated using [sqlite3_free_table()].
2377**
2378** ^(As an example of the result table format, suppose a query result
2379** is as follows:
2380**
2381** <blockquote><pre>
2382**        Name        | Age
2383**        -----------------------
2384**        Alice       | 43
2385**        Bob         | 28
2386**        Cindy       | 21
2387** </pre></blockquote>
2388**
2389** There are two column (M==2) and three rows (N==3).  Thus the
2390** result table has 8 entries.  Suppose the result table is stored
2391** in an array names azResult.  Then azResult holds this content:
2392**
2393** <blockquote><pre>
2394**        azResult&#91;0] = "Name";
2395**        azResult&#91;1] = "Age";
2396**        azResult&#91;2] = "Alice";
2397**        azResult&#91;3] = "43";
2398**        azResult&#91;4] = "Bob";
2399**        azResult&#91;5] = "28";
2400**        azResult&#91;6] = "Cindy";
2401**        azResult&#91;7] = "21";
2402** </pre></blockquote>)^
2403**
2404** ^The sqlite3_get_table() function evaluates one or more
2405** semicolon-separated SQL statements in the zero-terminated UTF-8
2406** string of its 2nd parameter and returns a result table to the
2407** pointer given in its 3rd parameter.
2408**
2409** After the application has finished with the result from sqlite3_get_table(),
2410** it must pass the result table pointer to sqlite3_free_table() in order to
2411** release the memory that was malloced.  Because of the way the
2412** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
2413** function must not try to call [sqlite3_free()] directly.  Only
2414** [sqlite3_free_table()] is able to release the memory properly and safely.
2415**
2416** The sqlite3_get_table() interface is implemented as a wrapper around
2417** [sqlite3_exec()].  The sqlite3_get_table() routine does not have access
2418** to any internal data structures of SQLite.  It uses only the public
2419** interface defined here.  As a consequence, errors that occur in the
2420** wrapper layer outside of the internal [sqlite3_exec()] call are not
2421** reflected in subsequent calls to [sqlite3_errcode()] or
2422** [sqlite3_errmsg()].
2423*/
2424SQLITE_API int sqlite3_get_table(
2425  sqlite3 *db,          /* An open database */
2426  const char *zSql,     /* SQL to be evaluated */
2427  char ***pazResult,    /* Results of the query */
2428  int *pnRow,           /* Number of result rows written here */
2429  int *pnColumn,        /* Number of result columns written here */
2430  char **pzErrmsg       /* Error msg written here */
2431);
2432SQLITE_API void sqlite3_free_table(char **result);
2433
2434/*
2435** CAPI3REF: Formatted String Printing Functions
2436**
2437** These routines are work-alikes of the "printf()" family of functions
2438** from the standard C library.
2439**
2440** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
2441** results into memory obtained from [sqlite3_malloc()].
2442** The strings returned by these two routines should be
2443** released by [sqlite3_free()].  ^Both routines return a
2444** NULL pointer if [sqlite3_malloc()] is unable to allocate enough
2445** memory to hold the resulting string.
2446**
2447** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from
2448** the standard C library.  The result is written into the
2449** buffer supplied as the second parameter whose size is given by
2450** the first parameter. Note that the order of the
2451** first two parameters is reversed from snprintf().)^  This is an
2452** historical accident that cannot be fixed without breaking
2453** backwards compatibility.  ^(Note also that sqlite3_snprintf()
2454** returns a pointer to its buffer instead of the number of
2455** characters actually written into the buffer.)^  We admit that
2456** the number of characters written would be a more useful return
2457** value but we cannot change the implementation of sqlite3_snprintf()
2458** now without breaking compatibility.
2459**
2460** ^As long as the buffer size is greater than zero, sqlite3_snprintf()
2461** guarantees that the buffer is always zero-terminated.  ^The first
2462** parameter "n" is the total size of the buffer, including space for
2463** the zero terminator.  So the longest string that can be completely
2464** written will be n-1 characters.
2465**
2466** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
2467**
2468** These routines all implement some additional formatting
2469** options that are useful for constructing SQL statements.
2470** All of the usual printf() formatting options apply.  In addition, there
2471** is are "%q", "%Q", and "%z" options.
2472**
2473** ^(The %q option works like %s in that it substitutes a null-terminated
2474** string from the argument list.  But %q also doubles every '\'' character.
2475** %q is designed for use inside a string literal.)^  By doubling each '\''
2476** character it escapes that character and allows it to be inserted into
2477** the string.
2478**
2479** For example, assume the string variable zText contains text as follows:
2480**
2481** <blockquote><pre>
2482**  char *zText = "It's a happy day!";
2483** </pre></blockquote>
2484**
2485** One can use this text in an SQL statement as follows:
2486**
2487** <blockquote><pre>
2488**  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);
2489**  sqlite3_exec(db, zSQL, 0, 0, 0);
2490**  sqlite3_free(zSQL);
2491** </pre></blockquote>
2492**
2493** Because the %q format string is used, the '\'' character in zText
2494** is escaped and the SQL generated is as follows:
2495**
2496** <blockquote><pre>
2497**  INSERT INTO table1 VALUES('It''s a happy day!')
2498** </pre></blockquote>
2499**
2500** This is correct.  Had we used %s instead of %q, the generated SQL
2501** would have looked like this:
2502**
2503** <blockquote><pre>
2504**  INSERT INTO table1 VALUES('It's a happy day!');
2505** </pre></blockquote>
2506**
2507** This second example is an SQL syntax error.  As a general rule you should
2508** always use %q instead of %s when inserting text into a string literal.
2509**
2510** ^(The %Q option works like %q except it also adds single quotes around
2511** the outside of the total string.  Additionally, if the parameter in the
2512** argument list is a NULL pointer, %Q substitutes the text "NULL" (without
2513** single quotes).)^  So, for example, one could say:
2514**
2515** <blockquote><pre>
2516**  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
2517**  sqlite3_exec(db, zSQL, 0, 0, 0);
2518**  sqlite3_free(zSQL);
2519** </pre></blockquote>
2520**
2521** The code above will render a correct SQL statement in the zSQL
2522** variable even if the zText variable is a NULL pointer.
2523**
2524** ^(The "%z" formatting option works like "%s" but with the
2525** addition that after the string has been read and copied into
2526** the result, [sqlite3_free()] is called on the input string.)^
2527*/
2528SQLITE_API char *sqlite3_mprintf(const char*,...);
2529SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
2530SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
2531SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
2532
2533/*
2534** CAPI3REF: Memory Allocation Subsystem
2535**
2536** The SQLite core uses these three routines for all of its own
2537** internal memory allocation needs. "Core" in the previous sentence
2538** does not include operating-system specific VFS implementation.  The
2539** Windows VFS uses native malloc() and free() for some operations.
2540**
2541** ^The sqlite3_malloc() routine returns a pointer to a block
2542** of memory at least N bytes in length, where N is the parameter.
2543** ^If sqlite3_malloc() is unable to obtain sufficient free
2544** memory, it returns a NULL pointer.  ^If the parameter N to
2545** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
2546** a NULL pointer.
2547**
2548** ^Calling sqlite3_free() with a pointer previously returned
2549** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
2550** that it might be reused.  ^The sqlite3_free() routine is
2551** a no-op if is called with a NULL pointer.  Passing a NULL pointer
2552** to sqlite3_free() is harmless.  After being freed, memory
2553** should neither be read nor written.  Even reading previously freed
2554** memory might result in a segmentation fault or other severe error.
2555** Memory corruption, a segmentation fault, or other severe error
2556** might result if sqlite3_free() is called with a non-NULL pointer that
2557** was not obtained from sqlite3_malloc() or sqlite3_realloc().
2558**
2559** ^(The sqlite3_realloc() interface attempts to resize a
2560** prior memory allocation to be at least N bytes, where N is the
2561** second parameter.  The memory allocation to be resized is the first
2562** parameter.)^ ^ If the first parameter to sqlite3_realloc()
2563** is a NULL pointer then its behavior is identical to calling
2564** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc().
2565** ^If the second parameter to sqlite3_realloc() is zero or
2566** negative then the behavior is exactly the same as calling
2567** sqlite3_free(P) where P is the first parameter to sqlite3_realloc().
2568** ^sqlite3_realloc() returns a pointer to a memory allocation
2569** of at least N bytes in size or NULL if sufficient memory is unavailable.
2570** ^If M is the size of the prior allocation, then min(N,M) bytes
2571** of the prior allocation are copied into the beginning of buffer returned
2572** by sqlite3_realloc() and the prior allocation is freed.
2573** ^If sqlite3_realloc() returns NULL, then the prior allocation
2574** is not freed.
2575**
2576** ^The memory returned by sqlite3_malloc() and sqlite3_realloc()
2577** is always aligned to at least an 8 byte boundary, or to a
2578** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
2579** option is used.
2580**
2581** In SQLite version 3.5.0 and 3.5.1, it was possible to define
2582** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
2583** implementation of these routines to be omitted.  That capability
2584** is no longer provided.  Only built-in memory allocators can be used.
2585**
2586** The Windows OS interface layer calls
2587** the system malloc() and free() directly when converting
2588** filenames between the UTF-8 encoding used by SQLite
2589** and whatever filename encoding is used by the particular Windows
2590** installation.  Memory allocation errors are detected, but
2591** they are reported back as [SQLITE_CANTOPEN] or
2592** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
2593**
2594** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
2595** must be either NULL or else pointers obtained from a prior
2596** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
2597** not yet been released.
2598**
2599** The application must not read or write any part of
2600** a block of memory after it has been released using
2601** [sqlite3_free()] or [sqlite3_realloc()].
2602*/
2603SQLITE_API void *sqlite3_malloc(int);
2604SQLITE_API void *sqlite3_realloc(void*, int);
2605SQLITE_API void sqlite3_free(void*);
2606
2607/*
2608** CAPI3REF: Memory Allocator Statistics
2609**
2610** SQLite provides these two interfaces for reporting on the status
2611** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
2612** routines, which form the built-in memory allocation subsystem.
2613**
2614** ^The [sqlite3_memory_used()] routine returns the number of bytes
2615** of memory currently outstanding (malloced but not freed).
2616** ^The [sqlite3_memory_highwater()] routine returns the maximum
2617** value of [sqlite3_memory_used()] since the high-water mark
2618** was last reset.  ^The values returned by [sqlite3_memory_used()] and
2619** [sqlite3_memory_highwater()] include any overhead
2620** added by SQLite in its implementation of [sqlite3_malloc()],
2621** but not overhead added by the any underlying system library
2622** routines that [sqlite3_malloc()] may call.
2623**
2624** ^The memory high-water mark is reset to the current value of
2625** [sqlite3_memory_used()] if and only if the parameter to
2626** [sqlite3_memory_highwater()] is true.  ^The value returned
2627** by [sqlite3_memory_highwater(1)] is the high-water mark
2628** prior to the reset.
2629*/
2630SQLITE_API sqlite3_int64 sqlite3_memory_used(void);
2631SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
2632
2633/*
2634** CAPI3REF: Pseudo-Random Number Generator
2635**
2636** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
2637** select random [ROWID | ROWIDs] when inserting new records into a table that
2638** already uses the largest possible [ROWID].  The PRNG is also used for
2639** the build-in random() and randomblob() SQL functions.  This interface allows
2640** applications to access the same PRNG for other purposes.
2641**
2642** ^A call to this routine stores N bytes of randomness into buffer P.
2643**
2644** ^The first time this routine is invoked (either internally or by
2645** the application) the PRNG is seeded using randomness obtained
2646** from the xRandomness method of the default [sqlite3_vfs] object.
2647** ^On all subsequent invocations, the pseudo-randomness is generated
2648** internally and without recourse to the [sqlite3_vfs] xRandomness
2649** method.
2650*/
2651SQLITE_API void sqlite3_randomness(int N, void *P);
2652
2653/*
2654** CAPI3REF: Compile-Time Authorization Callbacks
2655**
2656** ^This routine registers an authorizer callback with a particular
2657** [database connection], supplied in the first argument.
2658** ^The authorizer callback is invoked as SQL statements are being compiled
2659** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
2660** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()].  ^At various
2661** points during the compilation process, as logic is being created
2662** to perform various actions, the authorizer callback is invoked to
2663** see if those actions are allowed.  ^The authorizer callback should
2664** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the
2665** specific action but allow the SQL statement to continue to be
2666** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
2667** rejected with an error.  ^If the authorizer callback returns
2668** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]
2669** then the [sqlite3_prepare_v2()] or equivalent call that triggered
2670** the authorizer will fail with an error message.
2671**
2672** When the callback returns [SQLITE_OK], that means the operation
2673** requested is ok.  ^When the callback returns [SQLITE_DENY], the
2674** [sqlite3_prepare_v2()] or equivalent call that triggered the
2675** authorizer will fail with an error message explaining that
2676** access is denied.
2677**
2678** ^The first parameter to the authorizer callback is a copy of the third
2679** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
2680** to the callback is an integer [SQLITE_COPY | action code] that specifies
2681** the particular action to be authorized. ^The third through sixth parameters
2682** to the callback are zero-terminated strings that contain additional
2683** details about the action to be authorized.
2684**
2685** ^If the action code is [SQLITE_READ]
2686** and the callback returns [SQLITE_IGNORE] then the
2687** [prepared statement] statement is constructed to substitute
2688** a NULL value in place of the table column that would have
2689** been read if [SQLITE_OK] had been returned.  The [SQLITE_IGNORE]
2690** return can be used to deny an untrusted user access to individual
2691** columns of a table.
2692** ^If the action code is [SQLITE_DELETE] and the callback returns
2693** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
2694** [truncate optimization] is disabled and all rows are deleted individually.
2695**
2696** An authorizer is used when [sqlite3_prepare | preparing]
2697** SQL statements from an untrusted source, to ensure that the SQL statements
2698** do not try to access data they are not allowed to see, or that they do not
2699** try to execute malicious statements that damage the database.  For
2700** example, an application may allow a user to enter arbitrary
2701** SQL queries for evaluation by a database.  But the application does
2702** not want the user to be able to make arbitrary changes to the
2703** database.  An authorizer could then be put in place while the
2704** user-entered SQL is being [sqlite3_prepare | prepared] that
2705** disallows everything except [SELECT] statements.
2706**
2707** Applications that need to process SQL from untrusted sources
2708** might also consider lowering resource limits using [sqlite3_limit()]
2709** and limiting database size using the [max_page_count] [PRAGMA]
2710** in addition to using an authorizer.
2711**
2712** ^(Only a single authorizer can be in place on a database connection
2713** at a time.  Each call to sqlite3_set_authorizer overrides the
2714** previous call.)^  ^Disable the authorizer by installing a NULL callback.
2715** The authorizer is disabled by default.
2716**
2717** The authorizer callback must not do anything that will modify
2718** the database connection that invoked the authorizer callback.
2719** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
2720** database connections for the meaning of "modify" in this paragraph.
2721**
2722** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the
2723** statement might be re-prepared during [sqlite3_step()] due to a
2724** schema change.  Hence, the application should ensure that the
2725** correct authorizer callback remains in place during the [sqlite3_step()].
2726**
2727** ^Note that the authorizer callback is invoked only during
2728** [sqlite3_prepare()] or its variants.  Authorization is not
2729** performed during statement evaluation in [sqlite3_step()], unless
2730** as stated in the previous paragraph, sqlite3_step() invokes
2731** sqlite3_prepare_v2() to reprepare a statement after a schema change.
2732*/
2733SQLITE_API int sqlite3_set_authorizer(
2734  sqlite3*,
2735  int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
2736  void *pUserData
2737);
2738
2739/*
2740** CAPI3REF: Authorizer Return Codes
2741**
2742** The [sqlite3_set_authorizer | authorizer callback function] must
2743** return either [SQLITE_OK] or one of these two constants in order
2744** to signal SQLite whether or not the action is permitted.  See the
2745** [sqlite3_set_authorizer | authorizer documentation] for additional
2746** information.
2747*/
2748#define SQLITE_DENY   1   /* Abort the SQL statement with an error */
2749#define SQLITE_IGNORE 2   /* Don't allow access, but don't generate an error */
2750
2751/*
2752** CAPI3REF: Authorizer Action Codes
2753**
2754** The [sqlite3_set_authorizer()] interface registers a callback function
2755** that is invoked to authorize certain SQL statement actions.  The
2756** second parameter to the callback is an integer code that specifies
2757** what action is being authorized.  These are the integer action codes that
2758** the authorizer callback may be passed.
2759**
2760** These action code values signify what kind of operation is to be
2761** authorized.  The 3rd and 4th parameters to the authorization
2762** callback function will be parameters or NULL depending on which of these
2763** codes is used as the second parameter.  ^(The 5th parameter to the
2764** authorizer callback is the name of the database ("main", "temp",
2765** etc.) if applicable.)^  ^The 6th parameter to the authorizer callback
2766** is the name of the inner-most trigger or view that is responsible for
2767** the access attempt or NULL if this access attempt is directly from
2768** top-level SQL code.
2769*/
2770/******************************************* 3rd ************ 4th ***********/
2771#define SQLITE_CREATE_INDEX          1   /* Index Name      Table Name      */
2772#define SQLITE_CREATE_TABLE          2   /* Table Name      NULL            */
2773#define SQLITE_CREATE_TEMP_INDEX     3   /* Index Name      Table Name      */
2774#define SQLITE_CREATE_TEMP_TABLE     4   /* Table Name      NULL            */
2775#define SQLITE_CREATE_TEMP_TRIGGER   5   /* Trigger Name    Table Name      */
2776#define SQLITE_CREATE_TEMP_VIEW      6   /* View Name       NULL            */
2777#define SQLITE_CREATE_TRIGGER        7   /* Trigger Name    Table Name      */
2778#define SQLITE_CREATE_VIEW           8   /* View Name       NULL            */
2779#define SQLITE_DELETE                9   /* Table Name      NULL            */
2780#define SQLITE_DROP_INDEX           10   /* Index Name      Table Name      */
2781#define SQLITE_DROP_TABLE           11   /* Table Name      NULL            */
2782#define SQLITE_DROP_TEMP_INDEX      12   /* Index Name      Table Name      */
2783#define SQLITE_DROP_TEMP_TABLE      13   /* Table Name      NULL            */
2784#define SQLITE_DROP_TEMP_TRIGGER    14   /* Trigger Name    Table Name      */
2785#define SQLITE_DROP_TEMP_VIEW       15   /* View Name       NULL            */
2786#define SQLITE_DROP_TRIGGER         16   /* Trigger Name    Table Name      */
2787#define SQLITE_DROP_VIEW            17   /* View Name       NULL            */
2788#define SQLITE_INSERT               18   /* Table Name      NULL            */
2789#define SQLITE_PRAGMA               19   /* Pragma Name     1st arg or NULL */
2790#define SQLITE_READ                 20   /* Table Name      Column Name     */
2791#define SQLITE_SELECT               21   /* NULL            NULL            */
2792#define SQLITE_TRANSACTION          22   /* Operation       NULL            */
2793#define SQLITE_UPDATE               23   /* Table Name      Column Name     */
2794#define SQLITE_ATTACH               24   /* Filename        NULL            */
2795#define SQLITE_DETACH               25   /* Database Name   NULL            */
2796#define SQLITE_ALTER_TABLE          26   /* Database Name   Table Name      */
2797#define SQLITE_REINDEX              27   /* Index Name      NULL            */
2798#define SQLITE_ANALYZE              28   /* Table Name      NULL            */
2799#define SQLITE_CREATE_VTABLE        29   /* Table Name      Module Name     */
2800#define SQLITE_DROP_VTABLE          30   /* Table Name      Module Name     */
2801#define SQLITE_FUNCTION             31   /* NULL            Function Name   */
2802#define SQLITE_SAVEPOINT            32   /* Operation       Savepoint Name  */
2803#define SQLITE_COPY                  0   /* No longer used */
2804
2805/*
2806** CAPI3REF: Tracing And Profiling Functions
2807**
2808** These routines register callback functions that can be used for
2809** tracing and profiling the execution of SQL statements.
2810**
2811** ^The callback function registered by sqlite3_trace() is invoked at
2812** various times when an SQL statement is being run by [sqlite3_step()].
2813** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the
2814** SQL statement text as the statement first begins executing.
2815** ^(Additional sqlite3_trace() callbacks might occur
2816** as each triggered subprogram is entered.  The callbacks for triggers
2817** contain a UTF-8 SQL comment that identifies the trigger.)^
2818**
2819** ^The callback function registered by sqlite3_profile() is invoked
2820** as each SQL statement finishes.  ^The profile callback contains
2821** the original statement text and an estimate of wall-clock time
2822** of how long that statement took to run.  ^The profile callback
2823** time is in units of nanoseconds, however the current implementation
2824** is only capable of millisecond resolution so the six least significant
2825** digits in the time are meaningless.  Future versions of SQLite
2826** might provide greater resolution on the profiler callback.  The
2827** sqlite3_profile() function is considered experimental and is
2828** subject to change in future versions of SQLite.
2829*/
2830SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
2831SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
2832   void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2833
2834/*
2835** CAPI3REF: Query Progress Callbacks
2836**
2837** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
2838** function X to be invoked periodically during long running calls to
2839** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
2840** database connection D.  An example use for this
2841** interface is to keep a GUI updated during a large query.
2842**
2843** ^The parameter P is passed through as the only parameter to the
2844** callback function X.  ^The parameter N is the number of
2845** [virtual machine instructions] that are evaluated between successive
2846** invocations of the callback X.
2847**
2848** ^Only a single progress handler may be defined at one time per
2849** [database connection]; setting a new progress handler cancels the
2850** old one.  ^Setting parameter X to NULL disables the progress handler.
2851** ^The progress handler is also disabled by setting N to a value less
2852** than 1.
2853**
2854** ^If the progress callback returns non-zero, the operation is
2855** interrupted.  This feature can be used to implement a
2856** "Cancel" button on a GUI progress dialog box.
2857**
2858** The progress handler callback must not do anything that will modify
2859** the database connection that invoked the progress handler.
2860** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
2861** database connections for the meaning of "modify" in this paragraph.
2862**
2863*/
2864SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2865
2866/*
2867** CAPI3REF: Opening A New Database Connection
2868**
2869** ^These routines open an SQLite database file whose name is given by the
2870** filename argument. ^The filename argument is interpreted as UTF-8 for
2871** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2872** order for sqlite3_open16(). ^(A [database connection] handle is usually
2873** returned in *ppDb, even if an error occurs.  The only exception is that
2874** if SQLite is unable to allocate memory to hold the [sqlite3] object,
2875** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]
2876** object.)^ ^(If the database is opened (and/or created) successfully, then
2877** [SQLITE_OK] is returned.  Otherwise an [error code] is returned.)^ ^The
2878** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
2879** an English language description of the error following a failure of any
2880** of the sqlite3_open() routines.
2881**
2882** ^The default encoding for the database will be UTF-8 if
2883** sqlite3_open() or sqlite3_open_v2() is called and
2884** UTF-16 in the native byte order if sqlite3_open16() is used.
2885**
2886** Whether or not an error occurs when it is opened, resources
2887** associated with the [database connection] handle should be released by
2888** passing it to [sqlite3_close()] when it is no longer required.
2889**
2890** The sqlite3_open_v2() interface works like sqlite3_open()
2891** except that it accepts two additional parameters for additional control
2892** over the new database connection.  ^(The flags parameter to
2893** sqlite3_open_v2() can take one of
2894** the following three values, optionally combined with the
2895** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
2896** and/or [SQLITE_OPEN_PRIVATECACHE] flags:)^
2897**
2898** <dl>
2899** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
2900** <dd>The database is opened in read-only mode.  If the database does not
2901** already exist, an error is returned.</dd>)^
2902**
2903** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
2904** <dd>The database is opened for reading and writing if possible, or reading
2905** only if the file is write protected by the operating system.  In either
2906** case the database must already exist, otherwise an error is returned.</dd>)^
2907**
2908** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
2909** <dd>The database is opened for reading and writing, and is created if
2910** it does not already exist. This is the behavior that is always used for
2911** sqlite3_open() and sqlite3_open16().</dd>)^
2912** </dl>
2913**
2914** If the 3rd parameter to sqlite3_open_v2() is not one of the
2915** combinations shown above or one of the combinations shown above combined
2916** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX],
2917** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_PRIVATECACHE] flags,
2918** then the behavior is undefined.
2919**
2920** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
2921** opens in the multi-thread [threading mode] as long as the single-thread
2922** mode has not been set at compile-time or start-time.  ^If the
2923** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens
2924** in the serialized [threading mode] unless single-thread was
2925** previously selected at compile-time or start-time.
2926** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be
2927** eligible to use [shared cache mode], regardless of whether or not shared
2928** cache is enabled using [sqlite3_enable_shared_cache()].  ^The
2929** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not
2930** participate in [shared cache mode] even if it is enabled.
2931**
2932** ^If the filename is ":memory:", then a private, temporary in-memory database
2933** is created for the connection.  ^This in-memory database will vanish when
2934** the database connection is closed.  Future versions of SQLite might
2935** make use of additional special filenames that begin with the ":" character.
2936** It is recommended that when a database filename actually does begin with
2937** a ":" character you should prefix the filename with a pathname such as
2938** "./" to avoid ambiguity.
2939**
2940** ^If the filename is an empty string, then a private, temporary
2941** on-disk database will be created.  ^This private database will be
2942** automatically deleted as soon as the database connection is closed.
2943**
2944** ^The fourth parameter to sqlite3_open_v2() is the name of the
2945** [sqlite3_vfs] object that defines the operating system interface that
2946** the new database connection should use.  ^If the fourth parameter is
2947** a NULL pointer then the default [sqlite3_vfs] object is used.
2948**
2949** <b>Note to Windows users:</b>  The encoding used for the filename argument
2950** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
2951** codepage is currently defined.  Filenames containing international
2952** characters must be converted to UTF-8 prior to passing them into
2953** sqlite3_open() or sqlite3_open_v2().
2954*/
2955SQLITE_API int sqlite3_open(
2956  const char *filename,   /* Database filename (UTF-8) */
2957  sqlite3 **ppDb          /* OUT: SQLite db handle */
2958);
2959SQLITE_API int sqlite3_open16(
2960  const void *filename,   /* Database filename (UTF-16) */
2961  sqlite3 **ppDb          /* OUT: SQLite db handle */
2962);
2963SQLITE_API int sqlite3_open_v2(
2964  const char *filename,   /* Database filename (UTF-8) */
2965  sqlite3 **ppDb,         /* OUT: SQLite db handle */
2966  int flags,              /* Flags */
2967  const char *zVfs        /* Name of VFS module to use */
2968);
2969
2970/*
2971** CAPI3REF: Error Codes And Messages
2972**
2973** ^The sqlite3_errcode() interface returns the numeric [result code] or
2974** [extended result code] for the most recent failed sqlite3_* API call
2975** associated with a [database connection]. If a prior API call failed
2976** but the most recent API call succeeded, the return value from
2977** sqlite3_errcode() is undefined.  ^The sqlite3_extended_errcode()
2978** interface is the same except that it always returns the
2979** [extended result code] even when extended result codes are
2980** disabled.
2981**
2982** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
2983** text that describes the error, as either UTF-8 or UTF-16 respectively.
2984** ^(Memory to hold the error message string is managed internally.
2985** The application does not need to worry about freeing the result.
2986** However, the error string might be overwritten or deallocated by
2987** subsequent calls to other SQLite interface functions.)^
2988**
2989** When the serialized [threading mode] is in use, it might be the
2990** case that a second error occurs on a separate thread in between
2991** the time of the first error and the call to these interfaces.
2992** When that happens, the second error will be reported since these
2993** interfaces always report the most recent result.  To avoid
2994** this, each thread can obtain exclusive use of the [database connection] D
2995** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning
2996** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after
2997** all calls to the interfaces listed here are completed.
2998**
2999** If an interface fails with SQLITE_MISUSE, that means the interface
3000** was invoked incorrectly by the application.  In that case, the
3001** error code and message may or may not be set.
3002*/
3003SQLITE_API int sqlite3_errcode(sqlite3 *db);
3004SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
3005SQLITE_API const char *sqlite3_errmsg(sqlite3*);
3006SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
3007
3008/*
3009** CAPI3REF: SQL Statement Object
3010** KEYWORDS: {prepared statement} {prepared statements}
3011**
3012** An instance of this object represents a single SQL statement.
3013** This object is variously known as a "prepared statement" or a
3014** "compiled SQL statement" or simply as a "statement".
3015**
3016** The life of a statement object goes something like this:
3017**
3018** <ol>
3019** <li> Create the object using [sqlite3_prepare_v2()] or a related
3020**      function.
3021** <li> Bind values to [host parameters] using the sqlite3_bind_*()
3022**      interfaces.
3023** <li> Run the SQL by calling [sqlite3_step()] one or more times.
3024** <li> Reset the statement using [sqlite3_reset()] then go back
3025**      to step 2.  Do this zero or more times.
3026** <li> Destroy the object using [sqlite3_finalize()].
3027** </ol>
3028**
3029** Refer to documentation on individual methods above for additional
3030** information.
3031*/
3032typedef struct sqlite3_stmt sqlite3_stmt;
3033
3034/*
3035** CAPI3REF: Run-time Limits
3036**
3037** ^(This interface allows the size of various constructs to be limited
3038** on a connection by connection basis.  The first parameter is the
3039** [database connection] whose limit is to be set or queried.  The
3040** second parameter is one of the [limit categories] that define a
3041** class of constructs to be size limited.  The third parameter is the
3042** new limit for that construct.)^
3043**
3044** ^If the new limit is a negative number, the limit is unchanged.
3045** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a
3046** [limits | hard upper bound]
3047** set at compile-time by a C preprocessor macro called
3048** [limits | SQLITE_MAX_<i>NAME</i>].
3049** (The "_LIMIT_" in the name is changed to "_MAX_".))^
3050** ^Attempts to increase a limit above its hard upper bound are
3051** silently truncated to the hard upper bound.
3052**
3053** ^Regardless of whether or not the limit was changed, the
3054** [sqlite3_limit()] interface returns the prior value of the limit.
3055** ^Hence, to find the current value of a limit without changing it,
3056** simply invoke this interface with the third parameter set to -1.
3057**
3058** Run-time limits are intended for use in applications that manage
3059** both their own internal database and also databases that are controlled
3060** by untrusted external sources.  An example application might be a
3061** web browser that has its own databases for storing history and
3062** separate databases controlled by JavaScript applications downloaded
3063** off the Internet.  The internal databases can be given the
3064** large, default limits.  Databases managed by external sources can
3065** be given much smaller limits designed to prevent a denial of service
3066** attack.  Developers might also want to use the [sqlite3_set_authorizer()]
3067** interface to further control untrusted SQL.  The size of the database
3068** created by an untrusted script can be contained using the
3069** [max_page_count] [PRAGMA].
3070**
3071** New run-time limit categories may be added in future releases.
3072*/
3073SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
3074
3075/*
3076** CAPI3REF: Run-Time Limit Categories
3077** KEYWORDS: {limit category} {*limit categories}
3078**
3079** These constants define various performance limits
3080** that can be lowered at run-time using [sqlite3_limit()].
3081** The synopsis of the meanings of the various limits is shown below.
3082** Additional information is available at [limits | Limits in SQLite].
3083**
3084** <dl>
3085** ^(<dt>SQLITE_LIMIT_LENGTH</dt>
3086** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
3087**
3088** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
3089** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
3090**
3091** ^(<dt>SQLITE_LIMIT_COLUMN</dt>
3092** <dd>The maximum number of columns in a table definition or in the
3093** result set of a [SELECT] or the maximum number of columns in an index
3094** or in an ORDER BY or GROUP BY clause.</dd>)^
3095**
3096** ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
3097** <dd>The maximum depth of the parse tree on any expression.</dd>)^
3098**
3099** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
3100** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
3101**
3102** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
3103** <dd>The maximum number of instructions in a virtual machine program
3104** used to implement an SQL statement.  This limit is not currently
3105** enforced, though that might be added in some future release of
3106** SQLite.</dd>)^
3107**
3108** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
3109** <dd>The maximum number of arguments on a function.</dd>)^
3110**
3111** ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
3112** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
3113**
3114** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
3115** <dd>The maximum length of the pattern argument to the [LIKE] or
3116** [GLOB] operators.</dd>)^
3117**
3118** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
3119** <dd>The maximum index number of any [parameter] in an SQL statement.)^
3120**
3121** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
3122** <dd>The maximum depth of recursion for triggers.</dd>)^
3123** </dl>
3124*/
3125#define SQLITE_LIMIT_LENGTH                    0
3126#define SQLITE_LIMIT_SQL_LENGTH                1
3127#define SQLITE_LIMIT_COLUMN                    2
3128#define SQLITE_LIMIT_EXPR_DEPTH                3
3129#define SQLITE_LIMIT_COMPOUND_SELECT           4
3130#define SQLITE_LIMIT_VDBE_OP                   5
3131#define SQLITE_LIMIT_FUNCTION_ARG              6
3132#define SQLITE_LIMIT_ATTACHED                  7
3133#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH       8
3134#define SQLITE_LIMIT_VARIABLE_NUMBER           9
3135#define SQLITE_LIMIT_TRIGGER_DEPTH            10
3136
3137/*
3138** CAPI3REF: Compiling An SQL Statement
3139** KEYWORDS: {SQL statement compiler}
3140**
3141** To execute an SQL query, it must first be compiled into a byte-code
3142** program using one of these routines.
3143**
3144** The first argument, "db", is a [database connection] obtained from a
3145** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or
3146** [sqlite3_open16()].  The database connection must not have been closed.
3147**
3148** The second argument, "zSql", is the statement to be compiled, encoded
3149** as either UTF-8 or UTF-16.  The sqlite3_prepare() and sqlite3_prepare_v2()
3150** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2()
3151** use UTF-16.
3152**
3153** ^If the nByte argument is less than zero, then zSql is read up to the
3154** first zero terminator. ^If nByte is non-negative, then it is the maximum
3155** number of  bytes read from zSql.  ^When nByte is non-negative, the
3156** zSql string ends at either the first '\000' or '\u0000' character or
3157** the nByte-th byte, whichever comes first. If the caller knows
3158** that the supplied string is nul-terminated, then there is a small
3159** performance advantage to be gained by passing an nByte parameter that
3160** is equal to the number of bytes in the input string <i>including</i>
3161** the nul-terminator bytes.
3162**
3163** ^If pzTail is not NULL then *pzTail is made to point to the first byte
3164** past the end of the first SQL statement in zSql.  These routines only
3165** compile the first statement in zSql, so *pzTail is left pointing to
3166** what remains uncompiled.
3167**
3168** ^*ppStmt is left pointing to a compiled [prepared statement] that can be
3169** executed using [sqlite3_step()].  ^If there is an error, *ppStmt is set
3170** to NULL.  ^If the input text contains no SQL (if the input is an empty
3171** string or a comment) then *ppStmt is set to NULL.
3172** The calling procedure is responsible for deleting the compiled
3173** SQL statement using [sqlite3_finalize()] after it has finished with it.
3174** ppStmt may not be NULL.
3175**
3176** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK];
3177** otherwise an [error code] is returned.
3178**
3179** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are
3180** recommended for all new programs. The two older interfaces are retained
3181** for backwards compatibility, but their use is discouraged.
3182** ^In the "v2" interfaces, the prepared statement
3183** that is returned (the [sqlite3_stmt] object) contains a copy of the
3184** original SQL text. This causes the [sqlite3_step()] interface to
3185** behave differently in three ways:
3186**
3187** <ol>
3188** <li>
3189** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
3190** always used to do, [sqlite3_step()] will automatically recompile the SQL
3191** statement and try to run it again.
3192** </li>
3193**
3194** <li>
3195** ^When an error occurs, [sqlite3_step()] will return one of the detailed
3196** [error codes] or [extended error codes].  ^The legacy behavior was that
3197** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code
3198** and the application would have to make a second call to [sqlite3_reset()]
3199** in order to find the underlying cause of the problem. With the "v2" prepare
3200** interfaces, the underlying reason for the error is returned immediately.
3201** </li>
3202**
3203** <li>
3204** ^If the specific value bound to [parameter | host parameter] in the
3205** WHERE clause might influence the choice of query plan for a statement,
3206** then the statement will be automatically recompiled, as if there had been
3207** a schema change, on the first  [sqlite3_step()] call following any change
3208** to the [sqlite3_bind_text | bindings] of that [parameter].
3209** ^The specific value of WHERE-clause [parameter] might influence the
3210** choice of query plan if the parameter is the left-hand side of a [LIKE]
3211** or [GLOB] operator or if the parameter is compared to an indexed column
3212** and the [SQLITE_ENABLE_STAT2] compile-time option is enabled.
3213** the
3214** </li>
3215** </ol>
3216*/
3217SQLITE_API int sqlite3_prepare(
3218  sqlite3 *db,            /* Database handle */
3219  const char *zSql,       /* SQL statement, UTF-8 encoded */
3220  int nByte,              /* Maximum length of zSql in bytes. */
3221  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
3222  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
3223);
3224SQLITE_API int sqlite3_prepare_v2(
3225  sqlite3 *db,            /* Database handle */
3226  const char *zSql,       /* SQL statement, UTF-8 encoded */
3227  int nByte,              /* Maximum length of zSql in bytes. */
3228  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
3229  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
3230);
3231SQLITE_API int sqlite3_prepare16(
3232  sqlite3 *db,            /* Database handle */
3233  const void *zSql,       /* SQL statement, UTF-16 encoded */
3234  int nByte,              /* Maximum length of zSql in bytes. */
3235  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
3236  const void **pzTail     /* OUT: Pointer to unused portion of zSql */
3237);
3238SQLITE_API int sqlite3_prepare16_v2(
3239  sqlite3 *db,            /* Database handle */
3240  const void *zSql,       /* SQL statement, UTF-16 encoded */
3241  int nByte,              /* Maximum length of zSql in bytes. */
3242  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
3243  const void **pzTail     /* OUT: Pointer to unused portion of zSql */
3244);
3245
3246/*
3247** CAPI3REF: Retrieving Statement SQL
3248**
3249** ^This interface can be used to retrieve a saved copy of the original
3250** SQL text used to create a [prepared statement] if that statement was
3251** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
3252*/
3253SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
3254
3255/*
3256** CAPI3REF: Determine If An SQL Statement Writes The Database
3257**
3258** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3259** and only if the [prepared statement] X makes no direct changes to
3260** the content of the database file.
3261**
3262** Note that [application-defined SQL functions] or
3263** [virtual tables] might change the database indirectly as a side effect.
3264** ^(For example, if an application defines a function "eval()" that
3265** calls [sqlite3_exec()], then the following SQL statement would
3266** change the database file through side-effects:
3267**
3268** <blockquote><pre>
3269**    SELECT eval('DELETE FROM t1') FROM t2;
3270** </pre></blockquote>
3271**
3272** But because the [SELECT] statement does not change the database file
3273** directly, sqlite3_stmt_readonly() would still return true.)^
3274**
3275** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
3276** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
3277** since the statements themselves do not actually modify the database but
3278** rather they control the timing of when other statements modify the
3279** database.  ^The [ATTACH] and [DETACH] statements also cause
3280** sqlite3_stmt_readonly() to return true since, while those statements
3281** change the configuration of a database connection, they do not make
3282** changes to the content of the database files on disk.
3283*/
3284SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3285
3286/*
3287** CAPI3REF: Dynamically Typed Value Object
3288** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
3289**
3290** SQLite uses the sqlite3_value object to represent all values
3291** that can be stored in a database table. SQLite uses dynamic typing
3292** for the values it stores.  ^Values stored in sqlite3_value objects
3293** can be integers, floating point values, strings, BLOBs, or NULL.
3294**
3295** An sqlite3_value object may be either "protected" or "unprotected".
3296** Some interfaces require a protected sqlite3_value.  Other interfaces
3297** will accept either a protected or an unprotected sqlite3_value.
3298** Every interface that accepts sqlite3_value arguments specifies
3299** whether or not it requires a protected sqlite3_value.
3300**
3301** The terms "protected" and "unprotected" refer to whether or not
3302** a mutex is held.  An internal mutex is held for a protected
3303** sqlite3_value object but no mutex is held for an unprotected
3304** sqlite3_value object.  If SQLite is compiled to be single-threaded
3305** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
3306** or if SQLite is run in one of reduced mutex modes
3307** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
3308** then there is no distinction between protected and unprotected
3309** sqlite3_value objects and they can be used interchangeably.  However,
3310** for maximum code portability it is recommended that applications
3311** still make the distinction between protected and unprotected
3312** sqlite3_value objects even when not strictly required.
3313**
3314** ^The sqlite3_value objects that are passed as parameters into the
3315** implementation of [application-defined SQL functions] are protected.
3316** ^The sqlite3_value object returned by
3317** [sqlite3_column_value()] is unprotected.
3318** Unprotected sqlite3_value objects may only be used with
3319** [sqlite3_result_value()] and [sqlite3_bind_value()].
3320** The [sqlite3_value_blob | sqlite3_value_type()] family of
3321** interfaces require protected sqlite3_value objects.
3322*/
3323typedef struct Mem sqlite3_value;
3324
3325/*
3326** CAPI3REF: SQL Function Context Object
3327**
3328** The context in which an SQL function executes is stored in an
3329** sqlite3_context object.  ^A pointer to an sqlite3_context object
3330** is always first parameter to [application-defined SQL functions].
3331** The application-defined SQL function implementation will pass this
3332** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
3333** [sqlite3_aggregate_context()], [sqlite3_user_data()],
3334** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
3335** and/or [sqlite3_set_auxdata()].
3336*/
3337typedef struct sqlite3_context sqlite3_context;
3338
3339/*
3340** CAPI3REF: Binding Values To Prepared Statements
3341** KEYWORDS: {host parameter} {host parameters} {host parameter name}
3342** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
3343**
3344** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
3345** literals may be replaced by a [parameter] that matches one of following
3346** templates:
3347**
3348** <ul>
3349** <li>  ?
3350** <li>  ?NNN
3351** <li>  :VVV
3352** <li>  @VVV
3353** <li>  $VVV
3354** </ul>
3355**
3356** In the templates above, NNN represents an integer literal,
3357** and VVV represents an alphanumeric identifier.)^  ^The values of these
3358** parameters (also called "host parameter names" or "SQL parameters")
3359** can be set using the sqlite3_bind_*() routines defined here.
3360**
3361** ^The first argument to the sqlite3_bind_*() routines is always
3362** a pointer to the [sqlite3_stmt] object returned from
3363** [sqlite3_prepare_v2()] or its variants.
3364**
3365** ^The second argument is the index of the SQL parameter to be set.
3366** ^The leftmost SQL parameter has an index of 1.  ^When the same named
3367** SQL parameter is used more than once, second and subsequent
3368** occurrences have the same index as the first occurrence.
3369** ^The index for named parameters can be looked up using the
3370** [sqlite3_bind_parameter_index()] API if desired.  ^The index
3371** for "?NNN" parameters is the value of NNN.
3372** ^The NNN value must be between 1 and the [sqlite3_limit()]
3373** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
3374**
3375** ^The third argument is the value to bind to the parameter.
3376**
3377** ^(In those routines that have a fourth argument, its value is the
3378** number of bytes in the parameter.  To be clear: the value is the
3379** number of <u>bytes</u> in the value, not the number of characters.)^
3380** ^If the fourth parameter is negative, the length of the string is
3381** the number of bytes up to the first zero terminator.
3382**
3383** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
3384** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
3385** string after SQLite has finished with it.  ^The destructor is called
3386** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(),
3387** sqlite3_bind_text(), or sqlite3_bind_text16() fails.
3388** ^If the fifth argument is
3389** the special value [SQLITE_STATIC], then SQLite assumes that the
3390** information is in static, unmanaged space and does not need to be freed.
3391** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
3392** SQLite makes its own private copy of the data immediately, before
3393** the sqlite3_bind_*() routine returns.
3394**
3395** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
3396** is filled with zeroes.  ^A zeroblob uses a fixed amount of memory
3397** (just an integer to hold its size) while it is being processed.
3398** Zeroblobs are intended to serve as placeholders for BLOBs whose
3399** content is later written using
3400** [sqlite3_blob_open | incremental BLOB I/O] routines.
3401** ^A negative value for the zeroblob results in a zero-length BLOB.
3402**
3403** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
3404** for the [prepared statement] or with a prepared statement for which
3405** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
3406** then the call will return [SQLITE_MISUSE].  If any sqlite3_bind_()
3407** routine is passed a [prepared statement] that has been finalized, the
3408** result is undefined and probably harmful.
3409**
3410** ^Bindings are not cleared by the [sqlite3_reset()] routine.
3411** ^Unbound parameters are interpreted as NULL.
3412**
3413** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
3414** [error code] if anything goes wrong.
3415** ^[SQLITE_RANGE] is returned if the parameter
3416** index is out of range.  ^[SQLITE_NOMEM] is returned if malloc() fails.
3417**
3418** See also: [sqlite3_bind_parameter_count()],
3419** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
3420*/
3421SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
3422SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
3423SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
3424SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
3425SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
3426SQLITE_API int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));
3427SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
3428SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3429SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3430
3431/*
3432** CAPI3REF: Number Of SQL Parameters
3433**
3434** ^This routine can be used to find the number of [SQL parameters]
3435** in a [prepared statement].  SQL parameters are tokens of the
3436** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
3437** placeholders for values that are [sqlite3_bind_blob | bound]
3438** to the parameters at a later time.
3439**
3440** ^(This routine actually returns the index of the largest (rightmost)
3441** parameter. For all forms except ?NNN, this will correspond to the
3442** number of unique parameters.  If parameters of the ?NNN form are used,
3443** there may be gaps in the list.)^
3444**
3445** See also: [sqlite3_bind_blob|sqlite3_bind()],
3446** [sqlite3_bind_parameter_name()], and
3447** [sqlite3_bind_parameter_index()].
3448*/
3449SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*);
3450
3451/*
3452** CAPI3REF: Name Of A Host Parameter
3453**
3454** ^The sqlite3_bind_parameter_name(P,N) interface returns
3455** the name of the N-th [SQL parameter] in the [prepared statement] P.
3456** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
3457** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
3458** respectively.
3459** In other words, the initial ":" or "$" or "@" or "?"
3460** is included as part of the name.)^
3461** ^Parameters of the form "?" without a following integer have no name
3462** and are referred to as "nameless" or "anonymous parameters".
3463**
3464** ^The first host parameter has an index of 1, not 0.
3465**
3466** ^If the value N is out of range or if the N-th parameter is
3467** nameless, then NULL is returned.  ^The returned string is
3468** always in UTF-8 encoding even if the named parameter was
3469** originally specified as UTF-16 in [sqlite3_prepare16()] or
3470** [sqlite3_prepare16_v2()].
3471**
3472** See also: [sqlite3_bind_blob|sqlite3_bind()],
3473** [sqlite3_bind_parameter_count()], and
3474** [sqlite3_bind_parameter_index()].
3475*/
3476SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
3477
3478/*
3479** CAPI3REF: Index Of A Parameter With A Given Name
3480**
3481** ^Return the index of an SQL parameter given its name.  ^The
3482** index value returned is suitable for use as the second
3483** parameter to [sqlite3_bind_blob|sqlite3_bind()].  ^A zero
3484** is returned if no matching parameter is found.  ^The parameter
3485** name must be given in UTF-8 even if the original statement
3486** was prepared from UTF-16 text using [sqlite3_prepare16_v2()].
3487**
3488** See also: [sqlite3_bind_blob|sqlite3_bind()],
3489** [sqlite3_bind_parameter_count()], and
3490** [sqlite3_bind_parameter_index()].
3491*/
3492SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
3493
3494/*
3495** CAPI3REF: Reset All Bindings On A Prepared Statement
3496**
3497** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
3498** the [sqlite3_bind_blob | bindings] on a [prepared statement].
3499** ^Use this routine to reset all host parameters to NULL.
3500*/
3501SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*);
3502
3503/*
3504** CAPI3REF: Number Of Columns In A Result Set
3505**
3506** ^Return the number of columns in the result set returned by the
3507** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
3508** statement that does not return data (for example an [UPDATE]).
3509**
3510** See also: [sqlite3_data_count()]
3511*/
3512SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
3513
3514/*
3515** CAPI3REF: Column Names In A Result Set
3516**
3517** ^These routines return the name assigned to a particular column
3518** in the result set of a [SELECT] statement.  ^The sqlite3_column_name()
3519** interface returns a pointer to a zero-terminated UTF-8 string
3520** and sqlite3_column_name16() returns a pointer to a zero-terminated
3521** UTF-16 string.  ^The first parameter is the [prepared statement]
3522** that implements the [SELECT] statement. ^The second parameter is the
3523** column number.  ^The leftmost column is number 0.
3524**
3525** ^The returned string pointer is valid until either the [prepared statement]
3526** is destroyed by [sqlite3_finalize()] or until the statement is automatically
3527** reprepared by the first call to [sqlite3_step()] for a particular run
3528** or until the next call to
3529** sqlite3_column_name() or sqlite3_column_name16() on the same column.
3530**
3531** ^If sqlite3_malloc() fails during the processing of either routine
3532** (for example during a conversion from UTF-8 to UTF-16) then a
3533** NULL pointer is returned.
3534**
3535** ^The name of a result column is the value of the "AS" clause for
3536** that column, if there is an AS clause.  If there is no AS clause
3537** then the name of the column is unspecified and may change from
3538** one release of SQLite to the next.
3539*/
3540SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N);
3541SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N);
3542
3543/*
3544** CAPI3REF: Source Of Data In A Query Result
3545**
3546** ^These routines provide a means to determine the database, table, and
3547** table column that is the origin of a particular result column in
3548** [SELECT] statement.
3549** ^The name of the database or table or column can be returned as
3550** either a UTF-8 or UTF-16 string.  ^The _database_ routines return
3551** the database name, the _table_ routines return the table name, and
3552** the origin_ routines return the column name.
3553** ^The returned string is valid until the [prepared statement] is destroyed
3554** using [sqlite3_finalize()] or until the statement is automatically
3555** reprepared by the first call to [sqlite3_step()] for a particular run
3556** or until the same information is requested
3557** again in a different encoding.
3558**
3559** ^The names returned are the original un-aliased names of the
3560** database, table, and column.
3561**
3562** ^The first argument to these interfaces is a [prepared statement].
3563** ^These functions return information about the Nth result column returned by
3564** the statement, where N is the second function argument.
3565** ^The left-most column is column 0 for these routines.
3566**
3567** ^If the Nth column returned by the statement is an expression or
3568** subquery and is not a column value, then all of these functions return
3569** NULL.  ^These routine might also return NULL if a memory allocation error
3570** occurs.  ^Otherwise, they return the name of the attached database, table,
3571** or column that query result column was extracted from.
3572**
3573** ^As with all other SQLite APIs, those whose names end with "16" return
3574** UTF-16 encoded strings and the other functions return UTF-8.
3575**
3576** ^These APIs are only available if the library was compiled with the
3577** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
3578**
3579** If two or more threads call one or more of these routines against the same
3580** prepared statement and column at the same time then the results are
3581** undefined.
3582**
3583** If two or more threads call one or more
3584** [sqlite3_column_database_name | column metadata interfaces]
3585** for the same [prepared statement] and result column
3586** at the same time then the results are undefined.
3587*/
3588SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int);
3589SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
3590SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int);
3591SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
3592SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
3593SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
3594
3595/*
3596** CAPI3REF: Declared Datatype Of A Query Result
3597**
3598** ^(The first parameter is a [prepared statement].
3599** If this statement is a [SELECT] statement and the Nth column of the
3600** returned result set of that [SELECT] is a table column (not an
3601** expression or subquery) then the declared type of the table
3602** column is returned.)^  ^If the Nth column of the result set is an
3603** expression or subquery, then a NULL pointer is returned.
3604** ^The returned string is always UTF-8 encoded.
3605**
3606** ^(For example, given the database schema:
3607**
3608** CREATE TABLE t1(c1 VARIANT);
3609**
3610** and the following statement to be compiled:
3611**
3612** SELECT c1 + 1, c1 FROM t1;
3613**
3614** this routine would return the string "VARIANT" for the second result
3615** column (i==1), and a NULL pointer for the first result column (i==0).)^
3616**
3617** ^SQLite uses dynamic run-time typing.  ^So just because a column
3618** is declared to contain a particular type does not mean that the
3619** data stored in that column is of the declared type.  SQLite is
3620** strongly typed, but the typing is dynamic not static.  ^Type
3621** is associated with individual values, not with the containers
3622** used to hold those values.
3623*/
3624SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int);
3625SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
3626
3627/*
3628** CAPI3REF: Evaluate An SQL Statement
3629**
3630** After a [prepared statement] has been prepared using either
3631** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
3632** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
3633** must be called one or more times to evaluate the statement.
3634**
3635** The details of the behavior of the sqlite3_step() interface depend
3636** on whether the statement was prepared using the newer "v2" interface
3637** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy
3638** interface [sqlite3_prepare()] and [sqlite3_prepare16()].  The use of the
3639** new "v2" interface is recommended for new applications but the legacy
3640** interface will continue to be supported.
3641**
3642** ^In the legacy interface, the return value will be either [SQLITE_BUSY],
3643** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
3644** ^With the "v2" interface, any of the other [result codes] or
3645** [extended result codes] might be returned as well.
3646**
3647** ^[SQLITE_BUSY] means that the database engine was unable to acquire the
3648** database locks it needs to do its job.  ^If the statement is a [COMMIT]
3649** or occurs outside of an explicit transaction, then you can retry the
3650** statement.  If the statement is not a [COMMIT] and occurs within a
3651** explicit transaction then you should rollback the transaction before
3652** continuing.
3653**
3654** ^[SQLITE_DONE] means that the statement has finished executing
3655** successfully.  sqlite3_step() should not be called again on this virtual
3656** machine without first calling [sqlite3_reset()] to reset the virtual
3657** machine back to its initial state.
3658**
3659** ^If the SQL statement being executed returns any data, then [SQLITE_ROW]
3660** is returned each time a new row of data is ready for processing by the
3661** caller. The values may be accessed using the [column access functions].
3662** sqlite3_step() is called again to retrieve the next row of data.
3663**
3664** ^[SQLITE_ERROR] means that a run-time error (such as a constraint
3665** violation) has occurred.  sqlite3_step() should not be called again on
3666** the VM. More information may be found by calling [sqlite3_errmsg()].
3667** ^With the legacy interface, a more specific error code (for example,
3668** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
3669** can be obtained by calling [sqlite3_reset()] on the
3670** [prepared statement].  ^In the "v2" interface,
3671** the more specific error code is returned directly by sqlite3_step().
3672**
3673** [SQLITE_MISUSE] means that the this routine was called inappropriately.
3674** Perhaps it was called on a [prepared statement] that has
3675** already been [sqlite3_finalize | finalized] or on one that had
3676** previously returned [SQLITE_ERROR] or [SQLITE_DONE].  Or it could
3677** be the case that the same database connection is being used by two or
3678** more threads at the same moment in time.
3679**
3680** For all versions of SQLite up to and including 3.6.23.1, a call to
3681** [sqlite3_reset()] was required after sqlite3_step() returned anything
3682** other than [SQLITE_ROW] before any subsequent invocation of
3683** sqlite3_step().  Failure to reset the prepared statement using
3684** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
3685** sqlite3_step().  But after version 3.6.23.1, sqlite3_step() began
3686** calling [sqlite3_reset()] automatically in this circumstance rather
3687** than returning [SQLITE_MISUSE].  This is not considered a compatibility
3688** break because any application that ever receives an SQLITE_MISUSE error
3689** is broken by definition.  The [SQLITE_OMIT_AUTORESET] compile-time option
3690** can be used to restore the legacy behavior.
3691**
3692** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
3693** API always returns a generic error code, [SQLITE_ERROR], following any
3694** error other than [SQLITE_BUSY] and [SQLITE_MISUSE].  You must call
3695** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the
3696** specific [error codes] that better describes the error.
3697** We admit that this is a goofy design.  The problem has been fixed
3698** with the "v2" interface.  If you prepare all of your SQL statements
3699** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead
3700** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,
3701** then the more specific [error codes] are returned directly
3702** by sqlite3_step().  The use of the "v2" interface is recommended.
3703*/
3704SQLITE_API int sqlite3_step(sqlite3_stmt*);
3705
3706/*
3707** CAPI3REF: Number of columns in a result set
3708**
3709** ^The sqlite3_data_count(P) interface returns the number of columns in the
3710** current row of the result set of [prepared statement] P.
3711** ^If prepared statement P does not have results ready to return
3712** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
3713** interfaces) then sqlite3_data_count(P) returns 0.
3714** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
3715**
3716** See also: [sqlite3_column_count()]
3717*/
3718SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
3719
3720/*
3721** CAPI3REF: Fundamental Datatypes
3722** KEYWORDS: SQLITE_TEXT
3723**
3724** ^(Every value in SQLite has one of five fundamental datatypes:
3725**
3726** <ul>
3727** <li> 64-bit signed integer
3728** <li> 64-bit IEEE floating point number
3729** <li> string
3730** <li> BLOB
3731** <li> NULL
3732** </ul>)^
3733**
3734** These constants are codes for each of those types.
3735**
3736** Note that the SQLITE_TEXT constant was also used in SQLite version 2
3737** for a completely different meaning.  Software that links against both
3738** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not
3739** SQLITE_TEXT.
3740*/
3741#define SQLITE_INTEGER  1
3742#define SQLITE_FLOAT    2
3743#define SQLITE_BLOB     4
3744#define SQLITE_NULL     5
3745#ifdef SQLITE_TEXT
3746# undef SQLITE_TEXT
3747#else
3748# define SQLITE_TEXT     3
3749#endif
3750#define SQLITE3_TEXT     3
3751
3752/*
3753** CAPI3REF: Result Values From A Query
3754** KEYWORDS: {column access functions}
3755**
3756** These routines form the "result set" interface.
3757**
3758** ^These routines return information about a single column of the current
3759** result row of a query.  ^In every case the first argument is a pointer
3760** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]
3761** that was returned from [sqlite3_prepare_v2()] or one of its variants)
3762** and the second argument is the index of the column for which information
3763** should be returned. ^The leftmost column of the result set has the index 0.
3764** ^The number of columns in the result can be determined using
3765** [sqlite3_column_count()].
3766**
3767** If the SQL statement does not currently point to a valid row, or if the
3768** column index is out of range, the result is undefined.
3769** These routines may only be called when the most recent call to
3770** [sqlite3_step()] has returned [SQLITE_ROW] and neither
3771** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently.
3772** If any of these routines are called after [sqlite3_reset()] or
3773** [sqlite3_finalize()] or after [sqlite3_step()] has returned
3774** something other than [SQLITE_ROW], the results are undefined.
3775** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()]
3776** are called from a different thread while any of these routines
3777** are pending, then the results are undefined.
3778**
3779** ^The sqlite3_column_type() routine returns the
3780** [SQLITE_INTEGER | datatype code] for the initial data type
3781** of the result column.  ^The returned value is one of [SQLITE_INTEGER],
3782** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].  The value
3783** returned by sqlite3_column_type() is only meaningful if no type
3784** conversions have occurred as described below.  After a type conversion,
3785** the value returned by sqlite3_column_type() is undefined.  Future
3786** versions of SQLite may change the behavior of sqlite3_column_type()
3787** following a type conversion.
3788**
3789** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
3790** routine returns the number of bytes in that BLOB or string.
3791** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts
3792** the string to UTF-8 and then returns the number of bytes.
3793** ^If the result is a numeric value then sqlite3_column_bytes() uses
3794** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
3795** the number of bytes in that string.
3796** ^If the result is NULL, then sqlite3_column_bytes() returns zero.
3797**
3798** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16()
3799** routine returns the number of bytes in that BLOB or string.
3800** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts
3801** the string to UTF-16 and then returns the number of bytes.
3802** ^If the result is a numeric value then sqlite3_column_bytes16() uses
3803** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns
3804** the number of bytes in that string.
3805** ^If the result is NULL, then sqlite3_column_bytes16() returns zero.
3806**
3807** ^The values returned by [sqlite3_column_bytes()] and
3808** [sqlite3_column_bytes16()] do not include the zero terminators at the end
3809** of the string.  ^For clarity: the values returned by
3810** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of
3811** bytes in the string, not the number of characters.
3812**
3813** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
3814** even empty strings, are always zero terminated.  ^The return
3815** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
3816**
3817** ^The object returned by [sqlite3_column_value()] is an
3818** [unprotected sqlite3_value] object.  An unprotected sqlite3_value object
3819** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()].
3820** If the [unprotected sqlite3_value] object returned by
3821** [sqlite3_column_value()] is used in any other way, including calls
3822** to routines like [sqlite3_value_int()], [sqlite3_value_text()],
3823** or [sqlite3_value_bytes()], then the behavior is undefined.
3824**
3825** These routines attempt to convert the value where appropriate.  ^For
3826** example, if the internal representation is FLOAT and a text result
3827** is requested, [sqlite3_snprintf()] is used internally to perform the
3828** conversion automatically.  ^(The following table details the conversions
3829** that are applied:
3830**
3831** <blockquote>
3832** <table border="1">
3833** <tr><th> Internal<br>Type <th> Requested<br>Type <th>  Conversion
3834**
3835** <tr><td>  NULL    <td> INTEGER   <td> Result is 0
3836** <tr><td>  NULL    <td>  FLOAT    <td> Result is 0.0
3837** <tr><td>  NULL    <td>   TEXT    <td> Result is NULL pointer
3838** <tr><td>  NULL    <td>   BLOB    <td> Result is NULL pointer
3839** <tr><td> INTEGER  <td>  FLOAT    <td> Convert from integer to float
3840** <tr><td> INTEGER  <td>   TEXT    <td> ASCII rendering of the integer
3841** <tr><td> INTEGER  <td>   BLOB    <td> Same as INTEGER->TEXT
3842** <tr><td>  FLOAT   <td> INTEGER   <td> Convert from float to integer
3843** <tr><td>  FLOAT   <td>   TEXT    <td> ASCII rendering of the float
3844** <tr><td>  FLOAT   <td>   BLOB    <td> Same as FLOAT->TEXT
3845** <tr><td>  TEXT    <td> INTEGER   <td> Use atoi()
3846** <tr><td>  TEXT    <td>  FLOAT    <td> Use atof()
3847** <tr><td>  TEXT    <td>   BLOB    <td> No change
3848** <tr><td>  BLOB    <td> INTEGER   <td> Convert to TEXT then use atoi()
3849** <tr><td>  BLOB    <td>  FLOAT    <td> Convert to TEXT then use atof()
3850** <tr><td>  BLOB    <td>   TEXT    <td> Add a zero terminator if needed
3851** </table>
3852** </blockquote>)^
3853**
3854** The table above makes reference to standard C library functions atoi()
3855** and atof().  SQLite does not really use these functions.  It has its
3856** own equivalent internal routines.  The atoi() and atof() names are
3857** used in the table for brevity and because they are familiar to most
3858** C programmers.
3859**
3860** Note that when type conversions occur, pointers returned by prior
3861** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
3862** sqlite3_column_text16() may be invalidated.
3863** Type conversions and pointer invalidations might occur
3864** in the following cases:
3865**
3866** <ul>
3867** <li> The initial content is a BLOB and sqlite3_column_text() or
3868**      sqlite3_column_text16() is called.  A zero-terminator might
3869**      need to be added to the string.</li>
3870** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or
3871**      sqlite3_column_text16() is called.  The content must be converted
3872**      to UTF-16.</li>
3873** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
3874**      sqlite3_column_text() is called.  The content must be converted
3875**      to UTF-8.</li>
3876** </ul>
3877**
3878** ^Conversions between UTF-16be and UTF-16le are always done in place and do
3879** not invalidate a prior pointer, though of course the content of the buffer
3880** that the prior pointer references will have been modified.  Other kinds
3881** of conversion are done in place when it is possible, but sometimes they
3882** are not possible and in those cases prior pointers are invalidated.
3883**
3884** The safest and easiest to remember policy is to invoke these routines
3885** in one of the following ways:
3886**
3887** <ul>
3888**  <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
3889**  <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
3890**  <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
3891** </ul>
3892**
3893** In other words, you should call sqlite3_column_text(),
3894** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
3895** into the desired format, then invoke sqlite3_column_bytes() or
3896** sqlite3_column_bytes16() to find the size of the result.  Do not mix calls
3897** to sqlite3_column_text() or sqlite3_column_blob() with calls to
3898** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()
3899** with calls to sqlite3_column_bytes().
3900**
3901** ^The pointers returned are valid until a type conversion occurs as
3902** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
3903** [sqlite3_finalize()] is called.  ^The memory space used to hold strings
3904** and BLOBs is freed automatically.  Do <b>not</b> pass the pointers returned
3905** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
3906** [sqlite3_free()].
3907**
3908** ^(If a memory allocation error occurs during the evaluation of any
3909** of these routines, a default value is returned.  The default value
3910** is either the integer 0, the floating point number 0.0, or a NULL
3911** pointer.  Subsequent calls to [sqlite3_errcode()] will return
3912** [SQLITE_NOMEM].)^
3913*/
3914SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
3915SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
3916SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
3917SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol);
3918SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol);
3919SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
3920SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
3921SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
3922SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol);
3923SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
3924
3925/*
3926** CAPI3REF: Destroy A Prepared Statement Object
3927**
3928** ^The sqlite3_finalize() function is called to delete a [prepared statement].
3929** ^If the most recent evaluation of the statement encountered no errors or
3930** or if the statement is never been evaluated, then sqlite3_finalize() returns
3931** SQLITE_OK.  ^If the most recent evaluation of statement S failed, then
3932** sqlite3_finalize(S) returns the appropriate [error code] or
3933** [extended error code].
3934**
3935** ^The sqlite3_finalize(S) routine can be called at any point during
3936** the life cycle of [prepared statement] S:
3937** before statement S is ever evaluated, after
3938** one or more calls to [sqlite3_reset()], or after any call
3939** to [sqlite3_step()] regardless of whether or not the statement has
3940** completed execution.
3941**
3942** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op.
3943**
3944** The application must finalize every [prepared statement] in order to avoid
3945** resource leaks.  It is a grievous error for the application to try to use
3946** a prepared statement after it has been finalized.  Any use of a prepared
3947** statement after it has been finalized can result in undefined and
3948** undesirable behavior such as segfaults and heap corruption.
3949*/
3950SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
3951
3952/*
3953** CAPI3REF: Reset A Prepared Statement Object
3954**
3955** The sqlite3_reset() function is called to reset a [prepared statement]
3956** object back to its initial state, ready to be re-executed.
3957** ^Any SQL statement variables that had values bound to them using
3958** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
3959** Use [sqlite3_clear_bindings()] to reset the bindings.
3960**
3961** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S
3962** back to the beginning of its program.
3963**
3964** ^If the most recent call to [sqlite3_step(S)] for the
3965** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE],
3966** or if [sqlite3_step(S)] has never before been called on S,
3967** then [sqlite3_reset(S)] returns [SQLITE_OK].
3968**
3969** ^If the most recent call to [sqlite3_step(S)] for the
3970** [prepared statement] S indicated an error, then
3971** [sqlite3_reset(S)] returns an appropriate [error code].
3972**
3973** ^The [sqlite3_reset(S)] interface does not change the values
3974** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
3975*/
3976SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
3977
3978/*
3979** CAPI3REF: Create Or Redefine SQL Functions
3980** KEYWORDS: {function creation routines}
3981** KEYWORDS: {application-defined SQL function}
3982** KEYWORDS: {application-defined SQL functions}
3983**
3984** ^These functions (collectively known as "function creation routines")
3985** are used to add SQL functions or aggregates or to redefine the behavior
3986** of existing SQL functions or aggregates.  The only differences between
3987** these routines are the text encoding expected for
3988** the second parameter (the name of the function being created)
3989** and the presence or absence of a destructor callback for
3990** the application data pointer.
3991**
3992** ^The first parameter is the [database connection] to which the SQL
3993** function is to be added.  ^If an application uses more than one database
3994** connection then application-defined SQL functions must be added
3995** to each database connection separately.
3996**
3997** ^The second parameter is the name of the SQL function to be created or
3998** redefined.  ^The length of the name is limited to 255 bytes in a UTF-8
3999** representation, exclusive of the zero-terminator.  ^Note that the name
4000** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.
4001** ^Any attempt to create a function with a longer name
4002** will result in [SQLITE_MISUSE] being returned.
4003**
4004** ^The third parameter (nArg)
4005** is the number of arguments that the SQL function or
4006** aggregate takes. ^If this parameter is -1, then the SQL function or
4007** aggregate may take any number of arguments between 0 and the limit
4008** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]).  If the third
4009** parameter is less than -1 or greater than 127 then the behavior is
4010** undefined.
4011**
4012** ^The fourth parameter, eTextRep, specifies what
4013** [SQLITE_UTF8 | text encoding] this SQL function prefers for
4014** its parameters.  Every SQL function implementation must be able to work
4015** with UTF-8, UTF-16le, or UTF-16be.  But some implementations may be
4016** more efficient with one encoding than another.  ^An application may
4017** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
4018** times with the same function but with different values of eTextRep.
4019** ^When multiple implementations of the same function are available, SQLite
4020** will pick the one that involves the least amount of data conversion.
4021** If there is only a single implementation which does not care what text
4022** encoding is used, then the fourth argument should be [SQLITE_ANY].
4023**
4024** ^(The fifth parameter is an arbitrary pointer.  The implementation of the
4025** function can gain access to this pointer using [sqlite3_user_data()].)^
4026**
4027** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
4028** pointers to C-language functions that implement the SQL function or
4029** aggregate. ^A scalar SQL function requires an implementation of the xFunc
4030** callback only; NULL pointers must be passed as the xStep and xFinal
4031** parameters. ^An aggregate SQL function requires an implementation of xStep
4032** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
4033** SQL function or aggregate, pass NULL pointers for all three function
4034** callbacks.
4035**
4036** ^(If the ninth parameter to sqlite3_create_function_v2() is not NULL,
4037** then it is destructor for the application data pointer.
4038** The destructor is invoked when the function is deleted, either by being
4039** overloaded or when the database connection closes.)^
4040** ^The destructor is also invoked if the call to
4041** sqlite3_create_function_v2() fails.
4042** ^When the destructor callback of the tenth parameter is invoked, it
4043** is passed a single argument which is a copy of the application data
4044** pointer which was the fifth parameter to sqlite3_create_function_v2().
4045**
4046** ^It is permitted to register multiple implementations of the same
4047** functions with the same name but with either differing numbers of
4048** arguments or differing preferred text encodings.  ^SQLite will use
4049** the implementation that most closely matches the way in which the
4050** SQL function is used.  ^A function implementation with a non-negative
4051** nArg parameter is a better match than a function implementation with
4052** a negative nArg.  ^A function where the preferred text encoding
4053** matches the database encoding is a better
4054** match than a function where the encoding is different.
4055** ^A function where the encoding difference is between UTF16le and UTF16be
4056** is a closer match than a function where the encoding difference is
4057** between UTF8 and UTF16.
4058**
4059** ^Built-in functions may be overloaded by new application-defined functions.
4060**
4061** ^An application-defined function is permitted to call other
4062** SQLite interfaces.  However, such calls must not
4063** close the database connection nor finalize or reset the prepared
4064** statement in which the function is running.
4065*/
4066SQLITE_API int sqlite3_create_function(
4067  sqlite3 *db,
4068  const char *zFunctionName,
4069  int nArg,
4070  int eTextRep,
4071  void *pApp,
4072  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
4073  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
4074  void (*xFinal)(sqlite3_context*)
4075);
4076SQLITE_API int sqlite3_create_function16(
4077  sqlite3 *db,
4078  const void *zFunctionName,
4079  int nArg,
4080  int eTextRep,
4081  void *pApp,
4082  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
4083  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
4084  void (*xFinal)(sqlite3_context*)
4085);
4086SQLITE_API int sqlite3_create_function_v2(
4087  sqlite3 *db,
4088  const char *zFunctionName,
4089  int nArg,
4090  int eTextRep,
4091  void *pApp,
4092  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
4093  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
4094  void (*xFinal)(sqlite3_context*),
4095  void(*xDestroy)(void*)
4096);
4097
4098/*
4099** CAPI3REF: Text Encodings
4100**
4101** These constant define integer codes that represent the various
4102** text encodings supported by SQLite.
4103*/
4104#define SQLITE_UTF8           1
4105#define SQLITE_UTF16LE        2
4106#define SQLITE_UTF16BE        3
4107#define SQLITE_UTF16          4    /* Use native byte order */
4108#define SQLITE_ANY            5    /* sqlite3_create_function only */
4109#define SQLITE_UTF16_ALIGNED  8    /* sqlite3_create_collation only */
4110
4111/*
4112** CAPI3REF: Deprecated Functions
4113** DEPRECATED
4114**
4115** These functions are [deprecated].  In order to maintain
4116** backwards compatibility with older code, these functions continue
4117** to be supported.  However, new applications should avoid
4118** the use of these functions.  To help encourage people to avoid
4119** using these functions, we are not going to tell you what they do.
4120*/
4121#ifndef SQLITE_OMIT_DEPRECATED
4122SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
4123SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
4124SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
4125SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);
4126SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
4127SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64);
4128#endif
4129
4130/*
4131** CAPI3REF: Obtaining SQL Function Parameter Values
4132**
4133** The C-language implementation of SQL functions and aggregates uses
4134** this set of interface routines to access the parameter values on
4135** the function or aggregate.
4136**
4137** The xFunc (for scalar functions) or xStep (for aggregates) parameters
4138** to [sqlite3_create_function()] and [sqlite3_create_function16()]
4139** define callbacks that implement the SQL functions and aggregates.
4140** The 3rd parameter to these callbacks is an array of pointers to
4141** [protected sqlite3_value] objects.  There is one [sqlite3_value] object for
4142** each parameter to the SQL function.  These routines are used to
4143** extract values from the [sqlite3_value] objects.
4144**
4145** These routines work only with [protected sqlite3_value] objects.
4146** Any attempt to use these routines on an [unprotected sqlite3_value]
4147** object results in undefined behavior.
4148**
4149** ^These routines work just like the corresponding [column access functions]
4150** except that  these routines take a single [protected sqlite3_value] object
4151** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
4152**
4153** ^The sqlite3_value_text16() interface extracts a UTF-16 string
4154** in the native byte-order of the host machine.  ^The
4155** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
4156** extract UTF-16 strings as big-endian and little-endian respectively.
4157**
4158** ^(The sqlite3_value_numeric_type() interface attempts to apply
4159** numeric affinity to the value.  This means that an attempt is
4160** made to convert the value to an integer or floating point.  If
4161** such a conversion is possible without loss of information (in other
4162** words, if the value is a string that looks like a number)
4163** then the conversion is performed.  Otherwise no conversion occurs.
4164** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
4165**
4166** Please pay particular attention to the fact that the pointer returned
4167** from [sqlite3_value_blob()], [sqlite3_value_text()], or
4168** [sqlite3_value_text16()] can be invalidated by a subsequent call to
4169** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
4170** or [sqlite3_value_text16()].
4171**
4172** These routines must be called from the same thread as
4173** the SQL function that supplied the [sqlite3_value*] parameters.
4174*/
4175SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);
4176SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
4177SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
4178SQLITE_API double sqlite3_value_double(sqlite3_value*);
4179SQLITE_API int sqlite3_value_int(sqlite3_value*);
4180SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
4181SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);
4182SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);
4183SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);
4184SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
4185SQLITE_API int sqlite3_value_type(sqlite3_value*);
4186SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
4187
4188/*
4189** CAPI3REF: Obtain Aggregate Function Context
4190**
4191** Implementations of aggregate SQL functions use this
4192** routine to allocate memory for storing their state.
4193**
4194** ^The first time the sqlite3_aggregate_context(C,N) routine is called
4195** for a particular aggregate function, SQLite
4196** allocates N of memory, zeroes out that memory, and returns a pointer
4197** to the new memory. ^On second and subsequent calls to
4198** sqlite3_aggregate_context() for the same aggregate function instance,
4199** the same buffer is returned.  Sqlite3_aggregate_context() is normally
4200** called once for each invocation of the xStep callback and then one
4201** last time when the xFinal callback is invoked.  ^(When no rows match
4202** an aggregate query, the xStep() callback of the aggregate function
4203** implementation is never called and xFinal() is called exactly once.
4204** In those cases, sqlite3_aggregate_context() might be called for the
4205** first time from within xFinal().)^
4206**
4207** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer if N is
4208** less than or equal to zero or if a memory allocate error occurs.
4209**
4210** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
4211** determined by the N parameter on first successful call.  Changing the
4212** value of N in subsequent call to sqlite3_aggregate_context() within
4213** the same aggregate function instance will not resize the memory
4214** allocation.)^
4215**
4216** ^SQLite automatically frees the memory allocated by
4217** sqlite3_aggregate_context() when the aggregate query concludes.
4218**
4219** The first parameter must be a copy of the
4220** [sqlite3_context | SQL function context] that is the first parameter
4221** to the xStep or xFinal callback routine that implements the aggregate
4222** function.
4223**
4224** This routine must be called from the same thread in which
4225** the aggregate SQL function is running.
4226*/
4227SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
4228
4229/*
4230** CAPI3REF: User Data For Functions
4231**
4232** ^The sqlite3_user_data() interface returns a copy of
4233** the pointer that was the pUserData parameter (the 5th parameter)
4234** of the [sqlite3_create_function()]
4235** and [sqlite3_create_function16()] routines that originally
4236** registered the application defined function.
4237**
4238** This routine must be called from the same thread in which
4239** the application-defined function is running.
4240*/
4241SQLITE_API void *sqlite3_user_data(sqlite3_context*);
4242
4243/*
4244** CAPI3REF: Database Connection For Functions
4245**
4246** ^The sqlite3_context_db_handle() interface returns a copy of
4247** the pointer to the [database connection] (the 1st parameter)
4248** of the [sqlite3_create_function()]
4249** and [sqlite3_create_function16()] routines that originally
4250** registered the application defined function.
4251*/
4252SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
4253
4254/*
4255** CAPI3REF: Function Auxiliary Data
4256**
4257** The following two functions may be used by scalar SQL functions to
4258** associate metadata with argument values. If the same value is passed to
4259** multiple invocations of the same SQL function during query execution, under
4260** some circumstances the associated metadata may be preserved. This may
4261** be used, for example, to add a regular-expression matching scalar
4262** function. The compiled version of the regular expression is stored as
4263** metadata associated with the SQL value passed as the regular expression
4264** pattern.  The compiled regular expression can be reused on multiple
4265** invocations of the same function so that the original pattern string
4266** does not need to be recompiled on each invocation.
4267**
4268** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
4269** associated by the sqlite3_set_auxdata() function with the Nth argument
4270** value to the application-defined function. ^If no metadata has been ever
4271** been set for the Nth argument of the function, or if the corresponding
4272** function parameter has changed since the meta-data was set,
4273** then sqlite3_get_auxdata() returns a NULL pointer.
4274**
4275** ^The sqlite3_set_auxdata() interface saves the metadata
4276** pointed to by its 3rd parameter as the metadata for the N-th
4277** argument of the application-defined function.  Subsequent
4278** calls to sqlite3_get_auxdata() might return this data, if it has
4279** not been destroyed.
4280** ^If it is not NULL, SQLite will invoke the destructor
4281** function given by the 4th parameter to sqlite3_set_auxdata() on
4282** the metadata when the corresponding function parameter changes
4283** or when the SQL statement completes, whichever comes first.
4284**
4285** SQLite is free to call the destructor and drop metadata on any
4286** parameter of any function at any time.  ^The only guarantee is that
4287** the destructor will be called before the metadata is dropped.
4288**
4289** ^(In practice, metadata is preserved between function calls for
4290** expressions that are constant at compile time. This includes literal
4291** values and [parameters].)^
4292**
4293** These routines must be called from the same thread in which
4294** the SQL function is running.
4295*/
4296SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
4297SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
4298
4299
4300/*
4301** CAPI3REF: Constants Defining Special Destructor Behavior
4302**
4303** These are special values for the destructor that is passed in as the
4304** final argument to routines like [sqlite3_result_blob()].  ^If the destructor
4305** argument is SQLITE_STATIC, it means that the content pointer is constant
4306** and will never change.  It does not need to be destroyed.  ^The
4307** SQLITE_TRANSIENT value means that the content will likely change in
4308** the near future and that SQLite should make its own private copy of
4309** the content before returning.
4310**
4311** The typedef is necessary to work around problems in certain
4312** C++ compilers.  See ticket #2191.
4313*/
4314typedef void (*sqlite3_destructor_type)(void*);
4315#define SQLITE_STATIC      ((sqlite3_destructor_type)0)
4316#define SQLITE_TRANSIENT   ((sqlite3_destructor_type)-1)
4317
4318/*
4319** CAPI3REF: Setting The Result Of An SQL Function
4320**
4321** These routines are used by the xFunc or xFinal callbacks that
4322** implement SQL functions and aggregates.  See
4323** [sqlite3_create_function()] and [sqlite3_create_function16()]
4324** for additional information.
4325**
4326** These functions work very much like the [parameter binding] family of
4327** functions used to bind values to host parameters in prepared statements.
4328** Refer to the [SQL parameter] documentation for additional information.
4329**
4330** ^The sqlite3_result_blob() interface sets the result from
4331** an application-defined function to be the BLOB whose content is pointed
4332** to by the second parameter and which is N bytes long where N is the
4333** third parameter.
4334**
4335** ^The sqlite3_result_zeroblob() interfaces set the result of
4336** the application-defined function to be a BLOB containing all zero
4337** bytes and N bytes in size, where N is the value of the 2nd parameter.
4338**
4339** ^The sqlite3_result_double() interface sets the result from
4340** an application-defined function to be a floating point value specified
4341** by its 2nd argument.
4342**
4343** ^The sqlite3_result_error() and sqlite3_result_error16() functions
4344** cause the implemented SQL function to throw an exception.
4345** ^SQLite uses the string pointed to by the
4346** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
4347** as the text of an error message.  ^SQLite interprets the error
4348** message string from sqlite3_result_error() as UTF-8. ^SQLite
4349** interprets the string from sqlite3_result_error16() as UTF-16 in native
4350** byte order.  ^If the third parameter to sqlite3_result_error()
4351** or sqlite3_result_error16() is negative then SQLite takes as the error
4352** message all text up through the first zero character.
4353** ^If the third parameter to sqlite3_result_error() or
4354** sqlite3_result_error16() is non-negative then SQLite takes that many
4355** bytes (not characters) from the 2nd parameter as the error message.
4356** ^The sqlite3_result_error() and sqlite3_result_error16()
4357** routines make a private copy of the error message text before
4358** they return.  Hence, the calling function can deallocate or
4359** modify the text after they return without harm.
4360** ^The sqlite3_result_error_code() function changes the error code
4361** returned by SQLite as a result of an error in a function.  ^By default,
4362** the error code is SQLITE_ERROR.  ^A subsequent call to sqlite3_result_error()
4363** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
4364**
4365** ^The sqlite3_result_toobig() interface causes SQLite to throw an error
4366** indicating that a string or BLOB is too long to represent.
4367**
4368** ^The sqlite3_result_nomem() interface causes SQLite to throw an error
4369** indicating that a memory allocation failed.
4370**
4371** ^The sqlite3_result_int() interface sets the return value
4372** of the application-defined function to be the 32-bit signed integer
4373** value given in the 2nd argument.
4374** ^The sqlite3_result_int64() interface sets the return value
4375** of the application-defined function to be the 64-bit signed integer
4376** value given in the 2nd argument.
4377**
4378** ^The sqlite3_result_null() interface sets the return value
4379** of the application-defined function to be NULL.
4380**
4381** ^The sqlite3_result_text(), sqlite3_result_text16(),
4382** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
4383** set the return value of the application-defined function to be
4384** a text string which is represented as UTF-8, UTF-16 native byte order,
4385** UTF-16 little endian, or UTF-16 big endian, respectively.
4386** ^SQLite takes the text result from the application from
4387** the 2nd parameter of the sqlite3_result_text* interfaces.
4388** ^If the 3rd parameter to the sqlite3_result_text* interfaces
4389** is negative, then SQLite takes result text from the 2nd parameter
4390** through the first zero character.
4391** ^If the 3rd parameter to the sqlite3_result_text* interfaces
4392** is non-negative, then as many bytes (not characters) of the text
4393** pointed to by the 2nd parameter are taken as the application-defined
4394** function result.
4395** ^If the 4th parameter to the sqlite3_result_text* interfaces
4396** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
4397** function as the destructor on the text or BLOB result when it has
4398** finished using that result.
4399** ^If the 4th parameter to the sqlite3_result_text* interfaces or to
4400** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite
4401** assumes that the text or BLOB result is in constant space and does not
4402** copy the content of the parameter nor call a destructor on the content
4403** when it has finished using that result.
4404** ^If the 4th parameter to the sqlite3_result_text* interfaces
4405** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
4406** then SQLite makes a copy of the result into space obtained from
4407** from [sqlite3_malloc()] before it returns.
4408**
4409** ^The sqlite3_result_value() interface sets the result of
4410** the application-defined function to be a copy the
4411** [unprotected sqlite3_value] object specified by the 2nd parameter.  ^The
4412** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
4413** so that the [sqlite3_value] specified in the parameter may change or
4414** be deallocated after sqlite3_result_value() returns without harm.
4415** ^A [protected sqlite3_value] object may always be used where an
4416** [unprotected sqlite3_value] object is required, so either
4417** kind of [sqlite3_value] object can be used with this interface.
4418**
4419** If these routines are called from within the different thread
4420** than the one containing the application-defined function that received
4421** the [sqlite3_context] pointer, the results are undefined.
4422*/
4423SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
4424SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
4425SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
4426SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
4427SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
4428SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
4429SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int);
4430SQLITE_API void sqlite3_result_int(sqlite3_context*, int);
4431SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
4432SQLITE_API void sqlite3_result_null(sqlite3_context*);
4433SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
4434SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
4435SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
4436SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
4437SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4438SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
4439
4440/*
4441** CAPI3REF: Define New Collating Sequences
4442**
4443** ^These functions add, remove, or modify a [collation] associated
4444** with the [database connection] specified as the first argument.
4445**
4446** ^The name of the collation is a UTF-8 string
4447** for sqlite3_create_collation() and sqlite3_create_collation_v2()
4448** and a UTF-16 string in native byte order for sqlite3_create_collation16().
4449** ^Collation names that compare equal according to [sqlite3_strnicmp()] are
4450** considered to be the same name.
4451**
4452** ^(The third argument (eTextRep) must be one of the constants:
4453** <ul>
4454** <li> [SQLITE_UTF8],
4455** <li> [SQLITE_UTF16LE],
4456** <li> [SQLITE_UTF16BE],
4457** <li> [SQLITE_UTF16], or
4458** <li> [SQLITE_UTF16_ALIGNED].
4459** </ul>)^
4460** ^The eTextRep argument determines the encoding of strings passed
4461** to the collating function callback, xCallback.
4462** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
4463** force strings to be UTF16 with native byte order.
4464** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
4465** on an even byte address.
4466**
4467** ^The fourth argument, pArg, is an application data pointer that is passed
4468** through as the first argument to the collating function callback.
4469**
4470** ^The fifth argument, xCallback, is a pointer to the collating function.
4471** ^Multiple collating functions can be registered using the same name but
4472** with different eTextRep parameters and SQLite will use whichever
4473** function requires the least amount of data transformation.
4474** ^If the xCallback argument is NULL then the collating function is
4475** deleted.  ^When all collating functions having the same name are deleted,
4476** that collation is no longer usable.
4477**
4478** ^The collating function callback is invoked with a copy of the pArg
4479** application data pointer and with two strings in the encoding specified
4480** by the eTextRep argument.  The collating function must return an
4481** integer that is negative, zero, or positive
4482** if the first string is less than, equal to, or greater than the second,
4483** respectively.  A collating function must always return the same answer
4484** given the same inputs.  If two or more collating functions are registered
4485** to the same collation name (using different eTextRep values) then all
4486** must give an equivalent answer when invoked with equivalent strings.
4487** The collating function must obey the following properties for all
4488** strings A, B, and C:
4489**
4490** <ol>
4491** <li> If A==B then B==A.
4492** <li> If A==B and B==C then A==C.
4493** <li> If A&lt;B THEN B&gt;A.
4494** <li> If A&lt;B and B&lt;C then A&lt;C.
4495** </ol>
4496**
4497** If a collating function fails any of the above constraints and that
4498** collating function is  registered and used, then the behavior of SQLite
4499** is undefined.
4500**
4501** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
4502** with the addition that the xDestroy callback is invoked on pArg when
4503** the collating function is deleted.
4504** ^Collating functions are deleted when they are overridden by later
4505** calls to the collation creation functions or when the
4506** [database connection] is closed using [sqlite3_close()].
4507**
4508** ^The xDestroy callback is <u>not</u> called if the
4509** sqlite3_create_collation_v2() function fails.  Applications that invoke
4510** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should
4511** check the return code and dispose of the application data pointer
4512** themselves rather than expecting SQLite to deal with it for them.
4513** This is different from every other SQLite interface.  The inconsistency
4514** is unfortunate but cannot be changed without breaking backwards
4515** compatibility.
4516**
4517** See also:  [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
4518*/
4519SQLITE_API int sqlite3_create_collation(
4520  sqlite3*,
4521  const char *zName,
4522  int eTextRep,
4523  void *pArg,
4524  int(*xCompare)(void*,int,const void*,int,const void*)
4525);
4526SQLITE_API int sqlite3_create_collation_v2(
4527  sqlite3*,
4528  const char *zName,
4529  int eTextRep,
4530  void *pArg,
4531  int(*xCompare)(void*,int,const void*,int,const void*),
4532  void(*xDestroy)(void*)
4533);
4534SQLITE_API int sqlite3_create_collation16(
4535  sqlite3*,
4536  const void *zName,
4537  int eTextRep,
4538  void *pArg,
4539  int(*xCompare)(void*,int,const void*,int,const void*)
4540);
4541
4542/*
4543** CAPI3REF: Collation Needed Callbacks
4544**
4545** ^To avoid having to register all collation sequences before a database
4546** can be used, a single callback function may be registered with the
4547** [database connection] to be invoked whenever an undefined collation
4548** sequence is required.
4549**
4550** ^If the function is registered using the sqlite3_collation_needed() API,
4551** then it is passed the names of undefined collation sequences as strings
4552** encoded in UTF-8. ^If sqlite3_collation_needed16() is used,
4553** the names are passed as UTF-16 in machine native byte order.
4554** ^A call to either function replaces the existing collation-needed callback.
4555**
4556** ^(When the callback is invoked, the first argument passed is a copy
4557** of the second argument to sqlite3_collation_needed() or
4558** sqlite3_collation_needed16().  The second argument is the database
4559** connection.  The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE],
4560** or [SQLITE_UTF16LE], indicating the most desirable form of the collation
4561** sequence function required.  The fourth parameter is the name of the
4562** required collation sequence.)^
4563**
4564** The callback function should register the desired collation using
4565** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
4566** [sqlite3_create_collation_v2()].
4567*/
4568SQLITE_API int sqlite3_collation_needed(
4569  sqlite3*,
4570  void*,
4571  void(*)(void*,sqlite3*,int eTextRep,const char*)
4572);
4573SQLITE_API int sqlite3_collation_needed16(
4574  sqlite3*,
4575  void*,
4576  void(*)(void*,sqlite3*,int eTextRep,const void*)
4577);
4578
4579#ifdef SQLITE_HAS_CODEC
4580/*
4581** Specify the key for an encrypted database.  This routine should be
4582** called right after sqlite3_open().
4583**
4584** The code to implement this API is not available in the public release
4585** of SQLite.
4586*/
4587SQLITE_API int sqlite3_key(
4588  sqlite3 *db,                   /* Database to be rekeyed */
4589  const void *pKey, int nKey     /* The key */
4590);
4591
4592/*
4593** Change the key on an open database.  If the current database is not
4594** encrypted, this routine will encrypt it.  If pNew==0 or nNew==0, the
4595** database is decrypted.
4596**
4597** The code to implement this API is not available in the public release
4598** of SQLite.
4599*/
4600SQLITE_API int sqlite3_rekey(
4601  sqlite3 *db,                   /* Database to be rekeyed */
4602  const void *pKey, int nKey     /* The new key */
4603);
4604
4605/*
4606** Specify the activation key for a SEE database.  Unless
4607** activated, none of the SEE routines will work.
4608*/
4609SQLITE_API void sqlite3_activate_see(
4610  const char *zPassPhrase        /* Activation phrase */
4611);
4612#endif
4613
4614#ifdef SQLITE_ENABLE_CEROD
4615/*
4616** Specify the activation key for a CEROD database.  Unless
4617** activated, none of the CEROD routines will work.
4618*/
4619SQLITE_API void sqlite3_activate_cerod(
4620  const char *zPassPhrase        /* Activation phrase */
4621);
4622#endif
4623
4624/*
4625** CAPI3REF: Suspend Execution For A Short Time
4626**
4627** The sqlite3_sleep() function causes the current thread to suspend execution
4628** for at least a number of milliseconds specified in its parameter.
4629**
4630** If the operating system does not support sleep requests with
4631** millisecond time resolution, then the time will be rounded up to
4632** the nearest second. The number of milliseconds of sleep actually
4633** requested from the operating system is returned.
4634**
4635** ^SQLite implements this interface by calling the xSleep()
4636** method of the default [sqlite3_vfs] object.  If the xSleep() method
4637** of the default VFS is not implemented correctly, or not implemented at
4638** all, then the behavior of sqlite3_sleep() may deviate from the description
4639** in the previous paragraphs.
4640*/
4641SQLITE_API int sqlite3_sleep(int);
4642
4643/*
4644** CAPI3REF: Name Of The Folder Holding Temporary Files
4645**
4646** ^(If this global variable is made to point to a string which is
4647** the name of a folder (a.k.a. directory), then all temporary files
4648** created by SQLite when using a built-in [sqlite3_vfs | VFS]
4649** will be placed in that directory.)^  ^If this variable
4650** is a NULL pointer, then SQLite performs a search for an appropriate
4651** temporary file directory.
4652**
4653** It is not safe to read or modify this variable in more than one
4654** thread at a time.  It is not safe to read or modify this variable
4655** if a [database connection] is being used at the same time in a separate
4656** thread.
4657** It is intended that this variable be set once
4658** as part of process initialization and before any SQLite interface
4659** routines have been called and that this variable remain unchanged
4660** thereafter.
4661**
4662** ^The [temp_store_directory pragma] may modify this variable and cause
4663** it to point to memory obtained from [sqlite3_malloc].  ^Furthermore,
4664** the [temp_store_directory pragma] always assumes that any string
4665** that this variable points to is held in memory obtained from
4666** [sqlite3_malloc] and the pragma may attempt to free that memory
4667** using [sqlite3_free].
4668** Hence, if this variable is modified directly, either it should be
4669** made NULL or made to point to memory obtained from [sqlite3_malloc]
4670** or else the use of the [temp_store_directory pragma] should be avoided.
4671*/
4672SQLITE_API char *sqlite3_temp_directory;
4673
4674/*
4675** CAPI3REF: Test For Auto-Commit Mode
4676** KEYWORDS: {autocommit mode}
4677**
4678** ^The sqlite3_get_autocommit() interface returns non-zero or
4679** zero if the given database connection is or is not in autocommit mode,
4680** respectively.  ^Autocommit mode is on by default.
4681** ^Autocommit mode is disabled by a [BEGIN] statement.
4682** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].
4683**
4684** If certain kinds of errors occur on a statement within a multi-statement
4685** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR],
4686** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the
4687** transaction might be rolled back automatically.  The only way to
4688** find out whether SQLite automatically rolled back the transaction after
4689** an error is to use this function.
4690**
4691** If another thread changes the autocommit status of the database
4692** connection while this routine is running, then the return value
4693** is undefined.
4694*/
4695SQLITE_API int sqlite3_get_autocommit(sqlite3*);
4696
4697/*
4698** CAPI3REF: Find The Database Handle Of A Prepared Statement
4699**
4700** ^The sqlite3_db_handle interface returns the [database connection] handle
4701** to which a [prepared statement] belongs.  ^The [database connection]
4702** returned by sqlite3_db_handle is the same [database connection]
4703** that was the first argument
4704** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
4705** create the statement in the first place.
4706*/
4707SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
4708
4709/*
4710** CAPI3REF: Find the next prepared statement
4711**
4712** ^This interface returns a pointer to the next [prepared statement] after
4713** pStmt associated with the [database connection] pDb.  ^If pStmt is NULL
4714** then this interface returns a pointer to the first prepared statement
4715** associated with the database connection pDb.  ^If no prepared statement
4716** satisfies the conditions of this routine, it returns NULL.
4717**
4718** The [database connection] pointer D in a call to
4719** [sqlite3_next_stmt(D,S)] must refer to an open database
4720** connection and in particular must not be a NULL pointer.
4721*/
4722SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
4723
4724/*
4725** CAPI3REF: Commit And Rollback Notification Callbacks
4726**
4727** ^The sqlite3_commit_hook() interface registers a callback
4728** function to be invoked whenever a transaction is [COMMIT | committed].
4729** ^Any callback set by a previous call to sqlite3_commit_hook()
4730** for the same database connection is overridden.
4731** ^The sqlite3_rollback_hook() interface registers a callback
4732** function to be invoked whenever a transaction is [ROLLBACK | rolled back].
4733** ^Any callback set by a previous call to sqlite3_rollback_hook()
4734** for the same database connection is overridden.
4735** ^The pArg argument is passed through to the callback.
4736** ^If the callback on a commit hook function returns non-zero,
4737** then the commit is converted into a rollback.
4738**
4739** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions
4740** return the P argument from the previous call of the same function
4741** on the same [database connection] D, or NULL for
4742** the first call for each function on D.
4743**
4744** The callback implementation must not do anything that will modify
4745** the database connection that invoked the callback.  Any actions
4746** to modify the database connection must be deferred until after the
4747** completion of the [sqlite3_step()] call that triggered the commit
4748** or rollback hook in the first place.
4749** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
4750** database connections for the meaning of "modify" in this paragraph.
4751**
4752** ^Registering a NULL function disables the callback.
4753**
4754** ^When the commit hook callback routine returns zero, the [COMMIT]
4755** operation is allowed to continue normally.  ^If the commit hook
4756** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK].
4757** ^The rollback hook is invoked on a rollback that results from a commit
4758** hook returning non-zero, just as it would be with any other rollback.
4759**
4760** ^For the purposes of this API, a transaction is said to have been
4761** rolled back if an explicit "ROLLBACK" statement is executed, or
4762** an error or constraint causes an implicit rollback to occur.
4763** ^The rollback callback is not invoked if a transaction is
4764** automatically rolled back because the database connection is closed.
4765**
4766** See also the [sqlite3_update_hook()] interface.
4767*/
4768SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
4769SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
4770
4771/*
4772** CAPI3REF: Data Change Notification Callbacks
4773**
4774** ^The sqlite3_update_hook() interface registers a callback function
4775** with the [database connection] identified by the first argument
4776** to be invoked whenever a row is updated, inserted or deleted.
4777** ^Any callback set by a previous call to this function
4778** for the same database connection is overridden.
4779**
4780** ^The second argument is a pointer to the function to invoke when a
4781** row is updated, inserted or deleted.
4782** ^The first argument to the callback is a copy of the third argument
4783** to sqlite3_update_hook().
4784** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
4785** or [SQLITE_UPDATE], depending on the operation that caused the callback
4786** to be invoked.
4787** ^The third and fourth arguments to the callback contain pointers to the
4788** database and table name containing the affected row.
4789** ^The final callback parameter is the [rowid] of the row.
4790** ^In the case of an update, this is the [rowid] after the update takes place.
4791**
4792** ^(The update hook is not invoked when internal system tables are
4793** modified (i.e. sqlite_master and sqlite_sequence).)^
4794**
4795** ^In the current implementation, the update hook
4796** is not invoked when duplication rows are deleted because of an
4797** [ON CONFLICT | ON CONFLICT REPLACE] clause.  ^Nor is the update hook
4798** invoked when rows are deleted using the [truncate optimization].
4799** The exceptions defined in this paragraph might change in a future
4800** release of SQLite.
4801**
4802** The update hook implementation must not do anything that will modify
4803** the database connection that invoked the update hook.  Any actions
4804** to modify the database connection must be deferred until after the
4805** completion of the [sqlite3_step()] call that triggered the update hook.
4806** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
4807** database connections for the meaning of "modify" in this paragraph.
4808**
4809** ^The sqlite3_update_hook(D,C,P) function
4810** returns the P argument from the previous call
4811** on the same [database connection] D, or NULL for
4812** the first call on D.
4813**
4814** See also the [sqlite3_commit_hook()] and [sqlite3_rollback_hook()]
4815** interfaces.
4816*/
4817SQLITE_API void *sqlite3_update_hook(
4818  sqlite3*,
4819  void(*)(void *,int ,char const *,char const *,sqlite3_int64),
4820  void*
4821);
4822
4823/*
4824** CAPI3REF: Enable Or Disable Shared Pager Cache
4825** KEYWORDS: {shared cache}
4826**
4827** ^(This routine enables or disables the sharing of the database cache
4828** and schema data structures between [database connection | connections]
4829** to the same database. Sharing is enabled if the argument is true
4830** and disabled if the argument is false.)^
4831**
4832** ^Cache sharing is enabled and disabled for an entire process.
4833** This is a change as of SQLite version 3.5.0. In prior versions of SQLite,
4834** sharing was enabled or disabled for each thread separately.
4835**
4836** ^(The cache sharing mode set by this interface effects all subsequent
4837** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
4838** Existing database connections continue use the sharing mode
4839** that was in effect at the time they were opened.)^
4840**
4841** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled
4842** successfully.  An [error code] is returned otherwise.)^
4843**
4844** ^Shared cache is disabled by default. But this might change in
4845** future releases of SQLite.  Applications that care about shared
4846** cache setting should set it explicitly.
4847**
4848** See Also:  [SQLite Shared-Cache Mode]
4849*/
4850SQLITE_API int sqlite3_enable_shared_cache(int);
4851
4852/*
4853** CAPI3REF: Attempt To Free Heap Memory
4854**
4855** ^The sqlite3_release_memory() interface attempts to free N bytes
4856** of heap memory by deallocating non-essential memory allocations
4857** held by the database library.   Memory used to cache database
4858** pages to improve performance is an example of non-essential memory.
4859** ^sqlite3_release_memory() returns the number of bytes actually freed,
4860** which might be more or less than the amount requested.
4861** ^The sqlite3_release_memory() routine is a no-op returning zero
4862** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT].
4863*/
4864SQLITE_API int sqlite3_release_memory(int);
4865
4866/*
4867** CAPI3REF: Impose A Limit On Heap Size
4868**
4869** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
4870** soft limit on the amount of heap memory that may be allocated by SQLite.
4871** ^SQLite strives to keep heap memory utilization below the soft heap
4872** limit by reducing the number of pages held in the page cache
4873** as heap memory usages approaches the limit.
4874** ^The soft heap limit is "soft" because even though SQLite strives to stay
4875** below the limit, it will exceed the limit rather than generate
4876** an [SQLITE_NOMEM] error.  In other words, the soft heap limit
4877** is advisory only.
4878**
4879** ^The return value from sqlite3_soft_heap_limit64() is the size of
4880** the soft heap limit prior to the call.  ^If the argument N is negative
4881** then no change is made to the soft heap limit.  Hence, the current
4882** size of the soft heap limit can be determined by invoking
4883** sqlite3_soft_heap_limit64() with a negative argument.
4884**
4885** ^If the argument N is zero then the soft heap limit is disabled.
4886**
4887** ^(The soft heap limit is not enforced in the current implementation
4888** if one or more of following conditions are true:
4889**
4890** <ul>
4891** <li> The soft heap limit is set to zero.
4892** <li> Memory accounting is disabled using a combination of the
4893**      [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and
4894**      the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.
4895** <li> An alternative page cache implementation is specified using
4896**      [sqlite3_config]([SQLITE_CONFIG_PCACHE],...).
4897** <li> The page cache allocates from its own memory pool supplied
4898**      by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
4899**      from the heap.
4900** </ul>)^
4901**
4902** Beginning with SQLite version 3.7.3, the soft heap limit is enforced
4903** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT]
4904** compile-time option is invoked.  With [SQLITE_ENABLE_MEMORY_MANAGEMENT],
4905** the soft heap limit is enforced on every memory allocation.  Without
4906** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced
4907** when memory is allocated by the page cache.  Testing suggests that because
4908** the page cache is the predominate memory user in SQLite, most
4909** applications will achieve adequate soft heap limit enforcement without
4910** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT].
4911**
4912** The circumstances under which SQLite will enforce the soft heap limit may
4913** changes in future releases of SQLite.
4914*/
4915SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
4916
4917/*
4918** CAPI3REF: Deprecated Soft Heap Limit Interface
4919** DEPRECATED
4920**
4921** This is a deprecated version of the [sqlite3_soft_heap_limit64()]
4922** interface.  This routine is provided for historical compatibility
4923** only.  All new applications should use the
4924** [sqlite3_soft_heap_limit64()] interface rather than this one.
4925*/
4926SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N);
4927
4928
4929/*
4930** CAPI3REF: Extract Metadata About A Column Of A Table
4931**
4932** ^This routine returns metadata about a specific column of a specific
4933** database table accessible using the [database connection] handle
4934** passed as the first function argument.
4935**
4936** ^The column is identified by the second, third and fourth parameters to
4937** this function. ^The second parameter is either the name of the database
4938** (i.e. "main", "temp", or an attached database) containing the specified
4939** table or NULL. ^If it is NULL, then all attached databases are searched
4940** for the table using the same algorithm used by the database engine to
4941** resolve unqualified table references.
4942**
4943** ^The third and fourth parameters to this function are the table and column
4944** name of the desired column, respectively. Neither of these parameters
4945** may be NULL.
4946**
4947** ^Metadata is returned by writing to the memory locations passed as the 5th
4948** and subsequent parameters to this function. ^Any of these arguments may be
4949** NULL, in which case the corresponding element of metadata is omitted.
4950**
4951** ^(<blockquote>
4952** <table border="1">
4953** <tr><th> Parameter <th> Output<br>Type <th>  Description
4954**
4955** <tr><td> 5th <td> const char* <td> Data type
4956** <tr><td> 6th <td> const char* <td> Name of default collation sequence
4957** <tr><td> 7th <td> int         <td> True if column has a NOT NULL constraint
4958** <tr><td> 8th <td> int         <td> True if column is part of the PRIMARY KEY
4959** <tr><td> 9th <td> int         <td> True if column is [AUTOINCREMENT]
4960** </table>
4961** </blockquote>)^
4962**
4963** ^The memory pointed to by the character pointers returned for the
4964** declaration type and collation sequence is valid only until the next
4965** call to any SQLite API function.
4966**
4967** ^If the specified table is actually a view, an [error code] is returned.
4968**
4969** ^If the specified column is "rowid", "oid" or "_rowid_" and an
4970** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
4971** parameters are set for the explicitly declared column. ^(If there is no
4972** explicitly declared [INTEGER PRIMARY KEY] column, then the output
4973** parameters are set as follows:
4974**
4975** <pre>
4976**     data type: "INTEGER"
4977**     collation sequence: "BINARY"
4978**     not null: 0
4979**     primary key: 1
4980**     auto increment: 0
4981** </pre>)^
4982**
4983** ^(This function may load one or more schemas from database files. If an
4984** error occurs during this process, or if the requested table or column
4985** cannot be found, an [error code] is returned and an error message left
4986** in the [database connection] (to be retrieved using sqlite3_errmsg()).)^
4987**
4988** ^This API is only available if the library was compiled with the
4989** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
4990*/
4991SQLITE_API int sqlite3_table_column_metadata(
4992  sqlite3 *db,                /* Connection handle */
4993  const char *zDbName,        /* Database name or NULL */
4994  const char *zTableName,     /* Table name */
4995  const char *zColumnName,    /* Column name */
4996  char const **pzDataType,    /* OUTPUT: Declared data type */
4997  char const **pzCollSeq,     /* OUTPUT: Collation sequence name */
4998  int *pNotNull,              /* OUTPUT: True if NOT NULL constraint exists */
4999  int *pPrimaryKey,           /* OUTPUT: True if column part of PK */
5000  int *pAutoinc               /* OUTPUT: True if column is auto-increment */
5001);
5002
5003/*
5004** CAPI3REF: Load An Extension
5005**
5006** ^This interface loads an SQLite extension library from the named file.
5007**
5008** ^The sqlite3_load_extension() interface attempts to load an
5009** SQLite extension library contained in the file zFile.
5010**
5011** ^The entry point is zProc.
5012** ^zProc may be 0, in which case the name of the entry point
5013** defaults to "sqlite3_extension_init".
5014** ^The sqlite3_load_extension() interface returns
5015** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
5016** ^If an error occurs and pzErrMsg is not 0, then the
5017** [sqlite3_load_extension()] interface shall attempt to
5018** fill *pzErrMsg with error message text stored in memory
5019** obtained from [sqlite3_malloc()]. The calling function
5020** should free this memory by calling [sqlite3_free()].
5021**
5022** ^Extension loading must be enabled using
5023** [sqlite3_enable_load_extension()] prior to calling this API,
5024** otherwise an error will be returned.
5025**
5026** See also the [load_extension() SQL function].
5027*/
5028SQLITE_API int sqlite3_load_extension(
5029  sqlite3 *db,          /* Load the extension into this database connection */
5030  const char *zFile,    /* Name of the shared library containing extension */
5031  const char *zProc,    /* Entry point.  Derived from zFile if 0 */
5032  char **pzErrMsg       /* Put error message here if not 0 */
5033);
5034
5035/*
5036** CAPI3REF: Enable Or Disable Extension Loading
5037**
5038** ^So as not to open security holes in older applications that are
5039** unprepared to deal with extension loading, and as a means of disabling
5040** extension loading while evaluating user-entered SQL, the following API
5041** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
5042**
5043** ^Extension loading is off by default. See ticket #1863.
5044** ^Call the sqlite3_enable_load_extension() routine with onoff==1
5045** to turn extension loading on and call it with onoff==0 to turn
5046** it back off again.
5047*/
5048SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
5049
5050/*
5051** CAPI3REF: Automatically Load Statically Linked Extensions
5052**
5053** ^This interface causes the xEntryPoint() function to be invoked for
5054** each new [database connection] that is created.  The idea here is that
5055** xEntryPoint() is the entry point for a statically linked SQLite extension
5056** that is to be automatically loaded into all new database connections.
5057**
5058** ^(Even though the function prototype shows that xEntryPoint() takes
5059** no arguments and returns void, SQLite invokes xEntryPoint() with three
5060** arguments and expects and integer result as if the signature of the
5061** entry point where as follows:
5062**
5063** <blockquote><pre>
5064** &nbsp;  int xEntryPoint(
5065** &nbsp;    sqlite3 *db,
5066** &nbsp;    const char **pzErrMsg,
5067** &nbsp;    const struct sqlite3_api_routines *pThunk
5068** &nbsp;  );
5069** </pre></blockquote>)^
5070**
5071** If the xEntryPoint routine encounters an error, it should make *pzErrMsg
5072** point to an appropriate error message (obtained from [sqlite3_mprintf()])
5073** and return an appropriate [error code].  ^SQLite ensures that *pzErrMsg
5074** is NULL before calling the xEntryPoint().  ^SQLite will invoke
5075** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns.  ^If any
5076** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()],
5077** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail.
5078**
5079** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
5080** on the list of automatic extensions is a harmless no-op. ^No entry point
5081** will be called more than once for each database connection that is opened.
5082**
5083** See also: [sqlite3_reset_auto_extension()].
5084*/
5085SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void));
5086
5087/*
5088** CAPI3REF: Reset Automatic Extension Loading
5089**
5090** ^This interface disables all automatic extensions previously
5091** registered using [sqlite3_auto_extension()].
5092*/
5093SQLITE_API void sqlite3_reset_auto_extension(void);
5094
5095/*
5096** The interface to the virtual-table mechanism is currently considered
5097** to be experimental.  The interface might change in incompatible ways.
5098** If this is a problem for you, do not use the interface at this time.
5099**
5100** When the virtual-table mechanism stabilizes, we will declare the
5101** interface fixed, support it indefinitely, and remove this comment.
5102*/
5103
5104/*
5105** Structures used by the virtual table interface
5106*/
5107typedef struct sqlite3_vtab sqlite3_vtab;
5108typedef struct sqlite3_index_info sqlite3_index_info;
5109typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;
5110typedef struct sqlite3_module sqlite3_module;
5111
5112/*
5113** CAPI3REF: Virtual Table Object
5114** KEYWORDS: sqlite3_module {virtual table module}
5115**
5116** This structure, sometimes called a "virtual table module",
5117** defines the implementation of a [virtual tables].
5118** This structure consists mostly of methods for the module.
5119**
5120** ^A virtual table module is created by filling in a persistent
5121** instance of this structure and passing a pointer to that instance
5122** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].
5123** ^The registration remains valid until it is replaced by a different
5124** module or until the [database connection] closes.  The content
5125** of this structure must not change while it is registered with
5126** any database connection.
5127*/
5128struct sqlite3_module {
5129  int iVersion;
5130  int (*xCreate)(sqlite3*, void *pAux,
5131               int argc, const char *const*argv,
5132               sqlite3_vtab **ppVTab, char**);
5133  int (*xConnect)(sqlite3*, void *pAux,
5134               int argc, const char *const*argv,
5135               sqlite3_vtab **ppVTab, char**);
5136  int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
5137  int (*xDisconnect)(sqlite3_vtab *pVTab);
5138  int (*xDestroy)(sqlite3_vtab *pVTab);
5139  int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);
5140  int (*xClose)(sqlite3_vtab_cursor*);
5141  int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
5142                int argc, sqlite3_value **argv);
5143  int (*xNext)(sqlite3_vtab_cursor*);
5144  int (*xEof)(sqlite3_vtab_cursor*);
5145  int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int);
5146  int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid);
5147  int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *);
5148  int (*xBegin)(sqlite3_vtab *pVTab);
5149  int (*xSync)(sqlite3_vtab *pVTab);
5150  int (*xCommit)(sqlite3_vtab *pVTab);
5151  int (*xRollback)(sqlite3_vtab *pVTab);
5152  int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
5153                       void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
5154                       void **ppArg);
5155  int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
5156};
5157
5158/*
5159** CAPI3REF: Virtual Table Indexing Information
5160** KEYWORDS: sqlite3_index_info
5161**
5162** The sqlite3_index_info structure and its substructures is used as part
5163** of the [virtual table] interface to
5164** pass information into and receive the reply from the [xBestIndex]
5165** method of a [virtual table module].  The fields under **Inputs** are the
5166** inputs to xBestIndex and are read-only.  xBestIndex inserts its
5167** results into the **Outputs** fields.
5168**
5169** ^(The aConstraint[] array records WHERE clause constraints of the form:
5170**
5171** <blockquote>column OP expr</blockquote>
5172**
5173** where OP is =, &lt;, &lt;=, &gt;, or &gt;=.)^  ^(The particular operator is
5174** stored in aConstraint[].op using one of the
5175** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^
5176** ^(The index of the column is stored in
5177** aConstraint[].iColumn.)^  ^(aConstraint[].usable is TRUE if the
5178** expr on the right-hand side can be evaluated (and thus the constraint
5179** is usable) and false if it cannot.)^
5180**
5181** ^The optimizer automatically inverts terms of the form "expr OP column"
5182** and makes other simplifications to the WHERE clause in an attempt to
5183** get as many WHERE clause terms into the form shown above as possible.
5184** ^The aConstraint[] array only reports WHERE clause terms that are
5185** relevant to the particular virtual table being queried.
5186**
5187** ^Information about the ORDER BY clause is stored in aOrderBy[].
5188** ^Each term of aOrderBy records a column of the ORDER BY clause.
5189**
5190** The [xBestIndex] method must fill aConstraintUsage[] with information
5191** about what parameters to pass to xFilter.  ^If argvIndex>0 then
5192** the right-hand side of the corresponding aConstraint[] is evaluated
5193** and becomes the argvIndex-th entry in argv.  ^(If aConstraintUsage[].omit
5194** is true, then the constraint is assumed to be fully handled by the
5195** virtual table and is not checked again by SQLite.)^
5196**
5197** ^The idxNum and idxPtr values are recorded and passed into the
5198** [xFilter] method.
5199** ^[sqlite3_free()] is used to free idxPtr if and only if
5200** needToFreeIdxPtr is true.
5201**
5202** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
5203** the correct order to satisfy the ORDER BY clause so that no separate
5204** sorting step is required.
5205**
5206** ^The estimatedCost value is an estimate of the cost of doing the
5207** particular lookup.  A full scan of a table with N entries should have
5208** a cost of N.  A binary search of a table of N entries should have a
5209** cost of approximately log(N).
5210*/
5211struct sqlite3_index_info {
5212  /* Inputs */
5213  int nConstraint;           /* Number of entries in aConstraint */
5214  struct sqlite3_index_constraint {
5215     int iColumn;              /* Column on left-hand side of constraint */
5216     unsigned char op;         /* Constraint operator */
5217     unsigned char usable;     /* True if this constraint is usable */
5218     int iTermOffset;          /* Used internally - xBestIndex should ignore */
5219  } *aConstraint;            /* Table of WHERE clause constraints */
5220  int nOrderBy;              /* Number of terms in the ORDER BY clause */
5221  struct sqlite3_index_orderby {
5222     int iColumn;              /* Column number */
5223     unsigned char desc;       /* True for DESC.  False for ASC. */
5224  } *aOrderBy;               /* The ORDER BY clause */
5225  /* Outputs */
5226  struct sqlite3_index_constraint_usage {
5227    int argvIndex;           /* if >0, constraint is part of argv to xFilter */
5228    unsigned char omit;      /* Do not code a test for this constraint */
5229  } *aConstraintUsage;
5230  int idxNum;                /* Number used to identify the index */
5231  char *idxStr;              /* String, possibly obtained from sqlite3_malloc */
5232  int needToFreeIdxStr;      /* Free idxStr using sqlite3_free() if true */
5233  int orderByConsumed;       /* True if output is already ordered */
5234  double estimatedCost;      /* Estimated cost of using this index */
5235};
5236
5237/*
5238** CAPI3REF: Virtual Table Constraint Operator Codes
5239**
5240** These macros defined the allowed values for the
5241** [sqlite3_index_info].aConstraint[].op field.  Each value represents
5242** an operator that is part of a constraint term in the wHERE clause of
5243** a query that uses a [virtual table].
5244*/
5245#define SQLITE_INDEX_CONSTRAINT_EQ    2
5246#define SQLITE_INDEX_CONSTRAINT_GT    4
5247#define SQLITE_INDEX_CONSTRAINT_LE    8
5248#define SQLITE_INDEX_CONSTRAINT_LT    16
5249#define SQLITE_INDEX_CONSTRAINT_GE    32
5250#define SQLITE_INDEX_CONSTRAINT_MATCH 64
5251
5252/*
5253** CAPI3REF: Register A Virtual Table Implementation
5254**
5255** ^These routines are used to register a new [virtual table module] name.
5256** ^Module names must be registered before
5257** creating a new [virtual table] using the module and before using a
5258** preexisting [virtual table] for the module.
5259**
5260** ^The module name is registered on the [database connection] specified
5261** by the first parameter.  ^The name of the module is given by the
5262** second parameter.  ^The third parameter is a pointer to
5263** the implementation of the [virtual table module].   ^The fourth
5264** parameter is an arbitrary client data pointer that is passed through
5265** into the [xCreate] and [xConnect] methods of the virtual table module
5266** when a new virtual table is be being created or reinitialized.
5267**
5268** ^The sqlite3_create_module_v2() interface has a fifth parameter which
5269** is a pointer to a destructor for the pClientData.  ^SQLite will
5270** invoke the destructor function (if it is not NULL) when SQLite
5271** no longer needs the pClientData pointer.  ^The destructor will also
5272** be invoked if the call to sqlite3_create_module_v2() fails.
5273** ^The sqlite3_create_module()
5274** interface is equivalent to sqlite3_create_module_v2() with a NULL
5275** destructor.
5276*/
5277SQLITE_API int sqlite3_create_module(
5278  sqlite3 *db,               /* SQLite connection to register module with */
5279  const char *zName,         /* Name of the module */
5280  const sqlite3_module *p,   /* Methods for the module */
5281  void *pClientData          /* Client data for xCreate/xConnect */
5282);
5283SQLITE_API int sqlite3_create_module_v2(
5284  sqlite3 *db,               /* SQLite connection to register module with */
5285  const char *zName,         /* Name of the module */
5286  const sqlite3_module *p,   /* Methods for the module */
5287  void *pClientData,         /* Client data for xCreate/xConnect */
5288  void(*xDestroy)(void*)     /* Module destructor function */
5289);
5290
5291/*
5292** CAPI3REF: Virtual Table Instance Object
5293** KEYWORDS: sqlite3_vtab
5294**
5295** Every [virtual table module] implementation uses a subclass
5296** of this object to describe a particular instance
5297** of the [virtual table].  Each subclass will
5298** be tailored to the specific needs of the module implementation.
5299** The purpose of this superclass is to define certain fields that are
5300** common to all module implementations.
5301**
5302** ^Virtual tables methods can set an error message by assigning a
5303** string obtained from [sqlite3_mprintf()] to zErrMsg.  The method should
5304** take care that any prior string is freed by a call to [sqlite3_free()]
5305** prior to assigning a new string to zErrMsg.  ^After the error message
5306** is delivered up to the client application, the string will be automatically
5307** freed by sqlite3_free() and the zErrMsg field will be zeroed.
5308*/
5309struct sqlite3_vtab {
5310  const sqlite3_module *pModule;  /* The module for this virtual table */
5311  int nRef;                       /* NO LONGER USED */
5312  char *zErrMsg;                  /* Error message from sqlite3_mprintf() */
5313  /* Virtual table implementations will typically add additional fields */
5314};
5315
5316/*
5317** CAPI3REF: Virtual Table Cursor Object
5318** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
5319**
5320** Every [virtual table module] implementation uses a subclass of the
5321** following structure to describe cursors that point into the
5322** [virtual table] and are used
5323** to loop through the virtual table.  Cursors are created using the
5324** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed
5325** by the [sqlite3_module.xClose | xClose] method.  Cursors are used
5326** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods
5327** of the module.  Each module implementation will define
5328** the content of a cursor structure to suit its own needs.
5329**
5330** This superclass exists in order to define fields of the cursor that
5331** are common to all implementations.
5332*/
5333struct sqlite3_vtab_cursor {
5334  sqlite3_vtab *pVtab;      /* Virtual table of this cursor */
5335  /* Virtual table implementations will typically add additional fields */
5336};
5337
5338/*
5339** CAPI3REF: Declare The Schema Of A Virtual Table
5340**
5341** ^The [xCreate] and [xConnect] methods of a
5342** [virtual table module] call this interface
5343** to declare the format (the names and datatypes of the columns) of
5344** the virtual tables they implement.
5345*/
5346SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
5347
5348/*
5349** CAPI3REF: Overload A Function For A Virtual Table
5350**
5351** ^(Virtual tables can provide alternative implementations of functions
5352** using the [xFindFunction] method of the [virtual table module].
5353** But global versions of those functions
5354** must exist in order to be overloaded.)^
5355**
5356** ^(This API makes sure a global version of a function with a particular
5357** name and number of parameters exists.  If no such function exists
5358** before this API is called, a new function is created.)^  ^The implementation
5359** of the new function always causes an exception to be thrown.  So
5360** the new function is not good for anything by itself.  Its only
5361** purpose is to be a placeholder function that can be overloaded
5362** by a [virtual table].
5363*/
5364SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
5365
5366/*
5367** The interface to the virtual-table mechanism defined above (back up
5368** to a comment remarkably similar to this one) is currently considered
5369** to be experimental.  The interface might change in incompatible ways.
5370** If this is a problem for you, do not use the interface at this time.
5371**
5372** When the virtual-table mechanism stabilizes, we will declare the
5373** interface fixed, support it indefinitely, and remove this comment.
5374*/
5375
5376/*
5377** CAPI3REF: A Handle To An Open BLOB
5378** KEYWORDS: {BLOB handle} {BLOB handles}
5379**
5380** An instance of this object represents an open BLOB on which
5381** [sqlite3_blob_open | incremental BLOB I/O] can be performed.
5382** ^Objects of this type are created by [sqlite3_blob_open()]
5383** and destroyed by [sqlite3_blob_close()].
5384** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces
5385** can be used to read or write small subsections of the BLOB.
5386** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes.
5387*/
5388typedef struct sqlite3_blob sqlite3_blob;
5389
5390/*
5391** CAPI3REF: Open A BLOB For Incremental I/O
5392**
5393** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
5394** in row iRow, column zColumn, table zTable in database zDb;
5395** in other words, the same BLOB that would be selected by:
5396**
5397** <pre>
5398**     SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
5399** </pre>)^
5400**
5401** ^If the flags parameter is non-zero, then the BLOB is opened for read
5402** and write access. ^If it is zero, the BLOB is opened for read access.
5403** ^It is not possible to open a column that is part of an index or primary
5404** key for writing. ^If [foreign key constraints] are enabled, it is
5405** not possible to open a column that is part of a [child key] for writing.
5406**
5407** ^Note that the database name is not the filename that contains
5408** the database but rather the symbolic name of the database that
5409** appears after the AS keyword when the database is connected using [ATTACH].
5410** ^For the main database file, the database name is "main".
5411** ^For TEMP tables, the database name is "temp".
5412**
5413** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written
5414** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set
5415** to be a null pointer.)^
5416** ^This function sets the [database connection] error code and message
5417** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related
5418** functions. ^Note that the *ppBlob variable is always initialized in a
5419** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob
5420** regardless of the success or failure of this routine.
5421**
5422** ^(If the row that a BLOB handle points to is modified by an
5423** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
5424** then the BLOB handle is marked as "expired".
5425** This is true if any column of the row is changed, even a column
5426** other than the one the BLOB handle is open on.)^
5427** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for
5428** an expired BLOB handle fail with a return code of [SQLITE_ABORT].
5429** ^(Changes written into a BLOB prior to the BLOB expiring are not
5430** rolled back by the expiration of the BLOB.  Such changes will eventually
5431** commit if the transaction continues to completion.)^
5432**
5433** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
5434** the opened blob.  ^The size of a blob may not be changed by this
5435** interface.  Use the [UPDATE] SQL command to change the size of a
5436** blob.
5437**
5438** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
5439** and the built-in [zeroblob] SQL function can be used, if desired,
5440** to create an empty, zero-filled blob in which to read or write using
5441** this interface.
5442**
5443** To avoid a resource leak, every open [BLOB handle] should eventually
5444** be released by a call to [sqlite3_blob_close()].
5445*/
5446SQLITE_API int sqlite3_blob_open(
5447  sqlite3*,
5448  const char *zDb,
5449  const char *zTable,
5450  const char *zColumn,
5451  sqlite3_int64 iRow,
5452  int flags,
5453  sqlite3_blob **ppBlob
5454);
5455
5456/*
5457** CAPI3REF: Move a BLOB Handle to a New Row
5458**
5459** ^This function is used to move an existing blob handle so that it points
5460** to a different row of the same database table. ^The new row is identified
5461** by the rowid value passed as the second argument. Only the row can be
5462** changed. ^The database, table and column on which the blob handle is open
5463** remain the same. Moving an existing blob handle to a new row can be
5464** faster than closing the existing handle and opening a new one.
5465**
5466** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] -
5467** it must exist and there must be either a blob or text value stored in
5468** the nominated column.)^ ^If the new row is not present in the table, or if
5469** it does not contain a blob or text value, or if another error occurs, an
5470** SQLite error code is returned and the blob handle is considered aborted.
5471** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or
5472** [sqlite3_blob_reopen()] on an aborted blob handle immediately return
5473** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle
5474** always returns zero.
5475**
5476** ^This function sets the database handle error code and message.
5477*/
5478SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
5479
5480/*
5481** CAPI3REF: Close A BLOB Handle
5482**
5483** ^Closes an open [BLOB handle].
5484**
5485** ^Closing a BLOB shall cause the current transaction to commit
5486** if there are no other BLOBs, no pending prepared statements, and the
5487** database connection is in [autocommit mode].
5488** ^If any writes were made to the BLOB, they might be held in cache
5489** until the close operation if they will fit.
5490**
5491** ^(Closing the BLOB often forces the changes
5492** out to disk and so if any I/O errors occur, they will likely occur
5493** at the time when the BLOB is closed.  Any errors that occur during
5494** closing are reported as a non-zero return value.)^
5495**
5496** ^(The BLOB is closed unconditionally.  Even if this routine returns
5497** an error code, the BLOB is still closed.)^
5498**
5499** ^Calling this routine with a null pointer (such as would be returned
5500** by a failed call to [sqlite3_blob_open()]) is a harmless no-op.
5501*/
5502SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
5503
5504/*
5505** CAPI3REF: Return The Size Of An Open BLOB
5506**
5507** ^Returns the size in bytes of the BLOB accessible via the
5508** successfully opened [BLOB handle] in its only argument.  ^The
5509** incremental blob I/O routines can only read or overwriting existing
5510** blob content; they cannot change the size of a blob.
5511**
5512** This routine only works on a [BLOB handle] which has been created
5513** by a prior successful call to [sqlite3_blob_open()] and which has not
5514** been closed by [sqlite3_blob_close()].  Passing any other pointer in
5515** to this routine results in undefined and probably undesirable behavior.
5516*/
5517SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *);
5518
5519/*
5520** CAPI3REF: Read Data From A BLOB Incrementally
5521**
5522** ^(This function is used to read data from an open [BLOB handle] into a
5523** caller-supplied buffer. N bytes of data are copied into buffer Z
5524** from the open BLOB, starting at offset iOffset.)^
5525**
5526** ^If offset iOffset is less than N bytes from the end of the BLOB,
5527** [SQLITE_ERROR] is returned and no data is read.  ^If N or iOffset is
5528** less than zero, [SQLITE_ERROR] is returned and no data is read.
5529** ^The size of the blob (and hence the maximum value of N+iOffset)
5530** can be determined using the [sqlite3_blob_bytes()] interface.
5531**
5532** ^An attempt to read from an expired [BLOB handle] fails with an
5533** error code of [SQLITE_ABORT].
5534**
5535** ^(On success, sqlite3_blob_read() returns SQLITE_OK.
5536** Otherwise, an [error code] or an [extended error code] is returned.)^
5537**
5538** This routine only works on a [BLOB handle] which has been created
5539** by a prior successful call to [sqlite3_blob_open()] and which has not
5540** been closed by [sqlite3_blob_close()].  Passing any other pointer in
5541** to this routine results in undefined and probably undesirable behavior.
5542**
5543** See also: [sqlite3_blob_write()].
5544*/
5545SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
5546
5547/*
5548** CAPI3REF: Write Data Into A BLOB Incrementally
5549**
5550** ^This function is used to write data into an open [BLOB handle] from a
5551** caller-supplied buffer. ^N bytes of data are copied from the buffer Z
5552** into the open BLOB, starting at offset iOffset.
5553**
5554** ^If the [BLOB handle] passed as the first argument was not opened for
5555** writing (the flags parameter to [sqlite3_blob_open()] was zero),
5556** this function returns [SQLITE_READONLY].
5557**
5558** ^This function may only modify the contents of the BLOB; it is
5559** not possible to increase the size of a BLOB using this API.
5560** ^If offset iOffset is less than N bytes from the end of the BLOB,
5561** [SQLITE_ERROR] is returned and no data is written.  ^If N is
5562** less than zero [SQLITE_ERROR] is returned and no data is written.
5563** The size of the BLOB (and hence the maximum value of N+iOffset)
5564** can be determined using the [sqlite3_blob_bytes()] interface.
5565**
5566** ^An attempt to write to an expired [BLOB handle] fails with an
5567** error code of [SQLITE_ABORT].  ^Writes to the BLOB that occurred
5568** before the [BLOB handle] expired are not rolled back by the
5569** expiration of the handle, though of course those changes might
5570** have been overwritten by the statement that expired the BLOB handle
5571** or by other independent statements.
5572**
5573** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
5574** Otherwise, an  [error code] or an [extended error code] is returned.)^
5575**
5576** This routine only works on a [BLOB handle] which has been created
5577** by a prior successful call to [sqlite3_blob_open()] and which has not
5578** been closed by [sqlite3_blob_close()].  Passing any other pointer in
5579** to this routine results in undefined and probably undesirable behavior.
5580**
5581** See also: [sqlite3_blob_read()].
5582*/
5583SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
5584
5585/*
5586** CAPI3REF: Virtual File System Objects
5587**
5588** A virtual filesystem (VFS) is an [sqlite3_vfs] object
5589** that SQLite uses to interact
5590** with the underlying operating system.  Most SQLite builds come with a
5591** single default VFS that is appropriate for the host computer.
5592** New VFSes can be registered and existing VFSes can be unregistered.
5593** The following interfaces are provided.
5594**
5595** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name.
5596** ^Names are case sensitive.
5597** ^Names are zero-terminated UTF-8 strings.
5598** ^If there is no match, a NULL pointer is returned.
5599** ^If zVfsName is NULL then the default VFS is returned.
5600**
5601** ^New VFSes are registered with sqlite3_vfs_register().
5602** ^Each new VFS becomes the default VFS if the makeDflt flag is set.
5603** ^The same VFS can be registered multiple times without injury.
5604** ^To make an existing VFS into the default VFS, register it again
5605** with the makeDflt flag set.  If two different VFSes with the
5606** same name are registered, the behavior is undefined.  If a
5607** VFS is registered with a name that is NULL or an empty string,
5608** then the behavior is undefined.
5609**
5610** ^Unregister a VFS with the sqlite3_vfs_unregister() interface.
5611** ^(If the default VFS is unregistered, another VFS is chosen as
5612** the default.  The choice for the new VFS is arbitrary.)^
5613*/
5614SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName);
5615SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
5616SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*);
5617
5618/*
5619** CAPI3REF: Mutexes
5620**
5621** The SQLite core uses these routines for thread
5622** synchronization. Though they are intended for internal
5623** use by SQLite, code that links against SQLite is
5624** permitted to use any of these routines.
5625**
5626** The SQLite source code contains multiple implementations
5627** of these mutex routines.  An appropriate implementation
5628** is selected automatically at compile-time.  ^(The following
5629** implementations are available in the SQLite core:
5630**
5631** <ul>
5632** <li>   SQLITE_MUTEX_OS2
5633** <li>   SQLITE_MUTEX_PTHREAD
5634** <li>   SQLITE_MUTEX_W32
5635** <li>   SQLITE_MUTEX_NOOP
5636** </ul>)^
5637**
5638** ^The SQLITE_MUTEX_NOOP implementation is a set of routines
5639** that does no real locking and is appropriate for use in
5640** a single-threaded application.  ^The SQLITE_MUTEX_OS2,
5641** SQLITE_MUTEX_PTHREAD, and SQLITE_MUTEX_W32 implementations
5642** are appropriate for use on OS/2, Unix, and Windows.
5643**
5644** ^(If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
5645** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
5646** implementation is included with the library. In this case the
5647** application must supply a custom mutex implementation using the
5648** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
5649** before calling sqlite3_initialize() or any other public sqlite3_
5650** function that calls sqlite3_initialize().)^
5651**
5652** ^The sqlite3_mutex_alloc() routine allocates a new
5653** mutex and returns a pointer to it. ^If it returns NULL
5654** that means that a mutex could not be allocated.  ^SQLite
5655** will unwind its stack and return an error.  ^(The argument
5656** to sqlite3_mutex_alloc() is one of these integer constants:
5657**
5658** <ul>
5659** <li>  SQLITE_MUTEX_FAST
5660** <li>  SQLITE_MUTEX_RECURSIVE
5661** <li>  SQLITE_MUTEX_STATIC_MASTER
5662** <li>  SQLITE_MUTEX_STATIC_MEM
5663** <li>  SQLITE_MUTEX_STATIC_MEM2
5664** <li>  SQLITE_MUTEX_STATIC_PRNG
5665** <li>  SQLITE_MUTEX_STATIC_LRU
5666** <li>  SQLITE_MUTEX_STATIC_LRU2
5667** </ul>)^
5668**
5669** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
5670** cause sqlite3_mutex_alloc() to create
5671** a new mutex.  ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
5672** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
5673** The mutex implementation does not need to make a distinction
5674** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
5675** not want to.  ^SQLite will only request a recursive mutex in
5676** cases where it really needs one.  ^If a faster non-recursive mutex
5677** implementation is available on the host platform, the mutex subsystem
5678** might return such a mutex in response to SQLITE_MUTEX_FAST.
5679**
5680** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other
5681** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return
5682** a pointer to a static preexisting mutex.  ^Six static mutexes are
5683** used by the current version of SQLite.  Future versions of SQLite
5684** may add additional static mutexes.  Static mutexes are for internal
5685** use by SQLite only.  Applications that use SQLite mutexes should
5686** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
5687** SQLITE_MUTEX_RECURSIVE.
5688**
5689** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
5690** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
5691** returns a different mutex on every call.  ^But for the static
5692** mutex types, the same mutex is returned on every call that has
5693** the same type number.
5694**
5695** ^The sqlite3_mutex_free() routine deallocates a previously
5696** allocated dynamic mutex.  ^SQLite is careful to deallocate every
5697** dynamic mutex that it allocates.  The dynamic mutexes must not be in
5698** use when they are deallocated.  Attempting to deallocate a static
5699** mutex results in undefined behavior.  ^SQLite never deallocates
5700** a static mutex.
5701**
5702** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
5703** to enter a mutex.  ^If another thread is already within the mutex,
5704** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
5705** SQLITE_BUSY.  ^The sqlite3_mutex_try() interface returns [SQLITE_OK]
5706** upon successful entry.  ^(Mutexes created using
5707** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
5708** In such cases the,
5709** mutex must be exited an equal number of times before another thread
5710** can enter.)^  ^(If the same thread tries to enter any other
5711** kind of mutex more than once, the behavior is undefined.
5712** SQLite will never exhibit
5713** such behavior in its own use of mutexes.)^
5714**
5715** ^(Some systems (for example, Windows 95) do not support the operation
5716** implemented by sqlite3_mutex_try().  On those systems, sqlite3_mutex_try()
5717** will always return SQLITE_BUSY.  The SQLite core only ever uses
5718** sqlite3_mutex_try() as an optimization so this is acceptable behavior.)^
5719**
5720** ^The sqlite3_mutex_leave() routine exits a mutex that was
5721** previously entered by the same thread.   ^(The behavior
5722** is undefined if the mutex is not currently entered by the
5723** calling thread or is not currently allocated.  SQLite will
5724** never do either.)^
5725**
5726** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
5727** sqlite3_mutex_leave() is a NULL pointer, then all three routines
5728** behave as no-ops.
5729**
5730** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].
5731*/
5732SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int);
5733SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*);
5734SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*);
5735SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
5736SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
5737
5738/*
5739** CAPI3REF: Mutex Methods Object
5740**
5741** An instance of this structure defines the low-level routines
5742** used to allocate and use mutexes.
5743**
5744** Usually, the default mutex implementations provided by SQLite are
5745** sufficient, however the user has the option of substituting a custom
5746** implementation for specialized deployments or systems for which SQLite
5747** does not provide a suitable implementation. In this case, the user
5748** creates and populates an instance of this structure to pass
5749** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
5750** Additionally, an instance of this structure can be used as an
5751** output variable when querying the system for the current mutex
5752** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
5753**
5754** ^The xMutexInit method defined by this structure is invoked as
5755** part of system initialization by the sqlite3_initialize() function.
5756** ^The xMutexInit routine is called by SQLite exactly once for each
5757** effective call to [sqlite3_initialize()].
5758**
5759** ^The xMutexEnd method defined by this structure is invoked as
5760** part of system shutdown by the sqlite3_shutdown() function. The
5761** implementation of this method is expected to release all outstanding
5762** resources obtained by the mutex methods implementation, especially
5763** those obtained by the xMutexInit method.  ^The xMutexEnd()
5764** interface is invoked exactly once for each call to [sqlite3_shutdown()].
5765**
5766** ^(The remaining seven methods defined by this structure (xMutexAlloc,
5767** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and
5768** xMutexNotheld) implement the following interfaces (respectively):
5769**
5770** <ul>
5771**   <li>  [sqlite3_mutex_alloc()] </li>
5772**   <li>  [sqlite3_mutex_free()] </li>
5773**   <li>  [sqlite3_mutex_enter()] </li>
5774**   <li>  [sqlite3_mutex_try()] </li>
5775**   <li>  [sqlite3_mutex_leave()] </li>
5776**   <li>  [sqlite3_mutex_held()] </li>
5777**   <li>  [sqlite3_mutex_notheld()] </li>
5778** </ul>)^
5779**
5780** The only difference is that the public sqlite3_XXX functions enumerated
5781** above silently ignore any invocations that pass a NULL pointer instead
5782** of a valid mutex handle. The implementations of the methods defined
5783** by this structure are not required to handle this case, the results
5784** of passing a NULL pointer instead of a valid mutex handle are undefined
5785** (i.e. it is acceptable to provide an implementation that segfaults if
5786** it is passed a NULL pointer).
5787**
5788** The xMutexInit() method must be threadsafe.  ^It must be harmless to
5789** invoke xMutexInit() multiple times within the same process and without
5790** intervening calls to xMutexEnd().  Second and subsequent calls to
5791** xMutexInit() must be no-ops.
5792**
5793** ^xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
5794** and its associates).  ^Similarly, xMutexAlloc() must not use SQLite memory
5795** allocation for a static mutex.  ^However xMutexAlloc() may use SQLite
5796** memory allocation for a fast or recursive mutex.
5797**
5798** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is
5799** called, but only if the prior call to xMutexInit returned SQLITE_OK.
5800** If xMutexInit fails in any way, it is expected to clean up after itself
5801** prior to returning.
5802*/
5803typedef struct sqlite3_mutex_methods sqlite3_mutex_methods;
5804struct sqlite3_mutex_methods {
5805  int (*xMutexInit)(void);
5806  int (*xMutexEnd)(void);
5807  sqlite3_mutex *(*xMutexAlloc)(int);
5808  void (*xMutexFree)(sqlite3_mutex *);
5809  void (*xMutexEnter)(sqlite3_mutex *);
5810  int (*xMutexTry)(sqlite3_mutex *);
5811  void (*xMutexLeave)(sqlite3_mutex *);
5812  int (*xMutexHeld)(sqlite3_mutex *);
5813  int (*xMutexNotheld)(sqlite3_mutex *);
5814};
5815
5816/*
5817** CAPI3REF: Mutex Verification Routines
5818**
5819** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
5820** are intended for use inside assert() statements.  ^The SQLite core
5821** never uses these routines except inside an assert() and applications
5822** are advised to follow the lead of the core.  ^The SQLite core only
5823** provides implementations for these routines when it is compiled
5824** with the SQLITE_DEBUG flag.  ^External mutex implementations
5825** are only required to provide these routines if SQLITE_DEBUG is
5826** defined and if NDEBUG is not defined.
5827**
5828** ^These routines should return true if the mutex in their argument
5829** is held or not held, respectively, by the calling thread.
5830**
5831** ^The implementation is not required to provided versions of these
5832** routines that actually work. If the implementation does not provide working
5833** versions of these routines, it should at least provide stubs that always
5834** return true so that one does not get spurious assertion failures.
5835**
5836** ^If the argument to sqlite3_mutex_held() is a NULL pointer then
5837** the routine should return 1.   This seems counter-intuitive since
5838** clearly the mutex cannot be held if it does not exist.  But the
5839** the reason the mutex does not exist is because the build is not
5840** using mutexes.  And we do not want the assert() containing the
5841** call to sqlite3_mutex_held() to fail, so a non-zero return is
5842** the appropriate thing to do.  ^The sqlite3_mutex_notheld()
5843** interface should also return 1 when given a NULL pointer.
5844*/
5845#ifndef NDEBUG
5846SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);
5847SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
5848#endif
5849
5850/*
5851** CAPI3REF: Mutex Types
5852**
5853** The [sqlite3_mutex_alloc()] interface takes a single argument
5854** which is one of these integer constants.
5855**
5856** The set of static mutexes may change from one SQLite release to the
5857** next.  Applications that override the built-in mutex logic must be
5858** prepared to accommodate additional static mutexes.
5859*/
5860#define SQLITE_MUTEX_FAST             0
5861#define SQLITE_MUTEX_RECURSIVE        1
5862#define SQLITE_MUTEX_STATIC_MASTER    2
5863#define SQLITE_MUTEX_STATIC_MEM       3  /* sqlite3_malloc() */
5864#define SQLITE_MUTEX_STATIC_MEM2      4  /* NOT USED */
5865#define SQLITE_MUTEX_STATIC_OPEN      4  /* sqlite3BtreeOpen() */
5866#define SQLITE_MUTEX_STATIC_PRNG      5  /* sqlite3_random() */
5867#define SQLITE_MUTEX_STATIC_LRU       6  /* lru page list */
5868#define SQLITE_MUTEX_STATIC_LRU2      7  /* NOT USED */
5869#define SQLITE_MUTEX_STATIC_PMEM      7  /* sqlite3PageMalloc() */
5870
5871/*
5872** CAPI3REF: Retrieve the mutex for a database connection
5873**
5874** ^This interface returns a pointer the [sqlite3_mutex] object that
5875** serializes access to the [database connection] given in the argument
5876** when the [threading mode] is Serialized.
5877** ^If the [threading mode] is Single-thread or Multi-thread then this
5878** routine returns a NULL pointer.
5879*/
5880SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*);
5881
5882/*
5883** CAPI3REF: Low-Level Control Of Database Files
5884**
5885** ^The [sqlite3_file_control()] interface makes a direct call to the
5886** xFileControl method for the [sqlite3_io_methods] object associated
5887** with a particular database identified by the second argument. ^The
5888** name of the database is "main" for the main database or "temp" for the
5889** TEMP database, or the name that appears after the AS keyword for
5890** databases that are added using the [ATTACH] SQL command.
5891** ^A NULL pointer can be used in place of "main" to refer to the
5892** main database file.
5893** ^The third and fourth parameters to this routine
5894** are passed directly through to the second and third parameters of
5895** the xFileControl method.  ^The return value of the xFileControl
5896** method becomes the return value of this routine.
5897**
5898** ^The SQLITE_FCNTL_FILE_POINTER value for the op parameter causes
5899** a pointer to the underlying [sqlite3_file] object to be written into
5900** the space pointed to by the 4th parameter.  ^The SQLITE_FCNTL_FILE_POINTER
5901** case is a short-circuit path which does not actually invoke the
5902** underlying sqlite3_io_methods.xFileControl method.
5903**
5904** ^If the second parameter (zDbName) does not match the name of any
5905** open database file, then SQLITE_ERROR is returned.  ^This error
5906** code is not remembered and will not be recalled by [sqlite3_errcode()]
5907** or [sqlite3_errmsg()].  The underlying xFileControl method might
5908** also return SQLITE_ERROR.  There is no way to distinguish between
5909** an incorrect zDbName and an SQLITE_ERROR return from the underlying
5910** xFileControl method.
5911**
5912** See also: [SQLITE_FCNTL_LOCKSTATE]
5913*/
5914SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
5915
5916/*
5917** CAPI3REF: Testing Interface
5918**
5919** ^The sqlite3_test_control() interface is used to read out internal
5920** state of SQLite and to inject faults into SQLite for testing
5921** purposes.  ^The first parameter is an operation code that determines
5922** the number, meaning, and operation of all subsequent parameters.
5923**
5924** This interface is not for use by applications.  It exists solely
5925** for verifying the correct operation of the SQLite library.  Depending
5926** on how the SQLite library is compiled, this interface might not exist.
5927**
5928** The details of the operation codes, their meanings, the parameters
5929** they take, and what they do are all subject to change without notice.
5930** Unlike most of the SQLite API, this function is not guaranteed to
5931** operate consistently from one release to the next.
5932*/
5933SQLITE_API int sqlite3_test_control(int op, ...);
5934
5935/*
5936** CAPI3REF: Testing Interface Operation Codes
5937**
5938** These constants are the valid operation code parameters used
5939** as the first argument to [sqlite3_test_control()].
5940**
5941** These parameters and their meanings are subject to change
5942** without notice.  These values are for testing purposes only.
5943** Applications should not use any of these parameters or the
5944** [sqlite3_test_control()] interface.
5945*/
5946#define SQLITE_TESTCTRL_FIRST                    5
5947#define SQLITE_TESTCTRL_PRNG_SAVE                5
5948#define SQLITE_TESTCTRL_PRNG_RESTORE             6
5949#define SQLITE_TESTCTRL_PRNG_RESET               7
5950#define SQLITE_TESTCTRL_BITVEC_TEST              8
5951#define SQLITE_TESTCTRL_FAULT_INSTALL            9
5952#define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS     10
5953#define SQLITE_TESTCTRL_PENDING_BYTE            11
5954#define SQLITE_TESTCTRL_ASSERT                  12
5955#define SQLITE_TESTCTRL_ALWAYS                  13
5956#define SQLITE_TESTCTRL_RESERVE                 14
5957#define SQLITE_TESTCTRL_OPTIMIZATIONS           15
5958#define SQLITE_TESTCTRL_ISKEYWORD               16
5959#define SQLITE_TESTCTRL_PGHDRSZ                 17
5960#define SQLITE_TESTCTRL_SCRATCHMALLOC           18
5961#define SQLITE_TESTCTRL_LAST                    18
5962
5963/*
5964** CAPI3REF: SQLite Runtime Status
5965**
5966** ^This interface is used to retrieve runtime status information
5967** about the performance of SQLite, and optionally to reset various
5968** highwater marks.  ^The first argument is an integer code for
5969** the specific parameter to measure.  ^(Recognized integer codes
5970** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...].)^
5971** ^The current value of the parameter is returned into *pCurrent.
5972** ^The highest recorded value is returned in *pHighwater.  ^If the
5973** resetFlag is true, then the highest record value is reset after
5974** *pHighwater is written.  ^(Some parameters do not record the highest
5975** value.  For those parameters
5976** nothing is written into *pHighwater and the resetFlag is ignored.)^
5977** ^(Other parameters record only the highwater mark and not the current
5978** value.  For these latter parameters nothing is written into *pCurrent.)^
5979**
5980** ^The sqlite3_status() routine returns SQLITE_OK on success and a
5981** non-zero [error code] on failure.
5982**
5983** This routine is threadsafe but is not atomic.  This routine can be
5984** called while other threads are running the same or different SQLite
5985** interfaces.  However the values returned in *pCurrent and
5986** *pHighwater reflect the status of SQLite at different points in time
5987** and it is possible that another thread might change the parameter
5988** in between the times when *pCurrent and *pHighwater are written.
5989**
5990** See also: [sqlite3_db_status()]
5991*/
5992SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
5993
5994
5995/*
5996** CAPI3REF: Status Parameters
5997**
5998** These integer constants designate various run-time status parameters
5999** that can be returned by [sqlite3_status()].
6000**
6001** <dl>
6002** ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
6003** <dd>This parameter is the current amount of memory checked out
6004** using [sqlite3_malloc()], either directly or indirectly.  The
6005** figure includes calls made to [sqlite3_malloc()] by the application
6006** and internal memory usage by the SQLite library.  Scratch memory
6007** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
6008** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
6009** this parameter.  The amount returned is the sum of the allocation
6010** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
6011**
6012** ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
6013** <dd>This parameter records the largest memory allocation request
6014** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
6015** internal equivalents).  Only the value returned in the
6016** *pHighwater parameter to [sqlite3_status()] is of interest.
6017** The value written into the *pCurrent parameter is undefined.</dd>)^
6018**
6019** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
6020** <dd>This parameter records the number of separate memory allocations
6021** currently checked out.</dd>)^
6022**
6023** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
6024** <dd>This parameter returns the number of pages used out of the
6025** [pagecache memory allocator] that was configured using
6026** [SQLITE_CONFIG_PAGECACHE].  The
6027** value returned is in pages, not in bytes.</dd>)^
6028**
6029** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
6030** <dd>This parameter returns the number of bytes of page cache
6031** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
6032** buffer and where forced to overflow to [sqlite3_malloc()].  The
6033** returned value includes allocations that overflowed because they
6034** where too large (they were larger than the "sz" parameter to
6035** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
6036** no space was left in the page cache.</dd>)^
6037**
6038** ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
6039** <dd>This parameter records the largest memory allocation request
6040** handed to [pagecache memory allocator].  Only the value returned in the
6041** *pHighwater parameter to [sqlite3_status()] is of interest.
6042** The value written into the *pCurrent parameter is undefined.</dd>)^
6043**
6044** ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
6045** <dd>This parameter returns the number of allocations used out of the
6046** [scratch memory allocator] configured using
6047** [SQLITE_CONFIG_SCRATCH].  The value returned is in allocations, not
6048** in bytes.  Since a single thread may only have one scratch allocation
6049** outstanding at time, this parameter also reports the number of threads
6050** using scratch memory at the same time.</dd>)^
6051**
6052** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
6053** <dd>This parameter returns the number of bytes of scratch memory
6054** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
6055** buffer and where forced to overflow to [sqlite3_malloc()].  The values
6056** returned include overflows because the requested allocation was too
6057** larger (that is, because the requested allocation was larger than the
6058** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
6059** slots were available.
6060** </dd>)^
6061**
6062** ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
6063** <dd>This parameter records the largest memory allocation request
6064** handed to [scratch memory allocator].  Only the value returned in the
6065** *pHighwater parameter to [sqlite3_status()] is of interest.
6066** The value written into the *pCurrent parameter is undefined.</dd>)^
6067**
6068** ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
6069** <dd>This parameter records the deepest parser stack.  It is only
6070** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
6071** </dl>
6072**
6073** New status parameters may be added from time to time.
6074*/
6075#define SQLITE_STATUS_MEMORY_USED          0
6076#define SQLITE_STATUS_PAGECACHE_USED       1
6077#define SQLITE_STATUS_PAGECACHE_OVERFLOW   2
6078#define SQLITE_STATUS_SCRATCH_USED         3
6079#define SQLITE_STATUS_SCRATCH_OVERFLOW     4
6080#define SQLITE_STATUS_MALLOC_SIZE          5
6081#define SQLITE_STATUS_PARSER_STACK         6
6082#define SQLITE_STATUS_PAGECACHE_SIZE       7
6083#define SQLITE_STATUS_SCRATCH_SIZE         8
6084#define SQLITE_STATUS_MALLOC_COUNT         9
6085
6086/*
6087** CAPI3REF: Database Connection Status
6088**
6089** ^This interface is used to retrieve runtime status information
6090** about a single [database connection].  ^The first argument is the
6091** database connection object to be interrogated.  ^The second argument
6092** is an integer constant, taken from the set of
6093** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that
6094** determines the parameter to interrogate.  The set of
6095** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely
6096** to grow in future releases of SQLite.
6097**
6098** ^The current value of the requested parameter is written into *pCur
6099** and the highest instantaneous value is written into *pHiwtr.  ^If
6100** the resetFlg is true, then the highest instantaneous value is
6101** reset back down to the current value.
6102**
6103** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
6104** non-zero [error code] on failure.
6105**
6106** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
6107*/
6108SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
6109
6110/*
6111** CAPI3REF: Status Parameters for database connections
6112**
6113** These constants are the available integer "verbs" that can be passed as
6114** the second argument to the [sqlite3_db_status()] interface.
6115**
6116** New verbs may be added in future releases of SQLite. Existing verbs
6117** might be discontinued. Applications should check the return code from
6118** [sqlite3_db_status()] to make sure that the call worked.
6119** The [sqlite3_db_status()] interface will return a non-zero error code
6120** if a discontinued or unsupported verb is invoked.
6121**
6122** <dl>
6123** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
6124** <dd>This parameter returns the number of lookaside memory slots currently
6125** checked out.</dd>)^
6126**
6127** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
6128** <dd>This parameter returns the number malloc attempts that were
6129** satisfied using lookaside memory. Only the high-water value is meaningful;
6130** the current value is always zero.)^
6131**
6132** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
6133** <dd>This parameter returns the number malloc attempts that might have
6134** been satisfied using lookaside memory but failed due to the amount of
6135** memory requested being larger than the lookaside slot size.
6136** Only the high-water value is meaningful;
6137** the current value is always zero.)^
6138**
6139** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
6140** <dd>This parameter returns the number malloc attempts that might have
6141** been satisfied using lookaside memory but failed due to all lookaside
6142** memory already being in use.
6143** Only the high-water value is meaningful;
6144** the current value is always zero.)^
6145**
6146** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
6147** <dd>This parameter returns the approximate number of of bytes of heap
6148** memory used by all pager caches associated with the database connection.)^
6149** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
6150**
6151** ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
6152** <dd>This parameter returns the approximate number of of bytes of heap
6153** memory used to store the schema for all databases associated
6154** with the connection - main, temp, and any [ATTACH]-ed databases.)^
6155** ^The full amount of memory used by the schemas is reported, even if the
6156** schema memory is shared with other database connections due to
6157** [shared cache mode] being enabled.
6158** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
6159**
6160** ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
6161** <dd>This parameter returns the approximate number of of bytes of heap
6162** and lookaside memory used by all prepared statements associated with
6163** the database connection.)^
6164** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
6165** </dd>
6166** </dl>
6167*/
6168#define SQLITE_DBSTATUS_LOOKASIDE_USED       0
6169#define SQLITE_DBSTATUS_CACHE_USED           1
6170#define SQLITE_DBSTATUS_SCHEMA_USED          2
6171#define SQLITE_DBSTATUS_STMT_USED            3
6172#define SQLITE_DBSTATUS_LOOKASIDE_HIT        4
6173#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE  5
6174#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL  6
6175#define SQLITE_DBSTATUS_MAX                  6   /* Largest defined DBSTATUS */
6176
6177
6178/*
6179** CAPI3REF: Prepared Statement Status
6180**
6181** ^(Each prepared statement maintains various
6182** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
6183** of times it has performed specific operations.)^  These counters can
6184** be used to monitor the performance characteristics of the prepared
6185** statements.  For example, if the number of table steps greatly exceeds
6186** the number of table searches or result rows, that would tend to indicate
6187** that the prepared statement is using a full table scan rather than
6188** an index.
6189**
6190** ^(This interface is used to retrieve and reset counter values from
6191** a [prepared statement].  The first argument is the prepared statement
6192** object to be interrogated.  The second argument
6193** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter]
6194** to be interrogated.)^
6195** ^The current value of the requested counter is returned.
6196** ^If the resetFlg is true, then the counter is reset to zero after this
6197** interface call returns.
6198**
6199** See also: [sqlite3_status()] and [sqlite3_db_status()].
6200*/
6201SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
6202
6203/*
6204** CAPI3REF: Status Parameters for prepared statements
6205**
6206** These preprocessor macros define integer codes that name counter
6207** values associated with the [sqlite3_stmt_status()] interface.
6208** The meanings of the various counters are as follows:
6209**
6210** <dl>
6211** <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
6212** <dd>^This is the number of times that SQLite has stepped forward in
6213** a table as part of a full table scan.  Large numbers for this counter
6214** may indicate opportunities for performance improvement through
6215** careful use of indices.</dd>
6216**
6217** <dt>SQLITE_STMTSTATUS_SORT</dt>
6218** <dd>^This is the number of sort operations that have occurred.
6219** A non-zero value in this counter may indicate an opportunity to
6220** improvement performance through careful use of indices.</dd>
6221**
6222** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
6223** <dd>^This is the number of rows inserted into transient indices that
6224** were created automatically in order to help joins run faster.
6225** A non-zero value in this counter may indicate an opportunity to
6226** improvement performance by adding permanent indices that do not
6227** need to be reinitialized each time the statement is run.</dd>
6228**
6229** </dl>
6230*/
6231#define SQLITE_STMTSTATUS_FULLSCAN_STEP     1
6232#define SQLITE_STMTSTATUS_SORT              2
6233#define SQLITE_STMTSTATUS_AUTOINDEX         3
6234
6235/*
6236** CAPI3REF: Custom Page Cache Object
6237**
6238** The sqlite3_pcache type is opaque.  It is implemented by
6239** the pluggable module.  The SQLite core has no knowledge of
6240** its size or internal structure and never deals with the
6241** sqlite3_pcache object except by holding and passing pointers
6242** to the object.
6243**
6244** See [sqlite3_pcache_methods] for additional information.
6245*/
6246typedef struct sqlite3_pcache sqlite3_pcache;
6247
6248/*
6249** CAPI3REF: Application Defined Page Cache.
6250** KEYWORDS: {page cache}
6251**
6252** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
6253** register an alternative page cache implementation by passing in an
6254** instance of the sqlite3_pcache_methods structure.)^
6255** In many applications, most of the heap memory allocated by
6256** SQLite is used for the page cache.
6257** By implementing a
6258** custom page cache using this API, an application can better control
6259** the amount of memory consumed by SQLite, the way in which
6260** that memory is allocated and released, and the policies used to
6261** determine exactly which parts of a database file are cached and for
6262** how long.
6263**
6264** The alternative page cache mechanism is an
6265** extreme measure that is only needed by the most demanding applications.
6266** The built-in page cache is recommended for most uses.
6267**
6268** ^(The contents of the sqlite3_pcache_methods structure are copied to an
6269** internal buffer by SQLite within the call to [sqlite3_config].  Hence
6270** the application may discard the parameter after the call to
6271** [sqlite3_config()] returns.)^
6272**
6273** ^(The xInit() method is called once for each effective
6274** call to [sqlite3_initialize()])^
6275** (usually only once during the lifetime of the process). ^(The xInit()
6276** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^
6277** The intent of the xInit() method is to set up global data structures
6278** required by the custom page cache implementation.
6279** ^(If the xInit() method is NULL, then the
6280** built-in default page cache is used instead of the application defined
6281** page cache.)^
6282**
6283** ^The xShutdown() method is called by [sqlite3_shutdown()].
6284** It can be used to clean up
6285** any outstanding resources before process shutdown, if required.
6286** ^The xShutdown() method may be NULL.
6287**
6288** ^SQLite automatically serializes calls to the xInit method,
6289** so the xInit method need not be threadsafe.  ^The
6290** xShutdown method is only called from [sqlite3_shutdown()] so it does
6291** not need to be threadsafe either.  All other methods must be threadsafe
6292** in multithreaded applications.
6293**
6294** ^SQLite will never invoke xInit() more than once without an intervening
6295** call to xShutdown().
6296**
6297** ^SQLite invokes the xCreate() method to construct a new cache instance.
6298** SQLite will typically create one cache instance for each open database file,
6299** though this is not guaranteed. ^The
6300** first parameter, szPage, is the size in bytes of the pages that must
6301** be allocated by the cache.  ^szPage will not be a power of two.  ^szPage
6302** will the page size of the database file that is to be cached plus an
6303** increment (here called "R") of less than 250.  SQLite will use the
6304** extra R bytes on each page to store metadata about the underlying
6305** database page on disk.  The value of R depends
6306** on the SQLite version, the target platform, and how SQLite was compiled.
6307** ^(R is constant for a particular build of SQLite. Except, there are two
6308** distinct values of R when SQLite is compiled with the proprietary
6309** ZIPVFS extension.)^  ^The second argument to
6310** xCreate(), bPurgeable, is true if the cache being created will
6311** be used to cache database pages of a file stored on disk, or
6312** false if it is used for an in-memory database. The cache implementation
6313** does not have to do anything special based with the value of bPurgeable;
6314** it is purely advisory.  ^On a cache where bPurgeable is false, SQLite will
6315** never invoke xUnpin() except to deliberately delete a page.
6316** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
6317** false will always have the "discard" flag set to true.
6318** ^Hence, a cache created with bPurgeable false will
6319** never contain any unpinned pages.
6320**
6321** ^(The xCachesize() method may be called at any time by SQLite to set the
6322** suggested maximum cache-size (number of pages stored by) the cache
6323** instance passed as the first argument. This is the value configured using
6324** the SQLite "[PRAGMA cache_size]" command.)^  As with the bPurgeable
6325** parameter, the implementation is not required to do anything with this
6326** value; it is advisory only.
6327**
6328** The xPagecount() method must return the number of pages currently
6329** stored in the cache, both pinned and unpinned.
6330**
6331** The xFetch() method locates a page in the cache and returns a pointer to
6332** the page, or a NULL pointer.
6333** A "page", in this context, means a buffer of szPage bytes aligned at an
6334** 8-byte boundary. The page to be fetched is determined by the key. ^The
6335** mimimum key value is 1.  After it has been retrieved using xFetch, the page
6336** is considered to be "pinned".
6337**
6338** If the requested page is already in the page cache, then the page cache
6339** implementation must return a pointer to the page buffer with its content
6340** intact.  If the requested page is not already in the cache, then the
6341** cache implementation should use the value of the createFlag
6342** parameter to help it determined what action to take:
6343**
6344** <table border=1 width=85% align=center>
6345** <tr><th> createFlag <th> Behaviour when page is not already in cache
6346** <tr><td> 0 <td> Do not allocate a new page.  Return NULL.
6347** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
6348**                 Otherwise return NULL.
6349** <tr><td> 2 <td> Make every effort to allocate a new page.  Only return
6350**                 NULL if allocating a new page is effectively impossible.
6351** </table>
6352**
6353** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1.  SQLite
6354** will only use a createFlag of 2 after a prior call with a createFlag of 1
6355** failed.)^  In between the to xFetch() calls, SQLite may
6356** attempt to unpin one or more cache pages by spilling the content of
6357** pinned pages to disk and synching the operating system disk cache.
6358**
6359** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
6360** as its second argument.  If the third parameter, discard, is non-zero,
6361** then the page must be evicted from the cache.
6362** ^If the discard parameter is
6363** zero, then the page may be discarded or retained at the discretion of
6364** page cache implementation. ^The page cache implementation
6365** may choose to evict unpinned pages at any time.
6366**
6367** The cache must not perform any reference counting. A single
6368** call to xUnpin() unpins the page regardless of the number of prior calls
6369** to xFetch().
6370**
6371** The xRekey() method is used to change the key value associated with the
6372** page passed as the second argument. If the cache
6373** previously contains an entry associated with newKey, it must be
6374** discarded. ^Any prior cache entry associated with newKey is guaranteed not
6375** to be pinned.
6376**
6377** When SQLite calls the xTruncate() method, the cache must discard all
6378** existing cache entries with page numbers (keys) greater than or equal
6379** to the value of the iLimit parameter passed to xTruncate(). If any
6380** of these pages are pinned, they are implicitly unpinned, meaning that
6381** they can be safely discarded.
6382**
6383** ^The xDestroy() method is used to delete a cache allocated by xCreate().
6384** All resources associated with the specified cache should be freed. ^After
6385** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
6386** handle invalid, and will not use it with any other sqlite3_pcache_methods
6387** functions.
6388*/
6389typedef struct sqlite3_pcache_methods sqlite3_pcache_methods;
6390struct sqlite3_pcache_methods {
6391  void *pArg;
6392  int (*xInit)(void*);
6393  void (*xShutdown)(void*);
6394  sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable);
6395  void (*xCachesize)(sqlite3_pcache*, int nCachesize);
6396  int (*xPagecount)(sqlite3_pcache*);
6397  void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
6398  void (*xUnpin)(sqlite3_pcache*, void*, int discard);
6399  void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey);
6400  void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
6401  void (*xDestroy)(sqlite3_pcache*);
6402};
6403
6404/*
6405** CAPI3REF: Online Backup Object
6406**
6407** The sqlite3_backup object records state information about an ongoing
6408** online backup operation.  ^The sqlite3_backup object is created by
6409** a call to [sqlite3_backup_init()] and is destroyed by a call to
6410** [sqlite3_backup_finish()].
6411**
6412** See Also: [Using the SQLite Online Backup API]
6413*/
6414typedef struct sqlite3_backup sqlite3_backup;
6415
6416/*
6417** CAPI3REF: Online Backup API.
6418**
6419** The backup API copies the content of one database into another.
6420** It is useful either for creating backups of databases or
6421** for copying in-memory databases to or from persistent files.
6422**
6423** See Also: [Using the SQLite Online Backup API]
6424**
6425** ^SQLite holds a write transaction open on the destination database file
6426** for the duration of the backup operation.
6427** ^The source database is read-locked only while it is being read;
6428** it is not locked continuously for the entire backup operation.
6429** ^Thus, the backup may be performed on a live source database without
6430** preventing other database connections from
6431** reading or writing to the source database while the backup is underway.
6432**
6433** ^(To perform a backup operation:
6434**   <ol>
6435**     <li><b>sqlite3_backup_init()</b> is called once to initialize the
6436**         backup,
6437**     <li><b>sqlite3_backup_step()</b> is called one or more times to transfer
6438**         the data between the two databases, and finally
6439**     <li><b>sqlite3_backup_finish()</b> is called to release all resources
6440**         associated with the backup operation.
6441**   </ol>)^
6442** There should be exactly one call to sqlite3_backup_finish() for each
6443** successful call to sqlite3_backup_init().
6444**
6445** <b>sqlite3_backup_init()</b>
6446**
6447** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the
6448** [database connection] associated with the destination database
6449** and the database name, respectively.
6450** ^The database name is "main" for the main database, "temp" for the
6451** temporary database, or the name specified after the AS keyword in
6452** an [ATTACH] statement for an attached database.
6453** ^The S and M arguments passed to
6454** sqlite3_backup_init(D,N,S,M) identify the [database connection]
6455** and database name of the source database, respectively.
6456** ^The source and destination [database connections] (parameters S and D)
6457** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
6458** an error.
6459**
6460** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
6461** returned and an error code and error message are stored in the
6462** destination [database connection] D.
6463** ^The error code and message for the failed call to sqlite3_backup_init()
6464** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
6465** [sqlite3_errmsg16()] functions.
6466** ^A successful call to sqlite3_backup_init() returns a pointer to an
6467** [sqlite3_backup] object.
6468** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
6469** sqlite3_backup_finish() functions to perform the specified backup
6470** operation.
6471**
6472** <b>sqlite3_backup_step()</b>
6473**
6474** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
6475** the source and destination databases specified by [sqlite3_backup] object B.
6476** ^If N is negative, all remaining source pages are copied.
6477** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
6478** are still more pages to be copied, then the function returns [SQLITE_OK].
6479** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
6480** from source to destination, then it returns [SQLITE_DONE].
6481** ^If an error occurs while running sqlite3_backup_step(B,N),
6482** then an [error code] is returned. ^As well as [SQLITE_OK] and
6483** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
6484** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an
6485** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code.
6486**
6487** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
6488** <ol>
6489** <li> the destination database was opened read-only, or
6490** <li> the destination database is using write-ahead-log journaling
6491** and the destination and source page sizes differ, or
6492** <li> the destination database is an in-memory database and the
6493** destination and source page sizes differ.
6494** </ol>)^
6495**
6496** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
6497** the [sqlite3_busy_handler | busy-handler function]
6498** is invoked (if one is specified). ^If the
6499** busy-handler returns non-zero before the lock is available, then
6500** [SQLITE_BUSY] is returned to the caller. ^In this case the call to
6501** sqlite3_backup_step() can be retried later. ^If the source
6502** [database connection]
6503** is being used to write to the source database when sqlite3_backup_step()
6504** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this
6505** case the call to sqlite3_backup_step() can be retried later on. ^(If
6506** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or
6507** [SQLITE_READONLY] is returned, then
6508** there is no point in retrying the call to sqlite3_backup_step(). These
6509** errors are considered fatal.)^  The application must accept
6510** that the backup operation has failed and pass the backup operation handle
6511** to the sqlite3_backup_finish() to release associated resources.
6512**
6513** ^The first call to sqlite3_backup_step() obtains an exclusive lock
6514** on the destination file. ^The exclusive lock is not released until either
6515** sqlite3_backup_finish() is called or the backup operation is complete
6516** and sqlite3_backup_step() returns [SQLITE_DONE].  ^Every call to
6517** sqlite3_backup_step() obtains a [shared lock] on the source database that
6518** lasts for the duration of the sqlite3_backup_step() call.
6519** ^Because the source database is not locked between calls to
6520** sqlite3_backup_step(), the source database may be modified mid-way
6521** through the backup process.  ^If the source database is modified by an
6522** external process or via a database connection other than the one being
6523** used by the backup operation, then the backup will be automatically
6524** restarted by the next call to sqlite3_backup_step(). ^If the source
6525** database is modified by the using the same database connection as is used
6526** by the backup operation, then the backup database is automatically
6527** updated at the same time.
6528**
6529** <b>sqlite3_backup_finish()</b>
6530**
6531** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the
6532** application wishes to abandon the backup operation, the application
6533** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().
6534** ^The sqlite3_backup_finish() interfaces releases all
6535** resources associated with the [sqlite3_backup] object.
6536** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any
6537** active write-transaction on the destination database is rolled back.
6538** The [sqlite3_backup] object is invalid
6539** and may not be used following a call to sqlite3_backup_finish().
6540**
6541** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
6542** sqlite3_backup_step() errors occurred, regardless or whether or not
6543** sqlite3_backup_step() completed.
6544** ^If an out-of-memory condition or IO error occurred during any prior
6545** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
6546** sqlite3_backup_finish() returns the corresponding [error code].
6547**
6548** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
6549** is not a permanent error and does not affect the return value of
6550** sqlite3_backup_finish().
6551**
6552** <b>sqlite3_backup_remaining(), sqlite3_backup_pagecount()</b>
6553**
6554** ^Each call to sqlite3_backup_step() sets two values inside
6555** the [sqlite3_backup] object: the number of pages still to be backed
6556** up and the total number of pages in the source database file.
6557** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces
6558** retrieve these two values, respectively.
6559**
6560** ^The values returned by these functions are only updated by
6561** sqlite3_backup_step(). ^If the source database is modified during a backup
6562** operation, then the values are not updated to account for any extra
6563** pages that need to be updated or the size of the source database file
6564** changing.
6565**
6566** <b>Concurrent Usage of Database Handles</b>
6567**
6568** ^The source [database connection] may be used by the application for other
6569** purposes while a backup operation is underway or being initialized.
6570** ^If SQLite is compiled and configured to support threadsafe database
6571** connections, then the source database connection may be used concurrently
6572** from within other threads.
6573**
6574** However, the application must guarantee that the destination
6575** [database connection] is not passed to any other API (by any thread) after
6576** sqlite3_backup_init() is called and before the corresponding call to
6577** sqlite3_backup_finish().  SQLite does not currently check to see
6578** if the application incorrectly accesses the destination [database connection]
6579** and so no error code is reported, but the operations may malfunction
6580** nevertheless.  Use of the destination database connection while a
6581** backup is in progress might also also cause a mutex deadlock.
6582**
6583** If running in [shared cache mode], the application must
6584** guarantee that the shared cache used by the destination database
6585** is not accessed while the backup is running. In practice this means
6586** that the application must guarantee that the disk file being
6587** backed up to is not accessed by any connection within the process,
6588** not just the specific connection that was passed to sqlite3_backup_init().
6589**
6590** The [sqlite3_backup] object itself is partially threadsafe. Multiple
6591** threads may safely make multiple concurrent calls to sqlite3_backup_step().
6592** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount()
6593** APIs are not strictly speaking threadsafe. If they are invoked at the
6594** same time as another thread is invoking sqlite3_backup_step() it is
6595** possible that they return invalid values.
6596*/
6597SQLITE_API sqlite3_backup *sqlite3_backup_init(
6598  sqlite3 *pDest,                        /* Destination database handle */
6599  const char *zDestName,                 /* Destination database name */
6600  sqlite3 *pSource,                      /* Source database handle */
6601  const char *zSourceName                /* Source database name */
6602);
6603SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage);
6604SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p);
6605SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
6606SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
6607
6608/*
6609** CAPI3REF: Unlock Notification
6610**
6611** ^When running in shared-cache mode, a database operation may fail with
6612** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
6613** individual tables within the shared-cache cannot be obtained. See
6614** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
6615** ^This API may be used to register a callback that SQLite will invoke
6616** when the connection currently holding the required lock relinquishes it.
6617** ^This API is only available if the library was compiled with the
6618** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined.
6619**
6620** See Also: [Using the SQLite Unlock Notification Feature].
6621**
6622** ^Shared-cache locks are released when a database connection concludes
6623** its current transaction, either by committing it or rolling it back.
6624**
6625** ^When a connection (known as the blocked connection) fails to obtain a
6626** shared-cache lock and SQLITE_LOCKED is returned to the caller, the
6627** identity of the database connection (the blocking connection) that
6628** has locked the required resource is stored internally. ^After an
6629** application receives an SQLITE_LOCKED error, it may call the
6630** sqlite3_unlock_notify() method with the blocked connection handle as
6631** the first argument to register for a callback that will be invoked
6632** when the blocking connections current transaction is concluded. ^The
6633** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
6634** call that concludes the blocking connections transaction.
6635**
6636** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
6637** there is a chance that the blocking connection will have already
6638** concluded its transaction by the time sqlite3_unlock_notify() is invoked.
6639** If this happens, then the specified callback is invoked immediately,
6640** from within the call to sqlite3_unlock_notify().)^
6641**
6642** ^If the blocked connection is attempting to obtain a write-lock on a
6643** shared-cache table, and more than one other connection currently holds
6644** a read-lock on the same table, then SQLite arbitrarily selects one of
6645** the other connections to use as the blocking connection.
6646**
6647** ^(There may be at most one unlock-notify callback registered by a
6648** blocked connection. If sqlite3_unlock_notify() is called when the
6649** blocked connection already has a registered unlock-notify callback,
6650** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
6651** called with a NULL pointer as its second argument, then any existing
6652** unlock-notify callback is canceled. ^The blocked connections
6653** unlock-notify callback may also be canceled by closing the blocked
6654** connection using [sqlite3_close()].
6655**
6656** The unlock-notify callback is not reentrant. If an application invokes
6657** any sqlite3_xxx API functions from within an unlock-notify callback, a
6658** crash or deadlock may be the result.
6659**
6660** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always
6661** returns SQLITE_OK.
6662**
6663** <b>Callback Invocation Details</b>
6664**
6665** When an unlock-notify callback is registered, the application provides a
6666** single void* pointer that is passed to the callback when it is invoked.
6667** However, the signature of the callback function allows SQLite to pass
6668** it an array of void* context pointers. The first argument passed to
6669** an unlock-notify callback is a pointer to an array of void* pointers,
6670** and the second is the number of entries in the array.
6671**
6672** When a blocking connections transaction is concluded, there may be
6673** more than one blocked connection that has registered for an unlock-notify
6674** callback. ^If two or more such blocked connections have specified the
6675** same callback function, then instead of invoking the callback function
6676** multiple times, it is invoked once with the set of void* context pointers
6677** specified by the blocked connections bundled together into an array.
6678** This gives the application an opportunity to prioritize any actions
6679** related to the set of unblocked database connections.
6680**
6681** <b>Deadlock Detection</b>
6682**
6683** Assuming that after registering for an unlock-notify callback a
6684** database waits for the callback to be issued before taking any further
6685** action (a reasonable assumption), then using this API may cause the
6686** application to deadlock. For example, if connection X is waiting for
6687** connection Y's transaction to be concluded, and similarly connection
6688** Y is waiting on connection X's transaction, then neither connection
6689** will proceed and the system may remain deadlocked indefinitely.
6690**
6691** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock
6692** detection. ^If a given call to sqlite3_unlock_notify() would put the
6693** system in a deadlocked state, then SQLITE_LOCKED is returned and no
6694** unlock-notify callback is registered. The system is said to be in
6695** a deadlocked state if connection A has registered for an unlock-notify
6696** callback on the conclusion of connection B's transaction, and connection
6697** B has itself registered for an unlock-notify callback when connection
6698** A's transaction is concluded. ^Indirect deadlock is also detected, so
6699** the system is also considered to be deadlocked if connection B has
6700** registered for an unlock-notify callback on the conclusion of connection
6701** C's transaction, where connection C is waiting on connection A. ^Any
6702** number of levels of indirection are allowed.
6703**
6704** <b>The "DROP TABLE" Exception</b>
6705**
6706** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost
6707** always appropriate to call sqlite3_unlock_notify(). There is however,
6708** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement,
6709** SQLite checks if there are any currently executing SELECT statements
6710** that belong to the same connection. If there are, SQLITE_LOCKED is
6711** returned. In this case there is no "blocking connection", so invoking
6712** sqlite3_unlock_notify() results in the unlock-notify callback being
6713** invoked immediately. If the application then re-attempts the "DROP TABLE"
6714** or "DROP INDEX" query, an infinite loop might be the result.
6715**
6716** One way around this problem is to check the extended error code returned
6717** by an sqlite3_step() call. ^(If there is a blocking connection, then the
6718** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in
6719** the special "DROP TABLE/INDEX" case, the extended error code is just
6720** SQLITE_LOCKED.)^
6721*/
6722SQLITE_API int sqlite3_unlock_notify(
6723  sqlite3 *pBlocked,                          /* Waiting connection */
6724  void (*xNotify)(void **apArg, int nArg),    /* Callback function to invoke */
6725  void *pNotifyArg                            /* Argument to pass to xNotify */
6726);
6727
6728
6729/*
6730** CAPI3REF: String Comparison
6731**
6732** ^The [sqlite3_strnicmp()] API allows applications and extensions to
6733** compare the contents of two buffers containing UTF-8 strings in a
6734** case-independent fashion, using the same definition of case independence
6735** that SQLite uses internally when comparing identifiers.
6736*/
6737SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
6738
6739/*
6740** CAPI3REF: Error Logging Interface
6741**
6742** ^The [sqlite3_log()] interface writes a message into the error log
6743** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
6744** ^If logging is enabled, the zFormat string and subsequent arguments are
6745** used with [sqlite3_snprintf()] to generate the final output string.
6746**
6747** The sqlite3_log() interface is intended for use by extensions such as
6748** virtual tables, collating functions, and SQL functions.  While there is
6749** nothing to prevent an application from calling sqlite3_log(), doing so
6750** is considered bad form.
6751**
6752** The zFormat string must not be NULL.
6753**
6754** To avoid deadlocks and other threading problems, the sqlite3_log() routine
6755** will not use dynamically allocated memory.  The log message is stored in
6756** a fixed-length buffer on the stack.  If the log message is longer than
6757** a few hundred characters, it will be truncated to the length of the
6758** buffer.
6759*/
6760SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...);
6761
6762/*
6763** CAPI3REF: Write-Ahead Log Commit Hook
6764**
6765** ^The [sqlite3_wal_hook()] function is used to register a callback that
6766** will be invoked each time a database connection commits data to a
6767** [write-ahead log] (i.e. whenever a transaction is committed in
6768** [journal_mode | journal_mode=WAL mode]).
6769**
6770** ^The callback is invoked by SQLite after the commit has taken place and
6771** the associated write-lock on the database released, so the implementation
6772** may read, write or [checkpoint] the database as required.
6773**
6774** ^The first parameter passed to the callback function when it is invoked
6775** is a copy of the third parameter passed to sqlite3_wal_hook() when
6776** registering the callback. ^The second is a copy of the database handle.
6777** ^The third parameter is the name of the database that was written to -
6778** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter
6779** is the number of pages currently in the write-ahead log file,
6780** including those that were just committed.
6781**
6782** The callback function should normally return [SQLITE_OK].  ^If an error
6783** code is returned, that error will propagate back up through the
6784** SQLite code base to cause the statement that provoked the callback
6785** to report an error, though the commit will have still occurred. If the
6786** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value
6787** that does not correspond to any valid SQLite error code, the results
6788** are undefined.
6789**
6790** A single database handle may have at most a single write-ahead log callback
6791** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any
6792** previously registered write-ahead log callback. ^Note that the
6793** [sqlite3_wal_autocheckpoint()] interface and the
6794** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will
6795** those overwrite any prior [sqlite3_wal_hook()] settings.
6796*/
6797SQLITE_API void *sqlite3_wal_hook(
6798  sqlite3*,
6799  int(*)(void *,sqlite3*,const char*,int),
6800  void*
6801);
6802
6803/*
6804** CAPI3REF: Configure an auto-checkpoint
6805**
6806** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
6807** [sqlite3_wal_hook()] that causes any database on [database connection] D
6808** to automatically [checkpoint]
6809** after committing a transaction if there are N or
6810** more frames in the [write-ahead log] file.  ^Passing zero or
6811** a negative value as the nFrame parameter disables automatic
6812** checkpoints entirely.
6813**
6814** ^The callback registered by this function replaces any existing callback
6815** registered using [sqlite3_wal_hook()].  ^Likewise, registering a callback
6816** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
6817** configured by this function.
6818**
6819** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
6820** from SQL.
6821**
6822** ^Every new [database connection] defaults to having the auto-checkpoint
6823** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
6824** pages.  The use of this interface
6825** is only necessary if the default setting is found to be suboptimal
6826** for a particular application.
6827*/
6828SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
6829
6830/*
6831** CAPI3REF: Checkpoint a database
6832**
6833** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X
6834** on [database connection] D to be [checkpointed].  ^If X is NULL or an
6835** empty string, then a checkpoint is run on all databases of
6836** connection D.  ^If the database connection D is not in
6837** [WAL | write-ahead log mode] then this interface is a harmless no-op.
6838**
6839** ^The [wal_checkpoint pragma] can be used to invoke this interface
6840** from SQL.  ^The [sqlite3_wal_autocheckpoint()] interface and the
6841** [wal_autocheckpoint pragma] can be used to cause this interface to be
6842** run whenever the WAL reaches a certain size threshold.
6843**
6844** See also: [sqlite3_wal_checkpoint_v2()]
6845*/
6846SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
6847
6848/*
6849** CAPI3REF: Checkpoint a database
6850**
6851** Run a checkpoint operation on WAL database zDb attached to database
6852** handle db. The specific operation is determined by the value of the
6853** eMode parameter:
6854**
6855** <dl>
6856** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
6857**   Checkpoint as many frames as possible without waiting for any database
6858**   readers or writers to finish. Sync the db file if all frames in the log
6859**   are checkpointed. This mode is the same as calling
6860**   sqlite3_wal_checkpoint(). The busy-handler callback is never invoked.
6861**
6862** <dt>SQLITE_CHECKPOINT_FULL<dd>
6863**   This mode blocks (calls the busy-handler callback) until there is no
6864**   database writer and all readers are reading from the most recent database
6865**   snapshot. It then checkpoints all frames in the log file and syncs the
6866**   database file. This call blocks database writers while it is running,
6867**   but not database readers.
6868**
6869** <dt>SQLITE_CHECKPOINT_RESTART<dd>
6870**   This mode works the same way as SQLITE_CHECKPOINT_FULL, except after
6871**   checkpointing the log file it blocks (calls the busy-handler callback)
6872**   until all readers are reading from the database file only. This ensures
6873**   that the next client to write to the database file restarts the log file
6874**   from the beginning. This call blocks database writers while it is running,
6875**   but not database readers.
6876** </dl>
6877**
6878** If pnLog is not NULL, then *pnLog is set to the total number of frames in
6879** the log file before returning. If pnCkpt is not NULL, then *pnCkpt is set to
6880** the total number of checkpointed frames (including any that were already
6881** checkpointed when this function is called). *pnLog and *pnCkpt may be
6882** populated even if sqlite3_wal_checkpoint_v2() returns other than SQLITE_OK.
6883** If no values are available because of an error, they are both set to -1
6884** before returning to communicate this to the caller.
6885**
6886** All calls obtain an exclusive "checkpoint" lock on the database file. If
6887** any other process is running a checkpoint operation at the same time, the
6888** lock cannot be obtained and SQLITE_BUSY is returned. Even if there is a
6889** busy-handler configured, it will not be invoked in this case.
6890**
6891** The SQLITE_CHECKPOINT_FULL and RESTART modes also obtain the exclusive
6892** "writer" lock on the database file. If the writer lock cannot be obtained
6893** immediately, and a busy-handler is configured, it is invoked and the writer
6894** lock retried until either the busy-handler returns 0 or the lock is
6895** successfully obtained. The busy-handler is also invoked while waiting for
6896** database readers as described above. If the busy-handler returns 0 before
6897** the writer lock is obtained or while waiting for database readers, the
6898** checkpoint operation proceeds from that point in the same way as
6899** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible
6900** without blocking any further. SQLITE_BUSY is returned in this case.
6901**
6902** If parameter zDb is NULL or points to a zero length string, then the
6903** specified operation is attempted on all WAL databases. In this case the
6904** values written to output parameters *pnLog and *pnCkpt are undefined. If
6905** an SQLITE_BUSY error is encountered when processing one or more of the
6906** attached WAL databases, the operation is still attempted on any remaining
6907** attached databases and SQLITE_BUSY is returned to the caller. If any other
6908** error occurs while processing an attached database, processing is abandoned
6909** and the error code returned to the caller immediately. If no error
6910** (SQLITE_BUSY or otherwise) is encountered while processing the attached
6911** databases, SQLITE_OK is returned.
6912**
6913** If database zDb is the name of an attached database that is not in WAL
6914** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. If
6915** zDb is not NULL (or a zero length string) and is not the name of any
6916** attached database, SQLITE_ERROR is returned to the caller.
6917*/
6918SQLITE_API int sqlite3_wal_checkpoint_v2(
6919  sqlite3 *db,                    /* Database handle */
6920  const char *zDb,                /* Name of attached database (or NULL) */
6921  int eMode,                      /* SQLITE_CHECKPOINT_* value */
6922  int *pnLog,                     /* OUT: Size of WAL log in frames */
6923  int *pnCkpt                     /* OUT: Total number of frames checkpointed */
6924);
6925
6926/*
6927** CAPI3REF: Checkpoint operation parameters
6928**
6929** These constants can be used as the 3rd parameter to
6930** [sqlite3_wal_checkpoint_v2()].  See the [sqlite3_wal_checkpoint_v2()]
6931** documentation for additional information about the meaning and use of
6932** each of these values.
6933*/
6934#define SQLITE_CHECKPOINT_PASSIVE 0
6935#define SQLITE_CHECKPOINT_FULL    1
6936#define SQLITE_CHECKPOINT_RESTART 2
6937
6938
6939/* Begin recover.patch for Chromium */
6940/*
6941** Call to initialize the recover virtual-table modules (see recover.c).
6942**
6943** This could be loaded by default in main.c, but that would make the
6944** virtual table available to Web SQL.  Breaking it out allows only
6945** selected users to enable it (currently sql/recovery.cc).
6946*/
6947int recoverVtableInit(sqlite3 *db);
6948/* End recover.patch for Chromium */
6949
6950/*
6951** Undo the hack that converts floating point types to integer for
6952** builds on processors without floating point support.
6953*/
6954#ifdef SQLITE_OMIT_FLOATING_POINT
6955# undef double
6956#endif
6957
6958#if 0
6959}  /* End of the 'extern "C"' block */
6960#endif
6961#endif
6962
6963/*
6964** 2010 August 30
6965**
6966** The author disclaims copyright to this source code.  In place of
6967** a legal notice, here is a blessing:
6968**
6969**    May you do good and not evil.
6970**    May you find forgiveness for yourself and forgive others.
6971**    May you share freely, never taking more than you give.
6972**
6973*************************************************************************
6974*/
6975
6976#ifndef _SQLITE3RTREE_H_
6977#define _SQLITE3RTREE_H_
6978
6979
6980#if 0
6981extern "C" {
6982#endif
6983
6984typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry;
6985
6986/*
6987** Register a geometry callback named zGeom that can be used as part of an
6988** R-Tree geometry query as follows:
6989**
6990**   SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)
6991*/
6992SQLITE_API int sqlite3_rtree_geometry_callback(
6993  sqlite3 *db,
6994  const char *zGeom,
6995  int (*xGeom)(sqlite3_rtree_geometry *, int nCoord, double *aCoord, int *pRes),
6996  void *pContext
6997);
6998
6999
7000/*
7001** A pointer to a structure of the following type is passed as the first
7002** argument to callbacks registered using rtree_geometry_callback().
7003*/
7004struct sqlite3_rtree_geometry {
7005  void *pContext;                 /* Copy of pContext passed to s_r_g_c() */
7006  int nParam;                     /* Size of array aParam[] */
7007  double *aParam;                 /* Parameters passed to SQL geom function */
7008  void *pUser;                    /* Callback implementation user data */
7009  void (*xDelUser)(void *);       /* Called by SQLite to clean up pUser */
7010};
7011
7012
7013#if 0
7014}  /* end of the 'extern "C"' block */
7015#endif
7016
7017#endif  /* ifndef _SQLITE3RTREE_H_ */
7018
7019
7020/************** End of sqlite3.h *********************************************/
7021/************** Continuing where we left off in sqliteInt.h ******************/
7022/************** Include hash.h in the middle of sqliteInt.h ******************/
7023/************** Begin file hash.h ********************************************/
7024/*
7025** 2001 September 22
7026**
7027** The author disclaims copyright to this source code.  In place of
7028** a legal notice, here is a blessing:
7029**
7030**    May you do good and not evil.
7031**    May you find forgiveness for yourself and forgive others.
7032**    May you share freely, never taking more than you give.
7033**
7034*************************************************************************
7035** This is the header file for the generic hash-table implemenation
7036** used in SQLite.
7037*/
7038#ifndef _SQLITE_HASH_H_
7039#define _SQLITE_HASH_H_
7040
7041/* Forward declarations of structures. */
7042typedef struct Hash Hash;
7043typedef struct HashElem HashElem;
7044
7045/* A complete hash table is an instance of the following structure.
7046** The internals of this structure are intended to be opaque -- client
7047** code should not attempt to access or modify the fields of this structure
7048** directly.  Change this structure only by using the routines below.
7049** However, some of the "procedures" and "functions" for modifying and
7050** accessing this structure are really macros, so we can't really make
7051** this structure opaque.
7052**
7053** All elements of the hash table are on a single doubly-linked list.
7054** Hash.first points to the head of this list.
7055**
7056** There are Hash.htsize buckets.  Each bucket points to a spot in
7057** the global doubly-linked list.  The contents of the bucket are the
7058** element pointed to plus the next _ht.count-1 elements in the list.
7059**
7060** Hash.htsize and Hash.ht may be zero.  In that case lookup is done
7061** by a linear search of the global list.  For small tables, the
7062** Hash.ht table is never allocated because if there are few elements
7063** in the table, it is faster to do a linear search than to manage
7064** the hash table.
7065*/
7066struct Hash {
7067  unsigned int htsize;      /* Number of buckets in the hash table */
7068  unsigned int count;       /* Number of entries in this table */
7069  HashElem *first;          /* The first element of the array */
7070  struct _ht {              /* the hash table */
7071    int count;                 /* Number of entries with this hash */
7072    HashElem *chain;           /* Pointer to first entry with this hash */
7073  } *ht;
7074};
7075
7076/* Each element in the hash table is an instance of the following
7077** structure.  All elements are stored on a single doubly-linked list.
7078**
7079** Again, this structure is intended to be opaque, but it can't really
7080** be opaque because it is used by macros.
7081*/
7082struct HashElem {
7083  HashElem *next, *prev;       /* Next and previous elements in the table */
7084  void *data;                  /* Data associated with this element */
7085  const char *pKey; int nKey;  /* Key associated with this element */
7086};
7087
7088/*
7089** Access routines.  To delete, insert a NULL pointer.
7090*/
7091SQLITE_PRIVATE void sqlite3HashInit(Hash*);
7092SQLITE_PRIVATE void *sqlite3HashInsert(Hash*, const char *pKey, int nKey, void *pData);
7093SQLITE_PRIVATE void *sqlite3HashFind(const Hash*, const char *pKey, int nKey);
7094SQLITE_PRIVATE void sqlite3HashClear(Hash*);
7095
7096/*
7097** Macros for looping over all elements of a hash table.  The idiom is
7098** like this:
7099**
7100**   Hash h;
7101**   HashElem *p;
7102**   ...
7103**   for(p=sqliteHashFirst(&h); p; p=sqliteHashNext(p)){
7104**     SomeStructure *pData = sqliteHashData(p);
7105**     // do something with pData
7106**   }
7107*/
7108#define sqliteHashFirst(H)  ((H)->first)
7109#define sqliteHashNext(E)   ((E)->next)
7110#define sqliteHashData(E)   ((E)->data)
7111/* #define sqliteHashKey(E)    ((E)->pKey) // NOT USED */
7112/* #define sqliteHashKeysize(E) ((E)->nKey)  // NOT USED */
7113
7114/*
7115** Number of entries in a hash table
7116*/
7117/* #define sqliteHashCount(H)  ((H)->count) // NOT USED */
7118
7119#endif /* _SQLITE_HASH_H_ */
7120
7121/************** End of hash.h ************************************************/
7122/************** Continuing where we left off in sqliteInt.h ******************/
7123/************** Include parse.h in the middle of sqliteInt.h *****************/
7124/************** Begin file parse.h *******************************************/
7125#define TK_SEMI                            1
7126#define TK_EXPLAIN                         2
7127#define TK_QUERY                           3
7128#define TK_PLAN                            4
7129#define TK_BEGIN                           5
7130#define TK_TRANSACTION                     6
7131#define TK_DEFERRED                        7
7132#define TK_IMMEDIATE                       8
7133#define TK_EXCLUSIVE                       9
7134#define TK_COMMIT                         10
7135#define TK_END                            11
7136#define TK_ROLLBACK                       12
7137#define TK_SAVEPOINT                      13
7138#define TK_RELEASE                        14
7139#define TK_TO                             15
7140#define TK_TABLE                          16
7141#define TK_CREATE                         17
7142#define TK_IF                             18
7143#define TK_NOT                            19
7144#define TK_EXISTS                         20
7145#define TK_TEMP                           21
7146#define TK_LP                             22
7147#define TK_RP                             23
7148#define TK_AS                             24
7149#define TK_COMMA                          25
7150#define TK_ID                             26
7151#define TK_INDEXED                        27
7152#define TK_ABORT                          28
7153#define TK_ACTION                         29
7154#define TK_AFTER                          30
7155#define TK_ANALYZE                        31
7156#define TK_ASC                            32
7157#define TK_ATTACH                         33
7158#define TK_BEFORE                         34
7159#define TK_BY                             35
7160#define TK_CASCADE                        36
7161#define TK_CAST                           37
7162#define TK_COLUMNKW                       38
7163#define TK_CONFLICT                       39
7164#define TK_DATABASE                       40
7165#define TK_DESC                           41
7166#define TK_DETACH                         42
7167#define TK_EACH                           43
7168#define TK_FAIL                           44
7169#define TK_FOR                            45
7170#define TK_IGNORE                         46
7171#define TK_INITIALLY                      47
7172#define TK_INSTEAD                        48
7173#define TK_LIKE_KW                        49
7174#define TK_MATCH                          50
7175#define TK_NO                             51
7176#define TK_KEY                            52
7177#define TK_OF                             53
7178#define TK_OFFSET                         54
7179#define TK_PRAGMA                         55
7180#define TK_RAISE                          56
7181#define TK_REPLACE                        57
7182#define TK_RESTRICT                       58
7183#define TK_ROW                            59
7184#define TK_TRIGGER                        60
7185#define TK_VACUUM                         61
7186#define TK_VIEW                           62
7187#define TK_VIRTUAL                        63
7188#define TK_REINDEX                        64
7189#define TK_RENAME                         65
7190#define TK_CTIME_KW                       66
7191#define TK_ANY                            67
7192#define TK_OR                             68
7193#define TK_AND                            69
7194#define TK_IS                             70
7195#define TK_BETWEEN                        71
7196#define TK_IN                             72
7197#define TK_ISNULL                         73
7198#define TK_NOTNULL                        74
7199#define TK_NE                             75
7200#define TK_EQ                             76
7201#define TK_GT                             77
7202#define TK_LE                             78
7203#define TK_LT                             79
7204#define TK_GE                             80
7205#define TK_ESCAPE                         81
7206#define TK_BITAND                         82
7207#define TK_BITOR                          83
7208#define TK_LSHIFT                         84
7209#define TK_RSHIFT                         85
7210#define TK_PLUS                           86
7211#define TK_MINUS                          87
7212#define TK_STAR                           88
7213#define TK_SLASH                          89
7214#define TK_REM                            90
7215#define TK_CONCAT                         91
7216#define TK_COLLATE                        92
7217#define TK_BITNOT                         93
7218#define TK_STRING                         94
7219#define TK_JOIN_KW                        95
7220#define TK_CONSTRAINT                     96
7221#define TK_DEFAULT                        97
7222#define TK_NULL                           98
7223#define TK_PRIMARY                        99
7224#define TK_UNIQUE                         100
7225#define TK_CHECK                          101
7226#define TK_REFERENCES                     102
7227#define TK_AUTOINCR                       103
7228#define TK_ON                             104
7229#define TK_INSERT                         105
7230#define TK_DELETE                         106
7231#define TK_UPDATE                         107
7232#define TK_SET                            108
7233#define TK_DEFERRABLE                     109
7234#define TK_FOREIGN                        110
7235#define TK_DROP                           111
7236#define TK_UNION                          112
7237#define TK_ALL                            113
7238#define TK_EXCEPT                         114
7239#define TK_INTERSECT                      115
7240#define TK_SELECT                         116
7241#define TK_DISTINCT                       117
7242#define TK_DOT                            118
7243#define TK_FROM                           119
7244#define TK_JOIN                           120
7245#define TK_USING                          121
7246#define TK_ORDER                          122
7247#define TK_GROUP                          123
7248#define TK_HAVING                         124
7249#define TK_LIMIT                          125
7250#define TK_WHERE                          126
7251#define TK_INTO                           127
7252#define TK_VALUES                         128
7253#define TK_INTEGER                        129
7254#define TK_FLOAT                          130
7255#define TK_BLOB                           131
7256#define TK_REGISTER                       132
7257#define TK_VARIABLE                       133
7258#define TK_CASE                           134
7259#define TK_WHEN                           135
7260#define TK_THEN                           136
7261#define TK_ELSE                           137
7262#define TK_INDEX                          138
7263#define TK_ALTER                          139
7264#define TK_ADD                            140
7265#define TK_TO_TEXT                        141
7266#define TK_TO_BLOB                        142
7267#define TK_TO_NUMERIC                     143
7268#define TK_TO_INT                         144
7269#define TK_TO_REAL                        145
7270#define TK_ISNOT                          146
7271#define TK_END_OF_FILE                    147
7272#define TK_ILLEGAL                        148
7273#define TK_SPACE                          149
7274#define TK_UNCLOSED_STRING                150
7275#define TK_FUNCTION                       151
7276#define TK_COLUMN                         152
7277#define TK_AGG_FUNCTION                   153
7278#define TK_AGG_COLUMN                     154
7279#define TK_CONST_FUNC                     155
7280#define TK_UMINUS                         156
7281#define TK_UPLUS                          157
7282
7283/************** End of parse.h ***********************************************/
7284/************** Continuing where we left off in sqliteInt.h ******************/
7285#include <stdio.h>
7286#include <stdlib.h>
7287#include <string.h>
7288#include <assert.h>
7289#include <stddef.h>
7290
7291/*
7292** If compiling for a processor that lacks floating point support,
7293** substitute integer for floating-point
7294*/
7295#ifdef SQLITE_OMIT_FLOATING_POINT
7296# define double sqlite_int64
7297# define float sqlite_int64
7298# define LONGDOUBLE_TYPE sqlite_int64
7299# ifndef SQLITE_BIG_DBL
7300#   define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50)
7301# endif
7302# define SQLITE_OMIT_DATETIME_FUNCS 1
7303# define SQLITE_OMIT_TRACE 1
7304# undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
7305# undef SQLITE_HAVE_ISNAN
7306#endif
7307#ifndef SQLITE_BIG_DBL
7308# define SQLITE_BIG_DBL (1e99)
7309#endif
7310
7311/*
7312** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0
7313** afterward. Having this macro allows us to cause the C compiler
7314** to omit code used by TEMP tables without messy #ifndef statements.
7315*/
7316#ifdef SQLITE_OMIT_TEMPDB
7317#define OMIT_TEMPDB 1
7318#else
7319#define OMIT_TEMPDB 0
7320#endif
7321
7322/*
7323** The "file format" number is an integer that is incremented whenever
7324** the VDBE-level file format changes.  The following macros define the
7325** the default file format for new databases and the maximum file format
7326** that the library can read.
7327*/
7328#define SQLITE_MAX_FILE_FORMAT 4
7329#ifndef SQLITE_DEFAULT_FILE_FORMAT
7330# define SQLITE_DEFAULT_FILE_FORMAT 1
7331#endif
7332
7333/*
7334** Determine whether triggers are recursive by default.  This can be
7335** changed at run-time using a pragma.
7336*/
7337#ifndef SQLITE_DEFAULT_RECURSIVE_TRIGGERS
7338# define SQLITE_DEFAULT_RECURSIVE_TRIGGERS 0
7339#endif
7340
7341/*
7342** Provide a default value for SQLITE_TEMP_STORE in case it is not specified
7343** on the command-line
7344*/
7345#ifndef SQLITE_TEMP_STORE
7346# define SQLITE_TEMP_STORE 1
7347#endif
7348
7349/*
7350** GCC does not define the offsetof() macro so we'll have to do it
7351** ourselves.
7352*/
7353#ifndef offsetof
7354#define offsetof(STRUCTURE,FIELD) ((int)((char*)&((STRUCTURE*)0)->FIELD))
7355#endif
7356
7357/*
7358** Check to see if this machine uses EBCDIC.  (Yes, believe it or
7359** not, there are still machines out there that use EBCDIC.)
7360*/
7361#if 'A' == '\301'
7362# define SQLITE_EBCDIC 1
7363#else
7364# define SQLITE_ASCII 1
7365#endif
7366
7367/*
7368** Integers of known sizes.  These typedefs might change for architectures
7369** where the sizes very.  Preprocessor macros are available so that the
7370** types can be conveniently redefined at compile-type.  Like this:
7371**
7372**         cc '-DUINTPTR_TYPE=long long int' ...
7373*/
7374#ifndef UINT32_TYPE
7375# ifdef HAVE_UINT32_T
7376#  define UINT32_TYPE uint32_t
7377# else
7378#  define UINT32_TYPE unsigned int
7379# endif
7380#endif
7381#ifndef UINT16_TYPE
7382# ifdef HAVE_UINT16_T
7383#  define UINT16_TYPE uint16_t
7384# else
7385#  define UINT16_TYPE unsigned short int
7386# endif
7387#endif
7388#ifndef INT16_TYPE
7389# ifdef HAVE_INT16_T
7390#  define INT16_TYPE int16_t
7391# else
7392#  define INT16_TYPE short int
7393# endif
7394#endif
7395#ifndef UINT8_TYPE
7396# ifdef HAVE_UINT8_T
7397#  define UINT8_TYPE uint8_t
7398# else
7399#  define UINT8_TYPE unsigned char
7400# endif
7401#endif
7402#ifndef INT8_TYPE
7403# ifdef HAVE_INT8_T
7404#  define INT8_TYPE int8_t
7405# else
7406#  define INT8_TYPE signed char
7407# endif
7408#endif
7409#ifndef LONGDOUBLE_TYPE
7410# define LONGDOUBLE_TYPE long double
7411#endif
7412typedef sqlite_int64 i64;          /* 8-byte signed integer */
7413typedef sqlite_uint64 u64;         /* 8-byte unsigned integer */
7414typedef UINT32_TYPE u32;           /* 4-byte unsigned integer */
7415typedef UINT16_TYPE u16;           /* 2-byte unsigned integer */
7416typedef INT16_TYPE i16;            /* 2-byte signed integer */
7417typedef UINT8_TYPE u8;             /* 1-byte unsigned integer */
7418typedef INT8_TYPE i8;              /* 1-byte signed integer */
7419
7420/*
7421** SQLITE_MAX_U32 is a u64 constant that is the maximum u64 value
7422** that can be stored in a u32 without loss of data.  The value
7423** is 0x00000000ffffffff.  But because of quirks of some compilers, we
7424** have to specify the value in the less intuitive manner shown:
7425*/
7426#define SQLITE_MAX_U32  ((((u64)1)<<32)-1)
7427
7428/*
7429** Macros to determine whether the machine is big or little endian,
7430** evaluated at runtime.
7431*/
7432#ifdef SQLITE_AMALGAMATION
7433SQLITE_PRIVATE const int sqlite3one = 1;
7434#else
7435SQLITE_PRIVATE const int sqlite3one;
7436#endif
7437#if defined(i386) || defined(__i386__) || defined(_M_IX86)\
7438                             || defined(__x86_64) || defined(__x86_64__)
7439# define SQLITE_BIGENDIAN    0
7440# define SQLITE_LITTLEENDIAN 1
7441# define SQLITE_UTF16NATIVE  SQLITE_UTF16LE
7442#else
7443# define SQLITE_BIGENDIAN    (*(char *)(&sqlite3one)==0)
7444# define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
7445# define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)
7446#endif
7447
7448/*
7449** Constants for the largest and smallest possible 64-bit signed integers.
7450** These macros are designed to work correctly on both 32-bit and 64-bit
7451** compilers.
7452*/
7453#define LARGEST_INT64  (0xffffffff|(((i64)0x7fffffff)<<32))
7454#define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
7455
7456/*
7457** Round up a number to the next larger multiple of 8.  This is used
7458** to force 8-byte alignment on 64-bit architectures.
7459*/
7460#define ROUND8(x)     (((x)+7)&~7)
7461
7462/*
7463** Round down to the nearest multiple of 8
7464*/
7465#define ROUNDDOWN8(x) ((x)&~7)
7466
7467/*
7468** Assert that the pointer X is aligned to an 8-byte boundary.  This
7469** macro is used only within assert() to verify that the code gets
7470** all alignment restrictions correct.
7471**
7472** Except, if SQLITE_4_BYTE_ALIGNED_MALLOC is defined, then the
7473** underlying malloc() implemention might return us 4-byte aligned
7474** pointers.  In that case, only verify 4-byte alignment.
7475*/
7476#ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
7477# define EIGHT_BYTE_ALIGNMENT(X)   ((((char*)(X) - (char*)0)&3)==0)
7478#else
7479# define EIGHT_BYTE_ALIGNMENT(X)   ((((char*)(X) - (char*)0)&7)==0)
7480#endif
7481
7482
7483/*
7484** An instance of the following structure is used to store the busy-handler
7485** callback for a given sqlite handle.
7486**
7487** The sqlite.busyHandler member of the sqlite struct contains the busy
7488** callback for the database handle. Each pager opened via the sqlite
7489** handle is passed a pointer to sqlite.busyHandler. The busy-handler
7490** callback is currently invoked only from within pager.c.
7491*/
7492typedef struct BusyHandler BusyHandler;
7493struct BusyHandler {
7494  int (*xFunc)(void *,int);  /* The busy callback */
7495  void *pArg;                /* First arg to busy callback */
7496  int nBusy;                 /* Incremented with each busy call */
7497};
7498
7499/*
7500** Name of the master database table.  The master database table
7501** is a special table that holds the names and attributes of all
7502** user tables and indices.
7503*/
7504#define MASTER_NAME       "sqlite_master"
7505#define TEMP_MASTER_NAME  "sqlite_temp_master"
7506
7507/*
7508** The root-page of the master database table.
7509*/
7510#define MASTER_ROOT       1
7511
7512/*
7513** The name of the schema table.
7514*/
7515#define SCHEMA_TABLE(x)  ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME)
7516
7517/*
7518** A convenience macro that returns the number of elements in
7519** an array.
7520*/
7521#define ArraySize(X)    ((int)(sizeof(X)/sizeof(X[0])))
7522
7523/*
7524** The following value as a destructor means to use sqlite3DbFree().
7525** This is an internal extension to SQLITE_STATIC and SQLITE_TRANSIENT.
7526*/
7527#define SQLITE_DYNAMIC   ((sqlite3_destructor_type)sqlite3DbFree)
7528
7529/*
7530** When SQLITE_OMIT_WSD is defined, it means that the target platform does
7531** not support Writable Static Data (WSD) such as global and static variables.
7532** All variables must either be on the stack or dynamically allocated from
7533** the heap.  When WSD is unsupported, the variable declarations scattered
7534** throughout the SQLite code must become constants instead.  The SQLITE_WSD
7535** macro is used for this purpose.  And instead of referencing the variable
7536** directly, we use its constant as a key to lookup the run-time allocated
7537** buffer that holds real variable.  The constant is also the initializer
7538** for the run-time allocated buffer.
7539**
7540** In the usual case where WSD is supported, the SQLITE_WSD and GLOBAL
7541** macros become no-ops and have zero performance impact.
7542*/
7543#ifdef SQLITE_OMIT_WSD
7544  #define SQLITE_WSD const
7545  #define GLOBAL(t,v) (*(t*)sqlite3_wsd_find((void*)&(v), sizeof(v)))
7546  #define sqlite3GlobalConfig GLOBAL(struct Sqlite3Config, sqlite3Config)
7547SQLITE_API   int sqlite3_wsd_init(int N, int J);
7548SQLITE_API   void *sqlite3_wsd_find(void *K, int L);
7549#else
7550  #define SQLITE_WSD
7551  #define GLOBAL(t,v) v
7552  #define sqlite3GlobalConfig sqlite3Config
7553#endif
7554
7555/*
7556** The following macros are used to suppress compiler warnings and to
7557** make it clear to human readers when a function parameter is deliberately
7558** left unused within the body of a function. This usually happens when
7559** a function is called via a function pointer. For example the
7560** implementation of an SQL aggregate step callback may not use the
7561** parameter indicating the number of arguments passed to the aggregate,
7562** if it knows that this is enforced elsewhere.
7563**
7564** When a function parameter is not used at all within the body of a function,
7565** it is generally named "NotUsed" or "NotUsed2" to make things even clearer.
7566** However, these macros may also be used to suppress warnings related to
7567** parameters that may or may not be used depending on compilation options.
7568** For example those parameters only used in assert() statements. In these
7569** cases the parameters are named as per the usual conventions.
7570*/
7571#define UNUSED_PARAMETER(x) (void)(x)
7572#define UNUSED_PARAMETER2(x,y) UNUSED_PARAMETER(x),UNUSED_PARAMETER(y)
7573
7574/*
7575** Forward references to structures
7576*/
7577typedef struct AggInfo AggInfo;
7578typedef struct AuthContext AuthContext;
7579typedef struct AutoincInfo AutoincInfo;
7580typedef struct Bitvec Bitvec;
7581typedef struct CollSeq CollSeq;
7582typedef struct Column Column;
7583typedef struct Db Db;
7584typedef struct Schema Schema;
7585typedef struct Expr Expr;
7586typedef struct ExprList ExprList;
7587typedef struct ExprSpan ExprSpan;
7588typedef struct FKey FKey;
7589typedef struct FuncDestructor FuncDestructor;
7590typedef struct FuncDef FuncDef;
7591typedef struct FuncDefHash FuncDefHash;
7592typedef struct IdList IdList;
7593typedef struct Index Index;
7594typedef struct IndexSample IndexSample;
7595typedef struct KeyClass KeyClass;
7596typedef struct KeyInfo KeyInfo;
7597typedef struct Lookaside Lookaside;
7598typedef struct LookasideSlot LookasideSlot;
7599typedef struct Module Module;
7600typedef struct NameContext NameContext;
7601typedef struct Parse Parse;
7602typedef struct RowSet RowSet;
7603typedef struct Savepoint Savepoint;
7604typedef struct Select Select;
7605typedef struct SrcList SrcList;
7606typedef struct StrAccum StrAccum;
7607typedef struct Table Table;
7608typedef struct TableLock TableLock;
7609typedef struct Token Token;
7610typedef struct Trigger Trigger;
7611typedef struct TriggerPrg TriggerPrg;
7612typedef struct TriggerStep TriggerStep;
7613typedef struct UnpackedRecord UnpackedRecord;
7614typedef struct VTable VTable;
7615typedef struct Walker Walker;
7616typedef struct WherePlan WherePlan;
7617typedef struct WhereInfo WhereInfo;
7618typedef struct WhereLevel WhereLevel;
7619
7620/*
7621** Defer sourcing vdbe.h and btree.h until after the "u8" and
7622** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque
7623** pointer types (i.e. FuncDef) defined above.
7624*/
7625/************** Include btree.h in the middle of sqliteInt.h *****************/
7626/************** Begin file btree.h *******************************************/
7627/*
7628** 2001 September 15
7629**
7630** The author disclaims copyright to this source code.  In place of
7631** a legal notice, here is a blessing:
7632**
7633**    May you do good and not evil.
7634**    May you find forgiveness for yourself and forgive others.
7635**    May you share freely, never taking more than you give.
7636**
7637*************************************************************************
7638** This header file defines the interface that the sqlite B-Tree file
7639** subsystem.  See comments in the source code for a detailed description
7640** of what each interface routine does.
7641*/
7642#ifndef _BTREE_H_
7643#define _BTREE_H_
7644
7645/* TODO: This definition is just included so other modules compile. It
7646** needs to be revisited.
7647*/
7648#define SQLITE_N_BTREE_META 10
7649
7650/*
7651** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
7652** it must be turned on for each database using "PRAGMA auto_vacuum = 1".
7653*/
7654#ifndef SQLITE_DEFAULT_AUTOVACUUM
7655  #define SQLITE_DEFAULT_AUTOVACUUM 0
7656#endif
7657
7658#define BTREE_AUTOVACUUM_NONE 0        /* Do not do auto-vacuum */
7659#define BTREE_AUTOVACUUM_FULL 1        /* Do full auto-vacuum */
7660#define BTREE_AUTOVACUUM_INCR 2        /* Incremental vacuum */
7661
7662/*
7663** Forward declarations of structure
7664*/
7665typedef struct Btree Btree;
7666typedef struct BtCursor BtCursor;
7667typedef struct BtShared BtShared;
7668
7669
7670