/[zanavi_public1]/navit/navit/maptool/sqlite3.c
ZANavi

Contents of /navit/navit/maptool/sqlite3.c

Parent Directory Parent Directory | Revision Log Revision Log


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