sqlite3.c
Go to the documentation of this file.
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.13.0. 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 /************** Begin file sqliteInt.h ***************************************/
26 /*
27 ** 2001 September 15
28 **
29 ** The author disclaims copyright to this source code. In place of
30 ** a legal notice, here is a blessing:
31 **
32 ** May you do good and not evil.
33 ** May you find forgiveness for yourself and forgive others.
34 ** May you share freely, never taking more than you give.
35 **
36 *************************************************************************
37 ** Internal interface definitions for SQLite.
38 **
39 */
40 #ifndef _SQLITEINT_H_
41 #define _SQLITEINT_H_
42 
43 /* Special Comments:
44 **
45 ** Some comments have special meaning to the tools that measure test
46 ** coverage:
47 **
48 ** NO_TEST - The branches on this line are not
49 ** measured by branch coverage. This is
50 ** used on lines of code that actually
51 ** implement parts of coverage testing.
52 **
53 ** OPTIMIZATION-IF-TRUE - This branch is allowed to alway be false
54 ** and the correct answer is still obtained,
55 ** though perhaps more slowly.
56 **
57 ** OPTIMIZATION-IF-FALSE - This branch is allowed to alway be true
58 ** and the correct answer is still obtained,
59 ** though perhaps more slowly.
60 **
61 ** PREVENTS-HARMLESS-OVERREAD - This branch prevents a buffer overread
62 ** that would be harmless and undetectable
63 ** if it did occur.
64 **
65 ** In all cases, the special comment must be enclosed in the usual
66 ** slash-asterisk...asterisk-slash comment marks, with no spaces between the
67 ** asterisks and the comment text.
68 */
69 
70 /*
71 ** Make sure that rand_s() is available on Windows systems with MSVC 2005
72 ** or higher.
73 */
74 #if defined(_MSC_VER) && _MSC_VER>=1400
75 # define _CRT_RAND_S
76 #endif
77 
78 /*
79 ** Include the header file used to customize the compiler options for MSVC.
80 ** This should be done first so that it can successfully prevent spurious
81 ** compiler warnings due to subsequent content in this file and other files
82 ** that are included by this file.
83 */
84 /************** Include msvc.h in the middle of sqliteInt.h ******************/
85 /************** Begin file msvc.h ********************************************/
86 /*
87 ** 2015 January 12
88 **
89 ** The author disclaims copyright to this source code. In place of
90 ** a legal notice, here is a blessing:
91 **
92 ** May you do good and not evil.
93 ** May you find forgiveness for yourself and forgive others.
94 ** May you share freely, never taking more than you give.
95 **
96 ******************************************************************************
97 **
98 ** This file contains code that is specific to MSVC.
99 */
100 #ifndef _MSVC_H_
101 #define _MSVC_H_
102 
103 #if defined(_MSC_VER)
104 #pragma warning(disable : 4054)
105 #pragma warning(disable : 4055)
106 #pragma warning(disable : 4100)
107 #pragma warning(disable : 4127)
108 #pragma warning(disable : 4130)
109 #pragma warning(disable : 4152)
110 #pragma warning(disable : 4189)
111 #pragma warning(disable : 4206)
112 #pragma warning(disable : 4210)
113 #pragma warning(disable : 4232)
114 #pragma warning(disable : 4244)
115 #pragma warning(disable : 4305)
116 #pragma warning(disable : 4306)
117 #pragma warning(disable : 4702)
118 #pragma warning(disable : 4706)
119 #endif /* defined(_MSC_VER) */
120 
121 #endif /* _MSVC_H_ */
122 
123 /************** End of msvc.h ************************************************/
124 /************** Continuing where we left off in sqliteInt.h ******************/
125 
126 /*
127 ** Special setup for VxWorks
128 */
129 /************** Include vxworks.h in the middle of sqliteInt.h ***************/
130 /************** Begin file vxworks.h *****************************************/
131 /*
132 ** 2015-03-02
133 **
134 ** The author disclaims copyright to this source code. In place of
135 ** a legal notice, here is a blessing:
136 **
137 ** May you do good and not evil.
138 ** May you find forgiveness for yourself and forgive others.
139 ** May you share freely, never taking more than you give.
140 **
141 ******************************************************************************
142 **
143 ** This file contains code that is specific to Wind River's VxWorks
144 */
145 #if defined(__RTP__) || defined(_WRS2_KERNEL)
146 /* This is VxWorks. Set up things specially for that OS
147 */
148 #include <vxWorks.h>
149 #include <pthread.h> /* amalgamator: dontcache */
150 #define OS_VXWORKS 1
151 #define SQLITE_OS_OTHER 0
152 #define SQLITE_HOMEGROWN_RECURSIVE_MUTEX 1
153 #define SQLITE_OMIT_LOAD_EXTENSION 1
154 #define SQLITE_ENABLE_LOCKING_STYLE 0
155 #define HAVE_UTIME 1
156 #else
157 /* This is not VxWorks. */
158 #define OS_VXWORKS 0
159 #define HAVE_FCHOWN 1
160 #define HAVE_READLINK 1
161 #define HAVE_LSTAT 1
162 #endif /* defined(_WRS2_KERNEL) */
163 
164 /************** End of vxworks.h *********************************************/
165 /************** Continuing where we left off in sqliteInt.h ******************/
166 
167 /*
168 ** These #defines should enable >2GB file support on POSIX if the
169 ** underlying operating system supports it. If the OS lacks
170 ** large file support, or if the OS is windows, these should be no-ops.
171 **
172 ** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any
173 ** system #includes. Hence, this block of code must be the very first
174 ** code in all source files.
175 **
176 ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
177 ** on the compiler command line. This is necessary if you are compiling
178 ** on a recent machine (ex: Red Hat 7.2) but you want your code to work
179 ** on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2
180 ** without this option, LFS is enable. But LFS does not exist in the kernel
181 ** in Red Hat 6.0, so the code won't work. Hence, for maximum binary
182 ** portability you should omit LFS.
183 **
184 ** The previous paragraph was written in 2005. (This paragraph is written
185 ** on 2008-11-28.) These days, all Linux kernels support large files, so
186 ** you should probably leave LFS enabled. But some embedded platforms might
187 ** lack LFS in which case the SQLITE_DISABLE_LFS macro might still be useful.
188 **
189 ** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later.
190 */
191 #ifndef SQLITE_DISABLE_LFS
192 # define _LARGE_FILE 1
193 # ifndef _FILE_OFFSET_BITS
194 # define _FILE_OFFSET_BITS 64
195 # endif
196 # define _LARGEFILE_SOURCE 1
197 #endif
198 
199 /* What version of GCC is being used. 0 means GCC is not being used */
200 #ifdef __GNUC__
201 # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__)
202 #else
203 # define GCC_VERSION 0
204 #endif
205 
206 /* Needed for various definitions... */
207 #if defined(__GNUC__) && !defined(_GNU_SOURCE)
208 # define _GNU_SOURCE
209 #endif
210 
211 #if defined(__OpenBSD__) && !defined(_BSD_SOURCE)
212 # define _BSD_SOURCE
213 #endif
214 
215 /*
216 ** For MinGW, check to see if we can include the header file containing its
217 ** version information, among other things. Normally, this internal MinGW
218 ** header file would [only] be included automatically by other MinGW header
219 ** files; however, the contained version information is now required by this
220 ** header file to work around binary compatibility issues (see below) and
221 ** this is the only known way to reliably obtain it. This entire #if block
222 ** would be completely unnecessary if there was any other way of detecting
223 ** MinGW via their preprocessor (e.g. if they customized their GCC to define
224 ** some MinGW-specific macros). When compiling for MinGW, either the
225 ** _HAVE_MINGW_H or _HAVE__MINGW_H (note the extra underscore) macro must be
226 ** defined; otherwise, detection of conditions specific to MinGW will be
227 ** disabled.
228 */
229 #if defined(_HAVE_MINGW_H)
230 # include "mingw.h"
231 #elif defined(_HAVE__MINGW_H)
232 # include "_mingw.h"
233 #endif
234 
235 /*
236 ** For MinGW version 4.x (and higher), check to see if the _USE_32BIT_TIME_T
237 ** define is required to maintain binary compatibility with the MSVC runtime
238 ** library in use (e.g. for Windows XP).
239 */
240 #if !defined(_USE_32BIT_TIME_T) && !defined(_USE_64BIT_TIME_T) && \
241  defined(_WIN32) && !defined(_WIN64) && \
242  defined(__MINGW_MAJOR_VERSION) && __MINGW_MAJOR_VERSION >= 4 && \
243  defined(__MSVCRT__)
244 # define _USE_32BIT_TIME_T
245 #endif
246 
247 /* The public SQLite interface. The _FILE_OFFSET_BITS macro must appear
248 ** first in QNX. Also, the _USE_32BIT_TIME_T macro must appear first for
249 ** MinGW.
250 */
251 /************** Include sqlite3.h in the middle of sqliteInt.h ***************/
252 /************** Begin file sqlite3.h *****************************************/
253 /*
254 ** 2001 September 15
255 **
256 ** The author disclaims copyright to this source code. In place of
257 ** a legal notice, here is a blessing:
258 **
259 ** May you do good and not evil.
260 ** May you find forgiveness for yourself and forgive others.
261 ** May you share freely, never taking more than you give.
262 **
263 *************************************************************************
264 ** This header file defines the interface that the SQLite library
265 ** presents to client programs. If a C-function, structure, datatype,
266 ** or constant definition does not appear in this file, then it is
267 ** not a published API of SQLite, is subject to change without
268 ** notice, and should not be referenced by programs that use SQLite.
269 **
270 ** Some of the definitions that are in this file are marked as
271 ** "experimental". Experimental interfaces are normally new
272 ** features recently added to SQLite. We do not anticipate changes
273 ** to experimental interfaces but reserve the right to make minor changes
274 ** if experience from use "in the wild" suggest such changes are prudent.
275 **
276 ** The official C-language API documentation for SQLite is derived
277 ** from comments in this file. This file is the authoritative source
278 ** on how SQLite interfaces are supposed to operate.
279 **
280 ** The name of this file under configuration management is "sqlite.h.in".
281 ** The makefile makes some minor changes to this file (such as inserting
282 ** the version number) and changes its name to "sqlite3.h" as
283 ** part of the build process.
284 */
285 #ifndef _SQLITE3_H_
286 #define _SQLITE3_H_
287 #include <stdarg.h> /* Needed for the definition of va_list */
288 
289 /*
290 ** Make sure we can call this stuff from C++.
291 */
292 #if 0
293 extern "C" {
294 #endif
295 
296 
297 /*
298 ** Provide the ability to override linkage features of the interface.
299 */
300 #ifndef SQLITE_EXTERN
301 # define SQLITE_EXTERN extern
302 #endif
303 #ifndef SQLITE_API
304 # define SQLITE_API
305 #endif
306 #ifndef SQLITE_CDECL
307 # define SQLITE_CDECL
308 #endif
309 #ifndef SQLITE_STDCALL
310 # define SQLITE_STDCALL
311 #endif
312 
313 /*
314 ** These no-op macros are used in front of interfaces to mark those
315 ** interfaces as either deprecated or experimental. New applications
316 ** should not use deprecated interfaces - they are supported for backwards
317 ** compatibility only. Application writers should be aware that
318 ** experimental interfaces are subject to change in point releases.
319 **
320 ** These macros used to resolve to various kinds of compiler magic that
321 ** would generate warning messages when they were used. But that
322 ** compiler magic ended up generating such a flurry of bug reports
323 ** that we have taken it all out and gone back to using simple
324 ** noop macros.
325 */
326 #define SQLITE_DEPRECATED
327 #define SQLITE_EXPERIMENTAL
328 
329 /*
330 ** Ensure these symbols were not defined by some previous header file.
331 */
332 #ifdef SQLITE_VERSION
333 # undef SQLITE_VERSION
334 #endif
335 #ifdef SQLITE_VERSION_NUMBER
336 # undef SQLITE_VERSION_NUMBER
337 #endif
338 
339 /*
340 ** CAPI3REF: Compile-Time Library Version Numbers
341 **
342 ** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header
343 ** evaluates to a string literal that is the SQLite version in the
344 ** format "X.Y.Z" where X is the major version number (always 3 for
345 ** SQLite3) and Y is the minor version number and Z is the release number.)^
346 ** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer
347 ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
348 ** numbers used in [SQLITE_VERSION].)^
349 ** The SQLITE_VERSION_NUMBER for any given release of SQLite will also
350 ** be larger than the release from which it is derived. Either Y will
351 ** be held constant and Z will be incremented or else Y will be incremented
352 ** and Z will be reset to zero.
353 **
354 ** Since version 3.6.18, SQLite source code has been stored in the
355 ** <a href="http://www.fossil-scm.org/">Fossil configuration management
356 ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to
357 ** a string which identifies a particular check-in of SQLite
358 ** within its configuration management system. ^The SQLITE_SOURCE_ID
359 ** string contains the date and time of the check-in (UTC) and an SHA1
360 ** hash of the entire source tree.
361 **
362 ** See also: [sqlite3_libversion()],
363 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
364 ** [sqlite_version()] and [sqlite_source_id()].
365 */
366 #define SQLITE_VERSION "3.13.0"
367 #define SQLITE_VERSION_NUMBER 3013000
368 #define SQLITE_SOURCE_ID "2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2"
369 
370 /*
371 ** CAPI3REF: Run-Time Library Version Numbers
372 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
373 **
374 ** These interfaces provide the same information as the [SQLITE_VERSION],
375 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
376 ** but are associated with the library instead of the header file. ^(Cautious
377 ** programmers might include assert() statements in their application to
378 ** verify that values returned by these interfaces match the macros in
379 ** the header, and thus ensure that the application is
380 ** compiled with matching library and header files.
381 **
382 ** <blockquote><pre>
383 ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
384 ** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 );
385 ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
386 ** </pre></blockquote>)^
387 **
388 ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
389 ** macro. ^The sqlite3_libversion() function returns a pointer to the
390 ** to the sqlite3_version[] string constant. The sqlite3_libversion()
391 ** function is provided for use in DLLs since DLL users usually do not have
392 ** direct access to string constants within the DLL. ^The
393 ** sqlite3_libversion_number() function returns an integer equal to
394 ** [SQLITE_VERSION_NUMBER]. ^The sqlite3_sourceid() function returns
395 ** a pointer to a string constant whose value is the same as the
396 ** [SQLITE_SOURCE_ID] C preprocessor macro.
397 **
398 ** See also: [sqlite_version()] and [sqlite_source_id()].
399 */
402 SQLITE_API const char *SQLITE_STDCALL sqlite3_sourceid(void);
404 
405 /*
406 ** CAPI3REF: Run-Time Library Compilation Options Diagnostics
407 **
408 ** ^The sqlite3_compileoption_used() function returns 0 or 1
409 ** indicating whether the specified option was defined at
410 ** compile time. ^The SQLITE_ prefix may be omitted from the
411 ** option name passed to sqlite3_compileoption_used().
412 **
413 ** ^The sqlite3_compileoption_get() function allows iterating
414 ** over the list of options that were defined at compile time by
415 ** returning the N-th compile time option string. ^If N is out of range,
416 ** sqlite3_compileoption_get() returns a NULL pointer. ^The SQLITE_
417 ** prefix is omitted from any strings returned by
418 ** sqlite3_compileoption_get().
419 **
420 ** ^Support for the diagnostic functions sqlite3_compileoption_used()
421 ** and sqlite3_compileoption_get() may be omitted by specifying the
422 ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
423 **
424 ** See also: SQL functions [sqlite_compileoption_used()] and
425 ** [sqlite_compileoption_get()] and the [compile_options pragma].
426 */
427 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
428 SQLITE_API int SQLITE_STDCALL sqlite3_compileoption_used(const char *zOptName);
430 #endif
431 
432 /*
433 ** CAPI3REF: Test To See If The Library Is Threadsafe
434 **
435 ** ^The sqlite3_threadsafe() function returns zero if and only if
436 ** SQLite was compiled with mutexing code omitted due to the
437 ** [SQLITE_THREADSAFE] compile-time option being set to 0.
438 **
439 ** SQLite can be compiled with or without mutexes. When
440 ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes
441 ** are enabled and SQLite is threadsafe. When the
442 ** [SQLITE_THREADSAFE] macro is 0,
443 ** the mutexes are omitted. Without the mutexes, it is not safe
444 ** to use SQLite concurrently from more than one thread.
445 **
446 ** Enabling mutexes incurs a measurable performance penalty.
447 ** So if speed is of utmost importance, it makes sense to disable
448 ** the mutexes. But for maximum safety, mutexes should be enabled.
449 ** ^The default behavior is for mutexes to be enabled.
450 **
451 ** This interface can be used by an application to make sure that the
452 ** version of SQLite that it is linking against was compiled with
453 ** the desired setting of the [SQLITE_THREADSAFE] macro.
454 **
455 ** This interface only reports on the compile-time mutex setting
456 ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
457 ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
458 ** can be fully or partially disabled using a call to [sqlite3_config()]
459 ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
460 ** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the
461 ** sqlite3_threadsafe() function shows only the compile-time setting of
462 ** thread safety, not any run-time changes to that setting made by
463 ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
464 ** is unchanged by calls to sqlite3_config().)^
465 **
466 ** See the [threading mode] documentation for additional information.
467 */
469 
470 /*
471 ** CAPI3REF: Database Connection Handle
472 ** KEYWORDS: {database connection} {database connections}
473 **
474 ** Each open SQLite database is represented by a pointer to an instance of
475 ** the opaque structure named "sqlite3". It is useful to think of an sqlite3
476 ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and
477 ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
478 ** and [sqlite3_close_v2()] are its destructors. There are many other
479 ** interfaces (such as
480 ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
481 ** [sqlite3_busy_timeout()] to name but three) that are methods on an
482 ** sqlite3 object.
483 */
484 typedef struct sqlite3 sqlite3;
485 
486 /*
487 ** CAPI3REF: 64-Bit Integer Types
488 ** KEYWORDS: sqlite_int64 sqlite_uint64
489 **
490 ** Because there is no cross-platform way to specify 64-bit integer types
491 ** SQLite includes typedefs for 64-bit signed and unsigned integers.
492 **
493 ** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
494 ** The sqlite_int64 and sqlite_uint64 types are supported for backwards
495 ** compatibility only.
496 **
497 ** ^The sqlite3_int64 and sqlite_int64 types can store integer values
498 ** between -9223372036854775808 and +9223372036854775807 inclusive. ^The
499 ** sqlite3_uint64 and sqlite_uint64 types can store integer values
500 ** between 0 and +18446744073709551615 inclusive.
501 */
502 #ifdef SQLITE_INT64_TYPE
503  typedef SQLITE_INT64_TYPE sqlite_int64;
504  typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
505 #elif defined(_MSC_VER) || defined(__BORLANDC__)
506  typedef __int64 sqlite_int64;
507  typedef unsigned __int64 sqlite_uint64;
508 #else
509  typedef long long int sqlite_int64;
510  typedef unsigned long long int sqlite_uint64;
511 #endif
512 typedef sqlite_int64 sqlite3_int64;
513 typedef sqlite_uint64 sqlite3_uint64;
514 
515 /*
516 ** If compiling for a processor that lacks floating point support,
517 ** substitute integer for floating-point.
518 */
519 #ifdef SQLITE_OMIT_FLOATING_POINT
520 # define double sqlite3_int64
521 #endif
522 
523 /*
524 ** CAPI3REF: Closing A Database Connection
525 ** DESTRUCTOR: sqlite3
526 **
527 ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
528 ** for the [sqlite3] object.
529 ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
530 ** the [sqlite3] object is successfully destroyed and all associated
531 ** resources are deallocated.
532 **
533 ** ^If the database connection is associated with unfinalized prepared
534 ** statements or unfinished sqlite3_backup objects then sqlite3_close()
535 ** will leave the database connection open and return [SQLITE_BUSY].
536 ** ^If sqlite3_close_v2() is called with unfinalized prepared statements
537 ** and/or unfinished sqlite3_backups, then the database connection becomes
538 ** an unusable "zombie" which will automatically be deallocated when the
539 ** last prepared statement is finalized or the last sqlite3_backup is
540 ** finished. The sqlite3_close_v2() interface is intended for use with
541 ** host languages that are garbage collected, and where the order in which
542 ** destructors are called is arbitrary.
543 **
544 ** Applications should [sqlite3_finalize | finalize] all [prepared statements],
545 ** [sqlite3_blob_close | close] all [BLOB handles], and
546 ** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated
547 ** with the [sqlite3] object prior to attempting to close the object. ^If
548 ** sqlite3_close_v2() is called on a [database connection] that still has
549 ** outstanding [prepared statements], [BLOB handles], and/or
550 ** [sqlite3_backup] objects then it returns [SQLITE_OK] and the deallocation
551 ** of resources is deferred until all [prepared statements], [BLOB handles],
552 ** and [sqlite3_backup] objects are also destroyed.
553 **
554 ** ^If an [sqlite3] object is destroyed while a transaction is open,
555 ** the transaction is automatically rolled back.
556 **
557 ** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)]
558 ** must be either a NULL
559 ** pointer or an [sqlite3] object pointer obtained
560 ** from [sqlite3_open()], [sqlite3_open16()], or
561 ** [sqlite3_open_v2()], and not previously closed.
562 ** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer
563 ** argument is a harmless no-op.
564 */
567 
568 /*
569 ** The type for a callback function.
570 ** This is legacy and deprecated. It is included for historical
571 ** compatibility and is not documented.
572 */
573 typedef int (*sqlite3_callback)(void*,int,char**, char**);
574 
575 /*
576 ** CAPI3REF: One-Step Query Execution Interface
577 ** METHOD: sqlite3
578 **
579 ** The sqlite3_exec() interface is a convenience wrapper around
580 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
581 ** that allows an application to run multiple statements of SQL
582 ** without having to use a lot of C code.
583 **
584 ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
585 ** semicolon-separate SQL statements passed into its 2nd argument,
586 ** in the context of the [database connection] passed in as its 1st
587 ** argument. ^If the callback function of the 3rd argument to
588 ** sqlite3_exec() is not NULL, then it is invoked for each result row
589 ** coming out of the evaluated SQL statements. ^The 4th argument to
590 ** sqlite3_exec() is relayed through to the 1st argument of each
591 ** callback invocation. ^If the callback pointer to sqlite3_exec()
592 ** is NULL, then no callback is ever invoked and result rows are
593 ** ignored.
594 **
595 ** ^If an error occurs while evaluating the SQL statements passed into
596 ** sqlite3_exec(), then execution of the current statement stops and
597 ** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec()
598 ** is not NULL then any error message is written into memory obtained
599 ** from [sqlite3_malloc()] and passed back through the 5th parameter.
600 ** To avoid memory leaks, the application should invoke [sqlite3_free()]
601 ** on error message strings returned through the 5th parameter of
602 ** sqlite3_exec() after the error message string is no longer needed.
603 ** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors
604 ** occur, then sqlite3_exec() sets the pointer in its 5th parameter to
605 ** NULL before returning.
606 **
607 ** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec()
608 ** routine returns SQLITE_ABORT without invoking the callback again and
609 ** without running any subsequent SQL statements.
610 **
611 ** ^The 2nd argument to the sqlite3_exec() callback function is the
612 ** number of columns in the result. ^The 3rd argument to the sqlite3_exec()
613 ** callback is an array of pointers to strings obtained as if from
614 ** [sqlite3_column_text()], one for each column. ^If an element of a
615 ** result row is NULL then the corresponding string pointer for the
616 ** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the
617 ** sqlite3_exec() callback is an array of pointers to strings where each
618 ** entry represents the name of corresponding result column as obtained
619 ** from [sqlite3_column_name()].
620 **
621 ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
622 ** to an empty string, or a pointer that contains only whitespace and/or
623 ** SQL comments, then no SQL statements are evaluated and the database
624 ** is not changed.
625 **
626 ** Restrictions:
627 **
628 ** <ul>
629 ** <li> The application must ensure that the 1st parameter to sqlite3_exec()
630 ** is a valid and open [database connection].
631 ** <li> The application must not close the [database connection] specified by
632 ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
633 ** <li> The application must not modify the SQL statement text passed into
634 ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
635 ** </ul>
636 */
638  sqlite3*, /* An open database */
639  const char *sql, /* SQL to be evaluated */
640  int (*callback)(void*,int,char**,char**), /* Callback function */
641  void *, /* 1st argument to callback */
642  char **errmsg /* Error msg written here */
643 );
644 
645 /*
646 ** CAPI3REF: Result Codes
647 ** KEYWORDS: {result code definitions}
648 **
649 ** Many SQLite functions return an integer result code from the set shown
650 ** here in order to indicate success or failure.
651 **
652 ** New error codes may be added in future versions of SQLite.
653 **
654 ** See also: [extended result code definitions]
655 */
656 #define SQLITE_OK 0 /* Successful result */
657 /* beginning-of-error-codes */
658 #define SQLITE_ERROR 1 /* SQL error or missing database */
659 #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
660 #define SQLITE_PERM 3 /* Access permission denied */
661 #define SQLITE_ABORT 4 /* Callback routine requested an abort */
662 #define SQLITE_BUSY 5 /* The database file is locked */
663 #define SQLITE_LOCKED 6 /* A table in the database is locked */
664 #define SQLITE_NOMEM 7 /* A malloc() failed */
665 #define SQLITE_READONLY 8 /* Attempt to write a readonly database */
666 #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
667 #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
668 #define SQLITE_CORRUPT 11 /* The database disk image is malformed */
669 #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
670 #define SQLITE_FULL 13 /* Insertion failed because database is full */
671 #define SQLITE_CANTOPEN 14 /* Unable to open the database file */
672 #define SQLITE_PROTOCOL 15 /* Database lock protocol error */
673 #define SQLITE_EMPTY 16 /* Database is empty */
674 #define SQLITE_SCHEMA 17 /* The database schema changed */
675 #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
676 #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
677 #define SQLITE_MISMATCH 20 /* Data type mismatch */
678 #define SQLITE_MISUSE 21 /* Library used incorrectly */
679 #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
680 #define SQLITE_AUTH 23 /* Authorization denied */
681 #define SQLITE_FORMAT 24 /* Auxiliary database format error */
682 #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
683 #define SQLITE_NOTADB 26 /* File opened that is not a database file */
684 #define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */
685 #define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */
686 #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
687 #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
688 /* end-of-error-codes */
689 
690 /*
691 ** CAPI3REF: Extended Result Codes
692 ** KEYWORDS: {extended result code definitions}
693 **
694 ** In its default configuration, SQLite API routines return one of 30 integer
695 ** [result codes]. However, experience has shown that many of
696 ** these result codes are too coarse-grained. They do not provide as
697 ** much information about problems as programmers might like. In an effort to
698 ** address this, newer versions of SQLite (version 3.3.8 and later) include
699 ** support for additional result codes that provide more detailed information
700 ** about errors. These [extended result codes] are enabled or disabled
701 ** on a per database connection basis using the
702 ** [sqlite3_extended_result_codes()] API. Or, the extended code for
703 ** the most recent error can be obtained using
704 ** [sqlite3_extended_errcode()].
705 */
706 #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))
707 #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))
708 #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8))
709 #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8))
710 #define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8))
711 #define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8))
712 #define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8))
713 #define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8))
714 #define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8))
715 #define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8))
716 #define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8))
717 #define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8))
718 #define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8))
719 #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
720 #define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8))
721 #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8))
722 #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8))
723 #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8))
724 #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8))
725 #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8))
726 #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8))
727 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
728 #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))
729 #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
730 #define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
731 #define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
732 #define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8))
733 #define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8))
734 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
735 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
736 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
737 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
738 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
739 #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
740 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
741 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
742 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
743 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
744 #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
745 #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
746 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
747 #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
748 #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
749 #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
750 #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
751 #define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8))
752 #define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))
753 #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
754 #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
755 #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
756 #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
757 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
758 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
759 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
760 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
761 
762 /*
763 ** CAPI3REF: Flags For File Open Operations
764 **
765 ** These bit values are intended for use in the
766 ** 3rd parameter to the [sqlite3_open_v2()] interface and
767 ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
768 */
769 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
770 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
771 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
772 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
773 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
774 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
775 #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */
776 #define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */
777 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
778 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
779 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
780 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
781 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
782 #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */
783 #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */
784 #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
785 #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
786 #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
787 #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
788 #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
789 
790 /* Reserved: 0x00F00000 */
791 
792 /*
793 ** CAPI3REF: Device Characteristics
794 **
795 ** The xDeviceCharacteristics method of the [sqlite3_io_methods]
796 ** object returns an integer which is a vector of these
797 ** bit values expressing I/O characteristics of the mass storage
798 ** device that holds the file that the [sqlite3_io_methods]
799 ** refers to.
800 **
801 ** The SQLITE_IOCAP_ATOMIC property means that all writes of
802 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
803 ** mean that writes of blocks that are nnn bytes in size and
804 ** are aligned to an address which is an integer multiple of
805 ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
806 ** that when data is appended to a file, the data is appended
807 ** first then the size of the file is extended, never the other
808 ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
809 ** information is written to disk in the same order as calls
810 ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
811 ** after reboot following a crash or power loss, the only bytes in a
812 ** file that were written at the application level might have changed
813 ** and that adjacent bytes, even bytes within the same sector are
814 ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
815 ** flag indicate that a file cannot be deleted when open. The
816 ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
817 ** read-only media and cannot be changed even by processes with
818 ** elevated privileges.
819 */
820 #define SQLITE_IOCAP_ATOMIC 0x00000001
821 #define SQLITE_IOCAP_ATOMIC512 0x00000002
822 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
823 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
824 #define SQLITE_IOCAP_ATOMIC4K 0x00000010
825 #define SQLITE_IOCAP_ATOMIC8K 0x00000020
826 #define SQLITE_IOCAP_ATOMIC16K 0x00000040
827 #define SQLITE_IOCAP_ATOMIC32K 0x00000080
828 #define SQLITE_IOCAP_ATOMIC64K 0x00000100
829 #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
830 #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
831 #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800
832 #define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000
833 #define SQLITE_IOCAP_IMMUTABLE 0x00002000
834 
835 /*
836 ** CAPI3REF: File Locking Levels
837 **
838 ** SQLite uses one of these integer values as the second
839 ** argument to calls it makes to the xLock() and xUnlock() methods
840 ** of an [sqlite3_io_methods] object.
841 */
842 #define SQLITE_LOCK_NONE 0
843 #define SQLITE_LOCK_SHARED 1
844 #define SQLITE_LOCK_RESERVED 2
845 #define SQLITE_LOCK_PENDING 3
846 #define SQLITE_LOCK_EXCLUSIVE 4
847 
848 /*
849 ** CAPI3REF: Synchronization Type Flags
850 **
851 ** When SQLite invokes the xSync() method of an
852 ** [sqlite3_io_methods] object it uses a combination of
853 ** these integer values as the second argument.
854 **
855 ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
856 ** sync operation only needs to flush data to mass storage. Inode
857 ** information need not be flushed. If the lower four bits of the flag
858 ** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics.
859 ** If the lower four bits equal SQLITE_SYNC_FULL, that means
860 ** to use Mac OS X style fullsync instead of fsync().
861 **
862 ** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags
863 ** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL
864 ** settings. The [synchronous pragma] determines when calls to the
865 ** xSync VFS method occur and applies uniformly across all platforms.
866 ** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how
867 ** energetic or rigorous or forceful the sync operations are and
868 ** only make a difference on Mac OSX for the default SQLite code.
869 ** (Third-party VFS implementations might also make the distinction
870 ** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the
871 ** operating systems natively supported by SQLite, only Mac OSX
872 ** cares about the difference.)
873 */
874 #define SQLITE_SYNC_NORMAL 0x00002
875 #define SQLITE_SYNC_FULL 0x00003
876 #define SQLITE_SYNC_DATAONLY 0x00010
877 
878 /*
879 ** CAPI3REF: OS Interface Open File Handle
880 **
881 ** An [sqlite3_file] object represents an open file in the
882 ** [sqlite3_vfs | OS interface layer]. Individual OS interface
883 ** implementations will
884 ** want to subclass this object by appending additional fields
885 ** for their own use. The pMethods entry is a pointer to an
886 ** [sqlite3_io_methods] object that defines methods for performing
887 ** I/O operations on the open file.
888 */
889 typedef struct sqlite3_file sqlite3_file;
890 struct sqlite3_file {
891  const struct sqlite3_io_methods *pMethods; /* Methods for an open file */
892 };
893 
894 /*
895 ** CAPI3REF: OS Interface File Virtual Methods Object
896 **
897 ** Every file opened by the [sqlite3_vfs.xOpen] method populates an
898 ** [sqlite3_file] object (or, more commonly, a subclass of the
899 ** [sqlite3_file] object) with a pointer to an instance of this object.
900 ** This object defines the methods used to perform various operations
901 ** against the open file represented by the [sqlite3_file] object.
902 **
903 ** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element
904 ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
905 ** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The
906 ** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]
907 ** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element
908 ** to NULL.
909 **
910 ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
911 ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
912 ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]
913 ** flag may be ORed in to indicate that only the data of the file
914 ** and not its inode needs to be synced.
915 **
916 ** The integer values to xLock() and xUnlock() are one of
917 ** <ul>
918 ** <li> [SQLITE_LOCK_NONE],
919 ** <li> [SQLITE_LOCK_SHARED],
920 ** <li> [SQLITE_LOCK_RESERVED],
921 ** <li> [SQLITE_LOCK_PENDING], or
922 ** <li> [SQLITE_LOCK_EXCLUSIVE].
923 ** </ul>
924 ** xLock() increases the lock. xUnlock() decreases the lock.
925 ** The xCheckReservedLock() method checks whether any database connection,
926 ** either in this process or in some other process, is holding a RESERVED,
927 ** PENDING, or EXCLUSIVE lock on the file. It returns true
928 ** if such a lock exists and false otherwise.
929 **
930 ** The xFileControl() method is a generic interface that allows custom
931 ** VFS implementations to directly control an open file using the
932 ** [sqlite3_file_control()] interface. The second "op" argument is an
933 ** integer opcode. The third argument is a generic pointer intended to
934 ** point to a structure that may contain arguments or space in which to
935 ** write return values. Potential uses for xFileControl() might be
936 ** functions to enable blocking locks with timeouts, to change the
937 ** locking strategy (for example to use dot-file locks), to inquire
938 ** about the status of a lock, or to break stale locks. The SQLite
939 ** core reserves all opcodes less than 100 for its own use.
940 ** A [file control opcodes | list of opcodes] less than 100 is available.
941 ** Applications that define a custom xFileControl method should use opcodes
942 ** greater than 100 to avoid conflicts. VFS implementations should
943 ** return [SQLITE_NOTFOUND] for file control opcodes that they do not
944 ** recognize.
945 **
946 ** The xSectorSize() method returns the sector size of the
947 ** device that underlies the file. The sector size is the
948 ** minimum write that can be performed without disturbing
949 ** other bytes in the file. The xDeviceCharacteristics()
950 ** method returns a bit vector describing behaviors of the
951 ** underlying device:
952 **
953 ** <ul>
954 ** <li> [SQLITE_IOCAP_ATOMIC]
955 ** <li> [SQLITE_IOCAP_ATOMIC512]
956 ** <li> [SQLITE_IOCAP_ATOMIC1K]
957 ** <li> [SQLITE_IOCAP_ATOMIC2K]
958 ** <li> [SQLITE_IOCAP_ATOMIC4K]
959 ** <li> [SQLITE_IOCAP_ATOMIC8K]
960 ** <li> [SQLITE_IOCAP_ATOMIC16K]
961 ** <li> [SQLITE_IOCAP_ATOMIC32K]
962 ** <li> [SQLITE_IOCAP_ATOMIC64K]
963 ** <li> [SQLITE_IOCAP_SAFE_APPEND]
964 ** <li> [SQLITE_IOCAP_SEQUENTIAL]
965 ** </ul>
966 **
967 ** The SQLITE_IOCAP_ATOMIC property means that all writes of
968 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
969 ** mean that writes of blocks that are nnn bytes in size and
970 ** are aligned to an address which is an integer multiple of
971 ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
972 ** that when data is appended to a file, the data is appended
973 ** first then the size of the file is extended, never the other
974 ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
975 ** information is written to disk in the same order as calls
976 ** to xWrite().
977 **
978 ** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
979 ** in the unread portions of the buffer with zeros. A VFS that
980 ** fails to zero-fill short reads might seem to work. However,
981 ** failure to zero-fill short reads will eventually lead to
982 ** database corruption.
983 */
986  int iVersion;
987  int (*xClose)(sqlite3_file*);
988  int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
989  int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
990  int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
991  int (*xSync)(sqlite3_file*, int flags);
992  int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
993  int (*xLock)(sqlite3_file*, int);
994  int (*xUnlock)(sqlite3_file*, int);
995  int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);
996  int (*xFileControl)(sqlite3_file*, int op, void *pArg);
997  int (*xSectorSize)(sqlite3_file*);
998  int (*xDeviceCharacteristics)(sqlite3_file*);
999  /* Methods above are valid for version 1 */
1000  int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
1001  int (*xShmLock)(sqlite3_file*, int offset, int n, int flags);
1002  void (*xShmBarrier)(sqlite3_file*);
1003  int (*xShmUnmap)(sqlite3_file*, int deleteFlag);
1004  /* Methods above are valid for version 2 */
1005  int (*xFetch)(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
1006  int (*xUnfetch)(sqlite3_file*, sqlite3_int64 iOfst, void *p);
1007  /* Methods above are valid for version 3 */
1008  /* Additional methods may be added in future releases */
1009 };
1010 
1011 /*
1012 ** CAPI3REF: Standard File Control Opcodes
1013 ** KEYWORDS: {file control opcodes} {file control opcode}
1014 **
1015 ** These integer constants are opcodes for the xFileControl method
1016 ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
1017 ** interface.
1018 **
1019 ** <ul>
1020 ** <li>[[SQLITE_FCNTL_LOCKSTATE]]
1021 ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This
1022 ** opcode causes the xFileControl method to write the current state of
1023 ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
1024 ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
1025 ** into an integer that the pArg argument points to. This capability
1026 ** is used during testing and is only available when the SQLITE_TEST
1027 ** compile-time option is used.
1028 **
1029 ** <li>[[SQLITE_FCNTL_SIZE_HINT]]
1030 ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
1031 ** layer a hint of how large the database file will grow to be during the
1032 ** current transaction. This hint is not guaranteed to be accurate but it
1033 ** is often close. The underlying VFS might choose to preallocate database
1034 ** file space based on this hint in order to help writes to the database
1035 ** file run faster.
1036 **
1037 ** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
1038 ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
1039 ** extends and truncates the database file in chunks of a size specified
1040 ** by the user. The fourth argument to [sqlite3_file_control()] should
1041 ** point to an integer (type int) containing the new chunk-size to use
1042 ** for the nominated database. Allocating database file space in large
1043 ** chunks (say 1MB at a time), may reduce file-system fragmentation and
1044 ** improve performance on some systems.
1045 **
1046 ** <li>[[SQLITE_FCNTL_FILE_POINTER]]
1047 ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
1048 ** to the [sqlite3_file] object associated with a particular database
1049 ** connection. See also [SQLITE_FCNTL_JOURNAL_POINTER].
1050 **
1051 ** <li>[[SQLITE_FCNTL_JOURNAL_POINTER]]
1052 ** The [SQLITE_FCNTL_JOURNAL_POINTER] opcode is used to obtain a pointer
1053 ** to the [sqlite3_file] object associated with the journal file (either
1054 ** the [rollback journal] or the [write-ahead log]) for a particular database
1055 ** connection. See also [SQLITE_FCNTL_FILE_POINTER].
1056 **
1057 ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
1058 ** No longer in use.
1059 **
1060 ** <li>[[SQLITE_FCNTL_SYNC]]
1061 ** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
1062 ** sent to the VFS immediately before the xSync method is invoked on a
1063 ** database file descriptor. Or, if the xSync method is not invoked
1064 ** because the user has configured SQLite with
1065 ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
1066 ** of the xSync method. In most cases, the pointer argument passed with
1067 ** this file-control is NULL. However, if the database file is being synced
1068 ** as part of a multi-database commit, the argument points to a nul-terminated
1069 ** string containing the transactions master-journal file name. VFSes that
1070 ** do not need this signal should silently ignore this opcode. Applications
1071 ** should not call [sqlite3_file_control()] with this opcode as doing so may
1072 ** disrupt the operation of the specialized VFSes that do require it.
1073 **
1074 ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
1075 ** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite
1076 ** and sent to the VFS after a transaction has been committed immediately
1077 ** but before the database is unlocked. VFSes that do not need this signal
1078 ** should silently ignore this opcode. Applications should not call
1079 ** [sqlite3_file_control()] with this opcode as doing so may disrupt the
1080 ** operation of the specialized VFSes that do require it.
1081 **
1082 ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
1083 ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
1084 ** retry counts and intervals for certain disk I/O operations for the
1085 ** windows [VFS] in order to provide robustness in the presence of
1086 ** anti-virus programs. By default, the windows VFS will retry file read,
1087 ** file write, and file delete operations up to 10 times, with a delay
1088 ** of 25 milliseconds before the first retry and with the delay increasing
1089 ** by an additional 25 milliseconds with each subsequent retry. This
1090 ** opcode allows these two values (10 retries and 25 milliseconds of delay)
1091 ** to be adjusted. The values are changed for all database connections
1092 ** within the same process. The argument is a pointer to an array of two
1093 ** integers where the first integer i the new retry count and the second
1094 ** integer is the delay. If either integer is negative, then the setting
1095 ** is not changed but instead the prior value of that setting is written
1096 ** into the array entry, allowing the current retry settings to be
1097 ** interrogated. The zDbName parameter is ignored.
1098 **
1099 ** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
1100 ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
1101 ** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary
1102 ** write ahead log and shared memory files used for transaction control
1103 ** are automatically deleted when the latest connection to the database
1104 ** closes. Setting persistent WAL mode causes those files to persist after
1105 ** close. Persisting the files is useful when other processes that do not
1106 ** have write permission on the directory containing the database file want
1107 ** to read the database file, as the WAL and shared memory files must exist
1108 ** in order for the database to be readable. The fourth parameter to
1109 ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
1110 ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
1111 ** WAL mode. If the integer is -1, then it is overwritten with the current
1112 ** WAL persistence setting.
1113 **
1114 ** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]]
1115 ** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the
1116 ** persistent "powersafe-overwrite" or "PSOW" setting. The PSOW setting
1117 ** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the
1118 ** xDeviceCharacteristics methods. The fourth parameter to
1119 ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
1120 ** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage
1121 ** mode. If the integer is -1, then it is overwritten with the current
1122 ** zero-damage mode setting.
1123 **
1124 ** <li>[[SQLITE_FCNTL_OVERWRITE]]
1125 ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
1126 ** a write transaction to indicate that, unless it is rolled back for some
1127 ** reason, the entire database file will be overwritten by the current
1128 ** transaction. This is used by VACUUM operations.
1129 **
1130 ** <li>[[SQLITE_FCNTL_VFSNAME]]
1131 ** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
1132 ** all [VFSes] in the VFS stack. The names are of all VFS shims and the
1133 ** final bottom-level VFS are written into memory obtained from
1134 ** [sqlite3_malloc()] and the result is stored in the char* variable
1135 ** that the fourth parameter of [sqlite3_file_control()] points to.
1136 ** The caller is responsible for freeing the memory when done. As with
1137 ** all file-control actions, there is no guarantee that this will actually
1138 ** do anything. Callers should initialize the char* variable to a NULL
1139 ** pointer in case this file-control is not implemented. This file-control
1140 ** is intended for diagnostic use only.
1141 **
1142 ** <li>[[SQLITE_FCNTL_VFS_POINTER]]
1143 ** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level
1144 ** [VFSes] currently in use. ^(The argument X in
1145 ** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be
1146 ** of type "[sqlite3_vfs] **". This opcodes will set *X
1147 ** to a pointer to the top-level VFS.)^
1148 ** ^When there are multiple VFS shims in the stack, this opcode finds the
1149 ** upper-most shim only.
1150 **
1151 ** <li>[[SQLITE_FCNTL_PRAGMA]]
1152 ** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA]
1153 ** file control is sent to the open [sqlite3_file] object corresponding
1154 ** to the database file to which the pragma statement refers. ^The argument
1155 ** to the [SQLITE_FCNTL_PRAGMA] file control is an array of
1156 ** pointers to strings (char**) in which the second element of the array
1157 ** is the name of the pragma and the third element is the argument to the
1158 ** pragma or NULL if the pragma has no argument. ^The handler for an
1159 ** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element
1160 ** of the char** argument point to a string obtained from [sqlite3_mprintf()]
1161 ** or the equivalent and that string will become the result of the pragma or
1162 ** the error message if the pragma fails. ^If the
1163 ** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal
1164 ** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA]
1165 ** file control returns [SQLITE_OK], then the parser assumes that the
1166 ** VFS has handled the PRAGMA itself and the parser generates a no-op
1167 ** prepared statement if result string is NULL, or that returns a copy
1168 ** of the result string if the string is non-NULL.
1169 ** ^If the [SQLITE_FCNTL_PRAGMA] file control returns
1170 ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
1171 ** that the VFS encountered an error while handling the [PRAGMA] and the
1172 ** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA]
1173 ** file control occurs at the beginning of pragma statement analysis and so
1174 ** it is able to override built-in [PRAGMA] statements.
1175 **
1176 ** <li>[[SQLITE_FCNTL_BUSYHANDLER]]
1177 ** ^The [SQLITE_FCNTL_BUSYHANDLER]
1178 ** file-control may be invoked by SQLite on the database file handle
1179 ** shortly after it is opened in order to provide a custom VFS with access
1180 ** to the connections busy-handler callback. The argument is of type (void **)
1181 ** - an array of two (void *) values. The first (void *) actually points
1182 ** to a function of type (int (*)(void *)). In order to invoke the connections
1183 ** busy-handler, this function should be invoked with the second (void *) in
1184 ** the array as the only argument. If it returns non-zero, then the operation
1185 ** should be retried. If it returns zero, the custom VFS should abandon the
1186 ** current operation.
1187 **
1188 ** <li>[[SQLITE_FCNTL_TEMPFILENAME]]
1189 ** ^Application can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
1190 ** to have SQLite generate a
1191 ** temporary filename using the same algorithm that is followed to generate
1192 ** temporary filenames for TEMP tables and other internal uses. The
1193 ** argument should be a char** which will be filled with the filename
1194 ** written into memory obtained from [sqlite3_malloc()]. The caller should
1195 ** invoke [sqlite3_free()] on the result to avoid a memory leak.
1196 **
1197 ** <li>[[SQLITE_FCNTL_MMAP_SIZE]]
1198 ** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the
1199 ** maximum number of bytes that will be used for memory-mapped I/O.
1200 ** The argument is a pointer to a value of type sqlite3_int64 that
1201 ** is an advisory maximum number of bytes in the file to memory map. The
1202 ** pointer is overwritten with the old value. The limit is not changed if
1203 ** the value originally pointed to is negative, and so the current limit
1204 ** can be queried by passing in a pointer to a negative number. This
1205 ** file-control is used internally to implement [PRAGMA mmap_size].
1206 **
1207 ** <li>[[SQLITE_FCNTL_TRACE]]
1208 ** The [SQLITE_FCNTL_TRACE] file control provides advisory information
1209 ** to the VFS about what the higher layers of the SQLite stack are doing.
1210 ** This file control is used by some VFS activity tracing [shims].
1211 ** The argument is a zero-terminated string. Higher layers in the
1212 ** SQLite stack may generate instances of this file control if
1213 ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
1214 **
1215 ** <li>[[SQLITE_FCNTL_HAS_MOVED]]
1216 ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
1217 ** pointer to an integer and it writes a boolean into that integer depending
1218 ** on whether or not the file has been renamed, moved, or deleted since it
1219 ** was first opened.
1220 **
1221 ** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]
1222 ** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This
1223 ** opcode causes the xFileControl method to swap the file handle with the one
1224 ** pointed to by the pArg argument. This capability is used during testing
1225 ** and only needs to be supported when SQLITE_TEST is defined.
1226 **
1227 ** <li>[[SQLITE_FCNTL_WAL_BLOCK]]
1228 ** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might
1229 ** be advantageous to block on the next WAL lock if the lock is not immediately
1230 ** available. The WAL subsystem issues this signal during rare
1231 ** circumstances in order to fix a problem with priority inversion.
1232 ** Applications should <em>not</em> use this file-control.
1233 **
1234 ** <li>[[SQLITE_FCNTL_ZIPVFS]]
1235 ** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other
1236 ** VFS should return SQLITE_NOTFOUND for this opcode.
1237 **
1238 ** <li>[[SQLITE_FCNTL_RBU]]
1239 ** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
1240 ** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for
1241 ** this opcode.
1242 ** </ul>
1243 */
1244 #define SQLITE_FCNTL_LOCKSTATE 1
1245 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
1246 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
1247 #define SQLITE_FCNTL_LAST_ERRNO 4
1248 #define SQLITE_FCNTL_SIZE_HINT 5
1249 #define SQLITE_FCNTL_CHUNK_SIZE 6
1250 #define SQLITE_FCNTL_FILE_POINTER 7
1251 #define SQLITE_FCNTL_SYNC_OMITTED 8
1252 #define SQLITE_FCNTL_WIN32_AV_RETRY 9
1253 #define SQLITE_FCNTL_PERSIST_WAL 10
1254 #define SQLITE_FCNTL_OVERWRITE 11
1255 #define SQLITE_FCNTL_VFSNAME 12
1256 #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13
1257 #define SQLITE_FCNTL_PRAGMA 14
1258 #define SQLITE_FCNTL_BUSYHANDLER 15
1259 #define SQLITE_FCNTL_TEMPFILENAME 16
1260 #define SQLITE_FCNTL_MMAP_SIZE 18
1261 #define SQLITE_FCNTL_TRACE 19
1262 #define SQLITE_FCNTL_HAS_MOVED 20
1263 #define SQLITE_FCNTL_SYNC 21
1264 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
1265 #define SQLITE_FCNTL_WIN32_SET_HANDLE 23
1266 #define SQLITE_FCNTL_WAL_BLOCK 24
1267 #define SQLITE_FCNTL_ZIPVFS 25
1268 #define SQLITE_FCNTL_RBU 26
1269 #define SQLITE_FCNTL_VFS_POINTER 27
1270 #define SQLITE_FCNTL_JOURNAL_POINTER 28
1271 
1272 /* deprecated names */
1273 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1274 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1275 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
1276 
1277 
1278 /*
1279 ** CAPI3REF: Mutex Handle
1280 **
1281 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
1282 ** abstract type for a mutex object. The SQLite core never looks
1283 ** at the internal representation of an [sqlite3_mutex]. It only
1284 ** deals with pointers to the [sqlite3_mutex] object.
1285 **
1286 ** Mutexes are created using [sqlite3_mutex_alloc()].
1287 */
1289 
1290 /*
1291 ** CAPI3REF: OS Interface Object
1292 **
1293 ** An instance of the sqlite3_vfs object defines the interface between
1294 ** the SQLite core and the underlying operating system. The "vfs"
1295 ** in the name of the object stands for "virtual file system". See
1296 ** the [VFS | VFS documentation] for further information.
1297 **
1298 ** The value of the iVersion field is initially 1 but may be larger in
1299 ** future versions of SQLite. Additional fields may be appended to this
1300 ** object when the iVersion value is increased. Note that the structure
1301 ** of the sqlite3_vfs object changes in the transaction between
1302 ** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not
1303 ** modified.
1304 **
1305 ** The szOsFile field is the size of the subclassed [sqlite3_file]
1306 ** structure used by this VFS. mxPathname is the maximum length of
1307 ** a pathname in this VFS.
1308 **
1309 ** Registered sqlite3_vfs objects are kept on a linked list formed by
1310 ** the pNext pointer. The [sqlite3_vfs_register()]
1311 ** and [sqlite3_vfs_unregister()] interfaces manage this list
1312 ** in a thread-safe way. The [sqlite3_vfs_find()] interface
1313 ** searches the list. Neither the application code nor the VFS
1314 ** implementation should use the pNext pointer.
1315 **
1316 ** The pNext field is the only field in the sqlite3_vfs
1317 ** structure that SQLite will ever modify. SQLite will only access
1318 ** or modify this field while holding a particular static mutex.
1319 ** The application should never modify anything within the sqlite3_vfs
1320 ** object once the object has been registered.
1321 **
1322 ** The zName field holds the name of the VFS module. The name must
1323 ** be unique across all VFS modules.
1324 **
1325 ** [[sqlite3_vfs.xOpen]]
1326 ** ^SQLite guarantees that the zFilename parameter to xOpen
1327 ** is either a NULL pointer or string obtained
1328 ** from xFullPathname() with an optional suffix added.
1329 ** ^If a suffix is added to the zFilename parameter, it will
1330 ** consist of a single "-" character followed by no more than
1331 ** 11 alphanumeric and/or "-" characters.
1332 ** ^SQLite further guarantees that
1333 ** the string will be valid and unchanged until xClose() is
1334 ** called. Because of the previous sentence,
1335 ** the [sqlite3_file] can safely store a pointer to the
1336 ** filename if it needs to remember the filename for some reason.
1337 ** If the zFilename parameter to xOpen is a NULL pointer then xOpen
1338 ** must invent its own temporary name for the file. ^Whenever the
1339 ** xFilename parameter is NULL it will also be the case that the
1340 ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
1341 **
1342 ** The flags argument to xOpen() includes all bits set in
1343 ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]
1344 ** or [sqlite3_open16()] is used, then flags includes at least
1345 ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
1346 ** If xOpen() opens a file read-only then it sets *pOutFlags to
1347 ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.
1348 **
1349 ** ^(SQLite will also add one of the following flags to the xOpen()
1350 ** call, depending on the object being opened:
1351 **
1352 ** <ul>
1353 ** <li> [SQLITE_OPEN_MAIN_DB]
1354 ** <li> [SQLITE_OPEN_MAIN_JOURNAL]
1355 ** <li> [SQLITE_OPEN_TEMP_DB]
1356 ** <li> [SQLITE_OPEN_TEMP_JOURNAL]
1357 ** <li> [SQLITE_OPEN_TRANSIENT_DB]
1358 ** <li> [SQLITE_OPEN_SUBJOURNAL]
1359 ** <li> [SQLITE_OPEN_MASTER_JOURNAL]
1360 ** <li> [SQLITE_OPEN_WAL]
1361 ** </ul>)^
1362 **
1363 ** The file I/O implementation can use the object type flags to
1364 ** change the way it deals with files. For example, an application
1365 ** that does not care about crash recovery or rollback might make
1366 ** the open of a journal file a no-op. Writes to this journal would
1367 ** also be no-ops, and any attempt to read the journal would return
1368 ** SQLITE_IOERR. Or the implementation might recognize that a database
1369 ** file will be doing page-aligned sector reads and writes in a random
1370 ** order and set up its I/O subsystem accordingly.
1371 **
1372 ** SQLite might also add one of the following flags to the xOpen method:
1373 **
1374 ** <ul>
1375 ** <li> [SQLITE_OPEN_DELETEONCLOSE]
1376 ** <li> [SQLITE_OPEN_EXCLUSIVE]
1377 ** </ul>
1378 **
1379 ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
1380 ** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE]
1381 ** will be set for TEMP databases and their journals, transient
1382 ** databases, and subjournals.
1383 **
1384 ** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
1385 ** with the [SQLITE_OPEN_CREATE] flag, which are both directly
1386 ** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
1387 ** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the
1388 ** SQLITE_OPEN_CREATE, is used to indicate that file should always
1389 ** be created, and that it is an error if it already exists.
1390 ** It is <i>not</i> used to indicate the file should be opened
1391 ** for exclusive access.
1392 **
1393 ** ^At least szOsFile bytes of memory are allocated by SQLite
1394 ** to hold the [sqlite3_file] structure passed as the third
1395 ** argument to xOpen. The xOpen method does not have to
1396 ** allocate the structure; it should just fill it in. Note that
1397 ** the xOpen method must set the sqlite3_file.pMethods to either
1398 ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
1399 ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
1400 ** element will be valid after xOpen returns regardless of the success
1401 ** or failure of the xOpen call.
1402 **
1403 ** [[sqlite3_vfs.xAccess]]
1404 ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
1405 ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
1406 ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
1407 ** to test whether a file is at least readable. The file can be a
1408 ** directory.
1409 **
1410 ** ^SQLite will always allocate at least mxPathname+1 bytes for the
1411 ** output buffer xFullPathname. The exact size of the output buffer
1412 ** is also passed as a parameter to both methods. If the output buffer
1413 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
1414 ** handled as a fatal error by SQLite, vfs implementations should endeavor
1415 ** to prevent this by setting mxPathname to a sufficiently large value.
1416 **
1417 ** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
1418 ** interfaces are not strictly a part of the filesystem, but they are
1419 ** included in the VFS structure for completeness.
1420 ** The xRandomness() function attempts to return nBytes bytes
1421 ** of good-quality randomness into zOut. The return value is
1422 ** the actual number of bytes of randomness obtained.
1423 ** The xSleep() method causes the calling thread to sleep for at
1424 ** least the number of microseconds given. ^The xCurrentTime()
1425 ** method returns a Julian Day Number for the current date and time as
1426 ** a floating point value.
1427 ** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
1428 ** Day Number multiplied by 86400000 (the number of milliseconds in
1429 ** a 24-hour day).
1430 ** ^SQLite will use the xCurrentTimeInt64() method to get the current
1431 ** date and time if that method is available (if iVersion is 2 or
1432 ** greater and the function pointer is not NULL) and will fall back
1433 ** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
1434 **
1435 ** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
1436 ** are not used by the SQLite core. These optional interfaces are provided
1437 ** by some VFSes to facilitate testing of the VFS code. By overriding
1438 ** system calls with functions under its control, a test program can
1439 ** simulate faults and error conditions that would otherwise be difficult
1440 ** or impossible to induce. The set of system calls that can be overridden
1441 ** varies from one VFS to another, and from one version of the same VFS to the
1442 ** next. Applications that use these interfaces must be prepared for any
1443 ** or all of these interfaces to be NULL or for their behavior to change
1444 ** from one release to the next. Applications must not attempt to access
1445 ** any of these methods if the iVersion of the VFS is less than 3.
1446 */
1447 typedef struct sqlite3_vfs sqlite3_vfs;
1449 struct sqlite3_vfs {
1450  int iVersion; /* Structure version number (currently 3) */
1451  int szOsFile; /* Size of subclassed sqlite3_file */
1452  int mxPathname; /* Maximum file pathname length */
1453  sqlite3_vfs *pNext; /* Next registered VFS */
1454  const char *zName; /* Name of this virtual file system */
1455  void *pAppData; /* Pointer to application-specific data */
1456  int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*,
1457  int flags, int *pOutFlags);
1458  int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
1459  int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
1460  int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
1461  void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
1462  void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
1463  void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
1464  void (*xDlClose)(sqlite3_vfs*, void*);
1465  int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
1466  int (*xSleep)(sqlite3_vfs*, int microseconds);
1467  int (*xCurrentTime)(sqlite3_vfs*, double*);
1468  int (*xGetLastError)(sqlite3_vfs*, int, char *);
1469  /*
1470  ** The methods above are in version 1 of the sqlite_vfs object
1471  ** definition. Those that follow are added in version 2 or later
1472  */
1473  int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
1474  /*
1475  ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
1476  ** Those below are for version 3 and greater.
1477  */
1478  int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);
1479  sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);
1480  const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
1481  /*
1482  ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
1483  ** New fields may be appended in future versions. The iVersion
1484  ** value will increment whenever this happens.
1485  */
1486 };
1487 
1488 /*
1489 ** CAPI3REF: Flags for the xAccess VFS method
1490 **
1491 ** These integer constants can be used as the third parameter to
1492 ** the xAccess method of an [sqlite3_vfs] object. They determine
1493 ** what kind of permissions the xAccess method is looking for.
1494 ** With SQLITE_ACCESS_EXISTS, the xAccess method
1495 ** simply checks whether the file exists.
1496 ** With SQLITE_ACCESS_READWRITE, the xAccess method
1497 ** checks whether the named directory is both readable and writable
1498 ** (in other words, if files can be added, removed, and renamed within
1499 ** the directory).
1500 ** The SQLITE_ACCESS_READWRITE constant is currently used only by the
1501 ** [temp_store_directory pragma], though this could change in a future
1502 ** release of SQLite.
1503 ** With SQLITE_ACCESS_READ, the xAccess method
1504 ** checks whether the file is readable. The SQLITE_ACCESS_READ constant is
1505 ** currently unused, though it might be used in a future release of
1506 ** SQLite.
1507 */
1508 #define SQLITE_ACCESS_EXISTS 0
1509 #define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */
1510 #define SQLITE_ACCESS_READ 2 /* Unused */
1511 
1512 /*
1513 ** CAPI3REF: Flags for the xShmLock VFS method
1514 **
1515 ** These integer constants define the various locking operations
1516 ** allowed by the xShmLock method of [sqlite3_io_methods]. The
1517 ** following are the only legal combinations of flags to the
1518 ** xShmLock method:
1519 **
1520 ** <ul>
1521 ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_SHARED
1522 ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE
1523 ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
1524 ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
1525 ** </ul>
1526 **
1527 ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as
1528 ** was given on the corresponding lock.
1529 **
1530 ** The xShmLock method can transition between unlocked and SHARED or
1531 ** between unlocked and EXCLUSIVE. It cannot transition between SHARED
1532 ** and EXCLUSIVE.
1533 */
1534 #define SQLITE_SHM_UNLOCK 1
1535 #define SQLITE_SHM_LOCK 2
1536 #define SQLITE_SHM_SHARED 4
1537 #define SQLITE_SHM_EXCLUSIVE 8
1538 
1539 /*
1540 ** CAPI3REF: Maximum xShmLock index
1541 **
1542 ** The xShmLock method on [sqlite3_io_methods] may use values
1543 ** between 0 and this upper bound as its "offset" argument.
1544 ** The SQLite core will never attempt to acquire or release a
1545 ** lock outside of this range
1546 */
1547 #define SQLITE_SHM_NLOCK 8
1548 
1549 
1550 /*
1551 ** CAPI3REF: Initialize The SQLite Library
1552 **
1553 ** ^The sqlite3_initialize() routine initializes the
1554 ** SQLite library. ^The sqlite3_shutdown() routine
1555 ** deallocates any resources that were allocated by sqlite3_initialize().
1556 ** These routines are designed to aid in process initialization and
1557 ** shutdown on embedded systems. Workstation applications using
1558 ** SQLite normally do not need to invoke either of these routines.
1559 **
1560 ** A call to sqlite3_initialize() is an "effective" call if it is
1561 ** the first time sqlite3_initialize() is invoked during the lifetime of
1562 ** the process, or if it is the first time sqlite3_initialize() is invoked
1563 ** following a call to sqlite3_shutdown(). ^(Only an effective call
1564 ** of sqlite3_initialize() does any initialization. All other calls
1565 ** are harmless no-ops.)^
1566 **
1567 ** A call to sqlite3_shutdown() is an "effective" call if it is the first
1568 ** call to sqlite3_shutdown() since the last sqlite3_initialize(). ^(Only
1569 ** an effective call to sqlite3_shutdown() does any deinitialization.
1570 ** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^
1571 **
1572 ** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown()
1573 ** is not. The sqlite3_shutdown() interface must only be called from a
1574 ** single thread. All open [database connections] must be closed and all
1575 ** other SQLite resources must be deallocated prior to invoking
1576 ** sqlite3_shutdown().
1577 **
1578 ** Among other things, ^sqlite3_initialize() will invoke
1579 ** sqlite3_os_init(). Similarly, ^sqlite3_shutdown()
1580 ** will invoke sqlite3_os_end().
1581 **
1582 ** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success.
1583 ** ^If for some reason, sqlite3_initialize() is unable to initialize
1584 ** the library (perhaps it is unable to allocate a needed resource such
1585 ** as a mutex) it returns an [error code] other than [SQLITE_OK].
1586 **
1587 ** ^The sqlite3_initialize() routine is called internally by many other
1588 ** SQLite interfaces so that an application usually does not need to
1589 ** invoke sqlite3_initialize() directly. For example, [sqlite3_open()]
1590 ** calls sqlite3_initialize() so the SQLite library will be automatically
1591 ** initialized when [sqlite3_open()] is called if it has not be initialized
1592 ** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
1593 ** compile-time option, then the automatic calls to sqlite3_initialize()
1594 ** are omitted and the application must call sqlite3_initialize() directly
1595 ** prior to using any other SQLite interface. For maximum portability,
1596 ** it is recommended that applications always invoke sqlite3_initialize()
1597 ** directly prior to using any other SQLite interface. Future releases
1598 ** of SQLite may require this. In other words, the behavior exhibited
1599 ** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the
1600 ** default behavior in some future release of SQLite.
1601 **
1602 ** The sqlite3_os_init() routine does operating-system specific
1603 ** initialization of the SQLite library. The sqlite3_os_end()
1604 ** routine undoes the effect of sqlite3_os_init(). Typical tasks
1605 ** performed by these routines include allocation or deallocation
1606 ** of static resources, initialization of global variables,
1607 ** setting up a default [sqlite3_vfs] module, or setting up
1608 ** a default configuration using [sqlite3_config()].
1609 **
1610 ** The application should never invoke either sqlite3_os_init()
1611 ** or sqlite3_os_end() directly. The application should only invoke
1612 ** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init()
1613 ** interface is called automatically by sqlite3_initialize() and
1614 ** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate
1615 ** implementations for sqlite3_os_init() and sqlite3_os_end()
1616 ** are built into SQLite when it is compiled for Unix, Windows, or OS/2.
1617 ** When [custom builds | built for other platforms]
1618 ** (using the [SQLITE_OS_OTHER=1] compile-time
1619 ** option) the application must supply a suitable implementation for
1620 ** sqlite3_os_init() and sqlite3_os_end(). An application-supplied
1621 ** implementation of sqlite3_os_init() or sqlite3_os_end()
1622 ** must return [SQLITE_OK] on success and some other [error code] upon
1623 ** failure.
1624 */
1629 
1630 /*
1631 ** CAPI3REF: Configuring The SQLite Library
1632 **
1633 ** The sqlite3_config() interface is used to make global configuration
1634 ** changes to SQLite in order to tune SQLite to the specific needs of
1635 ** the application. The default configuration is recommended for most
1636 ** applications and so this routine is usually not necessary. It is
1637 ** provided to support rare applications with unusual needs.
1638 **
1639 ** <b>The sqlite3_config() interface is not threadsafe. The application
1640 ** must ensure that no other SQLite interfaces are invoked by other
1641 ** threads while sqlite3_config() is running.</b>
1642 **
1643 ** The sqlite3_config() interface
1644 ** may only be invoked prior to library initialization using
1645 ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
1646 ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before
1647 ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
1648 ** Note, however, that ^sqlite3_config() can be called as part of the
1649 ** implementation of an application-defined [sqlite3_os_init()].
1650 **
1651 ** The first argument to sqlite3_config() is an integer
1652 ** [configuration option] that determines
1653 ** what property of SQLite is to be configured. Subsequent arguments
1654 ** vary depending on the [configuration option]
1655 ** in the first argument.
1656 **
1657 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
1658 ** ^If the option is unknown or SQLite is unable to set the option
1659 ** then this routine returns a non-zero [error code].
1660 */
1661 SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
1662 
1663 /*
1664 ** CAPI3REF: Configure database connections
1665 ** METHOD: sqlite3
1666 **
1667 ** The sqlite3_db_config() interface is used to make configuration
1668 ** changes to a [database connection]. The interface is similar to
1669 ** [sqlite3_config()] except that the changes apply to a single
1670 ** [database connection] (specified in the first argument).
1671 **
1672 ** The second argument to sqlite3_db_config(D,V,...) is the
1673 ** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code
1674 ** that indicates what aspect of the [database connection] is being configured.
1675 ** Subsequent arguments vary depending on the configuration verb.
1676 **
1677 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
1678 ** the call is considered successful.
1679 */
1681 
1682 /*
1683 ** CAPI3REF: Memory Allocation Routines
1684 **
1685 ** An instance of this object defines the interface between SQLite
1686 ** and low-level memory allocation routines.
1687 **
1688 ** This object is used in only one place in the SQLite interface.
1689 ** A pointer to an instance of this object is the argument to
1690 ** [sqlite3_config()] when the configuration option is
1691 ** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC].
1692 ** By creating an instance of this object
1693 ** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC])
1694 ** during configuration, an application can specify an alternative
1695 ** memory allocation subsystem for SQLite to use for all of its
1696 ** dynamic memory needs.
1697 **
1698 ** Note that SQLite comes with several [built-in memory allocators]
1699 ** that are perfectly adequate for the overwhelming majority of applications
1700 ** and that this object is only useful to a tiny minority of applications
1701 ** with specialized memory allocation requirements. This object is
1702 ** also used during testing of SQLite in order to specify an alternative
1703 ** memory allocator that simulates memory out-of-memory conditions in
1704 ** order to verify that SQLite recovers gracefully from such
1705 ** conditions.
1706 **
1707 ** The xMalloc, xRealloc, and xFree methods must work like the
1708 ** malloc(), realloc() and free() functions from the standard C library.
1709 ** ^SQLite guarantees that the second argument to
1710 ** xRealloc is always a value returned by a prior call to xRoundup.
1711 **
1712 ** xSize should return the allocated size of a memory allocation
1713 ** previously obtained from xMalloc or xRealloc. The allocated size
1714 ** is always at least as big as the requested size but may be larger.
1715 **
1716 ** The xRoundup method returns what would be the allocated size of
1717 ** a memory allocation given a particular requested size. Most memory
1718 ** allocators round up memory allocations at least to the next multiple
1719 ** of 8. Some allocators round up to a larger multiple or to a power of 2.
1720 ** Every memory allocation request coming in through [sqlite3_malloc()]
1721 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
1722 ** that causes the corresponding memory allocation to fail.
1723 **
1724 ** The xInit method initializes the memory allocator. For example,
1725 ** it might allocate any require mutexes or initialize internal data
1726 ** structures. The xShutdown method is invoked (indirectly) by
1727 ** [sqlite3_shutdown()] and should deallocate any resources acquired
1728 ** by xInit. The pAppData pointer is used as the only parameter to
1729 ** xInit and xShutdown.
1730 **
1731 ** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes
1732 ** the xInit method, so the xInit method need not be threadsafe. The
1733 ** xShutdown method is only called from [sqlite3_shutdown()] so it does
1734 ** not need to be threadsafe either. For all other methods, SQLite
1735 ** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
1736 ** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
1737 ** it is by default) and so the methods are automatically serialized.
1738 ** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other
1739 ** methods must be threadsafe or else make their own arrangements for
1740 ** serialization.
1741 **
1742 ** SQLite will never invoke xInit() more than once without an intervening
1743 ** call to xShutdown().
1744 */
1747  void *(*xMalloc)(int); /* Memory allocation function */
1748  void (*xFree)(void*); /* Free a prior allocation */
1749  void *(*xRealloc)(void*,int); /* Resize an allocation */
1750  int (*xSize)(void*); /* Return the size of an allocation */
1751  int (*xRoundup)(int); /* Round up request size to allocation size */
1752  int (*xInit)(void*); /* Initialize the memory allocator */
1753  void (*xShutdown)(void*); /* Deinitialize the memory allocator */
1754  void *pAppData; /* Argument to xInit() and xShutdown() */
1755 };
1756 
1757 /*
1758 ** CAPI3REF: Configuration Options
1759 ** KEYWORDS: {configuration option}
1760 **
1761 ** These constants are the available integer configuration options that
1762 ** can be passed as the first argument to the [sqlite3_config()] interface.
1763 **
1764 ** New configuration options may be added in future releases of SQLite.
1765 ** Existing configuration options might be discontinued. Applications
1766 ** should check the return code from [sqlite3_config()] to make sure that
1767 ** the call worked. The [sqlite3_config()] interface will return a
1768 ** non-zero [error code] if a discontinued or unsupported configuration option
1769 ** is invoked.
1770 **
1771 ** <dl>
1772 ** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
1773 ** <dd>There are no arguments to this option. ^This option sets the
1774 ** [threading mode] to Single-thread. In other words, it disables
1775 ** all mutexing and puts SQLite into a mode where it can only be used
1776 ** by a single thread. ^If SQLite is compiled with
1777 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1778 ** it is not possible to change the [threading mode] from its default
1779 ** value of Single-thread and so [sqlite3_config()] will return
1780 ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
1781 ** configuration option.</dd>
1782 **
1783 ** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>
1784 ** <dd>There are no arguments to this option. ^This option sets the
1785 ** [threading mode] to Multi-thread. In other words, it disables
1786 ** mutexing on [database connection] and [prepared statement] objects.
1787 ** The application is responsible for serializing access to
1788 ** [database connections] and [prepared statements]. But other mutexes
1789 ** are enabled so that SQLite will be safe to use in a multi-threaded
1790 ** environment as long as no two threads attempt to use the same
1791 ** [database connection] at the same time. ^If SQLite is compiled with
1792 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1793 ** it is not possible to set the Multi-thread [threading mode] and
1794 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1795 ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
1796 **
1797 ** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>
1798 ** <dd>There are no arguments to this option. ^This option sets the
1799 ** [threading mode] to Serialized. In other words, this option enables
1800 ** all mutexes including the recursive
1801 ** mutexes on [database connection] and [prepared statement] objects.
1802 ** In this mode (which is the default when SQLite is compiled with
1803 ** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access
1804 ** to [database connections] and [prepared statements] so that the
1805 ** application is free to use the same [database connection] or the
1806 ** same [prepared statement] in different threads at the same time.
1807 ** ^If SQLite is compiled with
1808 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1809 ** it is not possible to set the Serialized [threading mode] and
1810 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1811 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
1812 **
1813 ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
1814 ** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is
1815 ** a pointer to an instance of the [sqlite3_mem_methods] structure.
1816 ** The argument specifies
1817 ** alternative low-level memory allocation routines to be used in place of
1818 ** the memory allocation routines built into SQLite.)^ ^SQLite makes
1819 ** its own private copy of the content of the [sqlite3_mem_methods] structure
1820 ** before the [sqlite3_config()] call returns.</dd>
1821 **
1822 ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
1823 ** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
1824 ** is a pointer to an instance of the [sqlite3_mem_methods] structure.
1825 ** The [sqlite3_mem_methods]
1826 ** structure is filled with the currently defined memory allocation routines.)^
1827 ** This option can be used to overload the default memory allocation
1828 ** routines with a wrapper that simulations memory allocation failure or
1829 ** tracks memory usage, for example. </dd>
1830 **
1831 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1832 ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
1833 ** interpreted as a boolean, which enables or disables the collection of
1834 ** memory allocation statistics. ^(When memory allocation statistics are
1835 ** disabled, the following SQLite interfaces become non-operational:
1836 ** <ul>
1837 ** <li> [sqlite3_memory_used()]
1838 ** <li> [sqlite3_memory_highwater()]
1839 ** <li> [sqlite3_soft_heap_limit64()]
1840 ** <li> [sqlite3_status64()]
1841 ** </ul>)^
1842 ** ^Memory allocation statistics are enabled by default unless SQLite is
1843 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1844 ** allocation statistics are disabled by default.
1845 ** </dd>
1846 **
1847 ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1848 ** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer
1849 ** that SQLite can use for scratch memory. ^(There are three arguments
1850 ** to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte
1851 ** aligned memory buffer from which the scratch allocations will be
1852 ** drawn, the size of each scratch allocation (sz),
1853 ** and the maximum number of scratch allocations (N).)^
1854 ** The first argument must be a pointer to an 8-byte aligned buffer
1855 ** of at least sz*N bytes of memory.
1856 ** ^SQLite will not use more than one scratch buffers per thread.
1857 ** ^SQLite will never request a scratch buffer that is more than 6
1858 ** times the database page size.
1859 ** ^If SQLite needs needs additional
1860 ** scratch memory beyond what is provided by this configuration option, then
1861 ** [sqlite3_malloc()] will be used to obtain the memory needed.<p>
1862 ** ^When the application provides any amount of scratch memory using
1863 ** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large
1864 ** [sqlite3_malloc|heap allocations].
1865 ** This can help [Robson proof|prevent memory allocation failures] due to heap
1866 ** fragmentation in low-memory embedded systems.
1867 ** </dd>
1868 **
1869 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1870 ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
1871 ** that SQLite can use for the database page cache with the default page
1872 ** cache implementation.
1873 ** This configuration option is a no-op if an application-define page
1874 ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2].
1875 ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
1876 ** 8-byte aligned memory (pMem), the size of each page cache line (sz),
1877 ** and the number of cache lines (N).
1878 ** The sz argument should be the size of the largest database page
1879 ** (a power of two between 512 and 65536) plus some extra bytes for each
1880 ** page header. ^The number of extra bytes needed by the page header
1881 ** can be determined using [SQLITE_CONFIG_PCACHE_HDRSZ].
1882 ** ^It is harmless, apart from the wasted memory,
1883 ** for the sz parameter to be larger than necessary. The pMem
1884 ** argument must be either a NULL pointer or a pointer to an 8-byte
1885 ** aligned block of memory of at least sz*N bytes, otherwise
1886 ** subsequent behavior is undefined.
1887 ** ^When pMem is not NULL, SQLite will strive to use the memory provided
1888 ** to satisfy page cache needs, falling back to [sqlite3_malloc()] if
1889 ** a page cache line is larger than sz bytes or if all of the pMem buffer
1890 ** is exhausted.
1891 ** ^If pMem is NULL and N is non-zero, then each database connection
1892 ** does an initial bulk allocation for page cache memory
1893 ** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or
1894 ** of -1024*N bytes if N is negative, . ^If additional
1895 ** page cache memory is needed beyond what is provided by the initial
1896 ** allocation, then SQLite goes to [sqlite3_malloc()] separately for each
1897 ** additional cache line. </dd>
1898 **
1899 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1900 ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
1901 ** that SQLite will use for all of its dynamic memory allocation needs
1902 ** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and
1903 ** [SQLITE_CONFIG_PAGECACHE].
1904 ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
1905 ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
1906 ** [SQLITE_ERROR] if invoked otherwise.
1907 ** ^There are three arguments to SQLITE_CONFIG_HEAP:
1908 ** An 8-byte aligned pointer to the memory,
1909 ** the number of bytes in the memory buffer, and the minimum allocation size.
1910 ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
1911 ** to using its default memory allocator (the system malloc() implementation),
1912 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
1913 ** memory pointer is not NULL then the alternative memory
1914 ** allocator is engaged to handle all of SQLites memory allocation needs.
1915 ** The first pointer (the memory pointer) must be aligned to an 8-byte
1916 ** boundary or subsequent behavior of SQLite will be undefined.
1917 ** The minimum allocation size is capped at 2**12. Reasonable values
1918 ** for the minimum allocation size are 2**5 through 2**8.</dd>
1919 **
1920 ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1921 ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
1922 ** pointer to an instance of the [sqlite3_mutex_methods] structure.
1923 ** The argument specifies alternative low-level mutex routines to be used
1924 ** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of
1925 ** the content of the [sqlite3_mutex_methods] structure before the call to
1926 ** [sqlite3_config()] returns. ^If SQLite is compiled with
1927 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1928 ** the entire mutexing subsystem is omitted from the build and hence calls to
1929 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
1930 ** return [SQLITE_ERROR].</dd>
1931 **
1932 ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
1933 ** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which
1934 ** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The
1935 ** [sqlite3_mutex_methods]
1936 ** structure is filled with the currently defined mutex routines.)^
1937 ** This option can be used to overload the default mutex allocation
1938 ** routines with a wrapper used to track mutex usage for performance
1939 ** profiling or testing, for example. ^If SQLite is compiled with
1940 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1941 ** the entire mutexing subsystem is omitted from the build and hence calls to
1942 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
1943 ** return [SQLITE_ERROR].</dd>
1944 **
1945 ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1946 ** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
1947 ** the default size of lookaside memory on each [database connection].
1948 ** The first argument is the
1949 ** size of each lookaside buffer slot and the second is the number of
1950 ** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE
1951 ** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1952 ** option to [sqlite3_db_config()] can be used to change the lookaside
1953 ** configuration on individual connections.)^ </dd>
1954 **
1955 ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
1956 ** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
1957 ** a pointer to an [sqlite3_pcache_methods2] object. This object specifies
1958 ** the interface to a custom page cache implementation.)^
1959 ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
1960 **
1961 ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
1962 ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
1963 ** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of
1964 ** the current page cache implementation into that object.)^ </dd>
1965 **
1966 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
1967 ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
1968 ** global [error log].
1969 ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
1970 ** function with a call signature of void(*)(void*,int,const char*),
1971 ** and a pointer to void. ^If the function pointer is not NULL, it is
1972 ** invoked by [sqlite3_log()] to process each logging event. ^If the
1973 ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
1974 ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
1975 ** passed through as the first parameter to the application-defined logger
1976 ** function whenever that function is invoked. ^The second parameter to
1977 ** the logger function is a copy of the first parameter to the corresponding
1978 ** [sqlite3_log()] call and is intended to be a [result code] or an
1979 ** [extended result code]. ^The third parameter passed to the logger is
1980 ** log message after formatting via [sqlite3_snprintf()].
1981 ** The SQLite logging interface is not reentrant; the logger function
1982 ** supplied by the application must not invoke any SQLite interface.
1983 ** In a multi-threaded application, the application-defined logger
1984 ** function must be threadsafe. </dd>
1985 **
1986 ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
1987 ** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.
1988 ** If non-zero, then URI handling is globally enabled. If the parameter is zero,
1989 ** then URI handling is globally disabled.)^ ^If URI handling is globally
1990 ** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()],
1991 ** [sqlite3_open16()] or
1992 ** specified as part of [ATTACH] commands are interpreted as URIs, regardless
1993 ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
1994 ** connection is opened. ^If it is globally disabled, filenames are
1995 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
1996 ** database connection is opened. ^(By default, URI handling is globally
1997 ** disabled. The default value may be changed by compiling with the
1998 ** [SQLITE_USE_URI] symbol defined.)^
1999 **
2000 ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
2001 ** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer
2002 ** argument which is interpreted as a boolean in order to enable or disable
2003 ** the use of covering indices for full table scans in the query optimizer.
2004 ** ^The default setting is determined
2005 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
2006 ** if that compile-time option is omitted.
2007 ** The ability to disable the use of covering indices for full table scans
2008 ** is because some incorrectly coded legacy applications might malfunction
2009 ** when the optimization is enabled. Providing the ability to
2010 ** disable the optimization allows the older, buggy application code to work
2011 ** without change even with newer versions of SQLite.
2012 **
2013 ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
2014 ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE
2015 ** <dd> These options are obsolete and should not be used by new code.
2016 ** They are retained for backwards compatibility but are now no-ops.
2017 ** </dd>
2018 **
2019 ** [[SQLITE_CONFIG_SQLLOG]]
2020 ** <dt>SQLITE_CONFIG_SQLLOG
2021 ** <dd>This option is only available if sqlite is compiled with the
2022 ** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should
2023 ** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int).
2024 ** The second should be of type (void*). The callback is invoked by the library
2025 ** in three separate circumstances, identified by the value passed as the
2026 ** fourth parameter. If the fourth parameter is 0, then the database connection
2027 ** passed as the second argument has just been opened. The third argument
2028 ** points to a buffer containing the name of the main database file. If the
2029 ** fourth parameter is 1, then the SQL statement that the third parameter
2030 ** points to has just been executed. Or, if the fourth parameter is 2, then
2031 ** the connection being passed as the second parameter is being closed. The
2032 ** third parameter is passed NULL In this case. An example of using this
2033 ** configuration option can be seen in the "test_sqllog.c" source file in
2034 ** the canonical SQLite source tree.</dd>
2035 **
2036 ** [[SQLITE_CONFIG_MMAP_SIZE]]
2037 ** <dt>SQLITE_CONFIG_MMAP_SIZE
2038 ** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values
2039 ** that are the default mmap size limit (the default setting for
2040 ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
2041 ** ^The default setting can be overridden by each database connection using
2042 ** either the [PRAGMA mmap_size] command, or by using the
2043 ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size
2044 ** will be silently truncated if necessary so that it does not exceed the
2045 ** compile-time maximum mmap size set by the
2046 ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
2047 ** ^If either argument to this option is negative, then that argument is
2048 ** changed to its compile-time default.
2049 **
2050 ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
2051 ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
2052 ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
2053 ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro
2054 ** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
2055 ** that specifies the maximum size of the created heap.
2056 **
2057 ** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
2058 ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
2059 ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
2060 ** is a pointer to an integer and writes into that integer the number of extra
2061 ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
2062 ** The amount of extra space required can change depending on the compiler,
2063 ** target platform, and SQLite version.
2064 **
2065 ** [[SQLITE_CONFIG_PMASZ]]
2066 ** <dt>SQLITE_CONFIG_PMASZ
2067 ** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which
2068 ** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded
2069 ** sorter to that integer. The default minimum PMA Size is set by the
2070 ** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched
2071 ** to help with sort operations when multithreaded sorting
2072 ** is enabled (using the [PRAGMA threads] command) and the amount of content
2073 ** to be sorted exceeds the page size times the minimum of the
2074 ** [PRAGMA cache_size] setting and this value.
2075 **
2076 ** [[SQLITE_CONFIG_STMTJRNL_SPILL]]
2077 ** <dt>SQLITE_CONFIG_STMTJRNL_SPILL
2078 ** <dd>^The SQLITE_CONFIG_STMTJRNL_SPILL option takes a single parameter which
2079 ** becomes the [statement journal] spill-to-disk threshold.
2080 ** [Statement journals] are held in memory until their size (in bytes)
2081 ** exceeds this threshold, at which point they are written to disk.
2082 ** Or if the threshold is -1, statement journals are always held
2083 ** exclusively in memory.
2084 ** Since many statement journals never become large, setting the spill
2085 ** threshold to a value such as 64KiB can greatly reduce the amount of
2086 ** I/O required to support statement rollback.
2087 ** The default value for this setting is controlled by the
2088 ** [SQLITE_STMTJRNL_SPILL] compile-time option.
2089 ** </dl>
2090 */
2091 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
2092 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
2093 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
2094 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
2095 #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */
2096 #define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */
2097 #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */
2098 #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */
2099 #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */
2100 #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */
2101 #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */
2102 /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
2103 #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */
2104 #define SQLITE_CONFIG_PCACHE 14 /* no-op */
2105 #define SQLITE_CONFIG_GETPCACHE 15 /* no-op */
2106 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
2107 #define SQLITE_CONFIG_URI 17 /* int */
2108 #define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */
2109 #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
2110 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
2111 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
2112 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
2113 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
2114 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
2115 #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
2116 #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
2117 
2118 /*
2119 ** CAPI3REF: Database Connection Configuration Options
2120 **
2121 ** These constants are the available integer configuration options that
2122 ** can be passed as the second argument to the [sqlite3_db_config()] interface.
2123 **
2124 ** New configuration options may be added in future releases of SQLite.
2125 ** Existing configuration options might be discontinued. Applications
2126 ** should check the return code from [sqlite3_db_config()] to make sure that
2127 ** the call worked. ^The [sqlite3_db_config()] interface will return a
2128 ** non-zero [error code] if a discontinued or unsupported configuration option
2129 ** is invoked.
2130 **
2131 ** <dl>
2132 ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
2133 ** <dd> ^This option takes three additional arguments that determine the
2134 ** [lookaside memory allocator] configuration for the [database connection].
2135 ** ^The first argument (the third parameter to [sqlite3_db_config()] is a
2136 ** pointer to a memory buffer to use for lookaside memory.
2137 ** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
2138 ** may be NULL in which case SQLite will allocate the
2139 ** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the
2140 ** size of each lookaside buffer slot. ^The third argument is the number of
2141 ** slots. The size of the buffer in the first argument must be greater than
2142 ** or equal to the product of the second and third arguments. The buffer
2143 ** must be aligned to an 8-byte boundary. ^If the second argument to
2144 ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
2145 ** rounded down to the next smaller multiple of 8. ^(The lookaside memory
2146 ** configuration for a database connection can only be changed when that
2147 ** connection is not currently using lookaside memory, or in other words
2148 ** when the "current value" returned by
2149 ** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
2150 ** Any attempt to change the lookaside memory configuration when lookaside
2151 ** memory is in use leaves the configuration unchanged and returns
2152 ** [SQLITE_BUSY].)^</dd>
2153 **
2154 ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
2155 ** <dd> ^This option is used to enable or disable the enforcement of
2156 ** [foreign key constraints]. There should be two additional arguments.
2157 ** The first argument is an integer which is 0 to disable FK enforcement,
2158 ** positive to enable FK enforcement or negative to leave FK enforcement
2159 ** unchanged. The second parameter is a pointer to an integer into which
2160 ** is written 0 or 1 to indicate whether FK enforcement is off or on
2161 ** following this call. The second parameter may be a NULL pointer, in
2162 ** which case the FK enforcement setting is not reported back. </dd>
2163 **
2164 ** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
2165 ** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
2166 ** There should be two additional arguments.
2167 ** The first argument is an integer which is 0 to disable triggers,
2168 ** positive to enable triggers or negative to leave the setting unchanged.
2169 ** The second parameter is a pointer to an integer into which
2170 ** is written 0 or 1 to indicate whether triggers are disabled or enabled
2171 ** following this call. The second parameter may be a NULL pointer, in
2172 ** which case the trigger setting is not reported back. </dd>
2173 **
2174 ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
2175 ** <dd> ^This option is used to enable or disable the two-argument
2176 ** version of the [fts3_tokenizer()] function which is part of the
2177 ** [FTS3] full-text search engine extension.
2178 ** There should be two additional arguments.
2179 ** The first argument is an integer which is 0 to disable fts3_tokenizer() or
2180 ** positive to enable fts3_tokenizer() or negative to leave the setting
2181 ** unchanged.
2182 ** The second parameter is a pointer to an integer into which
2183 ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
2184 ** following this call. The second parameter may be a NULL pointer, in
2185 ** which case the new setting is not reported back. </dd>
2186 **
2187 ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
2188 ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
2189 ** interface independently of the [load_extension()] SQL function.
2190 ** The [sqlite3_enable_load_extension()] API enables or disables both the
2191 ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
2192 ** There should be two additional arguments.
2193 ** When the first argument to this interface is 1, then only the C-API is
2194 ** enabled and the SQL function remains disabled. If the first argment to
2195 ** this interface is 0, then both the C-API and the SQL function are disabled.
2196 ** If the first argument is -1, then no changes are made to state of either the
2197 ** C-API or the SQL function.
2198 ** The second parameter is a pointer to an integer into which
2199 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
2200 ** is disabled or enabled following this call. The second parameter may
2201 ** be a NULL pointer, in which case the new setting is not reported back.
2202 ** </dd>
2203 **
2204 ** </dl>
2205 */
2206 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
2207 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
2208 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
2209 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
2210 #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
2211 
2212 
2213 /*
2214 ** CAPI3REF: Enable Or Disable Extended Result Codes
2215 ** METHOD: sqlite3
2216 **
2217 ** ^The sqlite3_extended_result_codes() routine enables or disables the
2218 ** [extended result codes] feature of SQLite. ^The extended result
2219 ** codes are disabled by default for historical compatibility.
2220 */
2222 
2223 /*
2224 ** CAPI3REF: Last Insert Rowid
2225 ** METHOD: sqlite3
2226 **
2227 ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
2228 ** has a unique 64-bit signed
2229 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
2230 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
2231 ** names are not also used by explicitly declared columns. ^If
2232 ** the table has a column of type [INTEGER PRIMARY KEY] then that column
2233 ** is another alias for the rowid.
2234 **
2235 ** ^The sqlite3_last_insert_rowid(D) interface returns the [rowid] of the
2236 ** most recent successful [INSERT] into a rowid table or [virtual table]
2237 ** on database connection D.
2238 ** ^Inserts into [WITHOUT ROWID] tables are not recorded.
2239 ** ^If no successful [INSERT]s into rowid tables
2240 ** have ever occurred on the database connection D,
2241 ** then sqlite3_last_insert_rowid(D) returns zero.
2242 **
2243 ** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
2244 ** method, then this routine will return the [rowid] of the inserted
2245 ** row as long as the trigger or virtual table method is running.
2246 ** But once the trigger or virtual table method ends, the value returned
2247 ** by this routine reverts to what it was before the trigger or virtual
2248 ** table method began.)^
2249 **
2250 ** ^An [INSERT] that fails due to a constraint violation is not a
2251 ** successful [INSERT] and does not change the value returned by this
2252 ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
2253 ** and INSERT OR ABORT make no changes to the return value of this
2254 ** routine when their insertion fails. ^(When INSERT OR REPLACE
2255 ** encounters a constraint violation, it does not fail. The
2256 ** INSERT continues to completion after deleting rows that caused
2257 ** the constraint problem so INSERT OR REPLACE will always change
2258 ** the return value of this interface.)^
2259 **
2260 ** ^For the purposes of this routine, an [INSERT] is considered to
2261 ** be successful even if it is subsequently rolled back.
2262 **
2263 ** This function is accessible to SQL statements via the
2264 ** [last_insert_rowid() SQL function].
2265 **
2266 ** If a separate thread performs a new [INSERT] on the same
2267 ** database connection while the [sqlite3_last_insert_rowid()]
2268 ** function is running and thus changes the last insert [rowid],
2269 ** then the value returned by [sqlite3_last_insert_rowid()] is
2270 ** unpredictable and might not equal either the old or the new
2271 ** last insert [rowid].
2272 */
2274 
2275 /*
2276 ** CAPI3REF: Count The Number Of Rows Modified
2277 ** METHOD: sqlite3
2278 **
2279 ** ^This function returns the number of rows modified, inserted or
2280 ** deleted by the most recently completed INSERT, UPDATE or DELETE
2281 ** statement on the database connection specified by the only parameter.
2282 ** ^Executing any other type of SQL statement does not modify the value
2283 ** returned by this function.
2284 **
2285 ** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
2286 ** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
2287 ** [foreign key actions] or [REPLACE] constraint resolution are not counted.
2288 **
2289 ** Changes to a view that are intercepted by
2290 ** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value
2291 ** returned by sqlite3_changes() immediately after an INSERT, UPDATE or
2292 ** DELETE statement run on a view is always zero. Only changes made to real
2293 ** tables are counted.
2294 **
2295 ** Things are more complicated if the sqlite3_changes() function is
2296 ** executed while a trigger program is running. This may happen if the
2297 ** program uses the [changes() SQL function], or if some other callback
2298 ** function invokes sqlite3_changes() directly. Essentially:
2299 **
2300 ** <ul>
2301 ** <li> ^(Before entering a trigger program the value returned by
2302 ** sqlite3_changes() function is saved. After the trigger program
2303 ** has finished, the original value is restored.)^
2304 **
2305 ** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE
2306 ** statement sets the value returned by sqlite3_changes()
2307 ** upon completion as normal. Of course, this value will not include
2308 ** any changes performed by sub-triggers, as the sqlite3_changes()
2309 ** value will be saved and restored after each sub-trigger has run.)^
2310 ** </ul>
2311 **
2312 ** ^This means that if the changes() SQL function (or similar) is used
2313 ** by the first INSERT, UPDATE or DELETE statement within a trigger, it
2314 ** returns the value as set when the calling statement began executing.
2315 ** ^If it is used by the second or subsequent such statement within a trigger
2316 ** program, the value returned reflects the number of rows modified by the
2317 ** previous INSERT, UPDATE or DELETE statement within the same trigger.
2318 **
2319 ** See also the [sqlite3_total_changes()] interface, the
2320 ** [count_changes pragma], and the [changes() SQL function].
2321 **
2322 ** If a separate thread makes changes on the same database connection
2323 ** while [sqlite3_changes()] is running then the value returned
2324 ** is unpredictable and not meaningful.
2325 */
2327 
2328 /*
2329 ** CAPI3REF: Total Number Of Rows Modified
2330 ** METHOD: sqlite3
2331 **
2332 ** ^This function returns the total number of rows inserted, modified or
2333 ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
2334 ** since the database connection was opened, including those executed as
2335 ** part of trigger programs. ^Executing any other type of SQL statement
2336 ** does not affect the value returned by sqlite3_total_changes().
2337 **
2338 ** ^Changes made as part of [foreign key actions] are included in the
2339 ** count, but those made as part of REPLACE constraint resolution are
2340 ** not. ^Changes to a view that are intercepted by INSTEAD OF triggers
2341 ** are not counted.
2342 **
2343 ** See also the [sqlite3_changes()] interface, the
2344 ** [count_changes pragma], and the [total_changes() SQL function].
2345 **
2346 ** If a separate thread makes changes on the same database connection
2347 ** while [sqlite3_total_changes()] is running then the value
2348 ** returned is unpredictable and not meaningful.
2349 */
2351 
2352 /*
2353 ** CAPI3REF: Interrupt A Long-Running Query
2354 ** METHOD: sqlite3
2355 **
2356 ** ^This function causes any pending database operation to abort and
2357 ** return at its earliest opportunity. This routine is typically
2358 ** called in response to a user action such as pressing "Cancel"
2359 ** or Ctrl-C where the user wants a long query operation to halt
2360 ** immediately.
2361 **
2362 ** ^It is safe to call this routine from a thread different from the
2363 ** thread that is currently running the database operation. But it
2364 ** is not safe to call this routine with a [database connection] that
2365 ** is closed or might close before sqlite3_interrupt() returns.
2366 **
2367 ** ^If an SQL operation is very nearly finished at the time when
2368 ** sqlite3_interrupt() is called, then it might not have an opportunity
2369 ** to be interrupted and might continue to completion.
2370 **
2371 ** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT].
2372 ** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
2373 ** that is inside an explicit transaction, then the entire transaction
2374 ** will be rolled back automatically.
2375 **
2376 ** ^The sqlite3_interrupt(D) call is in effect until all currently running
2377 ** SQL statements on [database connection] D complete. ^Any new SQL statements
2378 ** that are started after the sqlite3_interrupt() call and before the
2379 ** running statements reaches zero are interrupted as if they had been
2380 ** running prior to the sqlite3_interrupt() call. ^New SQL statements
2381 ** that are started after the running statement count reaches zero are
2382 ** not effected by the sqlite3_interrupt().
2383 ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
2384 ** SQL statements is a no-op and has no effect on SQL statements
2385 ** that are started after the sqlite3_interrupt() call returns.
2386 **
2387 ** If the database connection closes while [sqlite3_interrupt()]
2388 ** is running then bad things will likely happen.
2389 */
2391 
2392 /*
2393 ** CAPI3REF: Determine If An SQL Statement Is Complete
2394 **
2395 ** These routines are useful during command-line input to determine if the
2396 ** currently entered text seems to form a complete SQL statement or
2397 ** if additional input is needed before sending the text into
2398 ** SQLite for parsing. ^These routines return 1 if the input string
2399 ** appears to be a complete SQL statement. ^A statement is judged to be
2400 ** complete if it ends with a semicolon token and is not a prefix of a
2401 ** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within
2402 ** string literals or quoted identifier names or comments are not
2403 ** independent tokens (they are part of the token in which they are
2404 ** embedded) and thus do not count as a statement terminator. ^Whitespace
2405 ** and comments that follow the final semicolon are ignored.
2406 **
2407 ** ^These routines return 0 if the statement is incomplete. ^If a
2408 ** memory allocation fails, then SQLITE_NOMEM is returned.
2409 **
2410 ** ^These routines do not parse the SQL statements thus
2411 ** will not detect syntactically incorrect SQL.
2412 **
2413 ** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior
2414 ** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
2415 ** automatically by sqlite3_complete16(). If that initialization fails,
2416 ** then the return value from sqlite3_complete16() will be non-zero
2417 ** regardless of whether or not the input SQL is complete.)^
2418 **
2419 ** The input to [sqlite3_complete()] must be a zero-terminated
2420 ** UTF-8 string.
2421 **
2422 ** The input to [sqlite3_complete16()] must be a zero-terminated
2423 ** UTF-16 string in native byte order.
2424 */
2425 SQLITE_API int SQLITE_STDCALL sqlite3_complete(const char *sql);
2426 SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
2427 
2428 /*
2429 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2430 ** KEYWORDS: {busy-handler callback} {busy handler}
2431 ** METHOD: sqlite3
2432 **
2433 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2434 ** that might be invoked with argument P whenever
2435 ** an attempt is made to access a database table associated with
2436 ** [database connection] D when another thread
2437 ** or process has the table locked.
2438 ** The sqlite3_busy_handler() interface is used to implement
2439 ** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].
2440 **
2441 ** ^If the busy callback is NULL, then [SQLITE_BUSY]
2442 ** is returned immediately upon encountering the lock. ^If the busy callback
2443 ** is not NULL, then the callback might be invoked with two arguments.
2444 **
2445 ** ^The first argument to the busy handler is a copy of the void* pointer which
2446 ** is the third argument to sqlite3_busy_handler(). ^The second argument to
2447 ** the busy handler callback is the number of times that the busy handler has
2448 ** been invoked previously for the same locking event. ^If the
2449 ** busy callback returns 0, then no additional attempts are made to
2450 ** access the database and [SQLITE_BUSY] is returned
2451 ** to the application.
2452 ** ^If the callback returns non-zero, then another attempt
2453 ** is made to access the database and the cycle repeats.
2454 **
2455 ** The presence of a busy handler does not guarantee that it will be invoked
2456 ** when there is lock contention. ^If SQLite determines that invoking the busy
2457 ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
2458 ** to the application instead of invoking the
2459 ** busy handler.
2460 ** Consider a scenario where one process is holding a read lock that
2461 ** it is trying to promote to a reserved lock and
2462 ** a second process is holding a reserved lock that it is trying
2463 ** to promote to an exclusive lock. The first process cannot proceed
2464 ** because it is blocked by the second and the second process cannot
2465 ** proceed because it is blocked by the first. If both processes
2466 ** invoke the busy handlers, neither will make any progress. Therefore,
2467 ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
2468 ** will induce the first process to release its read lock and allow
2469 ** the second process to proceed.
2470 **
2471 ** ^The default busy callback is NULL.
2472 **
2473 ** ^(There can only be a single busy handler defined for each
2474 ** [database connection]. Setting a new busy handler clears any
2475 ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()]
2476 ** or evaluating [PRAGMA busy_timeout=N] will change the
2477 ** busy handler and thus clear any previously set busy handler.
2478 **
2479 ** The busy callback should not take any actions which modify the
2480 ** database connection that invoked the busy handler. In other words,
2481 ** the busy handler is not reentrant. Any such actions
2482 ** result in undefined behavior.
2483 **
2484 ** A busy handler must not close the database connection
2485 ** or [prepared statement] that invoked the busy handler.
2486 */
2487 SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
2488 
2489 /*
2490 ** CAPI3REF: Set A Busy Timeout
2491 ** METHOD: sqlite3
2492 **
2493 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
2494 ** for a specified amount of time when a table is locked. ^The handler
2495 ** will sleep multiple times until at least "ms" milliseconds of sleeping
2496 ** have accumulated. ^After at least "ms" milliseconds of sleeping,
2497 ** the handler returns 0 which causes [sqlite3_step()] to return
2498 ** [SQLITE_BUSY].
2499 **
2500 ** ^Calling this routine with an argument less than or equal to zero
2501 ** turns off all busy handlers.
2502 **
2503 ** ^(There can only be a single busy handler for a particular
2504 ** [database connection] at any given moment. If another busy handler
2505 ** was defined (using [sqlite3_busy_handler()]) prior to calling
2506 ** this routine, that other busy handler is cleared.)^
2507 **
2508 ** See also: [PRAGMA busy_timeout]
2509 */
2511 
2512 /*
2513 ** CAPI3REF: Convenience Routines For Running Queries
2514 ** METHOD: sqlite3
2515 **
2516 ** This is a legacy interface that is preserved for backwards compatibility.
2517 ** Use of this interface is not recommended.
2518 **
2519 ** Definition: A <b>result table</b> is memory data structure created by the
2520 ** [sqlite3_get_table()] interface. A result table records the
2521 ** complete query results from one or more queries.
2522 **
2523 ** The table conceptually has a number of rows and columns. But
2524 ** these numbers are not part of the result table itself. These
2525 ** numbers are obtained separately. Let N be the number of rows
2526 ** and M be the number of columns.
2527 **
2528 ** A result table is an array of pointers to zero-terminated UTF-8 strings.
2529 ** There are (N+1)*M elements in the array. The first M pointers point
2530 ** to zero-terminated strings that contain the names of the columns.
2531 ** The remaining entries all point to query results. NULL values result
2532 ** in NULL pointers. All other values are in their UTF-8 zero-terminated
2533 ** string representation as returned by [sqlite3_column_text()].
2534 **
2535 ** A result table might consist of one or more memory allocations.
2536 ** It is not safe to pass a result table directly to [sqlite3_free()].
2537 ** A result table should be deallocated using [sqlite3_free_table()].
2538 **
2539 ** ^(As an example of the result table format, suppose a query result
2540 ** is as follows:
2541 **
2542 ** <blockquote><pre>
2543 ** Name | Age
2544 ** -----------------------
2545 ** Alice | 43
2546 ** Bob | 28
2547 ** Cindy | 21
2548 ** </pre></blockquote>
2549 **
2550 ** There are two column (M==2) and three rows (N==3). Thus the
2551 ** result table has 8 entries. Suppose the result table is stored
2552 ** in an array names azResult. Then azResult holds this content:
2553 **
2554 ** <blockquote><pre>
2555 ** azResult&#91;0] = "Name";
2556 ** azResult&#91;1] = "Age";
2557 ** azResult&#91;2] = "Alice";
2558 ** azResult&#91;3] = "43";
2559 ** azResult&#91;4] = "Bob";
2560 ** azResult&#91;5] = "28";
2561 ** azResult&#91;6] = "Cindy";
2562 ** azResult&#91;7] = "21";
2563 ** </pre></blockquote>)^
2564 **
2565 ** ^The sqlite3_get_table() function evaluates one or more
2566 ** semicolon-separated SQL statements in the zero-terminated UTF-8
2567 ** string of its 2nd parameter and returns a result table to the
2568 ** pointer given in its 3rd parameter.
2569 **
2570 ** After the application has finished with the result from sqlite3_get_table(),
2571 ** it must pass the result table pointer to sqlite3_free_table() in order to
2572 ** release the memory that was malloced. Because of the way the
2573 ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
2574 ** function must not try to call [sqlite3_free()] directly. Only
2575 ** [sqlite3_free_table()] is able to release the memory properly and safely.
2576 **
2577 ** The sqlite3_get_table() interface is implemented as a wrapper around
2578 ** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access
2579 ** to any internal data structures of SQLite. It uses only the public
2580 ** interface defined here. As a consequence, errors that occur in the
2581 ** wrapper layer outside of the internal [sqlite3_exec()] call are not
2582 ** reflected in subsequent calls to [sqlite3_errcode()] or
2583 ** [sqlite3_errmsg()].
2584 */
2586  sqlite3 *db, /* An open database */
2587  const char *zSql, /* SQL to be evaluated */
2588  char ***pazResult, /* Results of the query */
2589  int *pnRow, /* Number of result rows written here */
2590  int *pnColumn, /* Number of result columns written here */
2591  char **pzErrmsg /* Error msg written here */
2592 );
2594 
2595 /*
2596 ** CAPI3REF: Formatted String Printing Functions
2597 **
2598 ** These routines are work-alikes of the "printf()" family of functions
2599 ** from the standard C library.
2600 ** These routines understand most of the common K&R formatting options,
2601 ** plus some additional non-standard formats, detailed below.
2602 ** Note that some of the more obscure formatting options from recent
2603 ** C-library standards are omitted from this implementation.
2604 **
2605 ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
2606 ** results into memory obtained from [sqlite3_malloc()].
2607 ** The strings returned by these two routines should be
2608 ** released by [sqlite3_free()]. ^Both routines return a
2609 ** NULL pointer if [sqlite3_malloc()] is unable to allocate enough
2610 ** memory to hold the resulting string.
2611 **
2612 ** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from
2613 ** the standard C library. The result is written into the
2614 ** buffer supplied as the second parameter whose size is given by
2615 ** the first parameter. Note that the order of the
2616 ** first two parameters is reversed from snprintf().)^ This is an
2617 ** historical accident that cannot be fixed without breaking
2618 ** backwards compatibility. ^(Note also that sqlite3_snprintf()
2619 ** returns a pointer to its buffer instead of the number of
2620 ** characters actually written into the buffer.)^ We admit that
2621 ** the number of characters written would be a more useful return
2622 ** value but we cannot change the implementation of sqlite3_snprintf()
2623 ** now without breaking compatibility.
2624 **
2625 ** ^As long as the buffer size is greater than zero, sqlite3_snprintf()
2626 ** guarantees that the buffer is always zero-terminated. ^The first
2627 ** parameter "n" is the total size of the buffer, including space for
2628 ** the zero terminator. So the longest string that can be completely
2629 ** written will be n-1 characters.
2630 **
2631 ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
2632 **
2633 ** These routines all implement some additional formatting
2634 ** options that are useful for constructing SQL statements.
2635 ** All of the usual printf() formatting options apply. In addition, there
2636 ** is are "%q", "%Q", "%w" and "%z" options.
2637 **
2638 ** ^(The %q option works like %s in that it substitutes a nul-terminated
2639 ** string from the argument list. But %q also doubles every '\'' character.
2640 ** %q is designed for use inside a string literal.)^ By doubling each '\''
2641 ** character it escapes that character and allows it to be inserted into
2642 ** the string.
2643 **
2644 ** For example, assume the string variable zText contains text as follows:
2645 **
2646 ** <blockquote><pre>
2647 ** char *zText = "It's a happy day!";
2648 ** </pre></blockquote>
2649 **
2650 ** One can use this text in an SQL statement as follows:
2651 **
2652 ** <blockquote><pre>
2653 ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);
2654 ** sqlite3_exec(db, zSQL, 0, 0, 0);
2655 ** sqlite3_free(zSQL);
2656 ** </pre></blockquote>
2657 **
2658 ** Because the %q format string is used, the '\'' character in zText
2659 ** is escaped and the SQL generated is as follows:
2660 **
2661 ** <blockquote><pre>
2662 ** INSERT INTO table1 VALUES('It''s a happy day!')
2663 ** </pre></blockquote>
2664 **
2665 ** This is correct. Had we used %s instead of %q, the generated SQL
2666 ** would have looked like this:
2667 **
2668 ** <blockquote><pre>
2669 ** INSERT INTO table1 VALUES('It's a happy day!');
2670 ** </pre></blockquote>
2671 **
2672 ** This second example is an SQL syntax error. As a general rule you should
2673 ** always use %q instead of %s when inserting text into a string literal.
2674 **
2675 ** ^(The %Q option works like %q except it also adds single quotes around
2676 ** the outside of the total string. Additionally, if the parameter in the
2677 ** argument list is a NULL pointer, %Q substitutes the text "NULL" (without
2678 ** single quotes).)^ So, for example, one could say:
2679 **
2680 ** <blockquote><pre>
2681 ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
2682 ** sqlite3_exec(db, zSQL, 0, 0, 0);
2683 ** sqlite3_free(zSQL);
2684 ** </pre></blockquote>
2685 **
2686 ** The code above will render a correct SQL statement in the zSQL
2687 ** variable even if the zText variable is a NULL pointer.
2688 **
2689 ** ^(The "%w" formatting option is like "%q" except that it expects to
2690 ** be contained within double-quotes instead of single quotes, and it
2691 ** escapes the double-quote character instead of the single-quote
2692 ** character.)^ The "%w" formatting option is intended for safely inserting
2693 ** table and column names into a constructed SQL statement.
2694 **
2695 ** ^(The "%z" formatting option works like "%s" but with the
2696 ** addition that after the string has been read and copied into
2697 ** the result, [sqlite3_free()] is called on the input string.)^
2698 */
2699 SQLITE_API char *SQLITE_CDECL sqlite3_mprintf(const char*,...);
2700 SQLITE_API char *SQLITE_STDCALL sqlite3_vmprintf(const char*, va_list);
2701 SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int,char*,const char*, ...);
2702 SQLITE_API char *SQLITE_STDCALL sqlite3_vsnprintf(int,char*,const char*, va_list);
2703 
2704 /*
2705 ** CAPI3REF: Memory Allocation Subsystem
2706 **
2707 ** The SQLite core uses these three routines for all of its own
2708 ** internal memory allocation needs. "Core" in the previous sentence
2709 ** does not include operating-system specific VFS implementation. The
2710 ** Windows VFS uses native malloc() and free() for some operations.
2711 **
2712 ** ^The sqlite3_malloc() routine returns a pointer to a block
2713 ** of memory at least N bytes in length, where N is the parameter.
2714 ** ^If sqlite3_malloc() is unable to obtain sufficient free
2715 ** memory, it returns a NULL pointer. ^If the parameter N to
2716 ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
2717 ** a NULL pointer.
2718 **
2719 ** ^The sqlite3_malloc64(N) routine works just like
2720 ** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead
2721 ** of a signed 32-bit integer.
2722 **
2723 ** ^Calling sqlite3_free() with a pointer previously returned
2724 ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
2725 ** that it might be reused. ^The sqlite3_free() routine is
2726 ** a no-op if is called with a NULL pointer. Passing a NULL pointer
2727 ** to sqlite3_free() is harmless. After being freed, memory
2728 ** should neither be read nor written. Even reading previously freed
2729 ** memory might result in a segmentation fault or other severe error.
2730 ** Memory corruption, a segmentation fault, or other severe error
2731 ** might result if sqlite3_free() is called with a non-NULL pointer that
2732 ** was not obtained from sqlite3_malloc() or sqlite3_realloc().
2733 **
2734 ** ^The sqlite3_realloc(X,N) interface attempts to resize a
2735 ** prior memory allocation X to be at least N bytes.
2736 ** ^If the X parameter to sqlite3_realloc(X,N)
2737 ** is a NULL pointer then its behavior is identical to calling
2738 ** sqlite3_malloc(N).
2739 ** ^If the N parameter to sqlite3_realloc(X,N) is zero or
2740 ** negative then the behavior is exactly the same as calling
2741 ** sqlite3_free(X).
2742 ** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
2743 ** of at least N bytes in size or NULL if insufficient memory is available.
2744 ** ^If M is the size of the prior allocation, then min(N,M) bytes
2745 ** of the prior allocation are copied into the beginning of buffer returned
2746 ** by sqlite3_realloc(X,N) and the prior allocation is freed.
2747 ** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
2748 ** prior allocation is not freed.
2749 **
2750 ** ^The sqlite3_realloc64(X,N) interfaces works the same as
2751 ** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
2752 ** of a 32-bit signed integer.
2753 **
2754 ** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
2755 ** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
2756 ** sqlite3_msize(X) returns the size of that memory allocation in bytes.
2757 ** ^The value returned by sqlite3_msize(X) might be larger than the number
2758 ** of bytes requested when X was allocated. ^If X is a NULL pointer then
2759 ** sqlite3_msize(X) returns zero. If X points to something that is not
2760 ** the beginning of memory allocation, or if it points to a formerly
2761 ** valid memory allocation that has now been freed, then the behavior
2762 ** of sqlite3_msize(X) is undefined and possibly harmful.
2763 **
2764 ** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(),
2765 ** sqlite3_malloc64(), and sqlite3_realloc64()
2766 ** is always aligned to at least an 8 byte boundary, or to a
2767 ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
2768 ** option is used.
2769 **
2770 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
2771 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
2772 ** implementation of these routines to be omitted. That capability
2773 ** is no longer provided. Only built-in memory allocators can be used.
2774 **
2775 ** Prior to SQLite version 3.7.10, the Windows OS interface layer called
2776 ** the system malloc() and free() directly when converting
2777 ** filenames between the UTF-8 encoding used by SQLite
2778 ** and whatever filename encoding is used by the particular Windows
2779 ** installation. Memory allocation errors were detected, but
2780 ** they were reported back as [SQLITE_CANTOPEN] or
2781 ** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
2782 **
2783 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
2784 ** must be either NULL or else pointers obtained from a prior
2785 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
2786 ** not yet been released.
2787 **
2788 ** The application must not read or write any part of
2789 ** a block of memory after it has been released using
2790 ** [sqlite3_free()] or [sqlite3_realloc()].
2791 */
2793 SQLITE_API void *SQLITE_STDCALL sqlite3_malloc64(sqlite3_uint64);
2794 SQLITE_API void *SQLITE_STDCALL sqlite3_realloc(void*, int);
2795 SQLITE_API void *SQLITE_STDCALL sqlite3_realloc64(void*, sqlite3_uint64);
2797 SQLITE_API sqlite3_uint64 SQLITE_STDCALL sqlite3_msize(void*);
2798 
2799 /*
2800 ** CAPI3REF: Memory Allocator Statistics
2801 **
2802 ** SQLite provides these two interfaces for reporting on the status
2803 ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
2804 ** routines, which form the built-in memory allocation subsystem.
2805 **
2806 ** ^The [sqlite3_memory_used()] routine returns the number of bytes
2807 ** of memory currently outstanding (malloced but not freed).
2808 ** ^The [sqlite3_memory_highwater()] routine returns the maximum
2809 ** value of [sqlite3_memory_used()] since the high-water mark
2810 ** was last reset. ^The values returned by [sqlite3_memory_used()] and
2811 ** [sqlite3_memory_highwater()] include any overhead
2812 ** added by SQLite in its implementation of [sqlite3_malloc()],
2813 ** but not overhead added by the any underlying system library
2814 ** routines that [sqlite3_malloc()] may call.
2815 **
2816 ** ^The memory high-water mark is reset to the current value of
2817 ** [sqlite3_memory_used()] if and only if the parameter to
2818 ** [sqlite3_memory_highwater()] is true. ^The value returned
2819 ** by [sqlite3_memory_highwater(1)] is the high-water mark
2820 ** prior to the reset.
2821 */
2822 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_used(void);
2823 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_highwater(int resetFlag);
2824 
2825 /*
2826 ** CAPI3REF: Pseudo-Random Number Generator
2827 **
2828 ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
2829 ** select random [ROWID | ROWIDs] when inserting new records into a table that
2830 ** already uses the largest possible [ROWID]. The PRNG is also used for
2831 ** the build-in random() and randomblob() SQL functions. This interface allows
2832 ** applications to access the same PRNG for other purposes.
2833 **
2834 ** ^A call to this routine stores N bytes of randomness into buffer P.
2835 ** ^The P parameter can be a NULL pointer.
2836 **
2837 ** ^If this routine has not been previously called or if the previous
2838 ** call had N less than one or a NULL pointer for P, then the PRNG is
2839 ** seeded using randomness obtained from the xRandomness method of
2840 ** the default [sqlite3_vfs] object.
2841 ** ^If the previous call to this routine had an N of 1 or more and a
2842 ** non-NULL P then the pseudo-randomness is generated
2843 ** internally and without recourse to the [sqlite3_vfs] xRandomness
2844 ** method.
2845 */
2846 SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
2847 
2848 /*
2849 ** CAPI3REF: Compile-Time Authorization Callbacks
2850 ** METHOD: sqlite3
2851 **
2852 ** ^This routine registers an authorizer callback with a particular
2853 ** [database connection], supplied in the first argument.
2854 ** ^The authorizer callback is invoked as SQL statements are being compiled
2855 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
2856 ** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()]. ^At various
2857 ** points during the compilation process, as logic is being created
2858 ** to perform various actions, the authorizer callback is invoked to
2859 ** see if those actions are allowed. ^The authorizer callback should
2860 ** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the
2861 ** specific action but allow the SQL statement to continue to be
2862 ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
2863 ** rejected with an error. ^If the authorizer callback returns
2864 ** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]
2865 ** then the [sqlite3_prepare_v2()] or equivalent call that triggered
2866 ** the authorizer will fail with an error message.
2867 **
2868 ** When the callback returns [SQLITE_OK], that means the operation
2869 ** requested is ok. ^When the callback returns [SQLITE_DENY], the
2870 ** [sqlite3_prepare_v2()] or equivalent call that triggered the
2871 ** authorizer will fail with an error message explaining that
2872 ** access is denied.
2873 **
2874 ** ^The first parameter to the authorizer callback is a copy of the third
2875 ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
2876 ** to the callback is an integer [SQLITE_COPY | action code] that specifies
2877 ** the particular action to be authorized. ^The third through sixth parameters
2878 ** to the callback are zero-terminated strings that contain additional
2879 ** details about the action to be authorized.
2880 **
2881 ** ^If the action code is [SQLITE_READ]
2882 ** and the callback returns [SQLITE_IGNORE] then the
2883 ** [prepared statement] statement is constructed to substitute
2884 ** a NULL value in place of the table column that would have
2885 ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE]
2886 ** return can be used to deny an untrusted user access to individual
2887 ** columns of a table.
2888 ** ^If the action code is [SQLITE_DELETE] and the callback returns
2889 ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
2890 ** [truncate optimization] is disabled and all rows are deleted individually.
2891 **
2892 ** An authorizer is used when [sqlite3_prepare | preparing]
2893 ** SQL statements from an untrusted source, to ensure that the SQL statements
2894 ** do not try to access data they are not allowed to see, or that they do not
2895 ** try to execute malicious statements that damage the database. For
2896 ** example, an application may allow a user to enter arbitrary
2897 ** SQL queries for evaluation by a database. But the application does
2898 ** not want the user to be able to make arbitrary changes to the
2899 ** database. An authorizer could then be put in place while the
2900 ** user-entered SQL is being [sqlite3_prepare | prepared] that
2901 ** disallows everything except [SELECT] statements.
2902 **
2903 ** Applications that need to process SQL from untrusted sources
2904 ** might also consider lowering resource limits using [sqlite3_limit()]
2905 ** and limiting database size using the [max_page_count] [PRAGMA]
2906 ** in addition to using an authorizer.
2907 **
2908 ** ^(Only a single authorizer can be in place on a database connection
2909 ** at a time. Each call to sqlite3_set_authorizer overrides the
2910 ** previous call.)^ ^Disable the authorizer by installing a NULL callback.
2911 ** The authorizer is disabled by default.
2912 **
2913 ** The authorizer callback must not do anything that will modify
2914 ** the database connection that invoked the authorizer callback.
2915 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
2916 ** database connections for the meaning of "modify" in this paragraph.
2917 **
2918 ** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the
2919 ** statement might be re-prepared during [sqlite3_step()] due to a
2920 ** schema change. Hence, the application should ensure that the
2921 ** correct authorizer callback remains in place during the [sqlite3_step()].
2922 **
2923 ** ^Note that the authorizer callback is invoked only during
2924 ** [sqlite3_prepare()] or its variants. Authorization is not
2925 ** performed during statement evaluation in [sqlite3_step()], unless
2926 ** as stated in the previous paragraph, sqlite3_step() invokes
2927 ** sqlite3_prepare_v2() to reprepare a statement after a schema change.
2928 */
2930  sqlite3*,
2931  int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
2932  void *pUserData
2933 );
2934 
2935 /*
2936 ** CAPI3REF: Authorizer Return Codes
2937 **
2938 ** The [sqlite3_set_authorizer | authorizer callback function] must
2939 ** return either [SQLITE_OK] or one of these two constants in order
2940 ** to signal SQLite whether or not the action is permitted. See the
2941 ** [sqlite3_set_authorizer | authorizer documentation] for additional
2942 ** information.
2943 **
2944 ** Note that SQLITE_IGNORE is also used as a [conflict resolution mode]
2945 ** returned from the [sqlite3_vtab_on_conflict()] interface.
2946 */
2947 #define SQLITE_DENY 1 /* Abort the SQL statement with an error */
2948 #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
2949 
2950 /*
2951 ** CAPI3REF: Authorizer Action Codes
2952 **
2953 ** The [sqlite3_set_authorizer()] interface registers a callback function
2954 ** that is invoked to authorize certain SQL statement actions. The
2955 ** second parameter to the callback is an integer code that specifies
2956 ** what action is being authorized. These are the integer action codes that
2957 ** the authorizer callback may be passed.
2958 **
2959 ** These action code values signify what kind of operation is to be
2960 ** authorized. The 3rd and 4th parameters to the authorization
2961 ** callback function will be parameters or NULL depending on which of these
2962 ** codes is used as the second parameter. ^(The 5th parameter to the
2963 ** authorizer callback is the name of the database ("main", "temp",
2964 ** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback
2965 ** is the name of the inner-most trigger or view that is responsible for
2966 ** the access attempt or NULL if this access attempt is directly from
2967 ** top-level SQL code.
2968 */
2969 /******************************************* 3rd ************ 4th ***********/
2970 #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
2971 #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
2972 #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
2973 #define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */
2974 #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */
2975 #define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */
2976 #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */
2977 #define SQLITE_CREATE_VIEW 8 /* View Name NULL */
2978 #define SQLITE_DELETE 9 /* Table Name NULL */
2979 #define SQLITE_DROP_INDEX 10 /* Index Name Table Name */
2980 #define SQLITE_DROP_TABLE 11 /* Table Name NULL */
2981 #define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */
2982 #define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */
2983 #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */
2984 #define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */
2985 #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */
2986 #define SQLITE_DROP_VIEW 17 /* View Name NULL */
2987 #define SQLITE_INSERT 18 /* Table Name NULL */
2988 #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */
2989 #define SQLITE_READ 20 /* Table Name Column Name */
2990 #define SQLITE_SELECT 21 /* NULL NULL */
2991 #define SQLITE_TRANSACTION 22 /* Operation NULL */
2992 #define SQLITE_UPDATE 23 /* Table Name Column Name */
2993 #define SQLITE_ATTACH 24 /* Filename NULL */
2994 #define SQLITE_DETACH 25 /* Database Name NULL */
2995 #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
2996 #define SQLITE_REINDEX 27 /* Index Name NULL */
2997 #define SQLITE_ANALYZE 28 /* Table Name NULL */
2998 #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
2999 #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
3000 #define SQLITE_FUNCTION 31 /* NULL Function Name */
3001 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
3002 #define SQLITE_COPY 0 /* No longer used */
3003 #define SQLITE_RECURSIVE 33 /* NULL NULL */
3004 
3005 /*
3006 ** CAPI3REF: Tracing And Profiling Functions
3007 ** METHOD: sqlite3
3008 **
3009 ** These routines register callback functions that can be used for
3010 ** tracing and profiling the execution of SQL statements.
3011 **
3012 ** ^The callback function registered by sqlite3_trace() is invoked at
3013 ** various times when an SQL statement is being run by [sqlite3_step()].
3014 ** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the
3015 ** SQL statement text as the statement first begins executing.
3016 ** ^(Additional sqlite3_trace() callbacks might occur
3017 ** as each triggered subprogram is entered. The callbacks for triggers
3018 ** contain a UTF-8 SQL comment that identifies the trigger.)^
3019 **
3020 ** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit
3021 ** the length of [bound parameter] expansion in the output of sqlite3_trace().
3022 **
3023 ** ^The callback function registered by sqlite3_profile() is invoked
3024 ** as each SQL statement finishes. ^The profile callback contains
3025 ** the original statement text and an estimate of wall-clock time
3026 ** of how long that statement took to run. ^The profile callback
3027 ** time is in units of nanoseconds, however the current implementation
3028 ** is only capable of millisecond resolution so the six least significant
3029 ** digits in the time are meaningless. Future versions of SQLite
3030 ** might provide greater resolution on the profiler callback. The
3031 ** sqlite3_profile() function is considered experimental and is
3032 ** subject to change in future versions of SQLite.
3033 */
3034 SQLITE_API void *SQLITE_STDCALL sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
3036  void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
3037 
3038 /*
3039 ** CAPI3REF: Query Progress Callbacks
3040 ** METHOD: sqlite3
3041 **
3042 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
3043 ** function X to be invoked periodically during long running calls to
3044 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
3045 ** database connection D. An example use for this
3046 ** interface is to keep a GUI updated during a large query.
3047 **
3048 ** ^The parameter P is passed through as the only parameter to the
3049 ** callback function X. ^The parameter N is the approximate number of
3050 ** [virtual machine instructions] that are evaluated between successive
3051 ** invocations of the callback X. ^If N is less than one then the progress
3052 ** handler is disabled.
3053 **
3054 ** ^Only a single progress handler may be defined at one time per
3055 ** [database connection]; setting a new progress handler cancels the
3056 ** old one. ^Setting parameter X to NULL disables the progress handler.
3057 ** ^The progress handler is also disabled by setting N to a value less
3058 ** than 1.
3059 **
3060 ** ^If the progress callback returns non-zero, the operation is
3061 ** interrupted. This feature can be used to implement a
3062 ** "Cancel" button on a GUI progress dialog box.
3063 **
3064 ** The progress handler callback must not do anything that will modify
3065 ** the database connection that invoked the progress handler.
3066 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3067 ** database connections for the meaning of "modify" in this paragraph.
3068 **
3069 */
3070 SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
3071 
3072 /*
3073 ** CAPI3REF: Opening A New Database Connection
3074 ** CONSTRUCTOR: sqlite3
3075 **
3076 ** ^These routines open an SQLite database file as specified by the
3077 ** filename argument. ^The filename argument is interpreted as UTF-8 for
3078 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
3079 ** order for sqlite3_open16(). ^(A [database connection] handle is usually
3080 ** returned in *ppDb, even if an error occurs. The only exception is that
3081 ** if SQLite is unable to allocate memory to hold the [sqlite3] object,
3082 ** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]
3083 ** object.)^ ^(If the database is opened (and/or created) successfully, then
3084 ** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The
3085 ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
3086 ** an English language description of the error following a failure of any
3087 ** of the sqlite3_open() routines.
3088 **
3089 ** ^The default encoding will be UTF-8 for databases created using
3090 ** sqlite3_open() or sqlite3_open_v2(). ^The default encoding for databases
3091 ** created using sqlite3_open16() will be UTF-16 in the native byte order.
3092 **
3093 ** Whether or not an error occurs when it is opened, resources
3094 ** associated with the [database connection] handle should be released by
3095 ** passing it to [sqlite3_close()] when it is no longer required.
3096 **
3097 ** The sqlite3_open_v2() interface works like sqlite3_open()
3098 ** except that it accepts two additional parameters for additional control
3099 ** over the new database connection. ^(The flags parameter to
3100 ** sqlite3_open_v2() can take one of
3101 ** the following three values, optionally combined with the
3102 ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
3103 ** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^
3104 **
3105 ** <dl>
3106 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
3107 ** <dd>The database is opened in read-only mode. If the database does not
3108 ** already exist, an error is returned.</dd>)^
3109 **
3110 ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
3111 ** <dd>The database is opened for reading and writing if possible, or reading
3112 ** only if the file is write protected by the operating system. In either
3113 ** case the database must already exist, otherwise an error is returned.</dd>)^
3114 **
3115 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
3116 ** <dd>The database is opened for reading and writing, and is created if
3117 ** it does not already exist. This is the behavior that is always used for
3118 ** sqlite3_open() and sqlite3_open16().</dd>)^
3119 ** </dl>
3120 **
3121 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
3122 ** combinations shown above optionally combined with other
3123 ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
3124 ** then the behavior is undefined.
3125 **
3126 ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
3127 ** opens in the multi-thread [threading mode] as long as the single-thread
3128 ** mode has not been set at compile-time or start-time. ^If the
3129 ** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens
3130 ** in the serialized [threading mode] unless single-thread was
3131 ** previously selected at compile-time or start-time.
3132 ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be
3133 ** eligible to use [shared cache mode], regardless of whether or not shared
3134 ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The
3135 ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not
3136 ** participate in [shared cache mode] even if it is enabled.
3137 **
3138 ** ^The fourth parameter to sqlite3_open_v2() is the name of the
3139 ** [sqlite3_vfs] object that defines the operating system interface that
3140 ** the new database connection should use. ^If the fourth parameter is
3141 ** a NULL pointer then the default [sqlite3_vfs] object is used.
3142 **
3143 ** ^If the filename is ":memory:", then a private, temporary in-memory database
3144 ** is created for the connection. ^This in-memory database will vanish when
3145 ** the database connection is closed. Future versions of SQLite might
3146 ** make use of additional special filenames that begin with the ":" character.
3147 ** It is recommended that when a database filename actually does begin with
3148 ** a ":" character you should prefix the filename with a pathname such as
3149 ** "./" to avoid ambiguity.
3150 **
3151 ** ^If the filename is an empty string, then a private, temporary
3152 ** on-disk database will be created. ^This private database will be
3153 ** automatically deleted as soon as the database connection is closed.
3154 **
3155 ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
3156 **
3157 ** ^If [URI filename] interpretation is enabled, and the filename argument
3158 ** begins with "file:", then the filename is interpreted as a URI. ^URI
3159 ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
3160 ** set in the fourth argument to sqlite3_open_v2(), or if it has
3161 ** been enabled globally using the [SQLITE_CONFIG_URI] option with the
3162 ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
3163 ** As of SQLite version 3.7.7, URI filename interpretation is turned off
3164 ** by default, but future releases of SQLite might enable URI filename
3165 ** interpretation by default. See "[URI filenames]" for additional
3166 ** information.
3167 **
3168 ** URI filenames are parsed according to RFC 3986. ^If the URI contains an
3169 ** authority, then it must be either an empty string or the string
3170 ** "localhost". ^If the authority is not an empty string or "localhost", an
3171 ** error is returned to the caller. ^The fragment component of a URI, if
3172 ** present, is ignored.
3173 **
3174 ** ^SQLite uses the path component of the URI as the name of the disk file
3175 ** which contains the database. ^If the path begins with a '/' character,
3176 ** then it is interpreted as an absolute path. ^If the path does not begin
3177 ** with a '/' (meaning that the authority section is omitted from the URI)
3178 ** then the path is interpreted as a relative path.
3179 ** ^(On windows, the first component of an absolute path
3180 ** is a drive specification (e.g. "C:").)^
3181 **
3182 ** [[core URI query parameters]]
3183 ** The query component of a URI may contain parameters that are interpreted
3184 ** either by SQLite itself, or by a [VFS | custom VFS implementation].
3185 ** SQLite and its built-in [VFSes] interpret the
3186 ** following query parameters:
3187 **
3188 ** <ul>
3189 ** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
3190 ** a VFS object that provides the operating system interface that should
3191 ** be used to access the database file on disk. ^If this option is set to
3192 ** an empty string the default VFS object is used. ^Specifying an unknown
3193 ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
3194 ** present, then the VFS specified by the option takes precedence over
3195 ** the value passed as the fourth parameter to sqlite3_open_v2().
3196 **
3197 ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
3198 ** "rwc", or "memory". Attempting to set it to any other value is
3199 ** an error)^.
3200 ** ^If "ro" is specified, then the database is opened for read-only
3201 ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
3202 ** third argument to sqlite3_open_v2(). ^If the mode option is set to
3203 ** "rw", then the database is opened for read-write (but not create)
3204 ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
3205 ** been set. ^Value "rwc" is equivalent to setting both
3206 ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is
3207 ** set to "memory" then a pure [in-memory database] that never reads
3208 ** or writes from disk is used. ^It is an error to specify a value for
3209 ** the mode parameter that is less restrictive than that specified by
3210 ** the flags passed in the third parameter to sqlite3_open_v2().
3211 **
3212 ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
3213 ** "private". ^Setting it to "shared" is equivalent to setting the
3214 ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
3215 ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
3216 ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
3217 ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
3218 ** a URI filename, its value overrides any behavior requested by setting
3219 ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
3220 **
3221 ** <li> <b>psow</b>: ^The psow parameter indicates whether or not the
3222 ** [powersafe overwrite] property does or does not apply to the
3223 ** storage media on which the database file resides.
3224 **
3225 ** <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter
3226 ** which if set disables file locking in rollback journal modes. This
3227 ** is useful for accessing a database on a filesystem that does not
3228 ** support locking. Caution: Database corruption might result if two
3229 ** or more processes write to the same database and any one of those
3230 ** processes uses nolock=1.
3231 **
3232 ** <li> <b>immutable</b>: ^The immutable parameter is a boolean query
3233 ** parameter that indicates that the database file is stored on
3234 ** read-only media. ^When immutable is set, SQLite assumes that the
3235 ** database file cannot be changed, even by a process with higher
3236 ** privilege, and so the database is opened read-only and all locking
3237 ** and change detection is disabled. Caution: Setting the immutable
3238 ** property on a database file that does in fact change can result
3239 ** in incorrect query results and/or [SQLITE_CORRUPT] errors.
3240 ** See also: [SQLITE_IOCAP_IMMUTABLE].
3241 **
3242 ** </ul>
3243 **
3244 ** ^Specifying an unknown parameter in the query component of a URI is not an
3245 ** error. Future versions of SQLite might understand additional query
3246 ** parameters. See "[query parameters with special meaning to SQLite]" for
3247 ** additional information.
3248 **
3249 ** [[URI filename examples]] <h3>URI filename examples</h3>
3250 **
3251 ** <table border="1" align=center cellpadding=5>
3252 ** <tr><th> URI filenames <th> Results
3253 ** <tr><td> file:data.db <td>
3254 ** Open the file "data.db" in the current directory.
3255 ** <tr><td> file:/home/fred/data.db<br>
3256 ** file:///home/fred/data.db <br>
3257 ** file://localhost/home/fred/data.db <br> <td>
3258 ** Open the database file "/home/fred/data.db".
3259 ** <tr><td> file://darkstar/home/fred/data.db <td>
3260 ** An error. "darkstar" is not a recognized authority.
3261 ** <tr><td style="white-space:nowrap">
3262 ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
3263 ** <td> Windows only: Open the file "data.db" on fred's desktop on drive
3264 ** C:. Note that the %20 escaping in this example is not strictly
3265 ** necessary - space characters can be used literally
3266 ** in URI filenames.
3267 ** <tr><td> file:data.db?mode=ro&cache=private <td>
3268 ** Open file "data.db" in the current directory for read-only access.
3269 ** Regardless of whether or not shared-cache mode is enabled by
3270 ** default, use a private cache.
3271 ** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td>
3272 ** Open file "/home/fred/data.db". Use the special VFS "unix-dotfile"
3273 ** that uses dot-files in place of posix advisory locking.
3274 ** <tr><td> file:data.db?mode=readonly <td>
3275 ** An error. "readonly" is not a valid option for the "mode" parameter.
3276 ** </table>
3277 **
3278 ** ^URI hexadecimal escape sequences (%HH) are supported within the path and
3279 ** query components of a URI. A hexadecimal escape sequence consists of a
3280 ** percent sign - "%" - followed by exactly two hexadecimal digits
3281 ** specifying an octet value. ^Before the path or query components of a
3282 ** URI filename are interpreted, they are encoded using UTF-8 and all
3283 ** hexadecimal escape sequences replaced by a single byte containing the
3284 ** corresponding octet. If this process generates an invalid UTF-8 encoding,
3285 ** the results are undefined.
3286 **
3287 ** <b>Note to Windows users:</b> The encoding used for the filename argument
3288 ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
3289 ** codepage is currently defined. Filenames containing international
3290 ** characters must be converted to UTF-8 prior to passing them into
3291 ** sqlite3_open() or sqlite3_open_v2().
3292 **
3293 ** <b>Note to Windows Runtime users:</b> The temporary directory must be set
3294 ** prior to calling sqlite3_open() or sqlite3_open_v2(). Otherwise, various
3295 ** features that require the use of temporary files may fail.
3296 **
3297 ** See also: [sqlite3_temp_directory]
3298 */
3300  const char *filename, /* Database filename (UTF-8) */
3301  sqlite3 **ppDb /* OUT: SQLite db handle */
3302 );
3304  const void *filename, /* Database filename (UTF-16) */
3305  sqlite3 **ppDb /* OUT: SQLite db handle */
3306 );
3308  const char *filename, /* Database filename (UTF-8) */
3309  sqlite3 **ppDb, /* OUT: SQLite db handle */
3310  int flags, /* Flags */
3311  const char *zVfs /* Name of VFS module to use */
3312 );
3313 
3314 /*
3315 ** CAPI3REF: Obtain Values For URI Parameters
3316 **
3317 ** These are utility routines, useful to VFS implementations, that check
3318 ** to see if a database file was a URI that contained a specific query
3319 ** parameter, and if so obtains the value of that query parameter.
3320 **
3321 ** If F is the database filename pointer passed into the xOpen() method of
3322 ** a VFS implementation when the flags parameter to xOpen() has one or
3323 ** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and
3324 ** P is the name of the query parameter, then
3325 ** sqlite3_uri_parameter(F,P) returns the value of the P
3326 ** parameter if it exists or a NULL pointer if P does not appear as a
3327 ** query parameter on F. If P is a query parameter of F
3328 ** has no explicit value, then sqlite3_uri_parameter(F,P) returns
3329 ** a pointer to an empty string.
3330 **
3331 ** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
3332 ** parameter and returns true (1) or false (0) according to the value
3333 ** of P. The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the
3334 ** value of query parameter P is one of "yes", "true", or "on" in any
3335 ** case or if the value begins with a non-zero number. The
3336 ** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
3337 ** query parameter P is one of "no", "false", or "off" in any case or
3338 ** if the value begins with a numeric zero. If P is not a query
3339 ** parameter on F or if the value of P is does not match any of the
3340 ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
3341 **
3342 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
3343 ** 64-bit signed integer and returns that integer, or D if P does not
3344 ** exist. If the value of P is something other than an integer, then
3345 ** zero is returned.
3346 **
3347 ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
3348 ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and
3349 ** is not a database file pathname pointer that SQLite passed into the xOpen
3350 ** VFS method, then the behavior of this routine is undefined and probably
3351 ** undesirable.
3352 */
3353 SQLITE_API const char *SQLITE_STDCALL sqlite3_uri_parameter(const char *zFilename, const char *zParam);
3354 SQLITE_API int SQLITE_STDCALL sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
3355 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
3356 
3357 
3358 /*
3359 ** CAPI3REF: Error Codes And Messages
3360 ** METHOD: sqlite3
3361 **
3362 ** ^If the most recent sqlite3_* API call associated with
3363 ** [database connection] D failed, then the sqlite3_errcode(D) interface
3364 ** returns the numeric [result code] or [extended result code] for that
3365 ** API call.
3366 ** If the most recent API call was successful,
3367 ** then the return value from sqlite3_errcode() is undefined.
3368 ** ^The sqlite3_extended_errcode()
3369 ** interface is the same except that it always returns the
3370 ** [extended result code] even when extended result codes are
3371 ** disabled.
3372 **
3373 ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
3374 ** text that describes the error, as either UTF-8 or UTF-16 respectively.
3375 ** ^(Memory to hold the error message string is managed internally.
3376 ** The application does not need to worry about freeing the result.
3377 ** However, the error string might be overwritten or deallocated by
3378 ** subsequent calls to other SQLite interface functions.)^
3379 **
3380 ** ^The sqlite3_errstr() interface returns the English-language text
3381 ** that describes the [result code], as UTF-8.
3382 ** ^(Memory to hold the error message string is managed internally
3383 ** and must not be freed by the application)^.
3384 **
3385 ** When the serialized [threading mode] is in use, it might be the
3386 ** case that a second error occurs on a separate thread in between
3387 ** the time of the first error and the call to these interfaces.
3388 ** When that happens, the second error will be reported since these
3389 ** interfaces always report the most recent result. To avoid
3390 ** this, each thread can obtain exclusive use of the [database connection] D
3391 ** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning
3392 ** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after
3393 ** all calls to the interfaces listed here are completed.
3394 **
3395 ** If an interface fails with SQLITE_MISUSE, that means the interface
3396 ** was invoked incorrectly by the application. In that case, the
3397 ** error code and message may or may not be set.
3398 */
3403 SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
3404 
3405 /*
3406 ** CAPI3REF: Prepared Statement Object
3407 ** KEYWORDS: {prepared statement} {prepared statements}
3408 **
3409 ** An instance of this object represents a single SQL statement that
3410 ** has been compiled into binary form and is ready to be evaluated.
3411 **
3412 ** Think of each SQL statement as a separate computer program. The
3413 ** original SQL text is source code. A prepared statement object
3414 ** is the compiled object code. All SQL must be converted into a
3415 ** prepared statement before it can be run.
3416 **
3417 ** The life-cycle of a prepared statement object usually goes like this:
3418 **
3419 ** <ol>
3420 ** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
3421 ** <li> Bind values to [parameters] using the sqlite3_bind_*()
3422 ** interfaces.
3423 ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
3424 ** <li> Reset the prepared statement using [sqlite3_reset()] then go back
3425 ** to step 2. Do this zero or more times.
3426 ** <li> Destroy the object using [sqlite3_finalize()].
3427 ** </ol>
3428 */
3430 
3431 /*
3432 ** CAPI3REF: Run-time Limits
3433 ** METHOD: sqlite3
3434 **
3435 ** ^(This interface allows the size of various constructs to be limited
3436 ** on a connection by connection basis. The first parameter is the
3437 ** [database connection] whose limit is to be set or queried. The
3438 ** second parameter is one of the [limit categories] that define a
3439 ** class of constructs to be size limited. The third parameter is the
3440 ** new limit for that construct.)^
3441 **
3442 ** ^If the new limit is a negative number, the limit is unchanged.
3443 ** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a
3444 ** [limits | hard upper bound]
3445 ** set at compile-time by a C preprocessor macro called
3446 ** [limits | SQLITE_MAX_<i>NAME</i>].
3447 ** (The "_LIMIT_" in the name is changed to "_MAX_".))^
3448 ** ^Attempts to increase a limit above its hard upper bound are
3449 ** silently truncated to the hard upper bound.
3450 **
3451 ** ^Regardless of whether or not the limit was changed, the
3452 ** [sqlite3_limit()] interface returns the prior value of the limit.
3453 ** ^Hence, to find the current value of a limit without changing it,
3454 ** simply invoke this interface with the third parameter set to -1.
3455 **
3456 ** Run-time limits are intended for use in applications that manage
3457 ** both their own internal database and also databases that are controlled
3458 ** by untrusted external sources. An example application might be a
3459 ** web browser that has its own databases for storing history and
3460 ** separate databases controlled by JavaScript applications downloaded
3461 ** off the Internet. The internal databases can be given the
3462 ** large, default limits. Databases managed by external sources can
3463 ** be given much smaller limits designed to prevent a denial of service
3464 ** attack. Developers might also want to use the [sqlite3_set_authorizer()]
3465 ** interface to further control untrusted SQL. The size of the database
3466 ** created by an untrusted script can be contained using the
3467 ** [max_page_count] [PRAGMA].
3468 **
3469 ** New run-time limit categories may be added in future releases.
3470 */
3471 SQLITE_API int SQLITE_STDCALL sqlite3_limit(sqlite3*, int id, int newVal);
3472 
3473 /*
3474 ** CAPI3REF: Run-Time Limit Categories
3475 ** KEYWORDS: {limit category} {*limit categories}
3476 **
3477 ** These constants define various performance limits
3478 ** that can be lowered at run-time using [sqlite3_limit()].
3479 ** The synopsis of the meanings of the various limits is shown below.
3480 ** Additional information is available at [limits | Limits in SQLite].
3481 **
3482 ** <dl>
3483 ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
3484 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
3485 **
3486 ** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
3487 ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
3488 **
3489 ** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>
3490 ** <dd>The maximum number of columns in a table definition or in the
3491 ** result set of a [SELECT] or the maximum number of columns in an index
3492 ** or in an ORDER BY or GROUP BY clause.</dd>)^
3493 **
3494 ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
3495 ** <dd>The maximum depth of the parse tree on any expression.</dd>)^
3496 **
3497 ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
3498 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
3499 **
3500 ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
3501 ** <dd>The maximum number of instructions in a virtual machine program
3502 ** used to implement an SQL statement. This limit is not currently
3503 ** enforced, though that might be added in some future release of
3504 ** SQLite.</dd>)^
3505 **
3506 ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
3507 ** <dd>The maximum number of arguments on a function.</dd>)^
3508 **
3509 ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
3510 ** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
3511 **
3512 ** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]
3513 ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
3514 ** <dd>The maximum length of the pattern argument to the [LIKE] or
3515 ** [GLOB] operators.</dd>)^
3516 **
3517 ** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
3518 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
3519 ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
3520 **
3521 ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
3522 ** <dd>The maximum depth of recursion for triggers.</dd>)^
3523 **
3524 ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
3525 ** <dd>The maximum number of auxiliary worker threads that a single
3526 ** [prepared statement] may start.</dd>)^
3527 ** </dl>
3528 */
3529 #define SQLITE_LIMIT_LENGTH 0
3530 #define SQLITE_LIMIT_SQL_LENGTH 1
3531 #define SQLITE_LIMIT_COLUMN 2
3532 #define SQLITE_LIMIT_EXPR_DEPTH 3
3533 #define SQLITE_LIMIT_COMPOUND_SELECT 4
3534 #define SQLITE_LIMIT_VDBE_OP 5
3535 #define SQLITE_LIMIT_FUNCTION_ARG 6
3536 #define SQLITE_LIMIT_ATTACHED 7
3537 #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
3538 #define SQLITE_LIMIT_VARIABLE_NUMBER 9
3539 #define SQLITE_LIMIT_TRIGGER_DEPTH 10
3540 #define SQLITE_LIMIT_WORKER_THREADS 11
3541 
3542 /*
3543 ** CAPI3REF: Compiling An SQL Statement
3544 ** KEYWORDS: {SQL statement compiler}
3545 ** METHOD: sqlite3
3546 ** CONSTRUCTOR: sqlite3_stmt
3547 **
3548 ** To execute an SQL query, it must first be compiled into a byte-code
3549 ** program using one of these routines.
3550 **
3551 ** The first argument, "db", is a [database connection] obtained from a
3552 ** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or
3553 ** [sqlite3_open16()]. The database connection must not have been closed.
3554 **
3555 ** The second argument, "zSql", is the statement to be compiled, encoded
3556 ** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2()
3557 ** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2()
3558 ** use UTF-16.
3559 **
3560 ** ^If the nByte argument is negative, then zSql is read up to the
3561 ** first zero terminator. ^If nByte is positive, then it is the
3562 ** number of bytes read from zSql. ^If nByte is zero, then no prepared
3563 ** statement is generated.
3564 ** If the caller knows that the supplied string is nul-terminated, then
3565 ** there is a small performance advantage to passing an nByte parameter that
3566 ** is the number of bytes in the input string <i>including</i>
3567 ** the nul-terminator.
3568 **
3569 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
3570 ** past the end of the first SQL statement in zSql. These routines only
3571 ** compile the first statement in zSql, so *pzTail is left pointing to
3572 ** what remains uncompiled.
3573 **
3574 ** ^*ppStmt is left pointing to a compiled [prepared statement] that can be
3575 ** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set
3576 ** to NULL. ^If the input text contains no SQL (if the input is an empty
3577 ** string or a comment) then *ppStmt is set to NULL.
3578 ** The calling procedure is responsible for deleting the compiled
3579 ** SQL statement using [sqlite3_finalize()] after it has finished with it.
3580 ** ppStmt may not be NULL.
3581 **
3582 ** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK];
3583 ** otherwise an [error code] is returned.
3584 **
3585 ** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are
3586 ** recommended for all new programs. The two older interfaces are retained
3587 ** for backwards compatibility, but their use is discouraged.
3588 ** ^In the "v2" interfaces, the prepared statement
3589 ** that is returned (the [sqlite3_stmt] object) contains a copy of the
3590 ** original SQL text. This causes the [sqlite3_step()] interface to
3591 ** behave differently in three ways:
3592 **
3593 ** <ol>
3594 ** <li>
3595 ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
3596 ** always used to do, [sqlite3_step()] will automatically recompile the SQL
3597 ** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY]
3598 ** retries will occur before sqlite3_step() gives up and returns an error.
3599 ** </li>
3600 **
3601 ** <li>
3602 ** ^When an error occurs, [sqlite3_step()] will return one of the detailed
3603 ** [error codes] or [extended error codes]. ^The legacy behavior was that
3604 ** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code
3605 ** and the application would have to make a second call to [sqlite3_reset()]
3606 ** in order to find the underlying cause of the problem. With the "v2" prepare
3607 ** interfaces, the underlying reason for the error is returned immediately.
3608 ** </li>
3609 **
3610 ** <li>
3611 ** ^If the specific value bound to [parameter | host parameter] in the
3612 ** WHERE clause might influence the choice of query plan for a statement,
3613 ** then the statement will be automatically recompiled, as if there had been
3614 ** a schema change, on the first [sqlite3_step()] call following any change
3615 ** to the [sqlite3_bind_text | bindings] of that [parameter].
3616 ** ^The specific value of WHERE-clause [parameter] might influence the
3617 ** choice of query plan if the parameter is the left-hand side of a [LIKE]
3618 ** or [GLOB] operator or if the parameter is compared to an indexed column
3619 ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
3620 ** </li>
3621 ** </ol>
3622 */
3624  sqlite3 *db, /* Database handle */
3625  const char *zSql, /* SQL statement, UTF-8 encoded */
3626  int nByte, /* Maximum length of zSql in bytes. */
3627  sqlite3_stmt **ppStmt, /* OUT: Statement handle */
3628  const char **pzTail /* OUT: Pointer to unused portion of zSql */
3629 );
3631  sqlite3 *db, /* Database handle */
3632  const char *zSql, /* SQL statement, UTF-8 encoded */
3633  int nByte, /* Maximum length of zSql in bytes. */
3634  sqlite3_stmt **ppStmt, /* OUT: Statement handle */
3635  const char **pzTail /* OUT: Pointer to unused portion of zSql */
3636 );
3638  sqlite3 *db, /* Database handle */
3639  const void *zSql, /* SQL statement, UTF-16 encoded */
3640  int nByte, /* Maximum length of zSql in bytes. */
3641  sqlite3_stmt **ppStmt, /* OUT: Statement handle */
3642  const void **pzTail /* OUT: Pointer to unused portion of zSql */
3643 );
3645  sqlite3 *db, /* Database handle */
3646  const void *zSql, /* SQL statement, UTF-16 encoded */
3647  int nByte, /* Maximum length of zSql in bytes. */
3648  sqlite3_stmt **ppStmt, /* OUT: Statement handle */
3649  const void **pzTail /* OUT: Pointer to unused portion of zSql */
3650 );
3651 
3652 /*
3653 ** CAPI3REF: Retrieving Statement SQL
3654 ** METHOD: sqlite3_stmt
3655 **
3656 ** ^This interface can be used to retrieve a saved copy of the original
3657 ** SQL text used to create a [prepared statement] if that statement was
3658 ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
3659 */
3661 
3662 /*
3663 ** CAPI3REF: Determine If An SQL Statement Writes The Database
3664 ** METHOD: sqlite3_stmt
3665 **
3666 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3667 ** and only if the [prepared statement] X makes no direct changes to
3668 ** the content of the database file.
3669 **
3670 ** Note that [application-defined SQL functions] or
3671 ** [virtual tables] might change the database indirectly as a side effect.
3672 ** ^(For example, if an application defines a function "eval()" that
3673 ** calls [sqlite3_exec()], then the following SQL statement would
3674 ** change the database file through side-effects:
3675 **
3676 ** <blockquote><pre>
3677 ** SELECT eval('DELETE FROM t1') FROM t2;
3678 ** </pre></blockquote>
3679 **
3680 ** But because the [SELECT] statement does not change the database file
3681 ** directly, sqlite3_stmt_readonly() would still return true.)^
3682 **
3683 ** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
3684 ** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
3685 ** since the statements themselves do not actually modify the database but
3686 ** rather they control the timing of when other statements modify the
3687 ** database. ^The [ATTACH] and [DETACH] statements also cause
3688 ** sqlite3_stmt_readonly() to return true since, while those statements
3689 ** change the configuration of a database connection, they do not make
3690 ** changes to the content of the database files on disk.
3691 */
3693 
3694 /*
3695 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3696 ** METHOD: sqlite3_stmt
3697 **
3698 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
3699 ** [prepared statement] S has been stepped at least once using
3700 ** [sqlite3_step(S)] but has neither run to completion (returned
3701 ** [SQLITE_DONE] from [sqlite3_step(S)]) nor
3702 ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
3703 ** interface returns false if S is a NULL pointer. If S is not a
3704 ** NULL pointer and is not a pointer to a valid [prepared statement]
3705 ** object, then the behavior is undefined and probably undesirable.
3706 **
3707 ** This interface can be used in combination [sqlite3_next_stmt()]
3708 ** to locate all prepared statements associated with a database
3709 ** connection that are in need of being reset. This can be used,
3710 ** for example, in diagnostic routines to search for prepared
3711 ** statements that are holding a transaction open.
3712 */
3714 
3715 /*
3716 ** CAPI3REF: Dynamically Typed Value Object
3717 ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
3718 **
3719 ** SQLite uses the sqlite3_value object to represent all values
3720 ** that can be stored in a database table. SQLite uses dynamic typing
3721 ** for the values it stores. ^Values stored in sqlite3_value objects
3722 ** can be integers, floating point values, strings, BLOBs, or NULL.
3723 **
3724 ** An sqlite3_value object may be either "protected" or "unprotected".
3725 ** Some interfaces require a protected sqlite3_value. Other interfaces
3726 ** will accept either a protected or an unprotected sqlite3_value.
3727 ** Every interface that accepts sqlite3_value arguments specifies
3728 ** whether or not it requires a protected sqlite3_value. The
3729 ** [sqlite3_value_dup()] interface can be used to construct a new
3730 ** protected sqlite3_value from an unprotected sqlite3_value.
3731 **
3732 ** The terms "protected" and "unprotected" refer to whether or not
3733 ** a mutex is held. An internal mutex is held for a protected
3734 ** sqlite3_value object but no mutex is held for an unprotected
3735 ** sqlite3_value object. If SQLite is compiled to be single-threaded
3736 ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
3737 ** or if SQLite is run in one of reduced mutex modes
3738 ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
3739 ** then there is no distinction between protected and unprotected
3740 ** sqlite3_value objects and they can be used interchangeably. However,
3741 ** for maximum code portability it is recommended that applications
3742 ** still make the distinction between protected and unprotected
3743 ** sqlite3_value objects even when not strictly required.
3744 **
3745 ** ^The sqlite3_value objects that are passed as parameters into the
3746 ** implementation of [application-defined SQL functions] are protected.
3747 ** ^The sqlite3_value object returned by
3748 ** [sqlite3_column_value()] is unprotected.
3749 ** Unprotected sqlite3_value objects may only be used with
3750 ** [sqlite3_result_value()] and [sqlite3_bind_value()].
3751 ** The [sqlite3_value_blob | sqlite3_value_type()] family of
3752 ** interfaces require protected sqlite3_value objects.
3753 */
3754 typedef struct Mem sqlite3_value;
3755 
3756 /*
3757 ** CAPI3REF: SQL Function Context Object
3758 **
3759 ** The context in which an SQL function executes is stored in an
3760 ** sqlite3_context object. ^A pointer to an sqlite3_context object
3761 ** is always first parameter to [application-defined SQL functions].
3762 ** The application-defined SQL function implementation will pass this
3763 ** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
3764 ** [sqlite3_aggregate_context()], [sqlite3_user_data()],
3765 ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
3766 ** and/or [sqlite3_set_auxdata()].
3767 */
3769 
3770 /*
3771 ** CAPI3REF: Binding Values To Prepared Statements
3772 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
3773 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
3774 ** METHOD: sqlite3_stmt
3775 **
3776 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
3777 ** literals may be replaced by a [parameter] that matches one of following
3778 ** templates:
3779 **
3780 ** <ul>
3781 ** <li> ?
3782 ** <li> ?NNN
3783 ** <li> :VVV
3784 ** <li> @VVV
3785 ** <li> $VVV
3786 ** </ul>
3787 **
3788 ** In the templates above, NNN represents an integer literal,
3789 ** and VVV represents an alphanumeric identifier.)^ ^The values of these
3790 ** parameters (also called "host parameter names" or "SQL parameters")
3791 ** can be set using the sqlite3_bind_*() routines defined here.
3792 **
3793 ** ^The first argument to the sqlite3_bind_*() routines is always
3794 ** a pointer to the [sqlite3_stmt] object returned from
3795 ** [sqlite3_prepare_v2()] or its variants.
3796 **
3797 ** ^The second argument is the index of the SQL parameter to be set.
3798 ** ^The leftmost SQL parameter has an index of 1. ^When the same named
3799 ** SQL parameter is used more than once, second and subsequent
3800 ** occurrences have the same index as the first occurrence.
3801 ** ^The index for named parameters can be looked up using the
3802 ** [sqlite3_bind_parameter_index()] API if desired. ^The index
3803 ** for "?NNN" parameters is the value of NNN.
3804 ** ^The NNN value must be between 1 and the [sqlite3_limit()]
3805 ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
3806 **
3807 ** ^The third argument is the value to bind to the parameter.
3808 ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
3809 ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
3810 ** is ignored and the end result is the same as sqlite3_bind_null().
3811 **
3812 ** ^(In those routines that have a fourth argument, its value is the
3813 ** number of bytes in the parameter. To be clear: the value is the
3814 ** number of <u>bytes</u> in the value, not the number of characters.)^
3815 ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
3816 ** is negative, then the length of the string is
3817 ** the number of bytes up to the first zero terminator.
3818 ** If the fourth parameter to sqlite3_bind_blob() is negative, then
3819 ** the behavior is undefined.
3820 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
3821 ** or sqlite3_bind_text16() or sqlite3_bind_text64() then
3822 ** that parameter must be the byte offset
3823 ** where the NUL terminator would occur assuming the string were NUL
3824 ** terminated. If any NUL characters occur at byte offsets less than
3825 ** the value of the fourth parameter then the resulting string value will
3826 ** contain embedded NULs. The result of expressions involving strings
3827 ** with embedded NULs is undefined.
3828 **
3829 ** ^The fifth argument to the BLOB and string binding interfaces
3830 ** is a destructor used to dispose of the BLOB or
3831 ** string after SQLite has finished with it. ^The destructor is called
3832 ** to dispose of the BLOB or string even if the call to bind API fails.
3833 ** ^If the fifth argument is
3834 ** the special value [SQLITE_STATIC], then SQLite assumes that the
3835 ** information is in static, unmanaged space and does not need to be freed.
3836 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
3837 ** SQLite makes its own private copy of the data immediately, before
3838 ** the sqlite3_bind_*() routine returns.
3839 **
3840 ** ^The sixth argument to sqlite3_bind_text64() must be one of
3841 ** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
3842 ** to specify the encoding of the text in the third parameter. If
3843 ** the sixth argument to sqlite3_bind_text64() is not one of the
3844 ** allowed values shown above, or if the text encoding is different
3845 ** from the encoding specified by the sixth parameter, then the behavior
3846 ** is undefined.
3847 **
3848 ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
3849 ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory
3850 ** (just an integer to hold its size) while it is being processed.
3851 ** Zeroblobs are intended to serve as placeholders for BLOBs whose
3852 ** content is later written using
3853 ** [sqlite3_blob_open | incremental BLOB I/O] routines.
3854 ** ^A negative value for the zeroblob results in a zero-length BLOB.
3855 **
3856 ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
3857 ** for the [prepared statement] or with a prepared statement for which
3858 ** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
3859 ** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_()
3860 ** routine is passed a [prepared statement] that has been finalized, the
3861 ** result is undefined and probably harmful.
3862 **
3863 ** ^Bindings are not cleared by the [sqlite3_reset()] routine.
3864 ** ^Unbound parameters are interpreted as NULL.
3865 **
3866 ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
3867 ** [error code] if anything goes wrong.
3868 ** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB
3869 ** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or
3870 ** [SQLITE_MAX_LENGTH].
3871 ** ^[SQLITE_RANGE] is returned if the parameter
3872 ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails.
3873 **
3874 ** See also: [sqlite3_bind_parameter_count()],
3875 ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
3876 */
3877 SQLITE_API int SQLITE_STDCALL sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
3878 SQLITE_API int SQLITE_STDCALL sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,
3879  void(*)(void*));
3882 SQLITE_API int SQLITE_STDCALL sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
3884 SQLITE_API int SQLITE_STDCALL sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
3885 SQLITE_API int SQLITE_STDCALL sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
3886 SQLITE_API int SQLITE_STDCALL sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
3887  void(*)(void*), unsigned char encoding);
3891 
3892 /*
3893 ** CAPI3REF: Number Of SQL Parameters
3894 ** METHOD: sqlite3_stmt
3895 **
3896 ** ^This routine can be used to find the number of [SQL parameters]
3897 ** in a [prepared statement]. SQL parameters are tokens of the
3898 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
3899 ** placeholders for values that are [sqlite3_bind_blob | bound]
3900 ** to the parameters at a later time.
3901 **
3902 ** ^(This routine actually returns the index of the largest (rightmost)
3903 ** parameter. For all forms except ?NNN, this will correspond to the
3904 ** number of unique parameters. If parameters of the ?NNN form are used,
3905 ** there may be gaps in the list.)^
3906 **
3907 ** See also: [sqlite3_bind_blob|sqlite3_bind()],
3908 ** [sqlite3_bind_parameter_name()], and
3909 ** [sqlite3_bind_parameter_index()].
3910 */
3912 
3913 /*
3914 ** CAPI3REF: Name Of A Host Parameter
3915 ** METHOD: sqlite3_stmt
3916 **
3917 ** ^The sqlite3_bind_parameter_name(P,N) interface returns
3918 ** the name of the N-th [SQL parameter] in the [prepared statement] P.
3919 ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
3920 ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
3921 ** respectively.
3922 ** In other words, the initial ":" or "$" or "@" or "?"
3923 ** is included as part of the name.)^
3924 ** ^Parameters of the form "?" without a following integer have no name
3925 ** and are referred to as "nameless" or "anonymous parameters".
3926 **
3927 ** ^The first host parameter has an index of 1, not 0.
3928 **
3929 ** ^If the value N is out of range or if the N-th parameter is
3930 ** nameless, then NULL is returned. ^The returned string is
3931 ** always in UTF-8 encoding even if the named parameter was
3932 ** originally specified as UTF-16 in [sqlite3_prepare16()] or
3933 ** [sqlite3_prepare16_v2()].
3934 **
3935 ** See also: [sqlite3_bind_blob|sqlite3_bind()],
3936 ** [sqlite3_bind_parameter_count()], and
3937 ** [sqlite3_bind_parameter_index()].
3938 */
3940 
3941 /*
3942 ** CAPI3REF: Index Of A Parameter With A Given Name
3943 ** METHOD: sqlite3_stmt
3944 **
3945 ** ^Return the index of an SQL parameter given its name. ^The
3946 ** index value returned is suitable for use as the second
3947 ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
3948 ** is returned if no matching parameter is found. ^The parameter
3949 ** name must be given in UTF-8 even if the original statement
3950 ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()].
3951 **
3952 ** See also: [sqlite3_bind_blob|sqlite3_bind()],
3953 ** [sqlite3_bind_parameter_count()], and
3954 ** [sqlite3_bind_parameter_name()].
3955 */
3957 
3958 /*
3959 ** CAPI3REF: Reset All Bindings On A Prepared Statement
3960 ** METHOD: sqlite3_stmt
3961 **
3962 ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
3963 ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
3964 ** ^Use this routine to reset all host parameters to NULL.
3965 */
3967 
3968 /*
3969 ** CAPI3REF: Number Of Columns In A Result Set
3970 ** METHOD: sqlite3_stmt
3971 **
3972 ** ^Return the number of columns in the result set returned by the
3973 ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
3974 ** statement that does not return data (for example an [UPDATE]).
3975 **
3976 ** See also: [sqlite3_data_count()]
3977 */
3979 
3980 /*
3981 ** CAPI3REF: Column Names In A Result Set
3982 ** METHOD: sqlite3_stmt
3983 **
3984 ** ^These routines return the name assigned to a particular column
3985 ** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
3986 ** interface returns a pointer to a zero-terminated UTF-8 string
3987 ** and sqlite3_column_name16() returns a pointer to a zero-terminated
3988 ** UTF-16 string. ^The first parameter is the [prepared statement]
3989 ** that implements the [SELECT] statement. ^The second parameter is the
3990 ** column number. ^The leftmost column is number 0.
3991 **
3992 ** ^The returned string pointer is valid until either the [prepared statement]
3993 ** is destroyed by [sqlite3_finalize()] or until the statement is automatically
3994 ** reprepared by the first call to [sqlite3_step()] for a particular run
3995 ** or until the next call to
3996 ** sqlite3_column_name() or sqlite3_column_name16() on the same column.
3997 **
3998 ** ^If sqlite3_malloc() fails during the processing of either routine
3999 ** (for example during a conversion from UTF-8 to UTF-16) then a
4000 ** NULL pointer is returned.
4001 **
4002 ** ^The name of a result column is the value of the "AS" clause for
4003 ** that column, if there is an AS clause. If there is no AS clause
4004 ** then the name of the column is unspecified and may change from
4005 ** one release of SQLite to the next.
4006 */
4009 
4010 /*
4011 ** CAPI3REF: Source Of Data In A Query Result
4012 ** METHOD: sqlite3_stmt
4013 **
4014 ** ^These routines provide a means to determine the database, table, and
4015 ** table column that is the origin of a particular result column in
4016 ** [SELECT] statement.
4017 ** ^The name of the database or table or column can be returned as
4018 ** either a UTF-8 or UTF-16 string. ^The _database_ routines return
4019 ** the database name, the _table_ routines return the table name, and
4020 ** the origin_ routines return the column name.
4021 ** ^The returned string is valid until the [prepared statement] is destroyed
4022 ** using [sqlite3_finalize()] or until the statement is automatically
4023 ** reprepared by the first call to [sqlite3_step()] for a particular run
4024 ** or until the same information is requested
4025 ** again in a different encoding.
4026 **
4027 ** ^The names returned are the original un-aliased names of the
4028 ** database, table, and column.
4029 **
4030 ** ^The first argument to these interfaces is a [prepared statement].
4031 ** ^These functions return information about the Nth result column returned by
4032 ** the statement, where N is the second function argument.
4033 ** ^The left-most column is column 0 for these routines.
4034 **
4035 ** ^If the Nth column returned by the statement is an expression or
4036 ** subquery and is not a column value, then all of these functions return
4037 ** NULL. ^These routine might also return NULL if a memory allocation error
4038 ** occurs. ^Otherwise, they return the name of the attached database, table,
4039 ** or column that query result column was extracted from.
4040 **
4041 ** ^As with all other SQLite APIs, those whose names end with "16" return
4042 ** UTF-16 encoded strings and the other functions return UTF-8.
4043 **
4044 ** ^These APIs are only available if the library was compiled with the
4045 ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
4046 **
4047 ** If two or more threads call one or more of these routines against the same
4048 ** prepared statement and column at the same time then the results are
4049 ** undefined.
4050 **
4051 ** If two or more threads call one or more
4052 ** [sqlite3_column_database_name | column metadata interfaces]
4053 ** for the same [prepared statement] and result column
4054 ** at the same time then the results are undefined.
4055 */
4062 
4063 /*
4064 ** CAPI3REF: Declared Datatype Of A Query Result
4065 ** METHOD: sqlite3_stmt
4066 **
4067 ** ^(The first parameter is a [prepared statement].
4068 ** If this statement is a [SELECT] statement and the Nth column of the
4069 ** returned result set of that [SELECT] is a table column (not an
4070 ** expression or subquery) then the declared type of the table
4071 ** column is returned.)^ ^If the Nth column of the result set is an
4072 ** expression or subquery, then a NULL pointer is returned.
4073 ** ^The returned string is always UTF-8 encoded.
4074 **
4075 ** ^(For example, given the database schema:
4076 **
4077 ** CREATE TABLE t1(c1 VARIANT);
4078 **
4079 ** and the following statement to be compiled:
4080 **
4081 ** SELECT c1 + 1, c1 FROM t1;
4082 **
4083 ** this routine would return the string "VARIANT" for the second result
4084 ** column (i==1), and a NULL pointer for the first result column (i==0).)^
4085 **
4086 ** ^SQLite uses dynamic run-time typing. ^So just because a column
4087 ** is declared to contain a particular type does not mean that the
4088 ** data stored in that column is of the declared type. SQLite is
4089 ** strongly typed, but the typing is dynamic not static. ^Type
4090 ** is associated with individual values, not with the containers
4091 ** used to hold those values.
4092 */
4095 
4096 /*
4097 ** CAPI3REF: Evaluate An SQL Statement
4098 ** METHOD: sqlite3_stmt
4099 **
4100 ** After a [prepared statement] has been prepared using either
4101 ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
4102 ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
4103 ** must be called one or more times to evaluate the statement.
4104 **
4105 ** The details of the behavior of the sqlite3_step() interface depend
4106 ** on whether the statement was prepared using the newer "v2" interface
4107 ** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy
4108 ** interface [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the
4109 ** new "v2" interface is recommended for new applications but the legacy
4110 ** interface will continue to be supported.
4111 **
4112 ** ^In the legacy interface, the return value will be either [SQLITE_BUSY],
4113 ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
4114 ** ^With the "v2" interface, any of the other [result codes] or
4115 ** [extended result codes] might be returned as well.
4116 **
4117 ** ^[SQLITE_BUSY] means that the database engine was unable to acquire the
4118 ** database locks it needs to do its job. ^If the statement is a [COMMIT]
4119 ** or occurs outside of an explicit transaction, then you can retry the
4120 ** statement. If the statement is not a [COMMIT] and occurs within an
4121 ** explicit transaction then you should rollback the transaction before
4122 ** continuing.
4123 **
4124 ** ^[SQLITE_DONE] means that the statement has finished executing
4125 ** successfully. sqlite3_step() should not be called again on this virtual
4126 ** machine without first calling [sqlite3_reset()] to reset the virtual
4127 ** machine back to its initial state.
4128 **
4129 ** ^If the SQL statement being executed returns any data, then [SQLITE_ROW]
4130 ** is returned each time a new row of data is ready for processing by the
4131 ** caller. The values may be accessed using the [column access functions].
4132 ** sqlite3_step() is called again to retrieve the next row of data.
4133 **
4134 ** ^[SQLITE_ERROR] means that a run-time error (such as a constraint
4135 ** violation) has occurred. sqlite3_step() should not be called again on
4136 ** the VM. More information may be found by calling [sqlite3_errmsg()].
4137 ** ^With the legacy interface, a more specific error code (for example,
4138 ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
4139 ** can be obtained by calling [sqlite3_reset()] on the
4140 ** [prepared statement]. ^In the "v2" interface,
4141 ** the more specific error code is returned directly by sqlite3_step().
4142 **
4143 ** [SQLITE_MISUSE] means that the this routine was called inappropriately.
4144 ** Perhaps it was called on a [prepared statement] that has
4145 ** already been [sqlite3_finalize | finalized] or on one that had
4146 ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could
4147 ** be the case that the same database connection is being used by two or
4148 ** more threads at the same moment in time.
4149 **
4150 ** For all versions of SQLite up to and including 3.6.23.1, a call to
4151 ** [sqlite3_reset()] was required after sqlite3_step() returned anything
4152 ** other than [SQLITE_ROW] before any subsequent invocation of
4153 ** sqlite3_step(). Failure to reset the prepared statement using
4154 ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
4155 ** sqlite3_step(). But after version 3.6.23.1, sqlite3_step() began
4156 ** calling [sqlite3_reset()] automatically in this circumstance rather
4157 ** than returning [SQLITE_MISUSE]. This is not considered a compatibility
4158 ** break because any application that ever receives an SQLITE_MISUSE error
4159 ** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option
4160 ** can be used to restore the legacy behavior.
4161 **
4162 ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
4163 ** API always returns a generic error code, [SQLITE_ERROR], following any
4164 ** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call
4165 ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the
4166 ** specific [error codes] that better describes the error.
4167 ** We admit that this is a goofy design. The problem has been fixed
4168 ** with the "v2" interface. If you prepare all of your SQL statements
4169 ** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead
4170 ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,
4171 ** then the more specific [error codes] are returned directly
4172 ** by sqlite3_step(). The use of the "v2" interface is recommended.
4173 */
4175 
4176 /*
4177 ** CAPI3REF: Number of columns in a result set
4178 ** METHOD: sqlite3_stmt
4179 **
4180 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
4181 ** current row of the result set of [prepared statement] P.
4182 ** ^If prepared statement P does not have results ready to return
4183 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
4184 ** interfaces) then sqlite3_data_count(P) returns 0.
4185 ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
4186 ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
4187 ** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)
4188 ** will return non-zero if previous call to [sqlite3_step](P) returned
4189 ** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]
4190 ** where it always returns zero since each step of that multi-step
4191 ** pragma returns 0 columns of data.
4192 **
4193 ** See also: [sqlite3_column_count()]
4194 */
4196 
4197 /*
4198 ** CAPI3REF: Fundamental Datatypes
4199 ** KEYWORDS: SQLITE_TEXT
4200 **
4201 ** ^(Every value in SQLite has one of five fundamental datatypes:
4202 **
4203 ** <ul>
4204 ** <li> 64-bit signed integer
4205 ** <li> 64-bit IEEE floating point number
4206 ** <li> string
4207 ** <li> BLOB
4208 ** <li> NULL
4209 ** </ul>)^
4210 **
4211 ** These constants are codes for each of those types.
4212 **
4213 ** Note that the SQLITE_TEXT constant was also used in SQLite version 2
4214 ** for a completely different meaning. Software that links against both
4215 ** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not
4216 ** SQLITE_TEXT.
4217 */
4218 #define SQLITE_INTEGER 1
4219 #define SQLITE_FLOAT 2
4220 #define SQLITE_BLOB 4
4221 #define SQLITE_NULL 5
4222 #ifdef SQLITE_TEXT
4223 # undef SQLITE_TEXT
4224 #else
4225 # define SQLITE_TEXT 3
4226 #endif
4227 #define SQLITE3_TEXT 3
4228 
4229 /*
4230 ** CAPI3REF: Result Values From A Query
4231 ** KEYWORDS: {column access functions}
4232 ** METHOD: sqlite3_stmt
4233 **
4234 ** ^These routines return information about a single column of the current
4235 ** result row of a query. ^In every case the first argument is a pointer
4236 ** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]
4237 ** that was returned from [sqlite3_prepare_v2()] or one of its variants)
4238 ** and the second argument is the index of the column for which information
4239 ** should be returned. ^The leftmost column of the result set has the index 0.
4240 ** ^The number of columns in the result can be determined using
4241 ** [sqlite3_column_count()].
4242 **
4243 ** If the SQL statement does not currently point to a valid row, or if the
4244 ** column index is out of range, the result is undefined.
4245 ** These routines may only be called when the most recent call to
4246 ** [sqlite3_step()] has returned [SQLITE_ROW] and neither
4247 ** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently.
4248 ** If any of these routines are called after [sqlite3_reset()] or
4249 ** [sqlite3_finalize()] or after [sqlite3_step()] has returned
4250 ** something other than [SQLITE_ROW], the results are undefined.
4251 ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()]
4252 ** are called from a different thread while any of these routines
4253 ** are pending, then the results are undefined.
4254 **
4255 ** ^The sqlite3_column_type() routine returns the
4256 ** [SQLITE_INTEGER | datatype code] for the initial data type
4257 ** of the result column. ^The returned value is one of [SQLITE_INTEGER],
4258 ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. The value
4259 ** returned by sqlite3_column_type() is only meaningful if no type
4260 ** conversions have occurred as described below. After a type conversion,
4261 ** the value returned by sqlite3_column_type() is undefined. Future
4262 ** versions of SQLite may change the behavior of sqlite3_column_type()
4263 ** following a type conversion.
4264 **
4265 ** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
4266 ** routine returns the number of bytes in that BLOB or string.
4267 ** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts
4268 ** the string to UTF-8 and then returns the number of bytes.
4269 ** ^If the result is a numeric value then sqlite3_column_bytes() uses
4270 ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
4271 ** the number of bytes in that string.
4272 ** ^If the result is NULL, then sqlite3_column_bytes() returns zero.
4273 **
4274 ** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16()
4275 ** routine returns the number of bytes in that BLOB or string.
4276 ** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts
4277 ** the string to UTF-16 and then returns the number of bytes.
4278 ** ^If the result is a numeric value then sqlite3_column_bytes16() uses
4279 ** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns
4280 ** the number of bytes in that string.
4281 ** ^If the result is NULL, then sqlite3_column_bytes16() returns zero.
4282 **
4283 ** ^The values returned by [sqlite3_column_bytes()] and
4284 ** [sqlite3_column_bytes16()] do not include the zero terminators at the end
4285 ** of the string. ^For clarity: the values returned by
4286 ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of
4287 ** bytes in the string, not the number of characters.
4288 **
4289 ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
4290 ** even empty strings, are always zero-terminated. ^The return
4291 ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
4292 **
4293 ** <b>Warning:</b> ^The object returned by [sqlite3_column_value()] is an
4294 ** [unprotected sqlite3_value] object. In a multithreaded environment,
4295 ** an unprotected sqlite3_value object may only be used safely with
4296 ** [sqlite3_bind_value()] and [sqlite3_result_value()].
4297 ** If the [unprotected sqlite3_value] object returned by
4298 ** [sqlite3_column_value()] is used in any other way, including calls
4299 ** to routines like [sqlite3_value_int()], [sqlite3_value_text()],
4300 ** or [sqlite3_value_bytes()], the behavior is not threadsafe.
4301 **
4302 ** These routines attempt to convert the value where appropriate. ^For
4303 ** example, if the internal representation is FLOAT and a text result
4304 ** is requested, [sqlite3_snprintf()] is used internally to perform the
4305 ** conversion automatically. ^(The following table details the conversions
4306 ** that are applied:
4307 **
4308 ** <blockquote>
4309 ** <table border="1">
4310 ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion
4311 **
4312 ** <tr><td> NULL <td> INTEGER <td> Result is 0
4313 ** <tr><td> NULL <td> FLOAT <td> Result is 0.0
4314 ** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer
4315 ** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer
4316 ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
4317 ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
4318 ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT
4319 ** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER
4320 ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
4321 ** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB
4322 ** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER
4323 ** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL
4324 ** <tr><td> TEXT <td> BLOB <td> No change
4325 ** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER
4326 ** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL
4327 ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed
4328 ** </table>
4329 ** </blockquote>)^
4330 **
4331 ** Note that when type conversions occur, pointers returned by prior
4332 ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
4333 ** sqlite3_column_text16() may be invalidated.
4334 ** Type conversions and pointer invalidations might occur
4335 ** in the following cases:
4336 **
4337 ** <ul>
4338 ** <li> The initial content is a BLOB and sqlite3_column_text() or
4339 ** sqlite3_column_text16() is called. A zero-terminator might
4340 ** need to be added to the string.</li>
4341 ** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or
4342 ** sqlite3_column_text16() is called. The content must be converted
4343 ** to UTF-16.</li>
4344 ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
4345 ** sqlite3_column_text() is called. The content must be converted
4346 ** to UTF-8.</li>
4347 ** </ul>
4348 **
4349 ** ^Conversions between UTF-16be and UTF-16le are always done in place and do
4350 ** not invalidate a prior pointer, though of course the content of the buffer
4351 ** that the prior pointer references will have been modified. Other kinds
4352 ** of conversion are done in place when it is possible, but sometimes they
4353 ** are not possible and in those cases prior pointers are invalidated.
4354 **
4355 ** The safest policy is to invoke these routines
4356 ** in one of the following ways:
4357 **
4358 ** <ul>
4359 ** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
4360 ** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
4361 ** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
4362 ** </ul>
4363 **
4364 ** In other words, you should call sqlite3_column_text(),
4365 ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
4366 ** into the desired format, then invoke sqlite3_column_bytes() or
4367 ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls
4368 ** to sqlite3_column_text() or sqlite3_column_blob() with calls to
4369 ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()
4370 ** with calls to sqlite3_column_bytes().
4371 **
4372 ** ^The pointers returned are valid until a type conversion occurs as
4373 ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
4374 ** [sqlite3_finalize()] is called. ^The memory space used to hold strings
4375 ** and BLOBs is freed automatically. Do <em>not</em> pass the pointers returned
4376 ** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
4377 ** [sqlite3_free()].
4378 **
4379 ** ^(If a memory allocation error occurs during the evaluation of any
4380 ** of these routines, a default value is returned. The default value
4381 ** is either the integer 0, the floating point number 0.0, or a NULL
4382 ** pointer. Subsequent calls to [sqlite3_errcode()] will return
4383 ** [SQLITE_NOMEM].)^
4384 */
4391 SQLITE_API const unsigned char *SQLITE_STDCALL sqlite3_column_text(sqlite3_stmt*, int iCol);
4395 
4396 /*
4397 ** CAPI3REF: Destroy A Prepared Statement Object
4398 ** DESTRUCTOR: sqlite3_stmt
4399 **
4400 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
4401 ** ^If the most recent evaluation of the statement encountered no errors
4402 ** or if the statement is never been evaluated, then sqlite3_finalize() returns
4403 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
4404 ** sqlite3_finalize(S) returns the appropriate [error code] or
4405 ** [extended error code].
4406 **
4407 ** ^The sqlite3_finalize(S) routine can be called at any point during
4408 ** the life cycle of [prepared statement] S:
4409 ** before statement S is ever evaluated, after
4410 ** one or more calls to [sqlite3_reset()], or after any call
4411 ** to [sqlite3_step()] regardless of whether or not the statement has
4412 ** completed execution.
4413 **
4414 ** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op.
4415 **
4416 ** The application must finalize every [prepared statement] in order to avoid
4417 ** resource leaks. It is a grievous error for the application to try to use
4418 ** a prepared statement after it has been finalized. Any use of a prepared
4419 ** statement after it has been finalized can result in undefined and
4420 ** undesirable behavior such as segfaults and heap corruption.
4421 */
4423 
4424 /*
4425 ** CAPI3REF: Reset A Prepared Statement Object
4426 ** METHOD: sqlite3_stmt
4427 **
4428 ** The sqlite3_reset() function is called to reset a [prepared statement]
4429 ** object back to its initial state, ready to be re-executed.
4430 ** ^Any SQL statement variables that had values bound to them using
4431 ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
4432 ** Use [sqlite3_clear_bindings()] to reset the bindings.
4433 **
4434 ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S
4435 ** back to the beginning of its program.
4436 **
4437 ** ^If the most recent call to [sqlite3_step(S)] for the
4438 ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE],
4439 ** or if [sqlite3_step(S)] has never before been called on S,
4440 ** then [sqlite3_reset(S)] returns [SQLITE_OK].
4441 **
4442 ** ^If the most recent call to [sqlite3_step(S)] for the
4443 ** [prepared statement] S indicated an error, then
4444 ** [sqlite3_reset(S)] returns an appropriate [error code].
4445 **
4446 ** ^The [sqlite3_reset(S)] interface does not change the values
4447 ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
4448 */
4450 
4451 /*
4452 ** CAPI3REF: Create Or Redefine SQL Functions
4453 ** KEYWORDS: {function creation routines}
4454 ** KEYWORDS: {application-defined SQL function}
4455 ** KEYWORDS: {application-defined SQL functions}
4456 ** METHOD: sqlite3
4457 **
4458 ** ^These functions (collectively known as "function creation routines")
4459 ** are used to add SQL functions or aggregates or to redefine the behavior
4460 ** of existing SQL functions or aggregates. The only differences between
4461 ** these routines are the text encoding expected for
4462 ** the second parameter (the name of the function being created)
4463 ** and the presence or absence of a destructor callback for
4464 ** the application data pointer.
4465 **
4466 ** ^The first parameter is the [database connection] to which the SQL
4467 ** function is to be added. ^If an application uses more than one database
4468 ** connection then application-defined SQL functions must be added
4469 ** to each database connection separately.
4470 **
4471 ** ^The second parameter is the name of the SQL function to be created or
4472 ** redefined. ^The length of the name is limited to 255 bytes in a UTF-8
4473 ** representation, exclusive of the zero-terminator. ^Note that the name
4474 ** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.
4475 ** ^Any attempt to create a function with a longer name
4476 ** will result in [SQLITE_MISUSE] being returned.
4477 **
4478 ** ^The third parameter (nArg)
4479 ** is the number of arguments that the SQL function or
4480 ** aggregate takes. ^If this parameter is -1, then the SQL function or
4481 ** aggregate may take any number of arguments between 0 and the limit
4482 ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third
4483 ** parameter is less than -1 or greater than 127 then the behavior is
4484 ** undefined.
4485 **
4486 ** ^The fourth parameter, eTextRep, specifies what
4487 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
4488 ** its parameters. The application should set this parameter to
4489 ** [SQLITE_UTF16LE] if the function implementation invokes
4490 ** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the
4491 ** implementation invokes [sqlite3_value_text16be()] on an input, or
4492 ** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8]
4493 ** otherwise. ^The same SQL function may be registered multiple times using
4494 ** different preferred text encodings, with different implementations for
4495 ** each encoding.
4496 ** ^When multiple implementations of the same function are available, SQLite
4497 ** will pick the one that involves the least amount of data conversion.
4498 **
4499 ** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC]
4500 ** to signal that the function will always return the same result given
4501 ** the same inputs within a single SQL statement. Most SQL functions are
4502 ** deterministic. The built-in [random()] SQL function is an example of a
4503 ** function that is not deterministic. The SQLite query planner is able to
4504 ** perform additional optimizations on deterministic functions, so use
4505 ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
4506 **
4507 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
4508 ** function can gain access to this pointer using [sqlite3_user_data()].)^
4509 **
4510 ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
4511 ** pointers to C-language functions that implement the SQL function or
4512 ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
4513 ** callback only; NULL pointers must be passed as the xStep and xFinal
4514 ** parameters. ^An aggregate SQL function requires an implementation of xStep
4515 ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
4516 ** SQL function or aggregate, pass NULL pointers for all three function
4517 ** callbacks.
4518 **
4519 ** ^(If the ninth parameter to sqlite3_create_function_v2() is not NULL,
4520 ** then it is destructor for the application data pointer.
4521 ** The destructor is invoked when the function is deleted, either by being
4522 ** overloaded or when the database connection closes.)^
4523 ** ^The destructor is also invoked if the call to
4524 ** sqlite3_create_function_v2() fails.
4525 ** ^When the destructor callback of the tenth parameter is invoked, it
4526 ** is passed a single argument which is a copy of the application data
4527 ** pointer which was the fifth parameter to sqlite3_create_function_v2().
4528 **
4529 ** ^It is permitted to register multiple implementations of the same
4530 ** functions with the same name but with either differing numbers of
4531 ** arguments or differing preferred text encodings. ^SQLite will use
4532 ** the implementation that most closely matches the way in which the
4533 ** SQL function is used. ^A function implementation with a non-negative
4534 ** nArg parameter is a better match than a function implementation with
4535 ** a negative nArg. ^A function where the preferred text encoding
4536 ** matches the database encoding is a better
4537 ** match than a function where the encoding is different.
4538 ** ^A function where the encoding difference is between UTF16le and UTF16be
4539 ** is a closer match than a function where the encoding difference is
4540 ** between UTF8 and UTF16.
4541 **
4542 ** ^Built-in functions may be overloaded by new application-defined functions.
4543 **
4544 ** ^An application-defined function is permitted to call other
4545 ** SQLite interfaces. However, such calls must not
4546 ** close the database connection nor finalize or reset the prepared
4547 ** statement in which the function is running.
4548 */
4550  sqlite3 *db,
4551  const char *zFunctionName,
4552  int nArg,
4553  int eTextRep,
4554  void *pApp,
4555  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
4556  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
4557  void (*xFinal)(sqlite3_context*)
4558 );
4560  sqlite3 *db,
4561  const void *zFunctionName,
4562  int nArg,
4563  int eTextRep,
4564  void *pApp,
4565  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
4566  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
4567  void (*xFinal)(sqlite3_context*)
4568 );
4570  sqlite3 *db,
4571  const char *zFunctionName,
4572  int nArg,
4573  int eTextRep,
4574  void *pApp,
4575  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
4576  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
4577  void (*xFinal)(sqlite3_context*),
4578  void(*xDestroy)(void*)
4579 );
4580 
4581 /*
4582 ** CAPI3REF: Text Encodings
4583 **
4584 ** These constant define integer codes that represent the various
4585 ** text encodings supported by SQLite.
4586 */
4587 #define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
4588 #define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
4589 #define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
4590 #define SQLITE_UTF16 4 /* Use native byte order */
4591 #define SQLITE_ANY 5 /* Deprecated */
4592 #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
4593 
4594 /*
4595 ** CAPI3REF: Function Flags
4596 **
4597 ** These constants may be ORed together with the
4598 ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
4599 ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
4600 ** [sqlite3_create_function_v2()].
4601 */
4602 #define SQLITE_DETERMINISTIC 0x800
4603 
4604 /*
4605 ** CAPI3REF: Deprecated Functions
4606 ** DEPRECATED
4607 **
4608 ** These functions are [deprecated]. In order to maintain
4609 ** backwards compatibility with older code, these functions continue
4610 ** to be supported. However, new applications should avoid
4611 ** the use of these functions. To encourage programmers to avoid
4612 ** these functions, we will not explain what they do.
4613 */
4614 #ifndef SQLITE_OMIT_DEPRECATED
4620 SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),
4621  void*,sqlite3_int64);
4622 #endif
4623 
4624 /*
4625 ** CAPI3REF: Obtaining SQL Values
4626 ** METHOD: sqlite3_value
4627 **
4628 ** The C-language implementation of SQL functions and aggregates uses
4629 ** this set of interface routines to access the parameter values on
4630 ** the function or aggregate.
4631 **
4632 ** The xFunc (for scalar functions) or xStep (for aggregates) parameters
4633 ** to [sqlite3_create_function()] and [sqlite3_create_function16()]
4634 ** define callbacks that implement the SQL functions and aggregates.
4635 ** The 3rd parameter to these callbacks is an array of pointers to
4636 ** [protected sqlite3_value] objects. There is one [sqlite3_value] object for
4637 ** each parameter to the SQL function. These routines are used to
4638 ** extract values from the [sqlite3_value] objects.
4639 **
4640 ** These routines work only with [protected sqlite3_value] objects.
4641 ** Any attempt to use these routines on an [unprotected sqlite3_value]
4642 ** object results in undefined behavior.
4643 **
4644 ** ^These routines work just like the corresponding [column access functions]
4645 ** except that these routines take a single [protected sqlite3_value] object
4646 ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
4647 **
4648 ** ^The sqlite3_value_text16() interface extracts a UTF-16 string
4649 ** in the native byte-order of the host machine. ^The
4650 ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
4651 ** extract UTF-16 strings as big-endian and little-endian respectively.
4652 **
4653 ** ^(The sqlite3_value_numeric_type() interface attempts to apply
4654 ** numeric affinity to the value. This means that an attempt is
4655 ** made to convert the value to an integer or floating point. If
4656 ** such a conversion is possible without loss of information (in other
4657 ** words, if the value is a string that looks like a number)
4658 ** then the conversion is performed. Otherwise no conversion occurs.
4659 ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
4660 **
4661 ** Please pay particular attention to the fact that the pointer returned
4662 ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
4663 ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
4664 ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
4665 ** or [sqlite3_value_text16()].
4666 **
4667 ** These routines must be called from the same thread as
4668 ** the SQL function that supplied the [sqlite3_value*] parameters.
4669 */
4682 
4683 /*
4684 ** CAPI3REF: Finding The Subtype Of SQL Values
4685 ** METHOD: sqlite3_value
4686 **
4687 ** The sqlite3_value_subtype(V) function returns the subtype for
4688 ** an [application-defined SQL function] argument V. The subtype
4689 ** information can be used to pass a limited amount of context from
4690 ** one SQL function to another. Use the [sqlite3_result_subtype()]
4691 ** routine to set the subtype for the return value of an SQL function.
4692 **
4693 ** SQLite makes no use of subtype itself. It merely passes the subtype
4694 ** from the result of one [application-defined SQL function] into the
4695 ** input of another.
4696 */
4698 
4699 /*
4700 ** CAPI3REF: Copy And Free SQL Values
4701 ** METHOD: sqlite3_value
4702 **
4703 ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
4704 ** object D and returns a pointer to that copy. ^The [sqlite3_value] returned
4705 ** is a [protected sqlite3_value] object even if the input is not.
4706 ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
4707 ** memory allocation fails.
4708 **
4709 ** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object
4710 ** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer
4711 ** then sqlite3_value_free(V) is a harmless no-op.
4712 */
4715 
4716 /*
4717 ** CAPI3REF: Obtain Aggregate Function Context
4718 ** METHOD: sqlite3_context
4719 **
4720 ** Implementations of aggregate SQL functions use this
4721 ** routine to allocate memory for storing their state.
4722 **
4723 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
4724 ** for a particular aggregate function, SQLite
4725 ** allocates N of memory, zeroes out that memory, and returns a pointer
4726 ** to the new memory. ^On second and subsequent calls to
4727 ** sqlite3_aggregate_context() for the same aggregate function instance,
4728 ** the same buffer is returned. Sqlite3_aggregate_context() is normally
4729 ** called once for each invocation of the xStep callback and then one
4730 ** last time when the xFinal callback is invoked. ^(When no rows match
4731 ** an aggregate query, the xStep() callback of the aggregate function
4732 ** implementation is never called and xFinal() is called exactly once.
4733 ** In those cases, sqlite3_aggregate_context() might be called for the
4734 ** first time from within xFinal().)^
4735 **
4736 ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
4737 ** when first called if N is less than or equal to zero or if a memory
4738 ** allocate error occurs.
4739 **
4740 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
4741 ** determined by the N parameter on first successful call. Changing the
4742 ** value of N in subsequent call to sqlite3_aggregate_context() within
4743 ** the same aggregate function instance will not resize the memory
4744 ** allocation.)^ Within the xFinal callback, it is customary to set
4745 ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
4746 ** pointless memory allocations occur.
4747 **
4748 ** ^SQLite automatically frees the memory allocated by
4749 ** sqlite3_aggregate_context() when the aggregate query concludes.
4750 **
4751 ** The first parameter must be a copy of the
4752 ** [sqlite3_context | SQL function context] that is the first parameter
4753 ** to the xStep or xFinal callback routine that implements the aggregate
4754 ** function.
4755 **
4756 ** This routine must be called from the same thread in which
4757 ** the aggregate SQL function is running.
4758 */
4760 
4761 /*
4762 ** CAPI3REF: User Data For Functions
4763 ** METHOD: sqlite3_context
4764 **
4765 ** ^The sqlite3_user_data() interface returns a copy of
4766 ** the pointer that was the pUserData parameter (the 5th parameter)
4767 ** of the [sqlite3_create_function()]
4768 ** and [sqlite3_create_function16()] routines that originally
4769 ** registered the application defined function.
4770 **
4771 ** This routine must be called from the same thread in which
4772 ** the application-defined function is running.
4773 */
4775 
4776 /*
4777 ** CAPI3REF: Database Connection For Functions
4778 ** METHOD: sqlite3_context
4779 **
4780 ** ^The sqlite3_context_db_handle() interface returns a copy of
4781 ** the pointer to the [database connection] (the 1st parameter)
4782 ** of the [sqlite3_create_function()]
4783 ** and [sqlite3_create_function16()] routines that originally
4784 ** registered the application defined function.
4785 */
4787 
4788 /*
4789 ** CAPI3REF: Function Auxiliary Data
4790 ** METHOD: sqlite3_context
4791 **
4792 ** These functions may be used by (non-aggregate) SQL functions to
4793 ** associate metadata with argument values. If the same value is passed to
4794 ** multiple invocations of the same SQL function during query execution, under
4795 ** some circumstances the associated metadata may be preserved. An example
4796 ** of where this might be useful is in a regular-expression matching
4797 ** function. The compiled version of the regular expression can be stored as
4798 ** metadata associated with the pattern string.
4799 ** Then as long as the pattern string remains the same,
4800 ** the compiled regular expression can be reused on multiple
4801 ** invocations of the same function.
4802 **
4803 ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
4804 ** associated by the sqlite3_set_auxdata() function with the Nth argument
4805 ** value to the application-defined function. ^If there is no metadata
4806 ** associated with the function argument, this sqlite3_get_auxdata() interface
4807 ** returns a NULL pointer.
4808 **
4809 ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
4810 ** argument of the application-defined function. ^Subsequent
4811 ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
4812 ** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or
4813 ** NULL if the metadata has been discarded.
4814 ** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL,
4815 ** SQLite will invoke the destructor function X with parameter P exactly
4816 ** once, when the metadata is discarded.
4817 ** SQLite is free to discard the metadata at any time, including: <ul>
4818 ** <li> when the corresponding function parameter changes, or
4819 ** <li> when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
4820 ** SQL statement, or
4821 ** <li> when sqlite3_set_auxdata() is invoked again on the same parameter, or
4822 ** <li> during the original sqlite3_set_auxdata() call when a memory
4823 ** allocation error occurs. </ul>)^
4824 **
4825 ** Note the last bullet in particular. The destructor X in
4826 ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the
4827 ** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata()
4828 ** should be called near the end of the function implementation and the
4829 ** function implementation should not make any use of P after
4830 ** sqlite3_set_auxdata() has been called.
4831 **
4832 ** ^(In practice, metadata is preserved between function calls for
4833 ** function parameters that are compile-time constants, including literal
4834 ** values and [parameters] and expressions composed from the same.)^
4835 **
4836 ** These routines must be called from the same thread in which
4837 ** the SQL function is running.
4838 */
4840 SQLITE_API void SQLITE_STDCALL sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
4841 
4842 
4843 /*
4844 ** CAPI3REF: Constants Defining Special Destructor Behavior
4845 **
4846 ** These are special values for the destructor that is passed in as the
4847 ** final argument to routines like [sqlite3_result_blob()]. ^If the destructor
4848 ** argument is SQLITE_STATIC, it means that the content pointer is constant
4849 ** and will never change. It does not need to be destroyed. ^The
4850 ** SQLITE_TRANSIENT value means that the content will likely change in
4851 ** the near future and that SQLite should make its own private copy of
4852 ** the content before returning.
4853 **
4854 ** The typedef is necessary to work around problems in certain
4855 ** C++ compilers.
4856 */
4857 typedef void (*sqlite3_destructor_type)(void*);
4858 #define SQLITE_STATIC ((sqlite3_destructor_type)0)
4859 #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
4860 
4861 /*
4862 ** CAPI3REF: Setting The Result Of An SQL Function
4863 ** METHOD: sqlite3_context
4864 **
4865 ** These routines are used by the xFunc or xFinal callbacks that
4866 ** implement SQL functions and aggregates. See
4867 ** [sqlite3_create_function()] and [sqlite3_create_function16()]
4868 ** for additional information.
4869 **
4870 ** These functions work very much like the [parameter binding] family of
4871 ** functions used to bind values to host parameters in prepared statements.
4872 ** Refer to the [SQL parameter] documentation for additional information.
4873 **
4874 ** ^The sqlite3_result_blob() interface sets the result from
4875 ** an application-defined function to be the BLOB whose content is pointed
4876 ** to by the second parameter and which is N bytes long where N is the
4877 ** third parameter.
4878 **
4879 ** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N)
4880 ** interfaces set the result of the application-defined function to be
4881 ** a BLOB containing all zero bytes and N bytes in size.
4882 **
4883 ** ^The sqlite3_result_double() interface sets the result from
4884 ** an application-defined function to be a floating point value specified
4885 ** by its 2nd argument.
4886 **
4887 ** ^The sqlite3_result_error() and sqlite3_result_error16() functions
4888 ** cause the implemented SQL function to throw an exception.
4889 ** ^SQLite uses the string pointed to by the
4890 ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
4891 ** as the text of an error message. ^SQLite interprets the error
4892 ** message string from sqlite3_result_error() as UTF-8. ^SQLite
4893 ** interprets the string from sqlite3_result_error16() as UTF-16 in native
4894 ** byte order. ^If the third parameter to sqlite3_result_error()
4895 ** or sqlite3_result_error16() is negative then SQLite takes as the error
4896 ** message all text up through the first zero character.
4897 ** ^If the third parameter to sqlite3_result_error() or
4898 ** sqlite3_result_error16() is non-negative then SQLite takes that many
4899 ** bytes (not characters) from the 2nd parameter as the error message.
4900 ** ^The sqlite3_result_error() and sqlite3_result_error16()
4901 ** routines make a private copy of the error message text before
4902 ** they return. Hence, the calling function can deallocate or
4903 ** modify the text after they return without harm.
4904 ** ^The sqlite3_result_error_code() function changes the error code
4905 ** returned by SQLite as a result of an error in a function. ^By default,
4906 ** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error()
4907 ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
4908 **
4909 ** ^The sqlite3_result_error_toobig() interface causes SQLite to throw an
4910 ** error indicating that a string or BLOB is too long to represent.
4911 **
4912 ** ^The sqlite3_result_error_nomem() interface causes SQLite to throw an
4913 ** error indicating that a memory allocation failed.
4914 **
4915 ** ^The sqlite3_result_int() interface sets the return value
4916 ** of the application-defined function to be the 32-bit signed integer
4917 ** value given in the 2nd argument.
4918 ** ^The sqlite3_result_int64() interface sets the return value
4919 ** of the application-defined function to be the 64-bit signed integer
4920 ** value given in the 2nd argument.
4921 **
4922 ** ^The sqlite3_result_null() interface sets the return value
4923 ** of the application-defined function to be NULL.
4924 **
4925 ** ^The sqlite3_result_text(), sqlite3_result_text16(),
4926 ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
4927 ** set the return value of the application-defined function to be
4928 ** a text string which is represented as UTF-8, UTF-16 native byte order,
4929 ** UTF-16 little endian, or UTF-16 big endian, respectively.
4930 ** ^The sqlite3_result_text64() interface sets the return value of an
4931 ** application-defined function to be a text string in an encoding
4932 ** specified by the fifth (and last) parameter, which must be one
4933 ** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE].
4934 ** ^SQLite takes the text result from the application from
4935 ** the 2nd parameter of the sqlite3_result_text* interfaces.
4936 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
4937 ** is negative, then SQLite takes result text from the 2nd parameter
4938 ** through the first zero character.
4939 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
4940 ** is non-negative, then as many bytes (not characters) of the text
4941 ** pointed to by the 2nd parameter are taken as the application-defined
4942 ** function result. If the 3rd parameter is non-negative, then it
4943 ** must be the byte offset into the string where the NUL terminator would
4944 ** appear if the string where NUL terminated. If any NUL characters occur
4945 ** in the string at a byte offset that is less than the value of the 3rd
4946 ** parameter, then the resulting string will contain embedded NULs and the
4947 ** result of expressions operating on strings with embedded NULs is undefined.
4948 ** ^If the 4th parameter to the sqlite3_result_text* interfaces
4949 ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
4950 ** function as the destructor on the text or BLOB result when it has
4951 ** finished using that result.
4952 ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to
4953 ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite
4954 ** assumes that the text or BLOB result is in constant space and does not
4955 ** copy the content of the parameter nor call a destructor on the content
4956 ** when it has finished using that result.
4957 ** ^If the 4th parameter to the sqlite3_result_text* interfaces
4958 ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
4959 ** then SQLite makes a copy of the result into space obtained from
4960 ** from [sqlite3_malloc()] before it returns.
4961 **
4962 ** ^The sqlite3_result_value() interface sets the result of
4963 ** the application-defined function to be a copy of the
4964 ** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The
4965 ** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
4966 ** so that the [sqlite3_value] specified in the parameter may change or
4967 ** be deallocated after sqlite3_result_value() returns without harm.
4968 ** ^A [protected sqlite3_value] object may always be used where an
4969 ** [unprotected sqlite3_value] object is required, so either
4970 ** kind of [sqlite3_value] object can be used with this interface.
4971 **
4972 ** If these routines are called from within the different thread
4973 ** than the one containing the application-defined function that received
4974 ** the [sqlite3_context] pointer, the results are undefined.
4975 */
4976 SQLITE_API void SQLITE_STDCALL sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
4978  sqlite3_uint64,void(*)(void*));
4988 SQLITE_API void SQLITE_STDCALL sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
4989 SQLITE_API void SQLITE_STDCALL sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64,
4990  void(*)(void*), unsigned char encoding);
4991 SQLITE_API void SQLITE_STDCALL sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
4992 SQLITE_API void SQLITE_STDCALL sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
4993 SQLITE_API void SQLITE_STDCALL sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
4997 
4998 
4999 /*
5000 ** CAPI3REF: Setting The Subtype Of An SQL Function
5001 ** METHOD: sqlite3_context
5002 **
5003 ** The sqlite3_result_subtype(C,T) function causes the subtype of
5004 ** the result from the [application-defined SQL function] with
5005 ** [sqlite3_context] C to be the value T. Only the lower 8 bits
5006 ** of the subtype T are preserved in current versions of SQLite;
5007 ** higher order bits are discarded.
5008 ** The number of subtype bytes preserved by SQLite might increase
5009 ** in future releases of SQLite.
5010 */
5012 
5013 /*
5014 ** CAPI3REF: Define New Collating Sequences
5015 ** METHOD: sqlite3
5016 **
5017 ** ^These functions add, remove, or modify a [collation] associated
5018 ** with the [database connection] specified as the first argument.
5019 **
5020 ** ^The name of the collation is a UTF-8 string
5021 ** for sqlite3_create_collation() and sqlite3_create_collation_v2()
5022 ** and a UTF-16 string in native byte order for sqlite3_create_collation16().
5023 ** ^Collation names that compare equal according to [sqlite3_strnicmp()] are
5024 ** considered to be the same name.
5025 **
5026 ** ^(The third argument (eTextRep) must be one of the constants:
5027 ** <ul>
5028 ** <li> [SQLITE_UTF8],
5029 ** <li> [SQLITE_UTF16LE],
5030 ** <li> [SQLITE_UTF16BE],
5031 ** <li> [SQLITE_UTF16], or
5032 ** <li> [SQLITE_UTF16_ALIGNED].
5033 ** </ul>)^
5034 ** ^The eTextRep argument determines the encoding of strings passed
5035 ** to the collating function callback, xCallback.
5036 ** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
5037 ** force strings to be UTF16 with native byte order.
5038 ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
5039 ** on an even byte address.
5040 **
5041 ** ^The fourth argument, pArg, is an application data pointer that is passed
5042 ** through as the first argument to the collating function callback.
5043 **
5044 ** ^The fifth argument, xCallback, is a pointer to the collating function.
5045 ** ^Multiple collating functions can be registered using the same name but
5046 ** with different eTextRep parameters and SQLite will use whichever
5047 ** function requires the least amount of data transformation.
5048 ** ^If the xCallback argument is NULL then the collating function is
5049 ** deleted. ^When all collating functions having the same name are deleted,
5050 ** that collation is no longer usable.
5051 **
5052 ** ^The collating function callback is invoked with a copy of the pArg
5053 ** application data pointer and with two strings in the encoding specified
5054 ** by the eTextRep argument. The collating function must return an
5055 ** integer that is negative, zero, or positive
5056 ** if the first string is less than, equal to, or greater than the second,
5057 ** respectively. A collating function must always return the same answer
5058 ** given the same inputs. If two or more collating functions are registered
5059 ** to the same collation name (using different eTextRep values) then all
5060 ** must give an equivalent answer when invoked with equivalent strings.
5061 ** The collating function must obey the following properties for all
5062 ** strings A, B, and C:
5063 **
5064 ** <ol>
5065 ** <li> If A==B then B==A.
5066 ** <li> If A==B and B==C then A==C.
5067 ** <li> If A&lt;B THEN B&gt;A.
5068 ** <li> If A&lt;B and B&lt;C then A&lt;C.
5069 ** </ol>
5070 **
5071 ** If a collating function fails any of the above constraints and that
5072 ** collating function is registered and used, then the behavior of SQLite
5073 ** is undefined.
5074 **
5075 ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
5076 ** with the addition that the xDestroy callback is invoked on pArg when
5077 ** the collating function is deleted.
5078 ** ^Collating functions are deleted when they are overridden by later
5079 ** calls to the collation creation functions or when the
5080 ** [database connection] is closed using [sqlite3_close()].
5081 **
5082 ** ^The xDestroy callback is <u>not</u> called if the
5083 ** sqlite3_create_collation_v2() function fails. Applications that invoke
5084 ** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should
5085 ** check the return code and dispose of the application data pointer
5086 ** themselves rather than expecting SQLite to deal with it for them.
5087 ** This is different from every other SQLite interface. The inconsistency
5088 ** is unfortunate but cannot be changed without breaking backwards
5089 ** compatibility.
5090 **
5091 ** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
5092 */
5094  sqlite3*,
5095  const char *zName,
5096  int eTextRep,
5097  void *pArg,
5098  int(*xCompare)(void*,int,const void*,int,const void*)
5099 );
5101  sqlite3*,
5102  const char *zName,
5103  int eTextRep,
5104  void *pArg,
5105  int(*xCompare)(void*,int,const void*,int,const void*),
5106  void(*xDestroy)(void*)
5107 );
5109  sqlite3*,
5110  const void *zName,
5111  int eTextRep,
5112  void *pArg,
5113  int(*xCompare)(void*,int,const void*,int,const void*)
5114 );
5115 
5116 /*
5117 ** CAPI3REF: Collation Needed Callbacks
5118 ** METHOD: sqlite3
5119 **
5120 ** ^To avoid having to register all collation sequences before a database
5121 ** can be used, a single callback function may be registered with the
5122 ** [database connection] to be invoked whenever an undefined collation
5123 ** sequence is required.
5124 **
5125 ** ^If the function is registered using the sqlite3_collation_needed() API,
5126 ** then it is passed the names of undefined collation sequences as strings
5127 ** encoded in UTF-8. ^If sqlite3_collation_needed16() is used,
5128 ** the names are passed as UTF-16 in machine native byte order.
5129 ** ^A call to either function replaces the existing collation-needed callback.
5130 **
5131 ** ^(When the callback is invoked, the first argument passed is a copy
5132 ** of the second argument to sqlite3_collation_needed() or
5133 ** sqlite3_collation_needed16(). The second argument is the database
5134 ** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE],
5135 ** or [SQLITE_UTF16LE], indicating the most desirable form of the collation
5136 ** sequence function required. The fourth parameter is the name of the
5137 ** required collation sequence.)^
5138 **
5139 ** The callback function should register the desired collation using
5140 ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
5141 ** [sqlite3_create_collation_v2()].
5142 */
5144  sqlite3*,
5145  void*,
5146  void(*)(void*,sqlite3*,int eTextRep,const char*)
5147 );
5149  sqlite3*,
5150  void*,
5151  void(*)(void*,sqlite3*,int eTextRep,const void*)
5152 );
5153 
5154 #ifdef SQLITE_HAS_CODEC
5155 /*
5156 ** Specify the key for an encrypted database. This routine should be
5157 ** called right after sqlite3_open().
5158 **
5159 ** The code to implement this API is not available in the public release
5160 ** of SQLite.
5161 */
5162 SQLITE_API int SQLITE_STDCALL sqlite3_key(
5163  sqlite3 *db, /* Database to be rekeyed */
5164  const void *pKey, int nKey /* The key */
5165 );
5166 SQLITE_API int SQLITE_STDCALL sqlite3_key_v2(
5167  sqlite3 *db, /* Database to be rekeyed */
5168  const char *zDbName, /* Name of the database */
5169  const void *pKey, int nKey /* The key */
5170 );
5171 
5172 /*
5173 ** Change the key on an open database. If the current database is not
5174 ** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the
5175 ** database is decrypted.
5176 **
5177 ** The code to implement this API is not available in the public release
5178 ** of SQLite.
5179 */
5180 SQLITE_API int SQLITE_STDCALL sqlite3_rekey(
5181  sqlite3 *db, /* Database to be rekeyed */
5182  const void *pKey, int nKey /* The new key */
5183 );
5184 SQLITE_API int SQLITE_STDCALL sqlite3_rekey_v2(
5185  sqlite3 *db, /* Database to be rekeyed */
5186  const char *zDbName, /* Name of the database */
5187  const void *pKey, int nKey /* The new key */
5188 );
5189 
5190 /*
5191 ** Specify the activation key for a SEE database. Unless
5192 ** activated, none of the SEE routines will work.
5193 */
5194 SQLITE_API void SQLITE_STDCALL sqlite3_activate_see(
5195  const char *zPassPhrase /* Activation phrase */
5196 );
5197 #endif
5198 
5199 #ifdef SQLITE_ENABLE_CEROD
5200 /*
5201 ** Specify the activation key for a CEROD database. Unless
5202 ** activated, none of the CEROD routines will work.
5203 */
5204 SQLITE_API void SQLITE_STDCALL sqlite3_activate_cerod(
5205  const char *zPassPhrase /* Activation phrase */
5206 );
5207 #endif
5208 
5209 /*
5210 ** CAPI3REF: Suspend Execution For A Short Time
5211 **
5212 ** The sqlite3_sleep() function causes the current thread to suspend execution
5213 ** for at least a number of milliseconds specified in its parameter.
5214 **
5215 ** If the operating system does not support sleep requests with
5216 ** millisecond time resolution, then the time will be rounded up to
5217 ** the nearest second. The number of milliseconds of sleep actually
5218 ** requested from the operating system is returned.
5219 **
5220 ** ^SQLite implements this interface by calling the xSleep()
5221 ** method of the default [sqlite3_vfs] object. If the xSleep() method
5222 ** of the default VFS is not implemented correctly, or not implemented at
5223 ** all, then the behavior of sqlite3_sleep() may deviate from the description
5224 ** in the previous paragraphs.
5225 */
5227 
5228 /*
5229 ** CAPI3REF: Name Of The Folder Holding Temporary Files
5230 **
5231 ** ^(If this global variable is made to point to a string which is
5232 ** the name of a folder (a.k.a. directory), then all temporary files
5233 ** created by SQLite when using a built-in [sqlite3_vfs | VFS]
5234 ** will be placed in that directory.)^ ^If this variable
5235 ** is a NULL pointer, then SQLite performs a search for an appropriate
5236 ** temporary file directory.
5237 **
5238 ** Applications are strongly discouraged from using this global variable.
5239 ** It is required to set a temporary folder on Windows Runtime (WinRT).
5240 ** But for all other platforms, it is highly recommended that applications
5241 ** neither read nor write this variable. This global variable is a relic
5242 ** that exists for backwards compatibility of legacy applications and should
5243 ** be avoided in new projects.
5244 **
5245 ** It is not safe to read or modify this variable in more than one
5246 ** thread at a time. It is not safe to read or modify this variable
5247 ** if a [database connection] is being used at the same time in a separate
5248 ** thread.
5249 ** It is intended that this variable be set once
5250 ** as part of process initialization and before any SQLite interface
5251 ** routines have been called and that this variable remain unchanged
5252 ** thereafter.
5253 **
5254 ** ^The [temp_store_directory pragma] may modify this variable and cause
5255 ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore,
5256 ** the [temp_store_directory pragma] always assumes that any string
5257 ** that this variable points to is held in memory obtained from
5258 ** [sqlite3_malloc] and the pragma may attempt to free that memory
5259 ** using [sqlite3_free].
5260 ** Hence, if this variable is modified directly, either it should be
5261 ** made NULL or made to point to memory obtained from [sqlite3_malloc]
5262 ** or else the use of the [temp_store_directory pragma] should be avoided.
5263 ** Except when requested by the [temp_store_directory pragma], SQLite
5264 ** does not free the memory that sqlite3_temp_directory points to. If
5265 ** the application wants that memory to be freed, it must do
5266 ** so itself, taking care to only do so after all [database connection]
5267 ** objects have been destroyed.
5268 **
5269 ** <b>Note to Windows Runtime users:</b> The temporary directory must be set
5270 ** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various
5271 ** features that require the use of temporary files may fail. Here is an
5272 ** example of how to do this using C++ with the Windows Runtime:
5273 **
5274 ** <blockquote><pre>
5275 ** LPCWSTR zPath = Windows::Storage::ApplicationData::Current->
5276 ** &nbsp; TemporaryFolder->Path->Data();
5277 ** char zPathBuf&#91;MAX_PATH + 1&#93;;
5278 ** memset(zPathBuf, 0, sizeof(zPathBuf));
5279 ** WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf, sizeof(zPathBuf),
5280 ** &nbsp; NULL, NULL);
5281 ** sqlite3_temp_directory = sqlite3_mprintf("%s", zPathBuf);
5282 ** </pre></blockquote>
5283 */
5285 
5286 /*
5287 ** CAPI3REF: Name Of The Folder Holding Database Files
5288 **
5289 ** ^(If this global variable is made to point to a string which is
5290 ** the name of a folder (a.k.a. directory), then all database files
5291 ** specified with a relative pathname and created or accessed by
5292 ** SQLite when using a built-in windows [sqlite3_vfs | VFS] will be assumed
5293 ** to be relative to that directory.)^ ^If this variable is a NULL
5294 ** pointer, then SQLite assumes that all database files specified
5295 ** with a relative pathname are relative to the current directory
5296 ** for the process. Only the windows VFS makes use of this global
5297 ** variable; it is ignored by the unix VFS.
5298 **
5299 ** Changing the value of this variable while a database connection is
5300 ** open can result in a corrupt database.
5301 **
5302 ** It is not safe to read or modify this variable in more than one
5303 ** thread at a time. It is not safe to read or modify this variable
5304 ** if a [database connection] is being used at the same time in a separate
5305 ** thread.
5306 ** It is intended that this variable be set once
5307 ** as part of process initialization and before any SQLite interface
5308 ** routines have been called and that this variable remain unchanged
5309 ** thereafter.
5310 **
5311 ** ^The [data_store_directory pragma] may modify this variable and cause
5312 ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore,
5313 ** the [data_store_directory pragma] always assumes that any string
5314 ** that this variable points to is held in memory obtained from
5315 ** [sqlite3_malloc] and the pragma may attempt to free that memory
5316 ** using [sqlite3_free].
5317 ** Hence, if this variable is modified directly, either it should be
5318 ** made NULL or made to point to memory obtained from [sqlite3_malloc]
5319 ** or else the use of the [data_store_directory pragma] should be avoided.
5320 */
5322 
5323 /*
5324 ** CAPI3REF: Test For Auto-Commit Mode
5325 ** KEYWORDS: {autocommit mode}
5326 ** METHOD: sqlite3
5327 **
5328 ** ^The sqlite3_get_autocommit() interface returns non-zero or
5329 ** zero if the given database connection is or is not in autocommit mode,
5330 ** respectively. ^Autocommit mode is on by default.
5331 ** ^Autocommit mode is disabled by a [BEGIN] statement.
5332 ** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].
5333 **
5334 ** If certain kinds of errors occur on a statement within a multi-statement
5335 ** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR],
5336 ** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the
5337 ** transaction might be rolled back automatically. The only way to
5338 ** find out whether SQLite automatically rolled back the transaction after
5339 ** an error is to use this function.
5340 **
5341 ** If another thread changes the autocommit status of the database
5342 ** connection while this routine is running, then the return value
5343 ** is undefined.
5344 */
5346 
5347 /*
5348 ** CAPI3REF: Find The Database Handle Of A Prepared Statement
5349 ** METHOD: sqlite3_stmt
5350 **
5351 ** ^The sqlite3_db_handle interface returns the [database connection] handle
5352 ** to which a [prepared statement] belongs. ^The [database connection]
5353 ** returned by sqlite3_db_handle is the same [database connection]
5354 ** that was the first argument
5355 ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
5356 ** create the statement in the first place.
5357 */
5359 
5360 /*
5361 ** CAPI3REF: Return The Filename For A Database Connection
5362 ** METHOD: sqlite3
5363 **
5364 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
5365 ** associated with database N of connection D. ^The main database file
5366 ** has the name "main". If there is no attached database N on the database
5367 ** connection D, or if database N is a temporary or in-memory database, then
5368 ** a NULL pointer is returned.
5369 **
5370 ** ^The filename returned by this function is the output of the
5371 ** xFullPathname method of the [VFS]. ^In other words, the filename
5372 ** will be an absolute pathname, even if the filename used
5373 ** to open the database originally was a URI or relative pathname.
5374 */
5375 SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
5376 
5377 /*
5378 ** CAPI3REF: Determine if a database is read-only
5379 ** METHOD: sqlite3
5380 **
5381 ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
5382 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
5383 ** the name of a database on connection D.
5384 */
5385 SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
5386 
5387 /*
5388 ** CAPI3REF: Find the next prepared statement
5389 ** METHOD: sqlite3
5390 **
5391 ** ^This interface returns a pointer to the next [prepared statement] after
5392 ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
5393 ** then this interface returns a pointer to the first prepared statement
5394 ** associated with the database connection pDb. ^If no prepared statement
5395 ** satisfies the conditions of this routine, it returns NULL.
5396 **
5397 ** The [database connection] pointer D in a call to
5398 ** [sqlite3_next_stmt(D,S)] must refer to an open database
5399 ** connection and in particular must not be a NULL pointer.
5400 */
5402 
5403 /*
5404 ** CAPI3REF: Commit And Rollback Notification Callbacks
5405 ** METHOD: sqlite3
5406 **
5407 ** ^The sqlite3_commit_hook() interface registers a callback
5408 ** function to be invoked whenever a transaction is [COMMIT | committed].
5409 ** ^Any callback set by a previous call to sqlite3_commit_hook()
5410 ** for the same database connection is overridden.
5411 ** ^The sqlite3_rollback_hook() interface registers a callback
5412 ** function to be invoked whenever a transaction is [ROLLBACK | rolled back].
5413 ** ^Any callback set by a previous call to sqlite3_rollback_hook()
5414 ** for the same database connection is overridden.
5415 ** ^The pArg argument is passed through to the callback.
5416 ** ^If the callback on a commit hook function returns non-zero,
5417 ** then the commit is converted into a rollback.
5418 **
5419 ** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions
5420 ** return the P argument from the previous call of the same function
5421 ** on the same [database connection] D, or NULL for
5422 ** the first call for each function on D.
5423 **
5424 ** The commit and rollback hook callbacks are not reentrant.
5425 ** The callback implementation must not do anything that will modify
5426 ** the database connection that invoked the callback. Any actions
5427 ** to modify the database connection must be deferred until after the
5428 ** completion of the [sqlite3_step()] call that triggered the commit
5429 ** or rollback hook in the first place.
5430 ** Note that running any other SQL statements, including SELECT statements,
5431 ** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify
5432 ** the database connections for the meaning of "modify" in this paragraph.
5433 **
5434 ** ^Registering a NULL function disables the callback.
5435 **
5436 ** ^When the commit hook callback routine returns zero, the [COMMIT]
5437 ** operation is allowed to continue normally. ^If the commit hook
5438 ** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK].
5439 ** ^The rollback hook is invoked on a rollback that results from a commit
5440 ** hook returning non-zero, just as it would be with any other rollback.
5441 **
5442 ** ^For the purposes of this API, a transaction is said to have been
5443 ** rolled back if an explicit "ROLLBACK" statement is executed, or
5444 ** an error or constraint causes an implicit rollback to occur.
5445 ** ^The rollback callback is not invoked if a transaction is
5446 ** automatically rolled back because the database connection is closed.
5447 **
5448 ** See also the [sqlite3_update_hook()] interface.
5449 */
5450 SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
5451 SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
5452 
5453 /*
5454 ** CAPI3REF: Data Change Notification Callbacks
5455 ** METHOD: sqlite3
5456 **
5457 ** ^The sqlite3_update_hook() interface registers a callback function
5458 ** with the [database connection] identified by the first argument
5459 ** to be invoked whenever a row is updated, inserted or deleted in
5460 ** a [rowid table].
5461 ** ^Any callback set by a previous call to this function
5462 ** for the same database connection is overridden.
5463 **
5464 ** ^The second argument is a pointer to the function to invoke when a
5465 ** row is updated, inserted or deleted in a rowid table.
5466 ** ^The first argument to the callback is a copy of the third argument
5467 ** to sqlite3_update_hook().
5468 ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
5469 ** or [SQLITE_UPDATE], depending on the operation that caused the callback
5470 ** to be invoked.
5471 ** ^The third and fourth arguments to the callback contain pointers to the
5472 ** database and table name containing the affected row.
5473 ** ^The final callback parameter is the [rowid] of the row.
5474 ** ^In the case of an update, this is the [rowid] after the update takes place.
5475 **
5476 ** ^(The update hook is not invoked when internal system tables are
5477 ** modified (i.e. sqlite_master and sqlite_sequence).)^
5478 ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
5479 **
5480 ** ^In the current implementation, the update hook
5481 ** is not invoked when duplication rows are deleted because of an
5482 ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
5483 ** invoked when rows are deleted using the [truncate optimization].
5484 ** The exceptions defined in this paragraph might change in a future
5485 ** release of SQLite.
5486 **
5487 ** The update hook implementation must not do anything that will modify
5488 ** the database connection that invoked the update hook. Any actions
5489 ** to modify the database connection must be deferred until after the
5490 ** completion of the [sqlite3_step()] call that triggered the update hook.
5491 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
5492 ** database connections for the meaning of "modify" in this paragraph.
5493 **
5494 ** ^The sqlite3_update_hook(D,C,P) function
5495 ** returns the P argument from the previous call
5496 ** on the same [database connection] D, or NULL for
5497 ** the first call on D.
5498 **
5499 ** See also the [sqlite3_commit_hook()], [sqlite3_rollback_hook()],
5500 ** and [sqlite3_preupdate_hook()] interfaces.
5501 */
5503  sqlite3*,
5504  void(*)(void *,int ,char const *,char const *,sqlite3_int64),
5505  void*
5506 );
5507 
5508 /*
5509 ** CAPI3REF: Enable Or Disable Shared Pager Cache
5510 **
5511 ** ^(This routine enables or disables the sharing of the database cache
5512 ** and schema data structures between [database connection | connections]
5513 ** to the same database. Sharing is enabled if the argument is true
5514 ** and disabled if the argument is false.)^
5515 **
5516 ** ^Cache sharing is enabled and disabled for an entire process.
5517 ** This is a change as of SQLite version 3.5.0. In prior versions of SQLite,
5518 ** sharing was enabled or disabled for each thread separately.
5519 **
5520 ** ^(The cache sharing mode set by this interface effects all subsequent
5521 ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
5522 ** Existing database connections continue use the sharing mode
5523 ** that was in effect at the time they were opened.)^
5524 **
5525 ** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled
5526 ** successfully. An [error code] is returned otherwise.)^
5527 **
5528 ** ^Shared cache is disabled by default. But this might change in
5529 ** future releases of SQLite. Applications that care about shared
5530 ** cache setting should set it explicitly.
5531 **
5532 ** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0
5533 ** and will always return SQLITE_MISUSE. On those systems,
5534 ** shared cache mode should be enabled per-database connection via
5535 ** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].
5536 **
5537 ** This interface is threadsafe on processors where writing a
5538 ** 32-bit integer is atomic.
5539 **
5540 ** See Also: [SQLite Shared-Cache Mode]
5541 */
5543 
5544 /*
5545 ** CAPI3REF: Attempt To Free Heap Memory
5546 **
5547 ** ^The sqlite3_release_memory() interface attempts to free N bytes
5548 ** of heap memory by deallocating non-essential memory allocations
5549 ** held by the database library. Memory used to cache database
5550 ** pages to improve performance is an example of non-essential memory.
5551 ** ^sqlite3_release_memory() returns the number of bytes actually freed,
5552 ** which might be more or less than the amount requested.
5553 ** ^The sqlite3_release_memory() routine is a no-op returning zero
5554 ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT].
5555 **
5556 ** See also: [sqlite3_db_release_memory()]
5557 */
5559 
5560 /*
5561 ** CAPI3REF: Free Memory Used By A Database Connection
5562 ** METHOD: sqlite3
5563 **
5564 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
5565 ** memory as possible from database connection D. Unlike the
5566 ** [sqlite3_release_memory()] interface, this interface is in effect even
5567 ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
5568 ** omitted.
5569 **
5570 ** See also: [sqlite3_release_memory()]
5571 */
5573 
5574 /*
5575 ** CAPI3REF: Impose A Limit On Heap Size
5576 **
5577 ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
5578 ** soft limit on the amount of heap memory that may be allocated by SQLite.
5579 ** ^SQLite strives to keep heap memory utilization below the soft heap
5580 ** limit by reducing the number of pages held in the page cache
5581 ** as heap memory usages approaches the limit.
5582 ** ^The soft heap limit is "soft" because even though SQLite strives to stay
5583 ** below the limit, it will exceed the limit rather than generate
5584 ** an [SQLITE_NOMEM] error. In other words, the soft heap limit
5585 ** is advisory only.
5586 **
5587 ** ^The return value from sqlite3_soft_heap_limit64() is the size of
5588 ** the soft heap limit prior to the call, or negative in the case of an
5589 ** error. ^If the argument N is negative
5590 ** then no change is made to the soft heap limit. Hence, the current
5591 ** size of the soft heap limit can be determined by invoking
5592 ** sqlite3_soft_heap_limit64() with a negative argument.
5593 **
5594 ** ^If the argument N is zero then the soft heap limit is disabled.
5595 **
5596 ** ^(The soft heap limit is not enforced in the current implementation
5597 ** if one or more of following conditions are true:
5598 **
5599 ** <ul>
5600 ** <li> The soft heap limit is set to zero.
5601 ** <li> Memory accounting is disabled using a combination of the
5602 ** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and
5603 ** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.
5604 ** <li> An alternative page cache implementation is specified using
5605 ** [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...).
5606 ** <li> The page cache allocates from its own memory pool supplied
5607 ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
5608 ** from the heap.
5609 ** </ul>)^
5610 **
5611 ** Beginning with SQLite version 3.7.3, the soft heap limit is enforced
5612 ** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT]
5613 ** compile-time option is invoked. With [SQLITE_ENABLE_MEMORY_MANAGEMENT],
5614 ** the soft heap limit is enforced on every memory allocation. Without
5615 ** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced
5616 ** when memory is allocated by the page cache. Testing suggests that because
5617 ** the page cache is the predominate memory user in SQLite, most
5618 ** applications will achieve adequate soft heap limit enforcement without
5619 ** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT].
5620 **
5621 ** The circumstances under which SQLite will enforce the soft heap limit may
5622 ** changes in future releases of SQLite.
5623 */
5624 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_soft_heap_limit64(sqlite3_int64 N);
5625 
5626 /*
5627 ** CAPI3REF: Deprecated Soft Heap Limit Interface
5628 ** DEPRECATED
5629 **
5630 ** This is a deprecated version of the [sqlite3_soft_heap_limit64()]
5631 ** interface. This routine is provided for historical compatibility
5632 ** only. All new applications should use the
5633 ** [sqlite3_soft_heap_limit64()] interface rather than this one.
5634 */
5636 
5637 
5638 /*
5639 ** CAPI3REF: Extract Metadata About A Column Of A Table
5640 ** METHOD: sqlite3
5641 **
5642 ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
5643 ** information about column C of table T in database D
5644 ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
5645 ** interface returns SQLITE_OK and fills in the non-NULL pointers in
5646 ** the final five arguments with appropriate values if the specified
5647 ** column exists. ^The sqlite3_table_column_metadata() interface returns
5648 ** SQLITE_ERROR and if the specified column does not exist.
5649 ** ^If the column-name parameter to sqlite3_table_column_metadata() is a
5650 ** NULL pointer, then this routine simply checks for the existance of the
5651 ** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
5652 ** does not.
5653 **
5654 ** ^The column is identified by the second, third and fourth parameters to
5655 ** this function. ^(The second parameter is either the name of the database
5656 ** (i.e. "main", "temp", or an attached database) containing the specified
5657 ** table or NULL.)^ ^If it is NULL, then all attached databases are searched
5658 ** for the table using the same algorithm used by the database engine to
5659 ** resolve unqualified table references.
5660 **
5661 ** ^The third and fourth parameters to this function are the table and column
5662 ** name of the desired column, respectively.
5663 **
5664 ** ^Metadata is returned by writing to the memory locations passed as the 5th
5665 ** and subsequent parameters to this function. ^Any of these arguments may be
5666 ** NULL, in which case the corresponding element of metadata is omitted.
5667 **
5668 ** ^(<blockquote>
5669 ** <table border="1">
5670 ** <tr><th> Parameter <th> Output<br>Type <th> Description
5671 **
5672 ** <tr><td> 5th <td> const char* <td> Data type
5673 ** <tr><td> 6th <td> const char* <td> Name of default collation sequence
5674 ** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint
5675 ** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY
5676 ** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT]
5677 ** </table>
5678 ** </blockquote>)^
5679 **
5680 ** ^The memory pointed to by the character pointers returned for the
5681 ** declaration type and collation sequence is valid until the next
5682 ** call to any SQLite API function.
5683 **
5684 ** ^If the specified table is actually a view, an [error code] is returned.
5685 **
5686 ** ^If the specified column is "rowid", "oid" or "_rowid_" and the table
5687 ** is not a [WITHOUT ROWID] table and an
5688 ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
5689 ** parameters are set for the explicitly declared column. ^(If there is no
5690 ** [INTEGER PRIMARY KEY] column, then the outputs
5691 ** for the [rowid] are set as follows:
5692 **
5693 ** <pre>
5694 ** data type: "INTEGER"
5695 ** collation sequence: "BINARY"
5696 ** not null: 0
5697 ** primary key: 1
5698 ** auto increment: 0
5699 ** </pre>)^
5700 **
5701 ** ^This function causes all database schemas to be read from disk and
5702 ** parsed, if that has not already been done, and returns an error if
5703 ** any errors are encountered while loading the schema.
5704 */
5706  sqlite3 *db, /* Connection handle */
5707  const char *zDbName, /* Database name or NULL */
5708  const char *zTableName, /* Table name */
5709  const char *zColumnName, /* Column name */
5710  char const **pzDataType, /* OUTPUT: Declared data type */
5711  char const **pzCollSeq, /* OUTPUT: Collation sequence name */
5712  int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */
5713  int *pPrimaryKey, /* OUTPUT: True if column part of PK */
5714  int *pAutoinc /* OUTPUT: True if column is auto-increment */
5715 );
5716 
5717 /*
5718 ** CAPI3REF: Load An Extension
5719 ** METHOD: sqlite3
5720 **
5721 ** ^This interface loads an SQLite extension library from the named file.
5722 **
5723 ** ^The sqlite3_load_extension() interface attempts to load an
5724 ** [SQLite extension] library contained in the file zFile. If
5725 ** the file cannot be loaded directly, attempts are made to load
5726 ** with various operating-system specific extensions added.
5727 ** So for example, if "samplelib" cannot be loaded, then names like
5728 ** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might
5729 ** be tried also.
5730 **
5731 ** ^The entry point is zProc.
5732 ** ^(zProc may be 0, in which case SQLite will try to come up with an
5733 ** entry point name on its own. It first tries "sqlite3_extension_init".
5734 ** If that does not work, it constructs a name "sqlite3_X_init" where the
5735 ** X is consists of the lower-case equivalent of all ASCII alphabetic
5736 ** characters in the filename from the last "/" to the first following
5737 ** "." and omitting any initial "lib".)^
5738 ** ^The sqlite3_load_extension() interface returns
5739 ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
5740 ** ^If an error occurs and pzErrMsg is not 0, then the
5741 ** [sqlite3_load_extension()] interface shall attempt to
5742 ** fill *pzErrMsg with error message text stored in memory
5743 ** obtained from [sqlite3_malloc()]. The calling function
5744 ** should free this memory by calling [sqlite3_free()].
5745 **
5746 ** ^Extension loading must be enabled using
5747 ** [sqlite3_enable_load_extension()] or
5748 ** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL)
5749 ** prior to calling this API,
5750 ** otherwise an error will be returned.
5751 **
5752 ** <b>Security warning:</b> It is recommended that the
5753 ** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this
5754 ** interface. The use of the [sqlite3_enable_load_extension()] interface
5755 ** should be avoided. This will keep the SQL function [load_extension()]
5756 ** disabled and prevent SQL injections from giving attackers
5757 ** access to extension loading capabilities.
5758 **
5759 ** See also the [load_extension() SQL function].
5760 */
5762  sqlite3 *db, /* Load the extension into this database connection */
5763  const char *zFile, /* Name of the shared library containing extension */
5764  const char *zProc, /* Entry point. Derived from zFile if 0 */
5765  char **pzErrMsg /* Put error message here if not 0 */
5766 );
5767 
5768 /*
5769 ** CAPI3REF: Enable Or Disable Extension Loading
5770 ** METHOD: sqlite3
5771 **
5772 ** ^So as not to open security holes in older applications that are
5773 ** unprepared to deal with [extension loading], and as a means of disabling
5774 ** [extension loading] while evaluating user-entered SQL, the following API
5775 ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
5776 **
5777 ** ^Extension loading is off by default.
5778 ** ^Call the sqlite3_enable_load_extension() routine with onoff==1
5779 ** to turn extension loading on and call it with onoff==0 to turn
5780 ** it back off again.
5781 **
5782 ** ^This interface enables or disables both the C-API
5783 ** [sqlite3_load_extension()] and the SQL function [load_extension()].
5784 ** Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
5785 ** to enable or disable only the C-API.
5786 **
5787 ** <b>Security warning:</b> It is recommended that extension loading
5788 ** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
5789 ** rather than this interface, so the [load_extension()] SQL function
5790 ** remains disabled. This will prevent SQL injections from giving attackers
5791 ** access to extension loading capabilities.
5792 */
5794 
5795 /*
5796 ** CAPI3REF: Automatically Load Statically Linked Extensions
5797 **
5798 ** ^This interface causes the xEntryPoint() function to be invoked for
5799 ** each new [database connection] that is created. The idea here is that
5800 ** xEntryPoint() is the entry point for a statically linked [SQLite extension]
5801 ** that is to be automatically loaded into all new database connections.
5802 **
5803 ** ^(Even though the function prototype shows that xEntryPoint() takes
5804 ** no arguments and returns void, SQLite invokes xEntryPoint() with three
5805 ** arguments and expects and integer result as if the signature of the
5806 ** entry point where as follows:
5807 **
5808 ** <blockquote><pre>
5809 ** &nbsp; int xEntryPoint(
5810 ** &nbsp; sqlite3 *db,
5811 ** &nbsp; const char **pzErrMsg,
5812 ** &nbsp; const struct sqlite3_api_routines *pThunk
5813 ** &nbsp; );
5814 ** </pre></blockquote>)^
5815 **
5816 ** If the xEntryPoint routine encounters an error, it should make *pzErrMsg
5817 ** point to an appropriate error message (obtained from [sqlite3_mprintf()])
5818 ** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg
5819 ** is NULL before calling the xEntryPoint(). ^SQLite will invoke
5820 ** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any
5821 ** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()],
5822 ** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail.
5823 **