1 | /****************************************************************************** |
2 | ** This file is an amalgamation of many separate C source files from SQLite |
3 | ** version 3.43.1. 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 | ** The content in this amalgamation comes from Fossil check-in |
21 | ** d3a40c05c49e1a49264912b1a05bc2143ac. |
22 | */ |
23 | #define SQLITE_CORE 1 |
24 | #define SQLITE_AMALGAMATION 1 |
25 | #ifndef SQLITE_PRIVATE |
26 | # define SQLITE_PRIVATE static |
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 | /* Special Comments: |
47 | ** |
48 | ** Some comments have special meaning to the tools that measure test |
49 | ** coverage: |
50 | ** |
51 | ** NO_TEST - The branches on this line are not |
52 | ** measured by branch coverage. This is |
53 | ** used on lines of code that actually |
54 | ** implement parts of coverage testing. |
55 | ** |
56 | ** OPTIMIZATION-IF-TRUE - This branch is allowed to always be false |
57 | ** and the correct answer is still obtained, |
58 | ** though perhaps more slowly. |
59 | ** |
60 | ** OPTIMIZATION-IF-FALSE - This branch is allowed to always be true |
61 | ** and the correct answer is still obtained, |
62 | ** though perhaps more slowly. |
63 | ** |
64 | ** PREVENTS-HARMLESS-OVERREAD - This branch prevents a buffer overread |
65 | ** that would be harmless and undetectable |
66 | ** if it did occur. |
67 | ** |
68 | ** In all cases, the special comment must be enclosed in the usual |
69 | ** slash-asterisk...asterisk-slash comment marks, with no spaces between the |
70 | ** asterisks and the comment text. |
71 | */ |
72 | |
73 | /* |
74 | ** Make sure the Tcl calling convention macro is defined. This macro is |
75 | ** only used by test code and Tcl integration code. |
76 | */ |
77 | #ifndef SQLITE_TCLAPI |
78 | # define SQLITE_TCLAPI |
79 | #endif |
80 | |
81 | /* |
82 | ** Include the header file used to customize the compiler options for MSVC. |
83 | ** This should be done first so that it can successfully prevent spurious |
84 | ** compiler warnings due to subsequent content in this file and other files |
85 | ** that are included by this file. |
86 | */ |
87 | /************** Include msvc.h in the middle of sqliteInt.h ******************/ |
88 | /************** Begin file msvc.h ********************************************/ |
89 | /* |
90 | ** 2015 January 12 |
91 | ** |
92 | ** The author disclaims copyright to this source code. In place of |
93 | ** a legal notice, here is a blessing: |
94 | ** |
95 | ** May you do good and not evil. |
96 | ** May you find forgiveness for yourself and forgive others. |
97 | ** May you share freely, never taking more than you give. |
98 | ** |
99 | ****************************************************************************** |
100 | ** |
101 | ** This file contains code that is specific to MSVC. |
102 | */ |
103 | #ifndef SQLITE_MSVC_H |
104 | #define SQLITE_MSVC_H |
105 | |
106 | #if defined(_MSC_VER) |
107 | #pragma warning(disable : 4054) |
108 | #pragma warning(disable : 4055) |
109 | #pragma warning(disable : 4100) |
110 | #pragma warning(disable : 4127) |
111 | #pragma warning(disable : 4130) |
112 | #pragma warning(disable : 4152) |
113 | #pragma warning(disable : 4189) |
114 | #pragma warning(disable : 4206) |
115 | #pragma warning(disable : 4210) |
116 | #pragma warning(disable : 4232) |
117 | #pragma warning(disable : 4244) |
118 | #pragma warning(disable : 4305) |
119 | #pragma warning(disable : 4306) |
120 | #pragma warning(disable : 4702) |
121 | #pragma warning(disable : 4706) |
122 | #endif /* defined(_MSC_VER) */ |
123 | |
124 | #if defined(_MSC_VER) && !defined(_WIN64) |
125 | #undef SQLITE_4_BYTE_ALIGNED_MALLOC |
126 | #define SQLITE_4_BYTE_ALIGNED_MALLOC |
127 | #endif /* defined(_MSC_VER) && !defined(_WIN64) */ |
128 | |
129 | #if !defined(HAVE_LOG2) && defined(_MSC_VER) && _MSC_VER<1800 |
130 | #define HAVE_LOG2 0 |
131 | #endif /* !defined(HAVE_LOG2) && defined(_MSC_VER) && _MSC_VER<1800 */ |
132 | |
133 | #endif /* SQLITE_MSVC_H */ |
134 | |
135 | /************** End of msvc.h ************************************************/ |
136 | /************** Continuing where we left off in sqliteInt.h ******************/ |
137 | |
138 | /* |
139 | ** Special setup for VxWorks |
140 | */ |
141 | /************** Include vxworks.h in the middle of sqliteInt.h ***************/ |
142 | /************** Begin file vxworks.h *****************************************/ |
143 | /* |
144 | ** 2015-03-02 |
145 | ** |
146 | ** The author disclaims copyright to this source code. In place of |
147 | ** a legal notice, here is a blessing: |
148 | ** |
149 | ** May you do good and not evil. |
150 | ** May you find forgiveness for yourself and forgive others. |
151 | ** May you share freely, never taking more than you give. |
152 | ** |
153 | ****************************************************************************** |
154 | ** |
155 | ** This file contains code that is specific to Wind River's VxWorks |
156 | */ |
157 | #if defined(__RTP__) || defined(_WRS_KERNEL) |
158 | /* This is VxWorks. Set up things specially for that OS |
159 | */ |
160 | #include <vxWorks.h> |
161 | #include <pthread.h> /* amalgamator: dontcache */ |
162 | #define OS_VXWORKS 1 |
163 | #define SQLITE_OS_OTHER 0 |
164 | #define SQLITE_HOMEGROWN_RECURSIVE_MUTEX 1 |
165 | #define SQLITE_OMIT_LOAD_EXTENSION 1 |
166 | #define SQLITE_ENABLE_LOCKING_STYLE 0 |
167 | #define HAVE_UTIME 1 |
168 | #else |
169 | /* This is not VxWorks. */ |
170 | #define OS_VXWORKS 0 |
171 | #define HAVE_FCHOWN 1 |
172 | #define HAVE_READLINK 1 |
173 | #define HAVE_LSTAT 1 |
174 | #endif /* defined(_WRS_KERNEL) */ |
175 | |
176 | /************** End of vxworks.h *********************************************/ |
177 | /************** Continuing where we left off in sqliteInt.h ******************/ |
178 | |
179 | /* |
180 | ** These #defines should enable >2GB file support on POSIX if the |
181 | ** underlying operating system supports it. If the OS lacks |
182 | ** large file support, or if the OS is windows, these should be no-ops. |
183 | ** |
184 | ** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any |
185 | ** system #includes. Hence, this block of code must be the very first |
186 | ** code in all source files. |
187 | ** |
188 | ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch |
189 | ** on the compiler command line. This is necessary if you are compiling |
190 | ** on a recent machine (ex: Red Hat 7.2) but you want your code to work |
191 | ** on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2 |
192 | ** without this option, LFS is enable. But LFS does not exist in the kernel |
193 | ** in Red Hat 6.0, so the code won't work. Hence, for maximum binary |
194 | ** portability you should omit LFS. |
195 | ** |
196 | ** The previous paragraph was written in 2005. (This paragraph is written |
197 | ** on 2008-11-28.) These days, all Linux kernels support large files, so |
198 | ** you should probably leave LFS enabled. But some embedded platforms might |
199 | ** lack LFS in which case the SQLITE_DISABLE_LFS macro might still be useful. |
200 | ** |
201 | ** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later. |
202 | */ |
203 | #ifndef SQLITE_DISABLE_LFS |
204 | # define _LARGE_FILE 1 |
205 | # ifndef _FILE_OFFSET_BITS |
206 | # define _FILE_OFFSET_BITS 64 |
207 | # endif |
208 | # define _LARGEFILE_SOURCE 1 |
209 | #endif |
210 | |
211 | /* The GCC_VERSION and MSVC_VERSION macros are used to |
212 | ** conditionally include optimizations for each of these compilers. A |
213 | ** value of 0 means that compiler is not being used. The |
214 | ** SQLITE_DISABLE_INTRINSIC macro means do not use any compiler-specific |
215 | ** optimizations, and hence set all compiler macros to 0 |
216 | ** |
217 | ** There was once also a CLANG_VERSION macro. However, we learn that the |
218 | ** version numbers in clang are for "marketing" only and are inconsistent |
219 | ** and unreliable. Fortunately, all versions of clang also recognize the |
220 | ** gcc version numbers and have reasonable settings for gcc version numbers, |
221 | ** so the GCC_VERSION macro will be set to a correct non-zero value even |
222 | ** when compiling with clang. |
223 | */ |
224 | #if defined(__GNUC__) && !defined(SQLITE_DISABLE_INTRINSIC) |
225 | # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__) |
226 | #else |
227 | # define GCC_VERSION 0 |
228 | #endif |
229 | #if defined(_MSC_VER) && !defined(SQLITE_DISABLE_INTRINSIC) |
230 | # define MSVC_VERSION _MSC_VER |
231 | #else |
232 | # define MSVC_VERSION 0 |
233 | #endif |
234 | |
235 | /* |
236 | ** Some C99 functions in "math.h" are only present for MSVC when its version |
237 | ** is associated with Visual Studio 2013 or higher. |
238 | */ |
239 | #ifndef SQLITE_HAVE_C99_MATH_FUNCS |
240 | # if MSVC_VERSION==0 || MSVC_VERSION>=1800 |
241 | # define SQLITE_HAVE_C99_MATH_FUNCS (1) |
242 | # else |
243 | # define SQLITE_HAVE_C99_MATH_FUNCS (0) |
244 | # endif |
245 | #endif |
246 | |
247 | /* Needed for various definitions... */ |
248 | #if defined(__GNUC__) && !defined(_GNU_SOURCE) |
249 | # define _GNU_SOURCE |
250 | #endif |
251 | |
252 | #if defined(__OpenBSD__) && !defined(_BSD_SOURCE) |
253 | # define _BSD_SOURCE |
254 | #endif |
255 | |
256 | /* |
257 | ** Macro to disable warnings about missing "break" at the end of a "case". |
258 | */ |
259 | #if GCC_VERSION>=7000000 |
260 | # define deliberate_fall_through __attribute__((fallthrough)); |
261 | #else |
262 | # define deliberate_fall_through |
263 | #endif |
264 | |
265 | /* |
266 | ** For MinGW, check to see if we can include the header file containing its |
267 | ** version information, among other things. Normally, this internal MinGW |
268 | ** header file would [only] be included automatically by other MinGW header |
269 | ** files; however, the contained version information is now required by this |
270 | ** header file to work around binary compatibility issues (see below) and |
271 | ** this is the only known way to reliably obtain it. This entire #if block |
272 | ** would be completely unnecessary if there was any other way of detecting |
273 | ** MinGW via their preprocessor (e.g. if they customized their GCC to define |
274 | ** some MinGW-specific macros). When compiling for MinGW, either the |
275 | ** _HAVE_MINGW_H or _HAVE__MINGW_H (note the extra underscore) macro must be |
276 | ** defined; otherwise, detection of conditions specific to MinGW will be |
277 | ** disabled. |
278 | */ |
279 | #if defined(_HAVE_MINGW_H) |
280 | # include "mingw.h" |
281 | #elif defined(_HAVE__MINGW_H) |
282 | # include "_mingw.h" |
283 | #endif |
284 | |
285 | /* |
286 | ** For MinGW version 4.x (and higher), check to see if the _USE_32BIT_TIME_T |
287 | ** define is required to maintain binary compatibility with the MSVC runtime |
288 | ** library in use (e.g. for Windows XP). |
289 | */ |
290 | #if !defined(_USE_32BIT_TIME_T) && !defined(_USE_64BIT_TIME_T) && \ |
291 | defined(_WIN32) && !defined(_WIN64) && \ |
292 | defined(__MINGW_MAJOR_VERSION) && __MINGW_MAJOR_VERSION >= 4 && \ |
293 | defined(__MSVCRT__) |
294 | # define _USE_32BIT_TIME_T |
295 | #endif |
296 | |
297 | /* Optionally #include a user-defined header, whereby compilation options |
298 | ** may be set prior to where they take effect, but after platform setup. |
299 | ** If SQLITE_CUSTOM_INCLUDE=? is defined, its value names the #include |
300 | ** file. |
301 | */ |
302 | #ifdef SQLITE_CUSTOM_INCLUDE |
303 | # define INC_STRINGIFY_(f) #f |
304 | # define INC_STRINGIFY(f) INC_STRINGIFY_(f) |
305 | # include INC_STRINGIFY(SQLITE_CUSTOM_INCLUDE) |
306 | #endif |
307 | |
308 | /* The public SQLite interface. The _FILE_OFFSET_BITS macro must appear |
309 | ** first in QNX. Also, the _USE_32BIT_TIME_T macro must appear first for |
310 | ** MinGW. |
311 | */ |
312 | /************** Include sqlite3.h in the middle of sqliteInt.h ***************/ |
313 | /************** Begin file sqlite3.h *****************************************/ |
314 | /* |
315 | ** 2001-09-15 |
316 | ** |
317 | ** The author disclaims copyright to this source code. In place of |
318 | ** a legal notice, here is a blessing: |
319 | ** |
320 | ** May you do good and not evil. |
321 | ** May you find forgiveness for yourself and forgive others. |
322 | ** May you share freely, never taking more than you give. |
323 | ** |
324 | ************************************************************************* |
325 | ** This header file defines the interface that the SQLite library |
326 | ** presents to client programs. If a C-function, structure, datatype, |
327 | ** or constant definition does not appear in this file, then it is |
328 | ** not a published API of SQLite, is subject to change without |
329 | ** notice, and should not be referenced by programs that use SQLite. |
330 | ** |
331 | ** Some of the definitions that are in this file are marked as |
332 | ** "experimental". Experimental interfaces are normally new |
333 | ** features recently added to SQLite. We do not anticipate changes |
334 | ** to experimental interfaces but reserve the right to make minor changes |
335 | ** if experience from use "in the wild" suggest such changes are prudent. |
336 | ** |
337 | ** The official C-language API documentation for SQLite is derived |
338 | ** from comments in this file. This file is the authoritative source |
339 | ** on how SQLite interfaces are supposed to operate. |
340 | ** |
341 | ** The name of this file under configuration management is "sqlite.h.in". |
342 | ** The makefile makes some minor changes to this file (such as inserting |
343 | ** the version number) and changes its name to "sqlite3.h" as |
344 | ** part of the build process. |
345 | */ |
346 | #ifndef SQLITE3_H |
347 | #define SQLITE3_H |
348 | #include <stdarg.h> /* Needed for the definition of va_list */ |
349 | |
350 | /* |
351 | ** Make sure we can call this stuff from C++. |
352 | */ |
353 | #if 0 |
354 | extern "C" { |
355 | #endif |
356 | |
357 | |
358 | /* |
359 | ** Facilitate override of interface linkage and calling conventions. |
360 | ** Be aware that these macros may not be used within this particular |
361 | ** translation of the amalgamation and its associated header file. |
362 | ** |
363 | ** The SQLITE_EXTERN and SQLITE_API macros are used to instruct the |
364 | ** compiler that the target identifier should have external linkage. |
365 | ** |
366 | ** The SQLITE_CDECL macro is used to set the calling convention for |
367 | ** public functions that accept a variable number of arguments. |
368 | ** |
369 | ** The SQLITE_APICALL macro is used to set the calling convention for |
370 | ** public functions that accept a fixed number of arguments. |
371 | ** |
372 | ** The SQLITE_STDCALL macro is no longer used and is now deprecated. |
373 | ** |
374 | ** The SQLITE_CALLBACK macro is used to set the calling convention for |
375 | ** function pointers. |
376 | ** |
377 | ** The SQLITE_SYSAPI macro is used to set the calling convention for |
378 | ** functions provided by the operating system. |
379 | ** |
380 | ** Currently, the SQLITE_CDECL, SQLITE_APICALL, SQLITE_CALLBACK, and |
381 | ** SQLITE_SYSAPI macros are used only when building for environments |
382 | ** that require non-default calling conventions. |
383 | */ |
384 | #ifndef SQLITE_EXTERN |
385 | # define SQLITE_EXTERN extern |
386 | #endif |
387 | #ifndef SQLITE_API |
388 | # define SQLITE_API |
389 | #endif |
390 | #ifndef SQLITE_CDECL |
391 | # define SQLITE_CDECL |
392 | #endif |
393 | #ifndef SQLITE_APICALL |
394 | # define SQLITE_APICALL |
395 | #endif |
396 | #ifndef SQLITE_STDCALL |
397 | # define SQLITE_STDCALL SQLITE_APICALL |
398 | #endif |
399 | #ifndef SQLITE_CALLBACK |
400 | # define SQLITE_CALLBACK |
401 | #endif |
402 | #ifndef SQLITE_SYSAPI |
403 | # define SQLITE_SYSAPI |
404 | #endif |
405 | |
406 | /* |
407 | ** These no-op macros are used in front of interfaces to mark those |
408 | ** interfaces as either deprecated or experimental. New applications |
409 | ** should not use deprecated interfaces - they are supported for backwards |
410 | ** compatibility only. Application writers should be aware that |
411 | ** experimental interfaces are subject to change in point releases. |
412 | ** |
413 | ** These macros used to resolve to various kinds of compiler magic that |
414 | ** would generate warning messages when they were used. But that |
415 | ** compiler magic ended up generating such a flurry of bug reports |
416 | ** that we have taken it all out and gone back to using simple |
417 | ** noop macros. |
418 | */ |
419 | #define SQLITE_DEPRECATED |
420 | #define SQLITE_EXPERIMENTAL |
421 | |
422 | /* |
423 | ** Ensure these symbols were not defined by some previous header file. |
424 | */ |
425 | #ifdef SQLITE_VERSION |
426 | # undef SQLITE_VERSION |
427 | #endif |
428 | #ifdef SQLITE_VERSION_NUMBER |
429 | # undef SQLITE_VERSION_NUMBER |
430 | #endif |
431 | |
432 | /* |
433 | ** CAPI3REF: Compile-Time Library Version Numbers |
434 | ** |
435 | ** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header |
436 | ** evaluates to a string literal that is the SQLite version in the |
437 | ** format "X.Y.Z" where X is the major version number (always 3 for |
438 | ** SQLite3) and Y is the minor version number and Z is the release number.)^ |
439 | ** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer |
440 | ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same |
441 | ** numbers used in [SQLITE_VERSION].)^ |
442 | ** The SQLITE_VERSION_NUMBER for any given release of SQLite will also |
443 | ** be larger than the release from which it is derived. Either Y will |
444 | ** be held constant and Z will be incremented or else Y will be incremented |
445 | ** and Z will be reset to zero. |
446 | ** |
447 | ** Since [version 3.6.18] ([dateof:3.6.18]), |
448 | ** SQLite source code has been stored in the |
449 | ** <a href="http://www.fossil-scm.org/">Fossil configuration management |
450 | ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to |
451 | ** a string which identifies a particular check-in of SQLite |
452 | ** within its configuration management system. ^The SQLITE_SOURCE_ID |
453 | ** string contains the date and time of the check-in (UTC) and a SHA1 |
454 | ** or SHA3-256 hash of the entire source tree. If the source code has |
455 | ** been edited in any way since it was last checked in, then the last |
456 | ** four hexadecimal digits of the hash may be modified. |
457 | ** |
458 | ** See also: [sqlite3_libversion()], |
459 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
460 | ** [sqlite_version()] and [sqlite_source_id()]. |
461 | */ |
462 | #define SQLITE_VERSION "3.43.1" |
463 | #define SQLITE_VERSION_NUMBER 3043001 |
464 | #define SQLITE_SOURCE_ID "2023-09-11 12:01:27 2d3a40c05c49e1a49264912b1a05bc2143ac0e7c3df588276ce80a4cbc9bd1b0" |
465 | |
466 | /* |
467 | ** CAPI3REF: Run-Time Library Version Numbers |
468 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
469 | ** |
470 | ** These interfaces provide the same information as the [SQLITE_VERSION], |
471 | ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros |
472 | ** but are associated with the library instead of the header file. ^(Cautious |
473 | ** programmers might include assert() statements in their application to |
474 | ** verify that values returned by these interfaces match the macros in |
475 | ** the header, and thus ensure that the application is |
476 | ** compiled with matching library and header files. |
477 | ** |
478 | ** <blockquote><pre> |
479 | ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER ); |
480 | ** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 ); |
481 | ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 ); |
482 | ** </pre></blockquote>)^ |
483 | ** |
484 | ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION] |
485 | ** macro. ^The sqlite3_libversion() function returns a pointer to the |
486 | ** to the sqlite3_version[] string constant. The sqlite3_libversion() |
487 | ** function is provided for use in DLLs since DLL users usually do not have |
488 | ** direct access to string constants within the DLL. ^The |
489 | ** sqlite3_libversion_number() function returns an integer equal to |
490 | ** [SQLITE_VERSION_NUMBER]. ^(The sqlite3_sourceid() function returns |
491 | ** a pointer to a string constant whose value is the same as the |
492 | ** [SQLITE_SOURCE_ID] C preprocessor macro. Except if SQLite is built |
493 | ** using an edited copy of [the amalgamation], then the last four characters |
494 | ** of the hash might be different from [SQLITE_SOURCE_ID].)^ |
495 | ** |
496 | ** See also: [sqlite_version()] and [sqlite_source_id()]. |
497 | */ |
498 | SQLITE_API const char sqlite3_version[] = SQLITE_VERSION; |
499 | SQLITE_API const char *sqlite3_libversion(void); |
500 | SQLITE_API const char *sqlite3_sourceid(void); |
501 | SQLITE_API int sqlite3_libversion_number(void); |
502 | |
503 | /* |
504 | ** CAPI3REF: Run-Time Library Compilation Options Diagnostics |
505 | ** |
506 | ** ^The sqlite3_compileoption_used() function returns 0 or 1 |
507 | ** indicating whether the specified option was defined at |
508 | ** compile time. ^The SQLITE_ prefix may be omitted from the |
509 | ** option name passed to sqlite3_compileoption_used(). |
510 | ** |
511 | ** ^The sqlite3_compileoption_get() function allows iterating |
512 | ** over the list of options that were defined at compile time by |
513 | ** returning the N-th compile time option string. ^If N is out of range, |
514 | ** sqlite3_compileoption_get() returns a NULL pointer. ^The SQLITE_ |
515 | ** prefix is omitted from any strings returned by |
516 | ** sqlite3_compileoption_get(). |
517 | ** |
518 | ** ^Support for the diagnostic functions sqlite3_compileoption_used() |
519 | ** and sqlite3_compileoption_get() may be omitted by specifying the |
520 | ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time. |
521 | ** |
522 | ** See also: SQL functions [sqlite_compileoption_used()] and |
523 | ** [sqlite_compileoption_get()] and the [compile_options pragma]. |
524 | */ |
525 | #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
526 | SQLITE_API int sqlite3_compileoption_used(const char *zOptName); |
527 | SQLITE_API const char *sqlite3_compileoption_get(int N); |
528 | #else |
529 | # define sqlite3_compileoption_used(X) 0 |
530 | # define sqlite3_compileoption_get(X) ((void*)0) |
531 | #endif |
532 | |
533 | /* |
534 | ** CAPI3REF: Test To See If The Library Is Threadsafe |
535 | ** |
536 | ** ^The sqlite3_threadsafe() function returns zero if and only if |
537 | ** SQLite was compiled with mutexing code omitted due to the |
538 | ** [SQLITE_THREADSAFE] compile-time option being set to 0. |
539 | ** |
540 | ** SQLite can be compiled with or without mutexes. When |
541 | ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes |
542 | ** are enabled and SQLite is threadsafe. When the |
543 | ** [SQLITE_THREADSAFE] macro is 0, |
544 | ** the mutexes are omitted. Without the mutexes, it is not safe |
545 | ** to use SQLite concurrently from more than one thread. |
546 | ** |
547 | ** Enabling mutexes incurs a measurable performance penalty. |
548 | ** So if speed is of utmost importance, it makes sense to disable |
549 | ** the mutexes. But for maximum safety, mutexes should be enabled. |
550 | ** ^The default behavior is for mutexes to be enabled. |
551 | ** |
552 | ** This interface can be used by an application to make sure that the |
553 | ** version of SQLite that it is linking against was compiled with |
554 | ** the desired setting of the [SQLITE_THREADSAFE] macro. |
555 | ** |
556 | ** This interface only reports on the compile-time mutex setting |
557 | ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with |
558 | ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but |
559 | ** can be fully or partially disabled using a call to [sqlite3_config()] |
560 | ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD], |
561 | ** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the |
562 | ** sqlite3_threadsafe() function shows only the compile-time setting of |
563 | ** thread safety, not any run-time changes to that setting made by |
564 | ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe() |
565 | ** is unchanged by calls to sqlite3_config().)^ |
566 | ** |
567 | ** See the [threading mode] documentation for additional information. |
568 | */ |
569 | SQLITE_API int sqlite3_threadsafe(void); |
570 | |
571 | /* |
572 | ** CAPI3REF: Database Connection Handle |
573 | ** KEYWORDS: {database connection} {database connections} |
574 | ** |
575 | ** Each open SQLite database is represented by a pointer to an instance of |
576 | ** the opaque structure named "sqlite3". It is useful to think of an sqlite3 |
577 | ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and |
578 | ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()] |
579 | ** and [sqlite3_close_v2()] are its destructors. There are many other |
580 | ** interfaces (such as |
581 | ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and |
582 | ** [sqlite3_busy_timeout()] to name but three) that are methods on an |
583 | ** sqlite3 object. |
584 | */ |
585 | typedef struct sqlite3 sqlite3; |
586 | |
587 | /* |
588 | ** CAPI3REF: 64-Bit Integer Types |
589 | ** KEYWORDS: sqlite_int64 sqlite_uint64 |
590 | ** |
591 | ** Because there is no cross-platform way to specify 64-bit integer types |
592 | ** SQLite includes typedefs for 64-bit signed and unsigned integers. |
593 | ** |
594 | ** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions. |
595 | ** The sqlite_int64 and sqlite_uint64 types are supported for backwards |
596 | ** compatibility only. |
597 | ** |
598 | ** ^The sqlite3_int64 and sqlite_int64 types can store integer values |
599 | ** between -9223372036854775808 and +9223372036854775807 inclusive. ^The |
600 | ** sqlite3_uint64 and sqlite_uint64 types can store integer values |
601 | ** between 0 and +18446744073709551615 inclusive. |
602 | */ |
603 | #ifdef SQLITE_INT64_TYPE |
604 | typedef SQLITE_INT64_TYPE sqlite_int64; |
605 | # ifdef SQLITE_UINT64_TYPE |
606 | typedef SQLITE_UINT64_TYPE sqlite_uint64; |
607 | # else |
608 | typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; |
609 | # endif |
610 | #elif defined(_MSC_VER) || defined(__BORLANDC__) |
611 | typedef __int64 sqlite_int64; |
612 | typedef unsigned __int64 sqlite_uint64; |
613 | #else |
614 | typedef long long int sqlite_int64; |
615 | typedef unsigned long long int sqlite_uint64; |
616 | #endif |
617 | typedef sqlite_int64 sqlite3_int64; |
618 | typedef sqlite_uint64 sqlite3_uint64; |
619 | |
620 | /* |
621 | ** If compiling for a processor that lacks floating point support, |
622 | ** substitute integer for floating-point. |
623 | */ |
624 | #ifdef SQLITE_OMIT_FLOATING_POINT |
625 | # define double sqlite3_int64 |
626 | #endif |
627 | |
628 | /* |
629 | ** CAPI3REF: Closing A Database Connection |
630 | ** DESTRUCTOR: sqlite3 |
631 | ** |
632 | ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors |
633 | ** for the [sqlite3] object. |
634 | ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if |
635 | ** the [sqlite3] object is successfully destroyed and all associated |
636 | ** resources are deallocated. |
637 | ** |
638 | ** Ideally, applications should [sqlite3_finalize | finalize] all |
639 | ** [prepared statements], [sqlite3_blob_close | close] all [BLOB handles], and |
640 | ** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated |
641 | ** with the [sqlite3] object prior to attempting to close the object. |
642 | ** ^If the database connection is associated with unfinalized prepared |
643 | ** statements, BLOB handlers, and/or unfinished sqlite3_backup objects then |
644 | ** sqlite3_close() will leave the database connection open and return |
645 | ** [SQLITE_BUSY]. ^If sqlite3_close_v2() is called with unfinalized prepared |
646 | ** statements, unclosed BLOB handlers, and/or unfinished sqlite3_backups, |
647 | ** it returns [SQLITE_OK] regardless, but instead of deallocating the database |
648 | ** connection immediately, it marks the database connection as an unusable |
649 | ** "zombie" and makes arrangements to automatically deallocate the database |
650 | ** connection after all prepared statements are finalized, all BLOB handles |
651 | ** are closed, and all backups have finished. The sqlite3_close_v2() interface |
652 | ** is intended for use with host languages that are garbage collected, and |
653 | ** where the order in which destructors are called is arbitrary. |
654 | ** |
655 | ** ^If an [sqlite3] object is destroyed while a transaction is open, |
656 | ** the transaction is automatically rolled back. |
657 | ** |
658 | ** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)] |
659 | ** must be either a NULL |
660 | ** pointer or an [sqlite3] object pointer obtained |
661 | ** from [sqlite3_open()], [sqlite3_open16()], or |
662 | ** [sqlite3_open_v2()], and not previously closed. |
663 | ** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer |
664 | ** argument is a harmless no-op. |
665 | */ |
666 | SQLITE_API int sqlite3_close(sqlite3*); |
667 | SQLITE_API int sqlite3_close_v2(sqlite3*); |
668 | |
669 | /* |
670 | ** The type for a callback function. |
671 | ** This is legacy and deprecated. It is included for historical |
672 | ** compatibility and is not documented. |
673 | */ |
674 | typedef int (*sqlite3_callback)(void*,int,char**, char**); |
675 | |
676 | /* |
677 | ** CAPI3REF: One-Step Query Execution Interface |
678 | ** METHOD: sqlite3 |
679 | ** |
680 | ** The sqlite3_exec() interface is a convenience wrapper around |
681 | ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()], |
682 | ** that allows an application to run multiple statements of SQL |
683 | ** without having to use a lot of C code. |
684 | ** |
685 | ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded, |
686 | ** semicolon-separate SQL statements passed into its 2nd argument, |
687 | ** in the context of the [database connection] passed in as its 1st |
688 | ** argument. ^If the callback function of the 3rd argument to |
689 | ** sqlite3_exec() is not NULL, then it is invoked for each result row |
690 | ** coming out of the evaluated SQL statements. ^The 4th argument to |
691 | ** sqlite3_exec() is relayed through to the 1st argument of each |
692 | ** callback invocation. ^If the callback pointer to sqlite3_exec() |
693 | ** is NULL, then no callback is ever invoked and result rows are |
694 | ** ignored. |
695 | ** |
696 | ** ^If an error occurs while evaluating the SQL statements passed into |
697 | ** sqlite3_exec(), then execution of the current statement stops and |
698 | ** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec() |
699 | ** is not NULL then any error message is written into memory obtained |
700 | ** from [sqlite3_malloc()] and passed back through the 5th parameter. |
701 | ** To avoid memory leaks, the application should invoke [sqlite3_free()] |
702 | ** on error message strings returned through the 5th parameter of |
703 | ** sqlite3_exec() after the error message string is no longer needed. |
704 | ** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors |
705 | ** occur, then sqlite3_exec() sets the pointer in its 5th parameter to |
706 | ** NULL before returning. |
707 | ** |
708 | ** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec() |
709 | ** routine returns SQLITE_ABORT without invoking the callback again and |
710 | ** without running any subsequent SQL statements. |
711 | ** |
712 | ** ^The 2nd argument to the sqlite3_exec() callback function is the |
713 | ** number of columns in the result. ^The 3rd argument to the sqlite3_exec() |
714 | ** callback is an array of pointers to strings obtained as if from |
715 | ** [sqlite3_column_text()], one for each column. ^If an element of a |
716 | ** result row is NULL then the corresponding string pointer for the |
717 | ** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the |
718 | ** sqlite3_exec() callback is an array of pointers to strings where each |
719 | ** entry represents the name of corresponding result column as obtained |
720 | ** from [sqlite3_column_name()]. |
721 | ** |
722 | ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer |
723 | ** to an empty string, or a pointer that contains only whitespace and/or |
724 | ** SQL comments, then no SQL statements are evaluated and the database |
725 | ** is not changed. |
726 | ** |
727 | ** Restrictions: |
728 | ** |
729 | ** <ul> |
730 | ** <li> The application must ensure that the 1st parameter to sqlite3_exec() |
731 | ** is a valid and open [database connection]. |
732 | ** <li> The application must not close the [database connection] specified by |
733 | ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running. |
734 | ** <li> The application must not modify the SQL statement text passed into |
735 | ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running. |
736 | ** </ul> |
737 | */ |
738 | SQLITE_API int sqlite3_exec( |
739 | sqlite3*, /* An open database */ |
740 | const char *sql, /* SQL to be evaluated */ |
741 | int (*callback)(void*,int,char**,char**), /* Callback function */ |
742 | void *, /* 1st argument to callback */ |
743 | char **errmsg /* Error msg written here */ |
744 | ); |
745 | |
746 | /* |
747 | ** CAPI3REF: Result Codes |
748 | ** KEYWORDS: {result code definitions} |
749 | ** |
750 | ** Many SQLite functions return an integer result code from the set shown |
751 | ** here in order to indicate success or failure. |
752 | ** |
753 | ** New error codes may be added in future versions of SQLite. |
754 | ** |
755 | ** See also: [extended result code definitions] |
756 | */ |
757 | #define SQLITE_OK 0 /* Successful result */ |
758 | /* beginning-of-error-codes */ |
759 | #define SQLITE_ERROR 1 /* Generic error */ |
760 | #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ |
761 | #define SQLITE_PERM 3 /* Access permission denied */ |
762 | #define SQLITE_ABORT 4 /* Callback routine requested an abort */ |
763 | #define SQLITE_BUSY 5 /* The database file is locked */ |
764 | #define SQLITE_LOCKED 6 /* A table in the database is locked */ |
765 | #define SQLITE_NOMEM 7 /* A malloc() failed */ |
766 | #define SQLITE_READONLY 8 /* Attempt to write a readonly database */ |
767 | #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/ |
768 | #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ |
769 | #define SQLITE_CORRUPT 11 /* The database disk image is malformed */ |
770 | #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */ |
771 | #define SQLITE_FULL 13 /* Insertion failed because database is full */ |
772 | #define SQLITE_CANTOPEN 14 /* Unable to open the database file */ |
773 | #define SQLITE_PROTOCOL 15 /* Database lock protocol error */ |
774 | #define SQLITE_EMPTY 16 /* Internal use only */ |
775 | #define SQLITE_SCHEMA 17 /* The database schema changed */ |
776 | #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */ |
777 | #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */ |
778 | #define SQLITE_MISMATCH 20 /* Data type mismatch */ |
779 | #define SQLITE_MISUSE 21 /* Library used incorrectly */ |
780 | #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */ |
781 | #define SQLITE_AUTH 23 /* Authorization denied */ |
782 | #define SQLITE_FORMAT 24 /* Not used */ |
783 | #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */ |
784 | #define SQLITE_NOTADB 26 /* File opened that is not a database file */ |
785 | #define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */ |
786 | #define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */ |
787 | #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */ |
788 | #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ |
789 | /* end-of-error-codes */ |
790 | |
791 | /* |
792 | ** CAPI3REF: Extended Result Codes |
793 | ** KEYWORDS: {extended result code definitions} |
794 | ** |
795 | ** In its default configuration, SQLite API routines return one of 30 integer |
796 | ** [result codes]. However, experience has shown that many of |
797 | ** these result codes are too coarse-grained. They do not provide as |
798 | ** much information about problems as programmers might like. In an effort to |
799 | ** address this, newer versions of SQLite (version 3.3.8 [dateof:3.3.8] |
800 | ** and later) include |
801 | ** support for additional result codes that provide more detailed information |
802 | ** about errors. These [extended result codes] are enabled or disabled |
803 | ** on a per database connection basis using the |
804 | ** [sqlite3_extended_result_codes()] API. Or, the extended code for |
805 | ** the most recent error can be obtained using |
806 | ** [sqlite3_extended_errcode()]. |
807 | */ |
808 | #define SQLITE_ERROR_MISSING_COLLSEQ (SQLITE_ERROR | (1<<8)) |
809 | #define SQLITE_ERROR_RETRY (SQLITE_ERROR | (2<<8)) |
810 | #define SQLITE_ERROR_SNAPSHOT (SQLITE_ERROR | (3<<8)) |
811 | #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) |
812 | #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) |
813 | #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) |
814 | #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) |
815 | #define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) |
816 | #define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) |
817 | #define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) |
818 | #define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) |
819 | #define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) |
820 | #define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) |
821 | #define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) |
822 | #define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) |
823 | #define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8)) |
824 | #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8)) |
825 | #define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8)) |
826 | #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8)) |
827 | #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8)) |
828 | #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) |
829 | #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) |
830 | #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) |
831 | #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) |
832 | #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) |
833 | #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8)) |
834 | #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8)) |
835 | #define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8)) |
836 | #define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8)) |
837 | #define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8)) |
838 | #define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8)) |
839 | #define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8)) |
840 | #define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8)) |
841 | #define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8)) |
842 | #define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8)) |
843 | #define SQLITE_IOERR_CORRUPTFS (SQLITE_IOERR | (33<<8)) |
844 | #define SQLITE_IOERR_IN_PAGE (SQLITE_IOERR | (34<<8)) |
845 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
846 | #define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8)) |
847 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
848 | #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8)) |
849 | #define SQLITE_BUSY_TIMEOUT (SQLITE_BUSY | (3<<8)) |
850 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
851 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
852 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
853 | #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) |
854 | #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */ |
855 | #define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8)) |
856 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
857 | #define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8)) |
858 | #define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8)) |
859 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
860 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
861 | #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) |
862 | #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8)) |
863 | #define SQLITE_READONLY_CANTINIT (SQLITE_READONLY | (5<<8)) |
864 | #define SQLITE_READONLY_DIRECTORY (SQLITE_READONLY | (6<<8)) |
865 | #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) |
866 | #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) |
867 | #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) |
868 | #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) |
869 | #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) |
870 | #define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8)) |
871 | #define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8)) |
872 | #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8)) |
873 | #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8)) |
874 | #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8)) |
875 | #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8)) |
876 | #define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT |(11<<8)) |
877 | #define SQLITE_CONSTRAINT_DATATYPE (SQLITE_CONSTRAINT |(12<<8)) |
878 | #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8)) |
879 | #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8)) |
880 | #define SQLITE_NOTICE_RBU (SQLITE_NOTICE | (3<<8)) |
881 | #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8)) |
882 | #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8)) |
883 | #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8)) |
884 | #define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */ |
885 | |
886 | /* |
887 | ** CAPI3REF: Flags For File Open Operations |
888 | ** |
889 | ** These bit values are intended for use in the |
890 | ** 3rd parameter to the [sqlite3_open_v2()] interface and |
891 | ** in the 4th parameter to the [sqlite3_vfs.xOpen] method. |
892 | ** |
893 | ** Only those flags marked as "Ok for sqlite3_open_v2()" may be |
894 | ** used as the third argument to the [sqlite3_open_v2()] interface. |
895 | ** The other flags have historically been ignored by sqlite3_open_v2(), |
896 | ** though future versions of SQLite might change so that an error is |
897 | ** raised if any of the disallowed bits are passed into sqlite3_open_v2(). |
898 | ** Applications should not depend on the historical behavior. |
899 | ** |
900 | ** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into |
901 | ** [sqlite3_open_v2()] does *not* cause the underlying database file |
902 | ** to be opened using O_EXCL. Passing SQLITE_OPEN_EXCLUSIVE into |
903 | ** [sqlite3_open_v2()] has historically be a no-op and might become an |
904 | ** error in future versions of SQLite. |
905 | */ |
906 | #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ |
907 | #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ |
908 | #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ |
909 | #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ |
910 | #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ |
911 | #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ |
912 | #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */ |
913 | #define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */ |
914 | #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ |
915 | #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ |
916 | #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ |
917 | #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ |
918 | #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ |
919 | #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */ |
920 | #define SQLITE_OPEN_SUPER_JOURNAL 0x00004000 /* VFS only */ |
921 | #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */ |
922 | #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ |
923 | #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ |
924 | #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ |
925 | #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ |
926 | #define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */ |
927 | #define SQLITE_OPEN_EXRESCODE 0x02000000 /* Extended result codes */ |
928 | |
929 | /* Reserved: 0x00F00000 */ |
930 | /* Legacy compatibility: */ |
931 | #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ |
932 | |
933 | |
934 | /* |
935 | ** CAPI3REF: Device Characteristics |
936 | ** |
937 | ** The xDeviceCharacteristics method of the [sqlite3_io_methods] |
938 | ** object returns an integer which is a vector of these |
939 | ** bit values expressing I/O characteristics of the mass storage |
940 | ** device that holds the file that the [sqlite3_io_methods] |
941 | ** refers to. |
942 | ** |
943 | ** The SQLITE_IOCAP_ATOMIC property means that all writes of |
944 | ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values |
945 | ** mean that writes of blocks that are nnn bytes in size and |
946 | ** are aligned to an address which is an integer multiple of |
947 | ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means |
948 | ** that when data is appended to a file, the data is appended |
949 | ** first then the size of the file is extended, never the other |
950 | ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that |
951 | ** information is written to disk in the same order as calls |
952 | ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that |
953 | ** after reboot following a crash or power loss, the only bytes in a |
954 | ** file that were written at the application level might have changed |
955 | ** and that adjacent bytes, even bytes within the same sector are |
956 | ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN |
957 | ** flag indicates that a file cannot be deleted when open. The |
958 | ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on |
959 | ** read-only media and cannot be changed even by processes with |
960 | ** elevated privileges. |
961 | ** |
962 | ** The SQLITE_IOCAP_BATCH_ATOMIC property means that the underlying |
963 | ** filesystem supports doing multiple write operations atomically when those |
964 | ** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and |
965 | ** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]. |
966 | */ |
967 | #define SQLITE_IOCAP_ATOMIC 0x00000001 |
968 | #define SQLITE_IOCAP_ATOMIC512 0x00000002 |
969 | #define SQLITE_IOCAP_ATOMIC1K 0x00000004 |
970 | #define SQLITE_IOCAP_ATOMIC2K 0x00000008 |
971 | #define SQLITE_IOCAP_ATOMIC4K 0x00000010 |
972 | #define SQLITE_IOCAP_ATOMIC8K 0x00000020 |
973 | #define SQLITE_IOCAP_ATOMIC16K 0x00000040 |
974 | #define SQLITE_IOCAP_ATOMIC32K 0x00000080 |
975 | #define SQLITE_IOCAP_ATOMIC64K 0x00000100 |
976 | #define SQLITE_IOCAP_SAFE_APPEND 0x00000200 |
977 | #define SQLITE_IOCAP_SEQUENTIAL 0x00000400 |
978 | #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800 |
979 | #define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000 |
980 | #define SQLITE_IOCAP_IMMUTABLE 0x00002000 |
981 | #define SQLITE_IOCAP_BATCH_ATOMIC 0x00004000 |
982 | |
983 | /* |
984 | ** CAPI3REF: File Locking Levels |
985 | ** |
986 | ** SQLite uses one of these integer values as the second |
987 | ** argument to calls it makes to the xLock() and xUnlock() methods |
988 | ** of an [sqlite3_io_methods] object. These values are ordered from |
989 | ** lest restrictive to most restrictive. |
990 | ** |
991 | ** The argument to xLock() is always SHARED or higher. The argument to |
992 | ** xUnlock is either SHARED or NONE. |
993 | */ |
994 | #define SQLITE_LOCK_NONE 0 /* xUnlock() only */ |
995 | #define SQLITE_LOCK_SHARED 1 /* xLock() or xUnlock() */ |
996 | #define SQLITE_LOCK_RESERVED 2 /* xLock() only */ |
997 | #define SQLITE_LOCK_PENDING 3 /* xLock() only */ |
998 | #define SQLITE_LOCK_EXCLUSIVE 4 /* xLock() only */ |
999 | |
1000 | /* |
1001 | ** CAPI3REF: Synchronization Type Flags |
1002 | ** |
1003 | ** When SQLite invokes the xSync() method of an |
1004 | ** [sqlite3_io_methods] object it uses a combination of |
1005 | ** these integer values as the second argument. |
1006 | ** |
1007 | ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the |
1008 | ** sync operation only needs to flush data to mass storage. Inode |
1009 | ** information need not be flushed. If the lower four bits of the flag |
1010 | ** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics. |
1011 | ** If the lower four bits equal SQLITE_SYNC_FULL, that means |
1012 | ** to use Mac OS X style fullsync instead of fsync(). |
1013 | ** |
1014 | ** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags |
1015 | ** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL |
1016 | ** settings. The [synchronous pragma] determines when calls to the |
1017 | ** xSync VFS method occur and applies uniformly across all platforms. |
1018 | ** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how |
1019 | ** energetic or rigorous or forceful the sync operations are and |
1020 | ** only make a difference on Mac OSX for the default SQLite code. |
1021 | ** (Third-party VFS implementations might also make the distinction |
1022 | ** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the |
1023 | ** operating systems natively supported by SQLite, only Mac OSX |
1024 | ** cares about the difference.) |
1025 | */ |
1026 | #define SQLITE_SYNC_NORMAL 0x00002 |
1027 | #define SQLITE_SYNC_FULL 0x00003 |
1028 | #define SQLITE_SYNC_DATAONLY 0x00010 |
1029 | |
1030 | /* |
1031 | ** CAPI3REF: OS Interface Open File Handle |
1032 | ** |
1033 | ** An [sqlite3_file] object represents an open file in the |
1034 | ** [sqlite3_vfs | OS interface layer]. Individual OS interface |
1035 | ** implementations will |
1036 | ** want to subclass this object by appending additional fields |
1037 | ** for their own use. The pMethods entry is a pointer to an |
1038 | ** [sqlite3_io_methods] object that defines methods for performing |
1039 | ** I/O operations on the open file. |
1040 | */ |
1041 | typedef struct sqlite3_file sqlite3_file; |
1042 | struct sqlite3_file { |
1043 | const struct sqlite3_io_methods *pMethods; /* Methods for an open file */ |
1044 | }; |
1045 | |
1046 | /* |
1047 | ** CAPI3REF: OS Interface File Virtual Methods Object |
1048 | ** |
1049 | ** Every file opened by the [sqlite3_vfs.xOpen] method populates an |
1050 | ** [sqlite3_file] object (or, more commonly, a subclass of the |
1051 | ** [sqlite3_file] object) with a pointer to an instance of this object. |
1052 | ** This object defines the methods used to perform various operations |
1053 | ** against the open file represented by the [sqlite3_file] object. |
1054 | ** |
1055 | ** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element |
1056 | ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method |
1057 | ** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The |
1058 | ** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen] |
1059 | ** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element |
1060 | ** to NULL. |
1061 | ** |
1062 | ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or |
1063 | ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync(). |
1064 | ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY] |
1065 | ** flag may be ORed in to indicate that only the data of the file |
1066 | ** and not its inode needs to be synced. |
1067 | ** |
1068 | ** The integer values to xLock() and xUnlock() are one of |
1069 | ** <ul> |
1070 | ** <li> [SQLITE_LOCK_NONE], |
1071 | ** <li> [SQLITE_LOCK_SHARED], |
1072 | ** <li> [SQLITE_LOCK_RESERVED], |
1073 | ** <li> [SQLITE_LOCK_PENDING], or |
1074 | ** <li> [SQLITE_LOCK_EXCLUSIVE]. |
1075 | ** </ul> |
1076 | ** xLock() upgrades the database file lock. In other words, xLock() moves the |
1077 | ** database file lock in the direction NONE toward EXCLUSIVE. The argument to |
1078 | ** xLock() is always on of SHARED, RESERVED, PENDING, or EXCLUSIVE, never |
1079 | ** SQLITE_LOCK_NONE. If the database file lock is already at or above the |
1080 | ** requested lock, then the call to xLock() is a no-op. |
1081 | ** xUnlock() downgrades the database file lock to either SHARED or NONE. |
1082 | * If the lock is already at or below the requested lock state, then the call |
1083 | ** to xUnlock() is a no-op. |
1084 | ** The xCheckReservedLock() method checks whether any database connection, |
1085 | ** either in this process or in some other process, is holding a RESERVED, |
1086 | ** PENDING, or EXCLUSIVE lock on the file. It returns true |
1087 | ** if such a lock exists and false otherwise. |
1088 | ** |
1089 | ** The xFileControl() method is a generic interface that allows custom |
1090 | ** VFS implementations to directly control an open file using the |
1091 | ** [sqlite3_file_control()] interface. The second "op" argument is an |
1092 | ** integer opcode. The third argument is a generic pointer intended to |
1093 | ** point to a structure that may contain arguments or space in which to |
1094 | ** write return values. Potential uses for xFileControl() might be |
1095 | ** functions to enable blocking locks with timeouts, to change the |
1096 | ** locking strategy (for example to use dot-file locks), to inquire |
1097 | ** about the status of a lock, or to break stale locks. The SQLite |
1098 | ** core reserves all opcodes less than 100 for its own use. |
1099 | ** A [file control opcodes | list of opcodes] less than 100 is available. |
1100 | ** Applications that define a custom xFileControl method should use opcodes |
1101 | ** greater than 100 to avoid conflicts. VFS implementations should |
1102 | ** return [SQLITE_NOTFOUND] for file control opcodes that they do not |
1103 | ** recognize. |
1104 | ** |
1105 | ** The xSectorSize() method returns the sector size of the |
1106 | ** device that underlies the file. The sector size is the |
1107 | ** minimum write that can be performed without disturbing |
1108 | ** other bytes in the file. The xDeviceCharacteristics() |
1109 | ** method returns a bit vector describing behaviors of the |
1110 | ** underlying device: |
1111 | ** |
1112 | ** <ul> |
1113 | ** <li> [SQLITE_IOCAP_ATOMIC] |
1114 | ** <li> [SQLITE_IOCAP_ATOMIC512] |
1115 | ** <li> [SQLITE_IOCAP_ATOMIC1K] |
1116 | ** <li> [SQLITE_IOCAP_ATOMIC2K] |
1117 | ** <li> [SQLITE_IOCAP_ATOMIC4K] |
1118 | ** <li> [SQLITE_IOCAP_ATOMIC8K] |
1119 | ** <li> [SQLITE_IOCAP_ATOMIC16K] |
1120 | ** <li> [SQLITE_IOCAP_ATOMIC32K] |
1121 | ** <li> [SQLITE_IOCAP_ATOMIC64K] |
1122 | ** <li> [SQLITE_IOCAP_SAFE_APPEND] |
1123 | ** <li> [SQLITE_IOCAP_SEQUENTIAL] |
1124 | ** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN] |
1125 | ** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE] |
1126 | ** <li> [SQLITE_IOCAP_IMMUTABLE] |
1127 | ** <li> [SQLITE_IOCAP_BATCH_ATOMIC] |
1128 | ** </ul> |
1129 | ** |
1130 | ** The SQLITE_IOCAP_ATOMIC property means that all writes of |
1131 | ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values |
1132 | ** mean that writes of blocks that are nnn bytes in size and |
1133 | ** are aligned to an address which is an integer multiple of |
1134 | ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means |
1135 | ** that when data is appended to a file, the data is appended |
1136 | ** first then the size of the file is extended, never the other |
1137 | ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that |
1138 | ** information is written to disk in the same order as calls |
1139 | ** to xWrite(). |
1140 | ** |
1141 | ** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill |
1142 | ** in the unread portions of the buffer with zeros. A VFS that |
1143 | ** fails to zero-fill short reads might seem to work. However, |
1144 | ** failure to zero-fill short reads will eventually lead to |
1145 | ** database corruption. |
1146 | */ |
1147 | typedef struct sqlite3_io_methods sqlite3_io_methods; |
1148 | struct sqlite3_io_methods { |
1149 | int iVersion; |
1150 | int (*xClose)(sqlite3_file*); |
1151 | int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); |
1152 | int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst); |
1153 | int (*xTruncate)(sqlite3_file*, sqlite3_int64 size); |
1154 | int (*xSync)(sqlite3_file*, int flags); |
1155 | int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize); |
1156 | int (*xLock)(sqlite3_file*, int); |
1157 | int (*xUnlock)(sqlite3_file*, int); |
1158 | int (*xCheckReservedLock)(sqlite3_file*, int *pResOut); |
1159 | int (*xFileControl)(sqlite3_file*, int op, void *pArg); |
1160 | int (*xSectorSize)(sqlite3_file*); |
1161 | int (*xDeviceCharacteristics)(sqlite3_file*); |
1162 | /* Methods above are valid for version 1 */ |
1163 | int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**); |
1164 | int (*xShmLock)(sqlite3_file*, int offset, int n, int flags); |
1165 | void (*xShmBarrier)(sqlite3_file*); |
1166 | int (*xShmUnmap)(sqlite3_file*, int deleteFlag); |
1167 | /* Methods above are valid for version 2 */ |
1168 | int (*xFetch)(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp); |
1169 | int (*xUnfetch)(sqlite3_file*, sqlite3_int64 iOfst, void *p); |
1170 | /* Methods above are valid for version 3 */ |
1171 | /* Additional methods may be added in future releases */ |
1172 | }; |
1173 | |
1174 | /* |
1175 | ** CAPI3REF: Standard File Control Opcodes |
1176 | ** KEYWORDS: {file control opcodes} {file control opcode} |
1177 | ** |
1178 | ** These integer constants are opcodes for the xFileControl method |
1179 | ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()] |
1180 | ** interface. |
1181 | ** |
1182 | ** <ul> |
1183 | ** <li>[[SQLITE_FCNTL_LOCKSTATE]] |
1184 | ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This |
1185 | ** opcode causes the xFileControl method to write the current state of |
1186 | ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED], |
1187 | ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE]) |
1188 | ** into an integer that the pArg argument points to. |
1189 | ** This capability is only available if SQLite is compiled with [SQLITE_DEBUG]. |
1190 | ** |
1191 | ** <li>[[SQLITE_FCNTL_SIZE_HINT]] |
1192 | ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS |
1193 | ** layer a hint of how large the database file will grow to be during the |
1194 | ** current transaction. This hint is not guaranteed to be accurate but it |
1195 | ** is often close. The underlying VFS might choose to preallocate database |
1196 | ** file space based on this hint in order to help writes to the database |
1197 | ** file run faster. |
1198 | ** |
1199 | ** <li>[[SQLITE_FCNTL_SIZE_LIMIT]] |
1200 | ** The [SQLITE_FCNTL_SIZE_LIMIT] opcode is used by in-memory VFS that |
1201 | ** implements [sqlite3_deserialize()] to set an upper bound on the size |
1202 | ** of the in-memory database. The argument is a pointer to a [sqlite3_int64]. |
1203 | ** If the integer pointed to is negative, then it is filled in with the |
1204 | ** current limit. Otherwise the limit is set to the larger of the value |
1205 | ** of the integer pointed to and the current database size. The integer |
1206 | ** pointed to is set to the new limit. |
1207 | ** |
1208 | ** <li>[[SQLITE_FCNTL_CHUNK_SIZE]] |
1209 | ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS |
1210 | ** extends and truncates the database file in chunks of a size specified |
1211 | ** by the user. The fourth argument to [sqlite3_file_control()] should |
1212 | ** point to an integer (type int) containing the new chunk-size to use |
1213 | ** for the nominated database. Allocating database file space in large |
1214 | ** chunks (say 1MB at a time), may reduce file-system fragmentation and |
1215 | ** improve performance on some systems. |
1216 | ** |
1217 | ** <li>[[SQLITE_FCNTL_FILE_POINTER]] |
1218 | ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer |
1219 | ** to the [sqlite3_file] object associated with a particular database |
1220 | ** connection. See also [SQLITE_FCNTL_JOURNAL_POINTER]. |
1221 | ** |
1222 | ** <li>[[SQLITE_FCNTL_JOURNAL_POINTER]] |
1223 | ** The [SQLITE_FCNTL_JOURNAL_POINTER] opcode is used to obtain a pointer |
1224 | ** to the [sqlite3_file] object associated with the journal file (either |
1225 | ** the [rollback journal] or the [write-ahead log]) for a particular database |
1226 | ** connection. See also [SQLITE_FCNTL_FILE_POINTER]. |
1227 | ** |
1228 | ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]] |
1229 | ** No longer in use. |
1230 | ** |
1231 | ** <li>[[SQLITE_FCNTL_SYNC]] |
1232 | ** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and |
1233 | ** sent to the VFS immediately before the xSync method is invoked on a |
1234 | ** database file descriptor. Or, if the xSync method is not invoked |
1235 | ** because the user has configured SQLite with |
1236 | ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place |
1237 | ** of the xSync method. In most cases, the pointer argument passed with |
1238 | ** this file-control is NULL. However, if the database file is being synced |
1239 | ** as part of a multi-database commit, the argument points to a nul-terminated |
1240 | ** string containing the transactions super-journal file name. VFSes that |
1241 | ** do not need this signal should silently ignore this opcode. Applications |
1242 | ** should not call [sqlite3_file_control()] with this opcode as doing so may |
1243 | ** disrupt the operation of the specialized VFSes that do require it. |
1244 | ** |
1245 | ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]] |
1246 | ** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite |
1247 | ** and sent to the VFS after a transaction has been committed immediately |
1248 | ** but before the database is unlocked. VFSes that do not need this signal |
1249 | ** should silently ignore this opcode. Applications should not call |
1250 | ** [sqlite3_file_control()] with this opcode as doing so may disrupt the |
1251 | ** operation of the specialized VFSes that do require it. |
1252 | ** |
1253 | ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]] |
1254 | ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic |
1255 | ** retry counts and intervals for certain disk I/O operations for the |
1256 | ** windows [VFS] in order to provide robustness in the presence of |
1257 | ** anti-virus programs. By default, the windows VFS will retry file read, |
1258 | ** file write, and file delete operations up to 10 times, with a delay |
1259 | ** of 25 milliseconds before the first retry and with the delay increasing |
1260 | ** by an additional 25 milliseconds with each subsequent retry. This |
1261 | ** opcode allows these two values (10 retries and 25 milliseconds of delay) |
1262 | ** to be adjusted. The values are changed for all database connections |
1263 | ** within the same process. The argument is a pointer to an array of two |
1264 | ** integers where the first integer is the new retry count and the second |
1265 | ** integer is the delay. If either integer is negative, then the setting |
1266 | ** is not changed but instead the prior value of that setting is written |
1267 | ** into the array entry, allowing the current retry settings to be |
1268 | ** interrogated. The zDbName parameter is ignored. |
1269 | ** |
1270 | ** <li>[[SQLITE_FCNTL_PERSIST_WAL]] |
1271 | ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the |
1272 | ** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary |
1273 | ** write ahead log ([WAL file]) and shared memory |
1274 | ** files used for transaction control |
1275 | ** are automatically deleted when the latest connection to the database |
1276 | ** closes. Setting persistent WAL mode causes those files to persist after |
1277 | ** close. Persisting the files is useful when other processes that do not |
1278 | ** have write permission on the directory containing the database file want |
1279 | ** to read the database file, as the WAL and shared memory files must exist |
1280 | ** in order for the database to be readable. The fourth parameter to |
1281 | ** [sqlite3_file_control()] for this opcode should be a pointer to an integer. |
1282 | ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent |
1283 | ** WAL mode. If the integer is -1, then it is overwritten with the current |
1284 | ** WAL persistence setting. |
1285 | ** |
1286 | ** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]] |
1287 | ** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the |
1288 | ** persistent "powersafe-overwrite" or "PSOW" setting. The PSOW setting |
1289 | ** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the |
1290 | ** xDeviceCharacteristics methods. The fourth parameter to |
1291 | ** [sqlite3_file_control()] for this opcode should be a pointer to an integer. |
1292 | ** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage |
1293 | ** mode. If the integer is -1, then it is overwritten with the current |
1294 | ** zero-damage mode setting. |
1295 | ** |
1296 | ** <li>[[SQLITE_FCNTL_OVERWRITE]] |
1297 | ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening |
1298 | ** a write transaction to indicate that, unless it is rolled back for some |
1299 | ** reason, the entire database file will be overwritten by the current |
1300 | ** transaction. This is used by VACUUM operations. |
1301 | ** |
1302 | ** <li>[[SQLITE_FCNTL_VFSNAME]] |
1303 | ** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of |
1304 | ** all [VFSes] in the VFS stack. The names are of all VFS shims and the |
1305 | ** final bottom-level VFS are written into memory obtained from |
1306 | ** [sqlite3_malloc()] and the result is stored in the char* variable |
1307 | ** that the fourth parameter of [sqlite3_file_control()] points to. |
1308 | ** The caller is responsible for freeing the memory when done. As with |
1309 | ** all file-control actions, there is no guarantee that this will actually |
1310 | ** do anything. Callers should initialize the char* variable to a NULL |
1311 | ** pointer in case this file-control is not implemented. This file-control |
1312 | ** is intended for diagnostic use only. |
1313 | ** |
1314 | ** <li>[[SQLITE_FCNTL_VFS_POINTER]] |
1315 | ** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level |
1316 | ** [VFSes] currently in use. ^(The argument X in |
1317 | ** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be |
1318 | ** of type "[sqlite3_vfs] **". This opcodes will set *X |
1319 | ** to a pointer to the top-level VFS.)^ |
1320 | ** ^When there are multiple VFS shims in the stack, this opcode finds the |
1321 | ** upper-most shim only. |
1322 | ** |
1323 | ** <li>[[SQLITE_FCNTL_PRAGMA]] |
1324 | ** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA] |
1325 | ** file control is sent to the open [sqlite3_file] object corresponding |
1326 | ** to the database file to which the pragma statement refers. ^The argument |
1327 | ** to the [SQLITE_FCNTL_PRAGMA] file control is an array of |
1328 | ** pointers to strings (char**) in which the second element of the array |
1329 | ** is the name of the pragma and the third element is the argument to the |
1330 | ** pragma or NULL if the pragma has no argument. ^The handler for an |
1331 | ** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element |
1332 | ** of the char** argument point to a string obtained from [sqlite3_mprintf()] |
1333 | ** or the equivalent and that string will become the result of the pragma or |
1334 | ** the error message if the pragma fails. ^If the |
1335 | ** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal |
1336 | ** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA] |
1337 | ** file control returns [SQLITE_OK], then the parser assumes that the |
1338 | ** VFS has handled the PRAGMA itself and the parser generates a no-op |
1339 | ** prepared statement if result string is NULL, or that returns a copy |
1340 | ** of the result string if the string is non-NULL. |
1341 | ** ^If the [SQLITE_FCNTL_PRAGMA] file control returns |
1342 | ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means |
1343 | ** that the VFS encountered an error while handling the [PRAGMA] and the |
1344 | ** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA] |
1345 | ** file control occurs at the beginning of pragma statement analysis and so |
1346 | ** it is able to override built-in [PRAGMA] statements. |
1347 | ** |
1348 | ** <li>[[SQLITE_FCNTL_BUSYHANDLER]] |
1349 | ** ^The [SQLITE_FCNTL_BUSYHANDLER] |
1350 | ** file-control may be invoked by SQLite on the database file handle |
1351 | ** shortly after it is opened in order to provide a custom VFS with access |
1352 | ** to the connection's busy-handler callback. The argument is of type (void**) |
1353 | ** - an array of two (void *) values. The first (void *) actually points |
1354 | ** to a function of type (int (*)(void *)). In order to invoke the connection's |
1355 | ** busy-handler, this function should be invoked with the second (void *) in |
1356 | ** the array as the only argument. If it returns non-zero, then the operation |
1357 | ** should be retried. If it returns zero, the custom VFS should abandon the |
1358 | ** current operation. |
1359 | ** |
1360 | ** <li>[[SQLITE_FCNTL_TEMPFILENAME]] |
1361 | ** ^Applications can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control |
1362 | ** to have SQLite generate a |
1363 | ** temporary filename using the same algorithm that is followed to generate |
1364 | ** temporary filenames for TEMP tables and other internal uses. The |
1365 | ** argument should be a char** which will be filled with the filename |
1366 | ** written into memory obtained from [sqlite3_malloc()]. The caller should |
1367 | ** invoke [sqlite3_free()] on the result to avoid a memory leak. |
1368 | ** |
1369 | ** <li>[[SQLITE_FCNTL_MMAP_SIZE]] |
1370 | ** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the |
1371 | ** maximum number of bytes that will be used for memory-mapped I/O. |
1372 | ** The argument is a pointer to a value of type sqlite3_int64 that |
1373 | ** is an advisory maximum number of bytes in the file to memory map. The |
1374 | ** pointer is overwritten with the old value. The limit is not changed if |
1375 | ** the value originally pointed to is negative, and so the current limit |
1376 | ** can be queried by passing in a pointer to a negative number. This |
1377 | ** file-control is used internally to implement [PRAGMA mmap_size]. |
1378 | ** |
1379 | ** <li>[[SQLITE_FCNTL_TRACE]] |
1380 | ** The [SQLITE_FCNTL_TRACE] file control provides advisory information |
1381 | ** to the VFS about what the higher layers of the SQLite stack are doing. |
1382 | ** This file control is used by some VFS activity tracing [shims]. |
1383 | ** The argument is a zero-terminated string. Higher layers in the |
1384 | ** SQLite stack may generate instances of this file control if |
1385 | ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled. |
1386 | ** |
1387 | ** <li>[[SQLITE_FCNTL_HAS_MOVED]] |
1388 | ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a |
1389 | ** pointer to an integer and it writes a boolean into that integer depending |
1390 | ** on whether or not the file has been renamed, moved, or deleted since it |
1391 | ** was first opened. |
1392 | ** |
1393 | ** <li>[[SQLITE_FCNTL_WIN32_GET_HANDLE]] |
1394 | ** The [SQLITE_FCNTL_WIN32_GET_HANDLE] opcode can be used to obtain the |
1395 | ** underlying native file handle associated with a file handle. This file |
1396 | ** control interprets its argument as a pointer to a native file handle and |
1397 | ** writes the resulting value there. |
1398 | ** |
1399 | ** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]] |
1400 | ** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This |
1401 | ** opcode causes the xFileControl method to swap the file handle with the one |
1402 | ** pointed to by the pArg argument. This capability is used during testing |
1403 | ** and only needs to be supported when SQLITE_TEST is defined. |
1404 | ** |
1405 | ** <li>[[SQLITE_FCNTL_WAL_BLOCK]] |
1406 | ** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might |
1407 | ** be advantageous to block on the next WAL lock if the lock is not immediately |
1408 | ** available. The WAL subsystem issues this signal during rare |
1409 | ** circumstances in order to fix a problem with priority inversion. |
1410 | ** Applications should <em>not</em> use this file-control. |
1411 | ** |
1412 | ** <li>[[SQLITE_FCNTL_ZIPVFS]] |
1413 | ** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other |
1414 | ** VFS should return SQLITE_NOTFOUND for this opcode. |
1415 | ** |
1416 | ** <li>[[SQLITE_FCNTL_RBU]] |
1417 | ** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by |
1418 | ** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for |
1419 | ** this opcode. |
1420 | ** |
1421 | ** <li>[[SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]] |
1422 | ** If the [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] opcode returns SQLITE_OK, then |
1423 | ** the file descriptor is placed in "batch write mode", which |
1424 | ** means all subsequent write operations will be deferred and done |
1425 | ** atomically at the next [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]. Systems |
1426 | ** that do not support batch atomic writes will return SQLITE_NOTFOUND. |
1427 | ** ^Following a successful SQLITE_FCNTL_BEGIN_ATOMIC_WRITE and prior to |
1428 | ** the closing [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] or |
1429 | ** [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE], SQLite will make |
1430 | ** no VFS interface calls on the same [sqlite3_file] file descriptor |
1431 | ** except for calls to the xWrite method and the xFileControl method |
1432 | ** with [SQLITE_FCNTL_SIZE_HINT]. |
1433 | ** |
1434 | ** <li>[[SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]] |
1435 | ** The [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] opcode causes all write |
1436 | ** operations since the previous successful call to |
1437 | ** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be performed atomically. |
1438 | ** This file control returns [SQLITE_OK] if and only if the writes were |
1439 | ** all performed successfully and have been committed to persistent storage. |
1440 | ** ^Regardless of whether or not it is successful, this file control takes |
1441 | ** the file descriptor out of batch write mode so that all subsequent |
1442 | ** write operations are independent. |
1443 | ** ^SQLite will never invoke SQLITE_FCNTL_COMMIT_ATOMIC_WRITE without |
1444 | ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]. |
1445 | ** |
1446 | ** <li>[[SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE]] |
1447 | ** The [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE] opcode causes all write |
1448 | ** operations since the previous successful call to |
1449 | ** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be rolled back. |
1450 | ** ^This file control takes the file descriptor out of batch write mode |
1451 | ** so that all subsequent write operations are independent. |
1452 | ** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without |
1453 | ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]. |
1454 | ** |
1455 | ** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]] |
1456 | ** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode is used to configure a VFS |
1457 | ** to block for up to M milliseconds before failing when attempting to |
1458 | ** obtain a file lock using the xLock or xShmLock methods of the VFS. |
1459 | ** The parameter is a pointer to a 32-bit signed integer that contains |
1460 | ** the value that M is to be set to. Before returning, the 32-bit signed |
1461 | ** integer is overwritten with the previous value of M. |
1462 | ** |
1463 | ** <li>[[SQLITE_FCNTL_DATA_VERSION]] |
1464 | ** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to |
1465 | ** a database file. The argument is a pointer to a 32-bit unsigned integer. |
1466 | ** The "data version" for the pager is written into the pointer. The |
1467 | ** "data version" changes whenever any change occurs to the corresponding |
1468 | ** database file, either through SQL statements on the same database |
1469 | ** connection or through transactions committed by separate database |
1470 | ** connections possibly in other processes. The [sqlite3_total_changes()] |
1471 | ** interface can be used to find if any database on the connection has changed, |
1472 | ** but that interface responds to changes on TEMP as well as MAIN and does |
1473 | ** not provide a mechanism to detect changes to MAIN only. Also, the |
1474 | ** [sqlite3_total_changes()] interface responds to internal changes only and |
1475 | ** omits changes made by other database connections. The |
1476 | ** [PRAGMA data_version] command provides a mechanism to detect changes to |
1477 | ** a single attached database that occur due to other database connections, |
1478 | ** but omits changes implemented by the database connection on which it is |
1479 | ** called. This file control is the only mechanism to detect changes that |
1480 | ** happen either internally or externally and that are associated with |
1481 | ** a particular attached database. |
1482 | ** |
1483 | ** <li>[[SQLITE_FCNTL_CKPT_START]] |
1484 | ** The [SQLITE_FCNTL_CKPT_START] opcode is invoked from within a checkpoint |
1485 | ** in wal mode before the client starts to copy pages from the wal |
1486 | ** file to the database file. |
1487 | ** |
1488 | ** <li>[[SQLITE_FCNTL_CKPT_DONE]] |
1489 | ** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint |
1490 | ** in wal mode after the client has finished copying pages from the wal |
1491 | ** file to the database file, but before the *-shm file is updated to |
1492 | ** record the fact that the pages have been checkpointed. |
1493 | ** |
1494 | ** <li>[[SQLITE_FCNTL_EXTERNAL_READER]] |
1495 | ** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect |
1496 | ** whether or not there is a database client in another process with a wal-mode |
1497 | ** transaction open on the database or not. It is only available on unix.The |
1498 | ** (void*) argument passed with this file-control should be a pointer to a |
1499 | ** value of type (int). The integer value is set to 1 if the database is a wal |
1500 | ** mode database and there exists at least one client in another process that |
1501 | ** currently has an SQL transaction open on the database. It is set to 0 if |
1502 | ** the database is not a wal-mode db, or if there is no such connection in any |
1503 | ** other process. This opcode cannot be used to detect transactions opened |
1504 | ** by clients within the current process, only within other processes. |
1505 | ** |
1506 | ** <li>[[SQLITE_FCNTL_CKSM_FILE]] |
1507 | ** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use internally by the |
1508 | ** [checksum VFS shim] only. |
1509 | ** |
1510 | ** <li>[[SQLITE_FCNTL_RESET_CACHE]] |
1511 | ** If there is currently no transaction open on the database, and the |
1512 | ** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control |
1513 | ** purges the contents of the in-memory page cache. If there is an open |
1514 | ** transaction, or if the db is a temp-db, this opcode is a no-op, not an error. |
1515 | ** </ul> |
1516 | */ |
1517 | #define SQLITE_FCNTL_LOCKSTATE 1 |
1518 | #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2 |
1519 | #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3 |
1520 | #define SQLITE_FCNTL_LAST_ERRNO 4 |
1521 | #define SQLITE_FCNTL_SIZE_HINT 5 |
1522 | #define SQLITE_FCNTL_CHUNK_SIZE 6 |
1523 | #define SQLITE_FCNTL_FILE_POINTER 7 |
1524 | #define SQLITE_FCNTL_SYNC_OMITTED 8 |
1525 | #define SQLITE_FCNTL_WIN32_AV_RETRY 9 |
1526 | #define SQLITE_FCNTL_PERSIST_WAL 10 |
1527 | #define SQLITE_FCNTL_OVERWRITE 11 |
1528 | #define SQLITE_FCNTL_VFSNAME 12 |
1529 | #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13 |
1530 | #define SQLITE_FCNTL_PRAGMA 14 |
1531 | #define SQLITE_FCNTL_BUSYHANDLER 15 |
1532 | #define SQLITE_FCNTL_TEMPFILENAME 16 |
1533 | #define SQLITE_FCNTL_MMAP_SIZE 18 |
1534 | #define SQLITE_FCNTL_TRACE 19 |
1535 | #define SQLITE_FCNTL_HAS_MOVED 20 |
1536 | #define SQLITE_FCNTL_SYNC 21 |
1537 | #define SQLITE_FCNTL_COMMIT_PHASETWO 22 |
1538 | #define SQLITE_FCNTL_WIN32_SET_HANDLE 23 |
1539 | #define SQLITE_FCNTL_WAL_BLOCK 24 |
1540 | #define SQLITE_FCNTL_ZIPVFS 25 |
1541 | #define SQLITE_FCNTL_RBU 26 |
1542 | #define SQLITE_FCNTL_VFS_POINTER 27 |
1543 | #define SQLITE_FCNTL_JOURNAL_POINTER 28 |
1544 | #define SQLITE_FCNTL_WIN32_GET_HANDLE 29 |
1545 | #define SQLITE_FCNTL_PDB 30 |
1546 | #define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31 |
1547 | #define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32 |
1548 | #define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33 |
1549 | #define SQLITE_FCNTL_LOCK_TIMEOUT 34 |
1550 | #define SQLITE_FCNTL_DATA_VERSION 35 |
1551 | #define SQLITE_FCNTL_SIZE_LIMIT 36 |
1552 | #define SQLITE_FCNTL_CKPT_DONE 37 |
1553 | #define SQLITE_FCNTL_RESERVE_BYTES 38 |
1554 | #define SQLITE_FCNTL_CKPT_START 39 |
1555 | #define SQLITE_FCNTL_EXTERNAL_READER 40 |
1556 | #define SQLITE_FCNTL_CKSM_FILE 41 |
1557 | #define SQLITE_FCNTL_RESET_CACHE 42 |
1558 | |
1559 | /* deprecated names */ |
1560 | #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE |
1561 | #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE |
1562 | #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO |
1563 | |
1564 | |
1565 | /* |
1566 | ** CAPI3REF: Mutex Handle |
1567 | ** |
1568 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
1569 | ** abstract type for a mutex object. The SQLite core never looks |
1570 | ** at the internal representation of an [sqlite3_mutex]. It only |
1571 | ** deals with pointers to the [sqlite3_mutex] object. |
1572 | ** |
1573 | ** Mutexes are created using [sqlite3_mutex_alloc()]. |
1574 | */ |
1575 | typedef struct sqlite3_mutex sqlite3_mutex; |
1576 | |
1577 | /* |
1578 | ** CAPI3REF: Loadable Extension Thunk |
1579 | ** |
1580 | ** A pointer to the opaque sqlite3_api_routines structure is passed as |
1581 | ** the third parameter to entry points of [loadable extensions]. This |
1582 | ** structure must be typedefed in order to work around compiler warnings |
1583 | ** on some platforms. |
1584 | */ |
1585 | typedef struct sqlite3_api_routines sqlite3_api_routines; |
1586 | |
1587 | /* |
1588 | ** CAPI3REF: File Name |
1589 | ** |
1590 | ** Type [sqlite3_filename] is used by SQLite to pass filenames to the |
1591 | ** xOpen method of a [VFS]. It may be cast to (const char*) and treated |
1592 | ** as a normal, nul-terminated, UTF-8 buffer containing the filename, but |
1593 | ** may also be passed to special APIs such as: |
1594 | ** |
1595 | ** <ul> |
1596 | ** <li> sqlite3_filename_database() |
1597 | ** <li> sqlite3_filename_journal() |
1598 | ** <li> sqlite3_filename_wal() |
1599 | ** <li> sqlite3_uri_parameter() |
1600 | ** <li> sqlite3_uri_boolean() |
1601 | ** <li> sqlite3_uri_int64() |
1602 | ** <li> sqlite3_uri_key() |
1603 | ** </ul> |
1604 | */ |
1605 | typedef const char *sqlite3_filename; |
1606 | |
1607 | /* |
1608 | ** CAPI3REF: OS Interface Object |
1609 | ** |
1610 | ** An instance of the sqlite3_vfs object defines the interface between |
1611 | ** the SQLite core and the underlying operating system. The "vfs" |
1612 | ** in the name of the object stands for "virtual file system". See |
1613 | ** the [VFS | VFS documentation] for further information. |
1614 | ** |
1615 | ** The VFS interface is sometimes extended by adding new methods onto |
1616 | ** the end. Each time such an extension occurs, the iVersion field |
1617 | ** is incremented. The iVersion value started out as 1 in |
1618 | ** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2 |
1619 | ** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased |
1620 | ** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6]. Additional fields |
1621 | ** may be appended to the sqlite3_vfs object and the iVersion value |
1622 | ** may increase again in future versions of SQLite. |
1623 | ** Note that due to an oversight, the structure |
1624 | ** of the sqlite3_vfs object changed in the transition from |
1625 | ** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0] |
1626 | ** and yet the iVersion field was not increased. |
1627 | ** |
1628 | ** The szOsFile field is the size of the subclassed [sqlite3_file] |
1629 | ** structure used by this VFS. mxPathname is the maximum length of |
1630 | ** a pathname in this VFS. |
1631 | ** |
1632 | ** Registered sqlite3_vfs objects are kept on a linked list formed by |
1633 | ** the pNext pointer. The [sqlite3_vfs_register()] |
1634 | ** and [sqlite3_vfs_unregister()] interfaces manage this list |
1635 | ** in a thread-safe way. The [sqlite3_vfs_find()] interface |
1636 | ** searches the list. Neither the application code nor the VFS |
1637 | ** implementation should use the pNext pointer. |
1638 | ** |
1639 | ** The pNext field is the only field in the sqlite3_vfs |
1640 | ** structure that SQLite will ever modify. SQLite will only access |
1641 | ** or modify this field while holding a particular static mutex. |
1642 | ** The application should never modify anything within the sqlite3_vfs |
1643 | ** object once the object has been registered. |
1644 | ** |
1645 | ** The zName field holds the name of the VFS module. The name must |
1646 | ** be unique across all VFS modules. |
1647 | ** |
1648 | ** [[sqlite3_vfs.xOpen]] |
1649 | ** ^SQLite guarantees that the zFilename parameter to xOpen |
1650 | ** is either a NULL pointer or string obtained |
1651 | ** from xFullPathname() with an optional suffix added. |
1652 | ** ^If a suffix is added to the zFilename parameter, it will |
1653 | ** consist of a single "-" character followed by no more than |
1654 | ** 11 alphanumeric and/or "-" characters. |
1655 | ** ^SQLite further guarantees that |
1656 | ** the string will be valid and unchanged until xClose() is |
1657 | ** called. Because of the previous sentence, |
1658 | ** the [sqlite3_file] can safely store a pointer to the |
1659 | ** filename if it needs to remember the filename for some reason. |
1660 | ** If the zFilename parameter to xOpen is a NULL pointer then xOpen |
1661 | ** must invent its own temporary name for the file. ^Whenever the |
1662 | ** xFilename parameter is NULL it will also be the case that the |
1663 | ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE]. |
1664 | ** |
1665 | ** The flags argument to xOpen() includes all bits set in |
1666 | ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()] |
1667 | ** or [sqlite3_open16()] is used, then flags includes at least |
1668 | ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]. |
1669 | ** If xOpen() opens a file read-only then it sets *pOutFlags to |
1670 | ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set. |
1671 | ** |
1672 | ** ^(SQLite will also add one of the following flags to the xOpen() |
1673 | ** call, depending on the object being opened: |
1674 | ** |
1675 | ** <ul> |
1676 | ** <li> [SQLITE_OPEN_MAIN_DB] |
1677 | ** <li> [SQLITE_OPEN_MAIN_JOURNAL] |
1678 | ** <li> [SQLITE_OPEN_TEMP_DB] |
1679 | ** <li> [SQLITE_OPEN_TEMP_JOURNAL] |
1680 | ** <li> [SQLITE_OPEN_TRANSIENT_DB] |
1681 | ** <li> [SQLITE_OPEN_SUBJOURNAL] |
1682 | ** <li> [SQLITE_OPEN_SUPER_JOURNAL] |
1683 | ** <li> [SQLITE_OPEN_WAL] |
1684 | ** </ul>)^ |
1685 | ** |
1686 | ** The file I/O implementation can use the object type flags to |
1687 | ** change the way it deals with files. For example, an application |
1688 | ** that does not care about crash recovery or rollback might make |
1689 | ** the open of a journal file a no-op. Writes to this journal would |
1690 | ** also be no-ops, and any attempt to read the journal would return |
1691 | ** SQLITE_IOERR. Or the implementation might recognize that a database |
1692 | ** file will be doing page-aligned sector reads and writes in a random |
1693 | ** order and set up its I/O subsystem accordingly. |
1694 | ** |
1695 | ** SQLite might also add one of the following flags to the xOpen method: |
1696 | ** |
1697 | ** <ul> |
1698 | ** <li> [SQLITE_OPEN_DELETEONCLOSE] |
1699 | ** <li> [SQLITE_OPEN_EXCLUSIVE] |
1700 | ** </ul> |
1701 | ** |
1702 | ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be |
1703 | ** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE] |
1704 | ** will be set for TEMP databases and their journals, transient |
1705 | ** databases, and subjournals. |
1706 | ** |
1707 | ** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction |
1708 | ** with the [SQLITE_OPEN_CREATE] flag, which are both directly |
1709 | ** analogous to the O_EXCL and O_CREAT flags of the POSIX open() |
1710 | ** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the |
1711 | ** SQLITE_OPEN_CREATE, is used to indicate that file should always |
1712 | ** be created, and that it is an error if it already exists. |
1713 | ** It is <i>not</i> used to indicate the file should be opened |
1714 | ** for exclusive access. |
1715 | ** |
1716 | ** ^At least szOsFile bytes of memory are allocated by SQLite |
1717 | ** to hold the [sqlite3_file] structure passed as the third |
1718 | ** argument to xOpen. The xOpen method does not have to |
1719 | ** allocate the structure; it should just fill it in. Note that |
1720 | ** the xOpen method must set the sqlite3_file.pMethods to either |
1721 | ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do |
1722 | ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods |
1723 | ** element will be valid after xOpen returns regardless of the success |
1724 | ** or failure of the xOpen call. |
1725 | ** |
1726 | ** [[sqlite3_vfs.xAccess]] |
1727 | ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] |
1728 | ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to |
1729 | ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ] |
1730 | ** to test whether a file is at least readable. The SQLITE_ACCESS_READ |
1731 | ** flag is never actually used and is not implemented in the built-in |
1732 | ** VFSes of SQLite. The file is named by the second argument and can be a |
1733 | ** directory. The xAccess method returns [SQLITE_OK] on success or some |
1734 | ** non-zero error code if there is an I/O error or if the name of |
1735 | ** the file given in the second argument is illegal. If SQLITE_OK |
1736 | ** is returned, then non-zero or zero is written into *pResOut to indicate |
1737 | ** whether or not the file is accessible. |
1738 | ** |
1739 | ** ^SQLite will always allocate at least mxPathname+1 bytes for the |
1740 | ** output buffer xFullPathname. The exact size of the output buffer |
1741 | ** is also passed as a parameter to both methods. If the output buffer |
1742 | ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is |
1743 | ** handled as a fatal error by SQLite, vfs implementations should endeavor |
1744 | ** to prevent this by setting mxPathname to a sufficiently large value. |
1745 | ** |
1746 | ** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64() |
1747 | ** interfaces are not strictly a part of the filesystem, but they are |
1748 | ** included in the VFS structure for completeness. |
1749 | ** The xRandomness() function attempts to return nBytes bytes |
1750 | ** of good-quality randomness into zOut. The return value is |
1751 | ** the actual number of bytes of randomness obtained. |
1752 | ** The xSleep() method causes the calling thread to sleep for at |
1753 | ** least the number of microseconds given. ^The xCurrentTime() |
1754 | ** method returns a Julian Day Number for the current date and time as |
1755 | ** a floating point value. |
1756 | ** ^The xCurrentTimeInt64() method returns, as an integer, the Julian |
1757 | ** Day Number multiplied by 86400000 (the number of milliseconds in |
1758 | ** a 24-hour day). |
1759 | ** ^SQLite will use the xCurrentTimeInt64() method to get the current |
1760 | ** date and time if that method is available (if iVersion is 2 or |
1761 | ** greater and the function pointer is not NULL) and will fall back |
1762 | ** to xCurrentTime() if xCurrentTimeInt64() is unavailable. |
1763 | ** |
1764 | ** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces |
1765 | ** are not used by the SQLite core. These optional interfaces are provided |
1766 | ** by some VFSes to facilitate testing of the VFS code. By overriding |
1767 | ** system calls with functions under its control, a test program can |
1768 | ** simulate faults and error conditions that would otherwise be difficult |
1769 | ** or impossible to induce. The set of system calls that can be overridden |
1770 | ** varies from one VFS to another, and from one version of the same VFS to the |
1771 | ** next. Applications that use these interfaces must be prepared for any |
1772 | ** or all of these interfaces to be NULL or for their behavior to change |
1773 | ** from one release to the next. Applications must not attempt to access |
1774 | ** any of these methods if the iVersion of the VFS is less than 3. |
1775 | */ |
1776 | typedef struct sqlite3_vfs sqlite3_vfs; |
1777 | typedef void (*sqlite3_syscall_ptr)(void); |
1778 | struct sqlite3_vfs { |
1779 | int iVersion; /* Structure version number (currently 3) */ |
1780 | int szOsFile; /* Size of subclassed sqlite3_file */ |
1781 | int mxPathname; /* Maximum file pathname length */ |
1782 | sqlite3_vfs *pNext; /* Next registered VFS */ |
1783 | const char *zName; /* Name of this virtual file system */ |
1784 | void *pAppData; /* Pointer to application-specific data */ |
1785 | int (*xOpen)(sqlite3_vfs*, sqlite3_filename zName, sqlite3_file*, |
1786 | int flags, int *pOutFlags); |
1787 | int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir); |
1788 | int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut); |
1789 | int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut); |
1790 | void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename); |
1791 | void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg); |
1792 | void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void); |
1793 | void (*xDlClose)(sqlite3_vfs*, void*); |
1794 | int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut); |
1795 | int (*xSleep)(sqlite3_vfs*, int microseconds); |
1796 | int (*xCurrentTime)(sqlite3_vfs*, double*); |
1797 | int (*xGetLastError)(sqlite3_vfs*, int, char *); |
1798 | /* |
1799 | ** The methods above are in version 1 of the sqlite_vfs object |
1800 | ** definition. Those that follow are added in version 2 or later |
1801 | */ |
1802 | int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*); |
1803 | /* |
1804 | ** The methods above are in versions 1 and 2 of the sqlite_vfs object. |
1805 | ** Those below are for version 3 and greater. |
1806 | */ |
1807 | int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr); |
1808 | sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName); |
1809 | const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName); |
1810 | /* |
1811 | ** The methods above are in versions 1 through 3 of the sqlite_vfs object. |
1812 | ** New fields may be appended in future versions. The iVersion |
1813 | ** value will increment whenever this happens. |
1814 | */ |
1815 | }; |
1816 | |
1817 | /* |
1818 | ** CAPI3REF: Flags for the xAccess VFS method |
1819 | ** |
1820 | ** These integer constants can be used as the third parameter to |
1821 | ** the xAccess method of an [sqlite3_vfs] object. They determine |
1822 | ** what kind of permissions the xAccess method is looking for. |
1823 | ** With SQLITE_ACCESS_EXISTS, the xAccess method |
1824 | ** simply checks whether the file exists. |
1825 | ** With SQLITE_ACCESS_READWRITE, the xAccess method |
1826 | ** checks whether the named directory is both readable and writable |
1827 | ** (in other words, if files can be added, removed, and renamed within |
1828 | ** the directory). |
1829 | ** The SQLITE_ACCESS_READWRITE constant is currently used only by the |
1830 | ** [temp_store_directory pragma], though this could change in a future |
1831 | ** release of SQLite. |
1832 | ** With SQLITE_ACCESS_READ, the xAccess method |
1833 | ** checks whether the file is readable. The SQLITE_ACCESS_READ constant is |
1834 | ** currently unused, though it might be used in a future release of |
1835 | ** SQLite. |
1836 | */ |
1837 | #define SQLITE_ACCESS_EXISTS 0 |
1838 | #define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */ |
1839 | #define SQLITE_ACCESS_READ 2 /* Unused */ |
1840 | |
1841 | /* |
1842 | ** CAPI3REF: Flags for the xShmLock VFS method |
1843 | ** |
1844 | ** These integer constants define the various locking operations |
1845 | ** allowed by the xShmLock method of [sqlite3_io_methods]. The |
1846 | ** following are the only legal combinations of flags to the |
1847 | ** xShmLock method: |
1848 | ** |
1849 | ** <ul> |
1850 | ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_SHARED |
1851 | ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE |
1852 | ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED |
1853 | ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE |
1854 | ** </ul> |
1855 | ** |
1856 | ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as |
1857 | ** was given on the corresponding lock. |
1858 | ** |
1859 | ** The xShmLock method can transition between unlocked and SHARED or |
1860 | ** between unlocked and EXCLUSIVE. It cannot transition between SHARED |
1861 | ** and EXCLUSIVE. |
1862 | */ |
1863 | #define SQLITE_SHM_UNLOCK 1 |
1864 | #define SQLITE_SHM_LOCK 2 |
1865 | #define SQLITE_SHM_SHARED 4 |
1866 | #define SQLITE_SHM_EXCLUSIVE 8 |
1867 | |
1868 | /* |
1869 | ** CAPI3REF: Maximum xShmLock index |
1870 | ** |
1871 | ** The xShmLock method on [sqlite3_io_methods] may use values |
1872 | ** between 0 and this upper bound as its "offset" argument. |
1873 | ** The SQLite core will never attempt to acquire or release a |
1874 | ** lock outside of this range |
1875 | */ |
1876 | #define SQLITE_SHM_NLOCK 8 |
1877 | |
1878 | |
1879 | /* |
1880 | ** CAPI3REF: Initialize The SQLite Library |
1881 | ** |
1882 | ** ^The sqlite3_initialize() routine initializes the |
1883 | ** SQLite library. ^The sqlite3_shutdown() routine |
1884 | ** deallocates any resources that were allocated by sqlite3_initialize(). |
1885 | ** These routines are designed to aid in process initialization and |
1886 | ** shutdown on embedded systems. Workstation applications using |
1887 | ** SQLite normally do not need to invoke either of these routines. |
1888 | ** |
1889 | ** A call to sqlite3_initialize() is an "effective" call if it is |
1890 | ** the first time sqlite3_initialize() is invoked during the lifetime of |
1891 | ** the process, or if it is the first time sqlite3_initialize() is invoked |
1892 | ** following a call to sqlite3_shutdown(). ^(Only an effective call |
1893 | ** of sqlite3_initialize() does any initialization. All other calls |
1894 | ** are harmless no-ops.)^ |
1895 | ** |
1896 | ** A call to sqlite3_shutdown() is an "effective" call if it is the first |
1897 | ** call to sqlite3_shutdown() since the last sqlite3_initialize(). ^(Only |
1898 | ** an effective call to sqlite3_shutdown() does any deinitialization. |
1899 | ** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^ |
1900 | ** |
1901 | ** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown() |
1902 | ** is not. The sqlite3_shutdown() interface must only be called from a |
1903 | ** single thread. All open [database connections] must be closed and all |
1904 | ** other SQLite resources must be deallocated prior to invoking |
1905 | ** sqlite3_shutdown(). |
1906 | ** |
1907 | ** Among other things, ^sqlite3_initialize() will invoke |
1908 | ** sqlite3_os_init(). Similarly, ^sqlite3_shutdown() |
1909 | ** will invoke sqlite3_os_end(). |
1910 | ** |
1911 | ** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success. |
1912 | ** ^If for some reason, sqlite3_initialize() is unable to initialize |
1913 | ** the library (perhaps it is unable to allocate a needed resource such |
1914 | ** as a mutex) it returns an [error code] other than [SQLITE_OK]. |
1915 | ** |
1916 | ** ^The sqlite3_initialize() routine is called internally by many other |
1917 | ** SQLite interfaces so that an application usually does not need to |
1918 | ** invoke sqlite3_initialize() directly. For example, [sqlite3_open()] |
1919 | ** calls sqlite3_initialize() so the SQLite library will be automatically |
1920 | ** initialized when [sqlite3_open()] is called if it has not be initialized |
1921 | ** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT] |
1922 | ** compile-time option, then the automatic calls to sqlite3_initialize() |
1923 | ** are omitted and the application must call sqlite3_initialize() directly |
1924 | ** prior to using any other SQLite interface. For maximum portability, |
1925 | ** it is recommended that applications always invoke sqlite3_initialize() |
1926 | ** directly prior to using any other SQLite interface. Future releases |
1927 | ** of SQLite may require this. In other words, the behavior exhibited |
1928 | ** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the |
1929 | ** default behavior in some future release of SQLite. |
1930 | ** |
1931 | ** The sqlite3_os_init() routine does operating-system specific |
1932 | ** initialization of the SQLite library. The sqlite3_os_end() |
1933 | ** routine undoes the effect of sqlite3_os_init(). Typical tasks |
1934 | ** performed by these routines include allocation or deallocation |
1935 | ** of static resources, initialization of global variables, |
1936 | ** setting up a default [sqlite3_vfs] module, or setting up |
1937 | ** a default configuration using [sqlite3_config()]. |
1938 | ** |
1939 | ** The application should never invoke either sqlite3_os_init() |
1940 | ** or sqlite3_os_end() directly. The application should only invoke |
1941 | ** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init() |
1942 | ** interface is called automatically by sqlite3_initialize() and |
1943 | ** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate |
1944 | ** implementations for sqlite3_os_init() and sqlite3_os_end() |
1945 | ** are built into SQLite when it is compiled for Unix, Windows, or OS/2. |
1946 | ** When [custom builds | built for other platforms] |
1947 | ** (using the [SQLITE_OS_OTHER=1] compile-time |
1948 | ** option) the application must supply a suitable implementation for |
1949 | ** sqlite3_os_init() and sqlite3_os_end(). An application-supplied |
1950 | ** implementation of sqlite3_os_init() or sqlite3_os_end() |
1951 | ** must return [SQLITE_OK] on success and some other [error code] upon |
1952 | ** failure. |
1953 | */ |
1954 | SQLITE_API int sqlite3_initialize(void); |
1955 | SQLITE_API int sqlite3_shutdown(void); |
1956 | SQLITE_API int sqlite3_os_init(void); |
1957 | SQLITE_API int sqlite3_os_end(void); |
1958 | |
1959 | /* |
1960 | ** CAPI3REF: Configuring The SQLite Library |
1961 | ** |
1962 | ** The sqlite3_config() interface is used to make global configuration |
1963 | ** changes to SQLite in order to tune SQLite to the specific needs of |
1964 | ** the application. The default configuration is recommended for most |
1965 | ** applications and so this routine is usually not necessary. It is |
1966 | ** provided to support rare applications with unusual needs. |
1967 | ** |
1968 | ** <b>The sqlite3_config() interface is not threadsafe. The application |
1969 | ** must ensure that no other SQLite interfaces are invoked by other |
1970 | ** threads while sqlite3_config() is running.</b> |
1971 | ** |
1972 | ** The first argument to sqlite3_config() is an integer |
1973 | ** [configuration option] that determines |
1974 | ** what property of SQLite is to be configured. Subsequent arguments |
1975 | ** vary depending on the [configuration option] |
1976 | ** in the first argument. |
1977 | ** |
1978 | ** For most configuration options, the sqlite3_config() interface |
1979 | ** may only be invoked prior to library initialization using |
1980 | ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. |
1981 | ** The exceptional configuration options that may be invoked at any time |
1982 | ** are called "anytime configuration options". |
1983 | ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before |
1984 | ** [sqlite3_shutdown()] with a first argument that is not an anytime |
1985 | ** configuration option, then the sqlite3_config() call will return SQLITE_MISUSE. |
1986 | ** Note, however, that ^sqlite3_config() can be called as part of the |
1987 | ** implementation of an application-defined [sqlite3_os_init()]. |
1988 | ** |
1989 | ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. |
1990 | ** ^If the option is unknown or SQLite is unable to set the option |
1991 | ** then this routine returns a non-zero [error code]. |
1992 | */ |
1993 | SQLITE_API int sqlite3_config(int, ...); |
1994 | |
1995 | /* |
1996 | ** CAPI3REF: Configure database connections |
1997 | ** METHOD: sqlite3 |
1998 | ** |
1999 | ** The sqlite3_db_config() interface is used to make configuration |
2000 | ** changes to a [database connection]. The interface is similar to |
2001 | ** [sqlite3_config()] except that the changes apply to a single |
2002 | ** [database connection] (specified in the first argument). |
2003 | ** |
2004 | ** The second argument to sqlite3_db_config(D,V,...) is the |
2005 | ** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code |
2006 | ** that indicates what aspect of the [database connection] is being configured. |
2007 | ** Subsequent arguments vary depending on the configuration verb. |
2008 | ** |
2009 | ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if |
2010 | ** the call is considered successful. |
2011 | */ |
2012 | SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...); |
2013 | |
2014 | /* |
2015 | ** CAPI3REF: Memory Allocation Routines |
2016 | ** |
2017 | ** An instance of this object defines the interface between SQLite |
2018 | ** and low-level memory allocation routines. |
2019 | ** |
2020 | ** This object is used in only one place in the SQLite interface. |
2021 | ** A pointer to an instance of this object is the argument to |
2022 | ** [sqlite3_config()] when the configuration option is |
2023 | ** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC]. |
2024 | ** By creating an instance of this object |
2025 | ** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC]) |
2026 | ** during configuration, an application can specify an alternative |
2027 | ** memory allocation subsystem for SQLite to use for all of its |
2028 | ** dynamic memory needs. |
2029 | ** |
2030 | ** Note that SQLite comes with several [built-in memory allocators] |
2031 | ** that are perfectly adequate for the overwhelming majority of applications |
2032 | ** and that this object is only useful to a tiny minority of applications |
2033 | ** with specialized memory allocation requirements. This object is |
2034 | ** also used during testing of SQLite in order to specify an alternative |
2035 | ** memory allocator that simulates memory out-of-memory conditions in |
2036 | ** order to verify that SQLite recovers gracefully from such |
2037 | ** conditions. |
2038 | ** |
2039 | ** The xMalloc, xRealloc, and xFree methods must work like the |
2040 | ** malloc(), realloc() and free() functions from the standard C library. |
2041 | ** ^SQLite guarantees that the second argument to |
2042 | ** xRealloc is always a value returned by a prior call to xRoundup. |
2043 | ** |
2044 | ** xSize should return the allocated size of a memory allocation |
2045 | ** previously obtained from xMalloc or xRealloc. The allocated size |
2046 | ** is always at least as big as the requested size but may be larger. |
2047 | ** |
2048 | ** The xRoundup method returns what would be the allocated size of |
2049 | ** a memory allocation given a particular requested size. Most memory |
2050 | ** allocators round up memory allocations at least to the next multiple |
2051 | ** of 8. Some allocators round up to a larger multiple or to a power of 2. |
2052 | ** Every memory allocation request coming in through [sqlite3_malloc()] |
2053 | ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0, |
2054 | ** that causes the corresponding memory allocation to fail. |
2055 | ** |
2056 | ** The xInit method initializes the memory allocator. For example, |
2057 | ** it might allocate any required mutexes or initialize internal data |
2058 | ** structures. The xShutdown method is invoked (indirectly) by |
2059 | ** [sqlite3_shutdown()] and should deallocate any resources acquired |
2060 | ** by xInit. The pAppData pointer is used as the only parameter to |
2061 | ** xInit and xShutdown. |
2062 | ** |
2063 | ** SQLite holds the [SQLITE_MUTEX_STATIC_MAIN] mutex when it invokes |
2064 | ** the xInit method, so the xInit method need not be threadsafe. The |
2065 | ** xShutdown method is only called from [sqlite3_shutdown()] so it does |
2066 | ** not need to be threadsafe either. For all other methods, SQLite |
2067 | ** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the |
2068 | ** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which |
2069 | ** it is by default) and so the methods are automatically serialized. |
2070 | ** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other |
2071 | ** methods must be threadsafe or else make their own arrangements for |
2072 | ** serialization. |
2073 | ** |
2074 | ** SQLite will never invoke xInit() more than once without an intervening |
2075 | ** call to xShutdown(). |
2076 | */ |
2077 | typedef struct sqlite3_mem_methods sqlite3_mem_methods; |
2078 | struct sqlite3_mem_methods { |
2079 | void *(*xMalloc)(int); /* Memory allocation function */ |
2080 | void (*xFree)(void*); /* Free a prior allocation */ |
2081 | void *(*xRealloc)(void*,int); /* Resize an allocation */ |
2082 | int (*xSize)(void*); /* Return the size of an allocation */ |
2083 | int (*xRoundup)(int); /* Round up request size to allocation size */ |
2084 | int (*xInit)(void*); /* Initialize the memory allocator */ |
2085 | void (*xShutdown)(void*); /* Deinitialize the memory allocator */ |
2086 | void *pAppData; /* Argument to xInit() and xShutdown() */ |
2087 | }; |
2088 | |
2089 | /* |
2090 | ** CAPI3REF: Configuration Options |
2091 | ** KEYWORDS: {configuration option} |
2092 | ** |
2093 | ** These constants are the available integer configuration options that |
2094 | ** can be passed as the first argument to the [sqlite3_config()] interface. |
2095 | ** |
2096 | ** Most of the configuration options for sqlite3_config() |
2097 | ** will only work if invoked prior to [sqlite3_initialize()] or after |
2098 | ** [sqlite3_shutdown()]. The few exceptions to this rule are called |
2099 | ** "anytime configuration options". |
2100 | ** ^Calling [sqlite3_config()] with a first argument that is not an |
2101 | ** anytime configuration option in between calls to [sqlite3_initialize()] and |
2102 | ** [sqlite3_shutdown()] is a no-op that returns SQLITE_MISUSE. |
2103 | ** |
2104 | ** The set of anytime configuration options can change (by insertions |
2105 | ** and/or deletions) from one release of SQLite to the next. |
2106 | ** As of SQLite version 3.42.0, the complete set of anytime configuration |
2107 | ** options is: |
2108 | ** <ul> |
2109 | ** <li> SQLITE_CONFIG_LOG |
2110 | ** <li> SQLITE_CONFIG_PCACHE_HDRSZ |
2111 | ** </ul> |
2112 | ** |
2113 | ** New configuration options may be added in future releases of SQLite. |
2114 | ** Existing configuration options might be discontinued. Applications |
2115 | ** should check the return code from [sqlite3_config()] to make sure that |
2116 | ** the call worked. The [sqlite3_config()] interface will return a |
2117 | ** non-zero [error code] if a discontinued or unsupported configuration option |
2118 | ** is invoked. |
2119 | ** |
2120 | ** <dl> |
2121 | ** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt> |
2122 | ** <dd>There are no arguments to this option. ^This option sets the |
2123 | ** [threading mode] to Single-thread. In other words, it disables |
2124 | ** all mutexing and puts SQLite into a mode where it can only be used |
2125 | ** by a single thread. ^If SQLite is compiled with |
2126 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
2127 | ** it is not possible to change the [threading mode] from its default |
2128 | ** value of Single-thread and so [sqlite3_config()] will return |
2129 | ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD |
2130 | ** configuration option.</dd> |
2131 | ** |
2132 | ** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt> |
2133 | ** <dd>There are no arguments to this option. ^This option sets the |
2134 | ** [threading mode] to Multi-thread. In other words, it disables |
2135 | ** mutexing on [database connection] and [prepared statement] objects. |
2136 | ** The application is responsible for serializing access to |
2137 | ** [database connections] and [prepared statements]. But other mutexes |
2138 | ** are enabled so that SQLite will be safe to use in a multi-threaded |
2139 | ** environment as long as no two threads attempt to use the same |
2140 | ** [database connection] at the same time. ^If SQLite is compiled with |
2141 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
2142 | ** it is not possible to set the Multi-thread [threading mode] and |
2143 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
2144 | ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd> |
2145 | ** |
2146 | ** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt> |
2147 | ** <dd>There are no arguments to this option. ^This option sets the |
2148 | ** [threading mode] to Serialized. In other words, this option enables |
2149 | ** all mutexes including the recursive |
2150 | ** mutexes on [database connection] and [prepared statement] objects. |
2151 | ** In this mode (which is the default when SQLite is compiled with |
2152 | ** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access |
2153 | ** to [database connections] and [prepared statements] so that the |
2154 | ** application is free to use the same [database connection] or the |
2155 | ** same [prepared statement] in different threads at the same time. |
2156 | ** ^If SQLite is compiled with |
2157 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
2158 | ** it is not possible to set the Serialized [threading mode] and |
2159 | ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
2160 | ** SQLITE_CONFIG_SERIALIZED configuration option.</dd> |
2161 | ** |
2162 | ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt> |
2163 | ** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is |
2164 | ** a pointer to an instance of the [sqlite3_mem_methods] structure. |
2165 | ** The argument specifies |
2166 | ** alternative low-level memory allocation routines to be used in place of |
2167 | ** the memory allocation routines built into SQLite.)^ ^SQLite makes |
2168 | ** its own private copy of the content of the [sqlite3_mem_methods] structure |
2169 | ** before the [sqlite3_config()] call returns.</dd> |
2170 | ** |
2171 | ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt> |
2172 | ** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which |
2173 | ** is a pointer to an instance of the [sqlite3_mem_methods] structure. |
2174 | ** The [sqlite3_mem_methods] |
2175 | ** structure is filled with the currently defined memory allocation routines.)^ |
2176 | ** This option can be used to overload the default memory allocation |
2177 | ** routines with a wrapper that simulations memory allocation failure or |
2178 | ** tracks memory usage, for example. </dd> |
2179 | ** |
2180 | ** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt> |
2181 | ** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes single argument of |
2182 | ** type int, interpreted as a boolean, which if true provides a hint to |
2183 | ** SQLite that it should avoid large memory allocations if possible. |
2184 | ** SQLite will run faster if it is free to make large memory allocations, |
2185 | ** but some application might prefer to run slower in exchange for |
2186 | ** guarantees about memory fragmentation that are possible if large |
2187 | ** allocations are avoided. This hint is normally off. |
2188 | ** </dd> |
2189 | ** |
2190 | ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> |
2191 | ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int, |
2192 | ** interpreted as a boolean, which enables or disables the collection of |
2193 | ** memory allocation statistics. ^(When memory allocation statistics are |
2194 | ** disabled, the following SQLite interfaces become non-operational: |
2195 | ** <ul> |
2196 | ** <li> [sqlite3_hard_heap_limit64()] |
2197 | ** <li> [sqlite3_memory_used()] |
2198 | ** <li> [sqlite3_memory_highwater()] |
2199 | ** <li> [sqlite3_soft_heap_limit64()] |
2200 | ** <li> [sqlite3_status64()] |
2201 | ** </ul>)^ |
2202 | ** ^Memory allocation statistics are enabled by default unless SQLite is |
2203 | ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory |
2204 | ** allocation statistics are disabled by default. |
2205 | ** </dd> |
2206 | ** |
2207 | ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt> |
2208 | ** <dd> The SQLITE_CONFIG_SCRATCH option is no longer used. |
2209 | ** </dd> |
2210 | ** |
2211 | ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt> |
2212 | ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool |
2213 | ** that SQLite can use for the database page cache with the default page |
2214 | ** cache implementation. |
2215 | ** This configuration option is a no-op if an application-defined page |
2216 | ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2]. |
2217 | ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to |
2218 | ** 8-byte aligned memory (pMem), the size of each page cache line (sz), |
2219 | ** and the number of cache lines (N). |
2220 | ** The sz argument should be the size of the largest database page |
2221 | ** (a power of two between 512 and 65536) plus some extra bytes for each |
2222 | ** page header. ^The number of extra bytes needed by the page header |
2223 | ** can be determined using [SQLITE_CONFIG_PCACHE_HDRSZ]. |
2224 | ** ^It is harmless, apart from the wasted memory, |
2225 | ** for the sz parameter to be larger than necessary. The pMem |
2226 | ** argument must be either a NULL pointer or a pointer to an 8-byte |
2227 | ** aligned block of memory of at least sz*N bytes, otherwise |
2228 | ** subsequent behavior is undefined. |
2229 | ** ^When pMem is not NULL, SQLite will strive to use the memory provided |
2230 | ** to satisfy page cache needs, falling back to [sqlite3_malloc()] if |
2231 | ** a page cache line is larger than sz bytes or if all of the pMem buffer |
2232 | ** is exhausted. |
2233 | ** ^If pMem is NULL and N is non-zero, then each database connection |
2234 | ** does an initial bulk allocation for page cache memory |
2235 | ** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or |
2236 | ** of -1024*N bytes if N is negative, . ^If additional |
2237 | ** page cache memory is needed beyond what is provided by the initial |
2238 | ** allocation, then SQLite goes to [sqlite3_malloc()] separately for each |
2239 | ** additional cache line. </dd> |
2240 | ** |
2241 | ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> |
2242 | ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer |
2243 | ** that SQLite will use for all of its dynamic memory allocation needs |
2244 | ** beyond those provided for by [SQLITE_CONFIG_PAGECACHE]. |
2245 | ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled |
2246 | ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns |
2247 | ** [SQLITE_ERROR] if invoked otherwise. |
2248 | ** ^There are three arguments to SQLITE_CONFIG_HEAP: |
2249 | ** An 8-byte aligned pointer to the memory, |
2250 | ** the number of bytes in the memory buffer, and the minimum allocation size. |
2251 | ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts |
2252 | ** to using its default memory allocator (the system malloc() implementation), |
2253 | ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the |
2254 | ** memory pointer is not NULL then the alternative memory |
2255 | ** allocator is engaged to handle all of SQLites memory allocation needs. |
2256 | ** The first pointer (the memory pointer) must be aligned to an 8-byte |
2257 | ** boundary or subsequent behavior of SQLite will be undefined. |
2258 | ** The minimum allocation size is capped at 2**12. Reasonable values |
2259 | ** for the minimum allocation size are 2**5 through 2**8.</dd> |
2260 | ** |
2261 | ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> |
2262 | ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a |
2263 | ** pointer to an instance of the [sqlite3_mutex_methods] structure. |
2264 | ** The argument specifies alternative low-level mutex routines to be used |
2265 | ** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of |
2266 | ** the content of the [sqlite3_mutex_methods] structure before the call to |
2267 | ** [sqlite3_config()] returns. ^If SQLite is compiled with |
2268 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
2269 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
2270 | ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will |
2271 | ** return [SQLITE_ERROR].</dd> |
2272 | ** |
2273 | ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt> |
2274 | ** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which |
2275 | ** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The |
2276 | ** [sqlite3_mutex_methods] |
2277 | ** structure is filled with the currently defined mutex routines.)^ |
2278 | ** This option can be used to overload the default mutex allocation |
2279 | ** routines with a wrapper used to track mutex usage for performance |
2280 | ** profiling or testing, for example. ^If SQLite is compiled with |
2281 | ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
2282 | ** the entire mutexing subsystem is omitted from the build and hence calls to |
2283 | ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will |
2284 | ** return [SQLITE_ERROR].</dd> |
2285 | ** |
2286 | ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt> |
2287 | ** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine |
2288 | ** the default size of lookaside memory on each [database connection]. |
2289 | ** The first argument is the |
2290 | ** size of each lookaside buffer slot and the second is the number of |
2291 | ** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE |
2292 | ** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] |
2293 | ** option to [sqlite3_db_config()] can be used to change the lookaside |
2294 | ** configuration on individual connections.)^ </dd> |
2295 | ** |
2296 | ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt> |
2297 | ** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is |
2298 | ** a pointer to an [sqlite3_pcache_methods2] object. This object specifies |
2299 | ** the interface to a custom page cache implementation.)^ |
2300 | ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd> |
2301 | ** |
2302 | ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt> |
2303 | ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which |
2304 | ** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of |
2305 | ** the current page cache implementation into that object.)^ </dd> |
2306 | ** |
2307 | ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> |
2308 | ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite |
2309 | ** global [error log]. |
2310 | ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a |
2311 | ** function with a call signature of void(*)(void*,int,const char*), |
2312 | ** and a pointer to void. ^If the function pointer is not NULL, it is |
2313 | ** invoked by [sqlite3_log()] to process each logging event. ^If the |
2314 | ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op. |
2315 | ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is |
2316 | ** passed through as the first parameter to the application-defined logger |
2317 | ** function whenever that function is invoked. ^The second parameter to |
2318 | ** the logger function is a copy of the first parameter to the corresponding |
2319 | ** [sqlite3_log()] call and is intended to be a [result code] or an |
2320 | ** [extended result code]. ^The third parameter passed to the logger is |
2321 | ** log message after formatting via [sqlite3_snprintf()]. |
2322 | ** The SQLite logging interface is not reentrant; the logger function |
2323 | ** supplied by the application must not invoke any SQLite interface. |
2324 | ** In a multi-threaded application, the application-defined logger |
2325 | ** function must be threadsafe. </dd> |
2326 | ** |
2327 | ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI |
2328 | ** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int. |
2329 | ** If non-zero, then URI handling is globally enabled. If the parameter is zero, |
2330 | ** then URI handling is globally disabled.)^ ^If URI handling is globally |
2331 | ** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()], |
2332 | ** [sqlite3_open16()] or |
2333 | ** specified as part of [ATTACH] commands are interpreted as URIs, regardless |
2334 | ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database |
2335 | ** connection is opened. ^If it is globally disabled, filenames are |
2336 | ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the |
2337 | ** database connection is opened. ^(By default, URI handling is globally |
2338 | ** disabled. The default value may be changed by compiling with the |
2339 | ** [SQLITE_USE_URI] symbol defined.)^ |
2340 | ** |
2341 | ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN |
2342 | ** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer |
2343 | ** argument which is interpreted as a boolean in order to enable or disable |
2344 | ** the use of covering indices for full table scans in the query optimizer. |
2345 | ** ^The default setting is determined |
2346 | ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on" |
2347 | ** if that compile-time option is omitted. |
2348 | ** The ability to disable the use of covering indices for full table scans |
2349 | ** is because some incorrectly coded legacy applications might malfunction |
2350 | ** when the optimization is enabled. Providing the ability to |
2351 | ** disable the optimization allows the older, buggy application code to work |
2352 | ** without change even with newer versions of SQLite. |
2353 | ** |
2354 | ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]] |
2355 | ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE |
2356 | ** <dd> These options are obsolete and should not be used by new code. |
2357 | ** They are retained for backwards compatibility but are now no-ops. |
2358 | ** </dd> |
2359 | ** |
2360 | ** [[SQLITE_CONFIG_SQLLOG]] |
2361 | ** <dt>SQLITE_CONFIG_SQLLOG |
2362 | ** <dd>This option is only available if sqlite is compiled with the |
2363 | ** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should |
2364 | ** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int). |
2365 | ** The second should be of type (void*). The callback is invoked by the library |
2366 | ** in three separate circumstances, identified by the value passed as the |
2367 | ** fourth parameter. If the fourth parameter is 0, then the database connection |
2368 | ** passed as the second argument has just been opened. The third argument |
2369 | ** points to a buffer containing the name of the main database file. If the |
2370 | ** fourth parameter is 1, then the SQL statement that the third parameter |
2371 | ** points to has just been executed. Or, if the fourth parameter is 2, then |
2372 | ** the connection being passed as the second parameter is being closed. The |
2373 | ** third parameter is passed NULL In this case. An example of using this |
2374 | ** configuration option can be seen in the "test_sqllog.c" source file in |
2375 | ** the canonical SQLite source tree.</dd> |
2376 | ** |
2377 | ** [[SQLITE_CONFIG_MMAP_SIZE]] |
2378 | ** <dt>SQLITE_CONFIG_MMAP_SIZE |
2379 | ** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values |
2380 | ** that are the default mmap size limit (the default setting for |
2381 | ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit. |
2382 | ** ^The default setting can be overridden by each database connection using |
2383 | ** either the [PRAGMA mmap_size] command, or by using the |
2384 | ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size |
2385 | ** will be silently truncated if necessary so that it does not exceed the |
2386 | ** compile-time maximum mmap size set by the |
2387 | ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^ |
2388 | ** ^If either argument to this option is negative, then that argument is |
2389 | ** changed to its compile-time default. |
2390 | ** |
2391 | ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]] |
2392 | ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE |
2393 | ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is |
2394 | ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro |
2395 | ** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value |
2396 | ** that specifies the maximum size of the created heap. |
2397 | ** |
2398 | ** [[SQLITE_CONFIG_PCACHE_HDRSZ]] |
2399 | ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ |
2400 | ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which |
2401 | ** is a pointer to an integer and writes into that integer the number of extra |
2402 | ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. |
2403 | ** The amount of extra space required can change depending on the compiler, |
2404 | ** target platform, and SQLite version. |
2405 | ** |
2406 | ** [[SQLITE_CONFIG_PMASZ]] |
2407 | ** <dt>SQLITE_CONFIG_PMASZ |
2408 | ** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which |
2409 | ** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded |
2410 | ** sorter to that integer. The default minimum PMA Size is set by the |
2411 | ** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched |
2412 | ** to help with sort operations when multithreaded sorting |
2413 | ** is enabled (using the [PRAGMA threads] command) and the amount of content |
2414 | ** to be sorted exceeds the page size times the minimum of the |
2415 | ** [PRAGMA cache_size] setting and this value. |
2416 | ** |
2417 | ** [[SQLITE_CONFIG_STMTJRNL_SPILL]] |
2418 | ** <dt>SQLITE_CONFIG_STMTJRNL_SPILL |
2419 | ** <dd>^The SQLITE_CONFIG_STMTJRNL_SPILL option takes a single parameter which |
2420 | ** becomes the [statement journal] spill-to-disk threshold. |
2421 | ** [Statement journals] are held in memory until their size (in bytes) |
2422 | ** exceeds this threshold, at which point they are written to disk. |
2423 | ** Or if the threshold is -1, statement journals are always held |
2424 | ** exclusively in memory. |
2425 | ** Since many statement journals never become large, setting the spill |
2426 | ** threshold to a value such as 64KiB can greatly reduce the amount of |
2427 | ** I/O required to support statement rollback. |
2428 | ** The default value for this setting is controlled by the |
2429 | ** [SQLITE_STMTJRNL_SPILL] compile-time option. |
2430 | ** |
2431 | ** [[SQLITE_CONFIG_SORTERREF_SIZE]] |
2432 | ** <dt>SQLITE_CONFIG_SORTERREF_SIZE |
2433 | ** <dd>The SQLITE_CONFIG_SORTERREF_SIZE option accepts a single parameter |
2434 | ** of type (int) - the new value of the sorter-reference size threshold. |
2435 | ** Usually, when SQLite uses an external sort to order records according |
2436 | ** to an ORDER BY clause, all fields required by the caller are present in the |
2437 | ** sorted records. However, if SQLite determines based on the declared type |
2438 | ** of a table column that its values are likely to be very large - larger |
2439 | ** than the configured sorter-reference size threshold - then a reference |
2440 | ** is stored in each sorted record and the required column values loaded |
2441 | ** from the database as records are returned in sorted order. The default |
2442 | ** value for this option is to never use this optimization. Specifying a |
2443 | ** negative value for this option restores the default behaviour. |
2444 | ** This option is only available if SQLite is compiled with the |
2445 | ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option. |
2446 | ** |
2447 | ** [[SQLITE_CONFIG_MEMDB_MAXSIZE]] |
2448 | ** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE |
2449 | ** <dd>The SQLITE_CONFIG_MEMDB_MAXSIZE option accepts a single parameter |
2450 | ** [sqlite3_int64] parameter which is the default maximum size for an in-memory |
2451 | ** database created using [sqlite3_deserialize()]. This default maximum |
2452 | ** size can be adjusted up or down for individual databases using the |
2453 | ** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this |
2454 | ** configuration setting is never used, then the default maximum is determined |
2455 | ** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that |
2456 | ** compile-time option is not set, then the default maximum is 1073741824. |
2457 | ** </dl> |
2458 | */ |
2459 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
2460 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
2461 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
2462 | #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ |
2463 | #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ |
2464 | #define SQLITE_CONFIG_SCRATCH 6 /* No longer used */ |
2465 | #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ |
2466 | #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ |
2467 | #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ |
2468 | #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ |
2469 | #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ |
2470 | /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ |
2471 | #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ |
2472 | #define SQLITE_CONFIG_PCACHE 14 /* no-op */ |
2473 | #define SQLITE_CONFIG_GETPCACHE 15 /* no-op */ |
2474 | #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ |
2475 | #define SQLITE_CONFIG_URI 17 /* int */ |
2476 | #define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */ |
2477 | #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */ |
2478 | #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */ |
2479 | #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */ |
2480 | #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */ |
2481 | #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */ |
2482 | #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */ |
2483 | #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */ |
2484 | #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */ |
2485 | #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */ |
2486 | #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */ |
2487 | #define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */ |
2488 | |
2489 | /* |
2490 | ** CAPI3REF: Database Connection Configuration Options |
2491 | ** |
2492 | ** These constants are the available integer configuration options that |
2493 | ** can be passed as the second argument to the [sqlite3_db_config()] interface. |
2494 | ** |
2495 | ** New configuration options may be added in future releases of SQLite. |
2496 | ** Existing configuration options might be discontinued. Applications |
2497 | ** should check the return code from [sqlite3_db_config()] to make sure that |
2498 | ** the call worked. ^The [sqlite3_db_config()] interface will return a |
2499 | ** non-zero [error code] if a discontinued or unsupported configuration option |
2500 | ** is invoked. |
2501 | ** |
2502 | ** <dl> |
2503 | ** [[SQLITE_DBCONFIG_LOOKASIDE]] |
2504 | ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt> |
2505 | ** <dd> ^This option takes three additional arguments that determine the |
2506 | ** [lookaside memory allocator] configuration for the [database connection]. |
2507 | ** ^The first argument (the third parameter to [sqlite3_db_config()] is a |
2508 | ** pointer to a memory buffer to use for lookaside memory. |
2509 | ** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb |
2510 | ** may be NULL in which case SQLite will allocate the |
2511 | ** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the |
2512 | ** size of each lookaside buffer slot. ^The third argument is the number of |
2513 | ** slots. The size of the buffer in the first argument must be greater than |
2514 | ** or equal to the product of the second and third arguments. The buffer |
2515 | ** must be aligned to an 8-byte boundary. ^If the second argument to |
2516 | ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally |
2517 | ** rounded down to the next smaller multiple of 8. ^(The lookaside memory |
2518 | ** configuration for a database connection can only be changed when that |
2519 | ** connection is not currently using lookaside memory, or in other words |
2520 | ** when the "current value" returned by |
2521 | ** [sqlite3_db_status](D,[SQLITE_DBSTATUS_LOOKASIDE_USED],...) is zero. |
2522 | ** Any attempt to change the lookaside memory configuration when lookaside |
2523 | ** memory is in use leaves the configuration unchanged and returns |
2524 | ** [SQLITE_BUSY].)^</dd> |
2525 | ** |
2526 | ** [[SQLITE_DBCONFIG_ENABLE_FKEY]] |
2527 | ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt> |
2528 | ** <dd> ^This option is used to enable or disable the enforcement of |
2529 | ** [foreign key constraints]. There should be two additional arguments. |
2530 | ** The first argument is an integer which is 0 to disable FK enforcement, |
2531 | ** positive to enable FK enforcement or negative to leave FK enforcement |
2532 | ** unchanged. The second parameter is a pointer to an integer into which |
2533 | ** is written 0 or 1 to indicate whether FK enforcement is off or on |
2534 | ** following this call. The second parameter may be a NULL pointer, in |
2535 | ** which case the FK enforcement setting is not reported back. </dd> |
2536 | ** |
2537 | ** [[SQLITE_DBCONFIG_ENABLE_TRIGGER]] |
2538 | ** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt> |
2539 | ** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers]. |
2540 | ** There should be two additional arguments. |
2541 | ** The first argument is an integer which is 0 to disable triggers, |
2542 | ** positive to enable triggers or negative to leave the setting unchanged. |
2543 | ** The second parameter is a pointer to an integer into which |
2544 | ** is written 0 or 1 to indicate whether triggers are disabled or enabled |
2545 | ** following this call. The second parameter may be a NULL pointer, in |
2546 | ** which case the trigger setting is not reported back. |
2547 | ** |
2548 | ** <p>Originally this option disabled all triggers. ^(However, since |
2549 | ** SQLite version 3.35.0, TEMP triggers are still allowed even if |
2550 | ** this option is off. So, in other words, this option now only disables |
2551 | ** triggers in the main database schema or in the schemas of ATTACH-ed |
2552 | ** databases.)^ </dd> |
2553 | ** |
2554 | ** [[SQLITE_DBCONFIG_ENABLE_VIEW]] |
2555 | ** <dt>SQLITE_DBCONFIG_ENABLE_VIEW</dt> |
2556 | ** <dd> ^This option is used to enable or disable [CREATE VIEW | views]. |
2557 | ** There should be two additional arguments. |
2558 | ** The first argument is an integer which is 0 to disable views, |
2559 | ** positive to enable views or negative to leave the setting unchanged. |
2560 | ** The second parameter is a pointer to an integer into which |
2561 | ** is written 0 or 1 to indicate whether views are disabled or enabled |
2562 | ** following this call. The second parameter may be a NULL pointer, in |
2563 | ** which case the view setting is not reported back. |
2564 | ** |
2565 | ** <p>Originally this option disabled all views. ^(However, since |
2566 | ** SQLite version 3.35.0, TEMP views are still allowed even if |
2567 | ** this option is off. So, in other words, this option now only disables |
2568 | ** views in the main database schema or in the schemas of ATTACH-ed |
2569 | ** databases.)^ </dd> |
2570 | ** |
2571 | ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]] |
2572 | ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt> |
2573 | ** <dd> ^This option is used to enable or disable the |
2574 | ** [fts3_tokenizer()] function which is part of the |
2575 | ** [FTS3] full-text search engine extension. |
2576 | ** There should be two additional arguments. |
2577 | ** The first argument is an integer which is 0 to disable fts3_tokenizer() or |
2578 | ** positive to enable fts3_tokenizer() or negative to leave the setting |
2579 | ** unchanged. |
2580 | ** The second parameter is a pointer to an integer into which |
2581 | ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled |
2582 | ** following this call. The second parameter may be a NULL pointer, in |
2583 | ** which case the new setting is not reported back. </dd> |
2584 | ** |
2585 | ** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]] |
2586 | ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt> |
2587 | ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()] |
2588 | ** interface independently of the [load_extension()] SQL function. |
2589 | ** The [sqlite3_enable_load_extension()] API enables or disables both the |
2590 | ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()]. |
2591 | ** There should be two additional arguments. |
2592 | ** When the first argument to this interface is 1, then only the C-API is |
2593 | ** enabled and the SQL function remains disabled. If the first argument to |
2594 | ** this interface is 0, then both the C-API and the SQL function are disabled. |
2595 | ** If the first argument is -1, then no changes are made to state of either the |
2596 | ** C-API or the SQL function. |
2597 | ** The second parameter is a pointer to an integer into which |
2598 | ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface |
2599 | ** is disabled or enabled following this call. The second parameter may |
2600 | ** be a NULL pointer, in which case the new setting is not reported back. |
2601 | ** </dd> |
2602 | ** |
2603 | ** [[SQLITE_DBCONFIG_MAINDBNAME]] <dt>SQLITE_DBCONFIG_MAINDBNAME</dt> |
2604 | ** <dd> ^This option is used to change the name of the "main" database |
2605 | ** schema. ^The sole argument is a pointer to a constant UTF8 string |
2606 | ** which will become the new schema name in place of "main". ^SQLite |
2607 | ** does not make a copy of the new main schema name string, so the application |
2608 | ** must ensure that the argument passed into this DBCONFIG option is unchanged |
2609 | ** until after the database connection closes. |
2610 | ** </dd> |
2611 | ** |
2612 | ** [[SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE]] |
2613 | ** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt> |
2614 | ** <dd> Usually, when a database in wal mode is closed or detached from a |
2615 | ** database handle, SQLite checks if this will mean that there are now no |
2616 | ** connections at all to the database. If so, it performs a checkpoint |
2617 | ** operation before closing the connection. This option may be used to |
2618 | ** override this behaviour. The first parameter passed to this operation |
2619 | ** is an integer - positive to disable checkpoints-on-close, or zero (the |
2620 | ** default) to enable them, and negative to leave the setting unchanged. |
2621 | ** The second parameter is a pointer to an integer |
2622 | ** into which is written 0 or 1 to indicate whether checkpoints-on-close |
2623 | ** have been disabled - 0 if they are not disabled, 1 if they are. |
2624 | ** </dd> |
2625 | ** |
2626 | ** [[SQLITE_DBCONFIG_ENABLE_QPSG]] <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt> |
2627 | ** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates |
2628 | ** the [query planner stability guarantee] (QPSG). When the QPSG is active, |
2629 | ** a single SQL query statement will always use the same algorithm regardless |
2630 | ** of values of [bound parameters].)^ The QPSG disables some query optimizations |
2631 | ** that look at the values of bound parameters, which can make some queries |
2632 | ** slower. But the QPSG has the advantage of more predictable behavior. With |
2633 | ** the QPSG active, SQLite will always use the same query plan in the field as |
2634 | ** was used during testing in the lab. |
2635 | ** The first argument to this setting is an integer which is 0 to disable |
2636 | ** the QPSG, positive to enable QPSG, or negative to leave the setting |
2637 | ** unchanged. The second parameter is a pointer to an integer into which |
2638 | ** is written 0 or 1 to indicate whether the QPSG is disabled or enabled |
2639 | ** following this call. |
2640 | ** </dd> |
2641 | ** |
2642 | ** [[SQLITE_DBCONFIG_TRIGGER_EQP]] <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt> |
2643 | ** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not |
2644 | ** include output for any operations performed by trigger programs. This |
2645 | ** option is used to set or clear (the default) a flag that governs this |
2646 | ** behavior. The first parameter passed to this operation is an integer - |
2647 | ** positive to enable output for trigger programs, or zero to disable it, |
2648 | ** or negative to leave the setting unchanged. |
2649 | ** The second parameter is a pointer to an integer into which is written |
2650 | ** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if |
2651 | ** it is not disabled, 1 if it is. |
2652 | ** </dd> |
2653 | ** |
2654 | ** [[SQLITE_DBCONFIG_RESET_DATABASE]] <dt>SQLITE_DBCONFIG_RESET_DATABASE</dt> |
2655 | ** <dd> Set the SQLITE_DBCONFIG_RESET_DATABASE flag and then run |
2656 | ** [VACUUM] in order to reset a database back to an empty database |
2657 | ** with no schema and no content. The following process works even for |
2658 | ** a badly corrupted database file: |
2659 | ** <ol> |
2660 | ** <li> If the database connection is newly opened, make sure it has read the |
2661 | ** database schema by preparing then discarding some query against the |
2662 | ** database, or calling sqlite3_table_column_metadata(), ignoring any |
2663 | ** errors. This step is only necessary if the application desires to keep |
2664 | ** the database in WAL mode after the reset if it was in WAL mode before |
2665 | ** the reset. |
2666 | ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0); |
2667 | ** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0); |
2668 | ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0); |
2669 | ** </ol> |
2670 | ** Because resetting a database is destructive and irreversible, the |
2671 | ** process requires the use of this obscure API and multiple steps to |
2672 | ** help ensure that it does not happen by accident. Because this |
2673 | ** feature must be capable of resetting corrupt databases, and |
2674 | ** shutting down virtual tables may require access to that corrupt |
2675 | ** storage, the library must abandon any installed virtual tables |
2676 | ** without calling their xDestroy() methods. |
2677 | ** |
2678 | ** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt> |
2679 | ** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the |
2680 | ** "defensive" flag for a database connection. When the defensive |
2681 | ** flag is enabled, language features that allow ordinary SQL to |
2682 | ** deliberately corrupt the database file are disabled. The disabled |
2683 | ** features include but are not limited to the following: |
2684 | ** <ul> |
2685 | ** <li> The [PRAGMA writable_schema=ON] statement. |
2686 | ** <li> The [PRAGMA journal_mode=OFF] statement. |
2687 | ** <li> The [PRAGMA schema_version=N] statement. |
2688 | ** <li> Writes to the [sqlite_dbpage] virtual table. |
2689 | ** <li> Direct writes to [shadow tables]. |
2690 | ** </ul> |
2691 | ** </dd> |
2692 | ** |
2693 | ** [[SQLITE_DBCONFIG_WRITABLE_SCHEMA]] <dt>SQLITE_DBCONFIG_WRITABLE_SCHEMA</dt> |
2694 | ** <dd>The SQLITE_DBCONFIG_WRITABLE_SCHEMA option activates or deactivates the |
2695 | ** "writable_schema" flag. This has the same effect and is logically equivalent |
2696 | ** to setting [PRAGMA writable_schema=ON] or [PRAGMA writable_schema=OFF]. |
2697 | ** The first argument to this setting is an integer which is 0 to disable |
2698 | ** the writable_schema, positive to enable writable_schema, or negative to |
2699 | ** leave the setting unchanged. The second parameter is a pointer to an |
2700 | ** integer into which is written 0 or 1 to indicate whether the writable_schema |
2701 | ** is enabled or disabled following this call. |
2702 | ** </dd> |
2703 | ** |
2704 | ** [[SQLITE_DBCONFIG_LEGACY_ALTER_TABLE]] |
2705 | ** <dt>SQLITE_DBCONFIG_LEGACY_ALTER_TABLE</dt> |
2706 | ** <dd>The SQLITE_DBCONFIG_LEGACY_ALTER_TABLE option activates or deactivates |
2707 | ** the legacy behavior of the [ALTER TABLE RENAME] command such it |
2708 | ** behaves as it did prior to [version 3.24.0] (2018-06-04). See the |
2709 | ** "Compatibility Notice" on the [ALTER TABLE RENAME documentation] for |
2710 | ** additional information. This feature can also be turned on and off |
2711 | ** using the [PRAGMA legacy_alter_table] statement. |
2712 | ** </dd> |
2713 | ** |
2714 | ** [[SQLITE_DBCONFIG_DQS_DML]] |
2715 | ** <dt>SQLITE_DBCONFIG_DQS_DML</dt> |
2716 | ** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates |
2717 | ** the legacy [double-quoted string literal] misfeature for DML statements |
2718 | ** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The |
2719 | ** default value of this setting is determined by the [-DSQLITE_DQS] |
2720 | ** compile-time option. |
2721 | ** </dd> |
2722 | ** |
2723 | ** [[SQLITE_DBCONFIG_DQS_DDL]] |
2724 | ** <dt>SQLITE_DBCONFIG_DQS_DDL</dt> |
2725 | ** <dd>The SQLITE_DBCONFIG_DQS option activates or deactivates |
2726 | ** the legacy [double-quoted string literal] misfeature for DDL statements, |
2727 | ** such as CREATE TABLE and CREATE INDEX. The |
2728 | ** default value of this setting is determined by the [-DSQLITE_DQS] |
2729 | ** compile-time option. |
2730 | ** </dd> |
2731 | ** |
2732 | ** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]] |
2733 | ** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</dt> |
2734 | ** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to |
2735 | ** assume that database schemas are untainted by malicious content. |
2736 | ** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite |
2737 | ** takes additional defensive steps to protect the application from harm |
2738 | ** including: |
2739 | ** <ul> |
2740 | ** <li> Prohibit the use of SQL functions inside triggers, views, |
2741 | ** CHECK constraints, DEFAULT clauses, expression indexes, |
2742 | ** partial indexes, or generated columns |
2743 | ** unless those functions are tagged with [SQLITE_INNOCUOUS]. |
2744 | ** <li> Prohibit the use of virtual tables inside of triggers or views |
2745 | ** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS]. |
2746 | ** </ul> |
2747 | ** This setting defaults to "on" for legacy compatibility, however |
2748 | ** all applications are advised to turn it off if possible. This setting |
2749 | ** can also be controlled using the [PRAGMA trusted_schema] statement. |
2750 | ** </dd> |
2751 | ** |
2752 | ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]] |
2753 | ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</dt> |
2754 | ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates |
2755 | ** the legacy file format flag. When activated, this flag causes all newly |
2756 | ** created database file to have a schema format version number (the 4-byte |
2757 | ** integer found at offset 44 into the database header) of 1. This in turn |
2758 | ** means that the resulting database file will be readable and writable by |
2759 | ** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting, |
2760 | ** newly created databases are generally not understandable by SQLite versions |
2761 | ** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there |
2762 | ** is now scarcely any need to generate database files that are compatible |
2763 | ** all the way back to version 3.0.0, and so this setting is of little |
2764 | ** practical use, but is provided so that SQLite can continue to claim the |
2765 | ** ability to generate new database files that are compatible with version |
2766 | ** 3.0.0. |
2767 | ** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on, |
2768 | ** the [VACUUM] command will fail with an obscure error when attempting to |
2769 | ** process a table with generated columns and a descending index. This is |
2770 | ** not considered a bug since SQLite versions 3.3.0 and earlier do not support |
2771 | ** either generated columns or descending indexes. |
2772 | ** </dd> |
2773 | ** |
2774 | ** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]] |
2775 | ** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt> |
2776 | ** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in |
2777 | ** SQLITE_ENABLE_STMT_SCANSTATUS builds. In this case, it sets or clears |
2778 | ** a flag that enables collection of the sqlite3_stmt_scanstatus_v2() |
2779 | ** statistics. For statistics to be collected, the flag must be set on |
2780 | ** the database handle both when the SQL statement is prepared and when it |
2781 | ** is stepped. The flag is set (collection of statistics is enabled) |
2782 | ** by default. This option takes two arguments: an integer and a pointer to |
2783 | ** an integer.. The first argument is 1, 0, or -1 to enable, disable, or |
2784 | ** leave unchanged the statement scanstatus option. If the second argument |
2785 | ** is not NULL, then the value of the statement scanstatus setting after |
2786 | ** processing the first argument is written into the integer that the second |
2787 | ** argument points to. |
2788 | ** </dd> |
2789 | ** |
2790 | ** [[SQLITE_DBCONFIG_REVERSE_SCANORDER]] |
2791 | ** <dt>SQLITE_DBCONFIG_REVERSE_SCANORDER</dt> |
2792 | ** <dd>The SQLITE_DBCONFIG_REVERSE_SCANORDER option changes the default order |
2793 | ** in which tables and indexes are scanned so that the scans start at the end |
2794 | ** and work toward the beginning rather than starting at the beginning and |
2795 | ** working toward the end. Setting SQLITE_DBCONFIG_REVERSE_SCANORDER is the |
2796 | ** same as setting [PRAGMA reverse_unordered_selects]. This option takes |
2797 | ** two arguments which are an integer and a pointer to an integer. The first |
2798 | ** argument is 1, 0, or -1 to enable, disable, or leave unchanged the |
2799 | ** reverse scan order flag, respectively. If the second argument is not NULL, |
2800 | ** then 0 or 1 is written into the integer that the second argument points to |
2801 | ** depending on if the reverse scan order flag is set after processing the |
2802 | ** first argument. |
2803 | ** </dd> |
2804 | ** |
2805 | ** </dl> |
2806 | */ |
2807 | #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */ |
2808 | #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */ |
2809 | #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */ |
2810 | #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */ |
2811 | #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */ |
2812 | #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */ |
2813 | #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */ |
2814 | #define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */ |
2815 | #define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */ |
2816 | #define SQLITE_DBCONFIG_RESET_DATABASE 1009 /* int int* */ |
2817 | #define SQLITE_DBCONFIG_DEFENSIVE 1010 /* int int* */ |
2818 | #define SQLITE_DBCONFIG_WRITABLE_SCHEMA 1011 /* int int* */ |
2819 | #define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE 1012 /* int int* */ |
2820 | #define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */ |
2821 | #define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */ |
2822 | #define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */ |
2823 | #define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */ |
2824 | #define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */ |
2825 | #define SQLITE_DBCONFIG_STMT_SCANSTATUS 1018 /* int int* */ |
2826 | #define SQLITE_DBCONFIG_REVERSE_SCANORDER 1019 /* int int* */ |
2827 | #define SQLITE_DBCONFIG_MAX 1019 /* Largest DBCONFIG */ |
2828 | |
2829 | /* |
2830 | ** CAPI3REF: Enable Or Disable Extended Result Codes |
2831 | ** METHOD: sqlite3 |
2832 | ** |
2833 | ** ^The sqlite3_extended_result_codes() routine enables or disables the |
2834 | ** [extended result codes] feature of SQLite. ^The extended result |
2835 | ** codes are disabled by default for historical compatibility. |
2836 | */ |
2837 | SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff); |
2838 | |
2839 | /* |
2840 | ** CAPI3REF: Last Insert Rowid |
2841 | ** METHOD: sqlite3 |
2842 | ** |
2843 | ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables) |
2844 | ** has a unique 64-bit signed |
2845 | ** integer key called the [ROWID | "rowid"]. ^The rowid is always available |
2846 | ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those |
2847 | ** names are not also used by explicitly declared columns. ^If |
2848 | ** the table has a column of type [INTEGER PRIMARY KEY] then that column |
2849 | ** is another alias for the rowid. |
2850 | ** |
2851 | ** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of |
2852 | ** the most recent successful [INSERT] into a rowid table or [virtual table] |
2853 | ** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not |
2854 | ** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred |
2855 | ** on the database connection D, then sqlite3_last_insert_rowid(D) returns |
2856 | ** zero. |
2857 | ** |
2858 | ** As well as being set automatically as rows are inserted into database |
2859 | ** tables, the value returned by this function may be set explicitly by |
2860 | ** [sqlite3_set_last_insert_rowid()] |
2861 | ** |
2862 | ** Some virtual table implementations may INSERT rows into rowid tables as |
2863 | ** part of committing a transaction (e.g. to flush data accumulated in memory |
2864 | ** to disk). In this case subsequent calls to this function return the rowid |
2865 | ** associated with these internal INSERT operations, which leads to |
2866 | ** unintuitive results. Virtual table implementations that do write to rowid |
2867 | ** tables in this way can avoid this problem by restoring the original |
2868 | ** rowid value using [sqlite3_set_last_insert_rowid()] before returning |
2869 | ** control to the user. |
2870 | ** |
2871 | ** ^(If an [INSERT] occurs within a trigger then this routine will |
2872 | ** return the [rowid] of the inserted row as long as the trigger is |
2873 | ** running. Once the trigger program ends, the value returned |
2874 | ** by this routine reverts to what it was before the trigger was fired.)^ |
2875 | ** |
2876 | ** ^An [INSERT] that fails due to a constraint violation is not a |
2877 | ** successful [INSERT] and does not change the value returned by this |
2878 | ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, |
2879 | ** and INSERT OR ABORT make no changes to the return value of this |
2880 | ** routine when their insertion fails. ^(When INSERT OR REPLACE |
2881 | ** encounters a constraint violation, it does not fail. The |
2882 | ** INSERT continues to completion after deleting rows that caused |
2883 | ** the constraint problem so INSERT OR REPLACE will always change |
2884 | ** the return value of this interface.)^ |
2885 | ** |
2886 | ** ^For the purposes of this routine, an [INSERT] is considered to |
2887 | ** be successful even if it is subsequently rolled back. |
2888 | ** |
2889 | ** This function is accessible to SQL statements via the |
2890 | ** [last_insert_rowid() SQL function]. |
2891 | ** |
2892 | ** If a separate thread performs a new [INSERT] on the same |
2893 | ** database connection while the [sqlite3_last_insert_rowid()] |
2894 | ** function is running and thus changes the last insert [rowid], |
2895 | ** then the value returned by [sqlite3_last_insert_rowid()] is |
2896 | ** unpredictable and might not equal either the old or the new |
2897 | ** last insert [rowid]. |
2898 | */ |
2899 | SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); |
2900 | |
2901 | /* |
2902 | ** CAPI3REF: Set the Last Insert Rowid value. |
2903 | ** METHOD: sqlite3 |
2904 | ** |
2905 | ** The sqlite3_set_last_insert_rowid(D, R) method allows the application to |
2906 | ** set the value returned by calling sqlite3_last_insert_rowid(D) to R |
2907 | ** without inserting a row into the database. |
2908 | */ |
2909 | SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64); |
2910 | |
2911 | /* |
2912 | ** CAPI3REF: Count The Number Of Rows Modified |
2913 | ** METHOD: sqlite3 |
2914 | ** |
2915 | ** ^These functions return the number of rows modified, inserted or |
2916 | ** deleted by the most recently completed INSERT, UPDATE or DELETE |
2917 | ** statement on the database connection specified by the only parameter. |
2918 | ** The two functions are identical except for the type of the return value |
2919 | ** and that if the number of rows modified by the most recent INSERT, UPDATE |
2920 | ** or DELETE is greater than the maximum value supported by type "int", then |
2921 | ** the return value of sqlite3_changes() is undefined. ^Executing any other |
2922 | ** type of SQL statement does not modify the value returned by these functions. |
2923 | ** |
2924 | ** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are |
2925 | ** considered - auxiliary changes caused by [CREATE TRIGGER | triggers], |
2926 | ** [foreign key actions] or [REPLACE] constraint resolution are not counted. |
2927 | ** |
2928 | ** Changes to a view that are intercepted by |
2929 | ** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value |
2930 | ** returned by sqlite3_changes() immediately after an INSERT, UPDATE or |
2931 | ** DELETE statement run on a view is always zero. Only changes made to real |
2932 | ** tables are counted. |
2933 | ** |
2934 | ** Things are more complicated if the sqlite3_changes() function is |
2935 | ** executed while a trigger program is running. This may happen if the |
2936 | ** program uses the [changes() SQL function], or if some other callback |
2937 | ** function invokes sqlite3_changes() directly. Essentially: |
2938 | ** |
2939 | ** <ul> |
2940 | ** <li> ^(Before entering a trigger program the value returned by |
2941 | ** sqlite3_changes() function is saved. After the trigger program |
2942 | ** has finished, the original value is restored.)^ |
2943 | ** |
2944 | ** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE |
2945 | ** statement sets the value returned by sqlite3_changes() |
2946 | ** upon completion as normal. Of course, this value will not include |
2947 | ** any changes performed by sub-triggers, as the sqlite3_changes() |
2948 | ** value will be saved and restored after each sub-trigger has run.)^ |
2949 | ** </ul> |
2950 | ** |
2951 | ** ^This means that if the changes() SQL function (or similar) is used |
2952 | ** by the first INSERT, UPDATE or DELETE statement within a trigger, it |
2953 | ** returns the value as set when the calling statement began executing. |
2954 | ** ^If it is used by the second or subsequent such statement within a trigger |
2955 | ** program, the value returned reflects the number of rows modified by the |
2956 | ** previous INSERT, UPDATE or DELETE statement within the same trigger. |
2957 | ** |
2958 | ** If a separate thread makes changes on the same database connection |
2959 | ** while [sqlite3_changes()] is running then the value returned |
2960 | ** is unpredictable and not meaningful. |
2961 | ** |
2962 | ** See also: |
2963 | ** <ul> |
2964 | ** <li> the [sqlite3_total_changes()] interface |
2965 | ** <li> the [count_changes pragma] |
2966 | ** <li> the [changes() SQL function] |
2967 | ** <li> the [data_version pragma] |
2968 | ** </ul> |
2969 | */ |
2970 | SQLITE_API int sqlite3_changes(sqlite3*); |
2971 | SQLITE_API sqlite3_int64 sqlite3_changes64(sqlite3*); |
2972 | |
2973 | /* |
2974 | ** CAPI3REF: Total Number Of Rows Modified |
2975 | ** METHOD: sqlite3 |
2976 | ** |
2977 | ** ^These functions return the total number of rows inserted, modified or |
2978 | ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed |
2979 | ** since the database connection was opened, including those executed as |
2980 | ** part of trigger programs. The two functions are identical except for the |
2981 | ** type of the return value and that if the number of rows modified by the |
2982 | ** connection exceeds the maximum value supported by type "int", then |
2983 | ** the return value of sqlite3_total_changes() is undefined. ^Executing |
2984 | ** any other type of SQL statement does not affect the value returned by |
2985 | ** sqlite3_total_changes(). |
2986 | ** |
2987 | ** ^Changes made as part of [foreign key actions] are included in the |
2988 | ** count, but those made as part of REPLACE constraint resolution are |
2989 | ** not. ^Changes to a view that are intercepted by INSTEAD OF triggers |
2990 | ** are not counted. |
2991 | ** |
2992 | ** The [sqlite3_total_changes(D)] interface only reports the number |
2993 | ** of rows that changed due to SQL statement run against database |
2994 | ** connection D. Any changes by other database connections are ignored. |
2995 | ** To detect changes against a database file from other database |
2996 | ** connections use the [PRAGMA data_version] command or the |
2997 | ** [SQLITE_FCNTL_DATA_VERSION] [file control]. |
2998 | ** |
2999 | ** If a separate thread makes changes on the same database connection |
3000 | ** while [sqlite3_total_changes()] is running then the value |
3001 | ** returned is unpredictable and not meaningful. |
3002 | ** |
3003 | ** See also: |
3004 | ** <ul> |
3005 | ** <li> the [sqlite3_changes()] interface |
3006 | ** <li> the [count_changes pragma] |
3007 | ** <li> the [changes() SQL function] |
3008 | ** <li> the [data_version pragma] |
3009 | ** <li> the [SQLITE_FCNTL_DATA_VERSION] [file control] |
3010 | ** </ul> |
3011 | */ |
3012 | SQLITE_API int sqlite3_total_changes(sqlite3*); |
3013 | SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3*); |
3014 | |
3015 | /* |
3016 | ** CAPI3REF: Interrupt A Long-Running Query |
3017 | ** METHOD: sqlite3 |
3018 | ** |
3019 | ** ^This function causes any pending database operation to abort and |
3020 | ** return at its earliest opportunity. This routine is typically |
3021 | ** called in response to a user action such as pressing "Cancel" |
3022 | ** or Ctrl-C where the user wants a long query operation to halt |
3023 | ** immediately. |
3024 | ** |
3025 | ** ^It is safe to call this routine from a thread different from the |
3026 | ** thread that is currently running the database operation. But it |
3027 | ** is not safe to call this routine with a [database connection] that |
3028 | ** is closed or might close before sqlite3_interrupt() returns. |
3029 | ** |
3030 | ** ^If an SQL operation is very nearly finished at the time when |
3031 | ** sqlite3_interrupt() is called, then it might not have an opportunity |
3032 | ** to be interrupted and might continue to completion. |
3033 | ** |
3034 | ** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT]. |
3035 | ** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE |
3036 | ** that is inside an explicit transaction, then the entire transaction |
3037 | ** will be rolled back automatically. |
3038 | ** |
3039 | ** ^The sqlite3_interrupt(D) call is in effect until all currently running |
3040 | ** SQL statements on [database connection] D complete. ^Any new SQL statements |
3041 | ** that are started after the sqlite3_interrupt() call and before the |
3042 | ** running statement count reaches zero are interrupted as if they had been |
3043 | ** running prior to the sqlite3_interrupt() call. ^New SQL statements |
3044 | ** that are started after the running statement count reaches zero are |
3045 | ** not effected by the sqlite3_interrupt(). |
3046 | ** ^A call to sqlite3_interrupt(D) that occurs when there are no running |
3047 | ** SQL statements is a no-op and has no effect on SQL statements |
3048 | ** that are started after the sqlite3_interrupt() call returns. |
3049 | ** |
3050 | ** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether |
3051 | ** or not an interrupt is currently in effect for [database connection] D. |
3052 | ** It returns 1 if an interrupt is currently in effect, or 0 otherwise. |
3053 | */ |
3054 | SQLITE_API void sqlite3_interrupt(sqlite3*); |
3055 | SQLITE_API int sqlite3_is_interrupted(sqlite3*); |
3056 | |
3057 | /* |
3058 | ** CAPI3REF: Determine If An SQL Statement Is Complete |
3059 | ** |
3060 | ** These routines are useful during command-line input to determine if the |
3061 | ** currently entered text seems to form a complete SQL statement or |
3062 | ** if additional input is needed before sending the text into |
3063 | ** SQLite for parsing. ^These routines return 1 if the input string |
3064 | ** appears to be a complete SQL statement. ^A statement is judged to be |
3065 | ** complete if it ends with a semicolon token and is not a prefix of a |
3066 | ** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within |
3067 | ** string literals or quoted identifier names or comments are not |
3068 | ** independent tokens (they are part of the token in which they are |
3069 | ** embedded) and thus do not count as a statement terminator. ^Whitespace |
3070 | ** and comments that follow the final semicolon are ignored. |
3071 | ** |
3072 | ** ^These routines return 0 if the statement is incomplete. ^If a |
3073 | ** memory allocation fails, then SQLITE_NOMEM is returned. |
3074 | ** |
3075 | ** ^These routines do not parse the SQL statements thus |
3076 | ** will not detect syntactically incorrect SQL. |
3077 | ** |
3078 | ** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior |
3079 | ** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked |
3080 | ** automatically by sqlite3_complete16(). If that initialization fails, |
3081 | ** then the return value from sqlite3_complete16() will be non-zero |
3082 | ** regardless of whether or not the input SQL is complete.)^ |
3083 | ** |
3084 | ** The input to [sqlite3_complete()] must be a zero-terminated |
3085 | ** UTF-8 string. |
3086 | ** |
3087 | ** The input to [sqlite3_complete16()] must be a zero-terminated |
3088 | ** UTF-16 string in native byte order. |
3089 | */ |
3090 | SQLITE_API int sqlite3_complete(const char *sql); |
3091 | SQLITE_API int sqlite3_complete16(const void *sql); |
3092 | |
3093 | /* |
3094 | ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors |
3095 | ** KEYWORDS: {busy-handler callback} {busy handler} |
3096 | ** METHOD: sqlite3 |
3097 | ** |
3098 | ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X |
3099 | ** that might be invoked with argument P whenever |
3100 | ** an attempt is made to access a database table associated with |
3101 | ** [database connection] D when another thread |
3102 | ** or process has the table locked. |
3103 | ** The sqlite3_busy_handler() interface is used to implement |
3104 | ** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout]. |
3105 | ** |
3106 | ** ^If the busy callback is NULL, then [SQLITE_BUSY] |
3107 | ** is returned immediately upon encountering the lock. ^If the busy callback |
3108 | ** is not NULL, then the callback might be invoked with two arguments. |
3109 | ** |
3110 | ** ^The first argument to the busy handler is a copy of the void* pointer which |
3111 | ** is the third argument to sqlite3_busy_handler(). ^The second argument to |
3112 | ** the busy handler callback is the number of times that the busy handler has |
3113 | ** been invoked previously for the same locking event. ^If the |
3114 | ** busy callback returns 0, then no additional attempts are made to |
3115 | ** access the database and [SQLITE_BUSY] is returned |
3116 | ** to the application. |
3117 | ** ^If the callback returns non-zero, then another attempt |
3118 | ** is made to access the database and the cycle repeats. |
3119 | ** |
3120 | ** The presence of a busy handler does not guarantee that it will be invoked |
3121 | ** when there is lock contention. ^If SQLite determines that invoking the busy |
3122 | ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY] |
3123 | ** to the application instead of invoking the |
3124 | ** busy handler. |
3125 | ** Consider a scenario where one process is holding a read lock that |
3126 | ** it is trying to promote to a reserved lock and |
3127 | ** a second process is holding a reserved lock that it is trying |
3128 | ** to promote to an exclusive lock. The first process cannot proceed |
3129 | ** because it is blocked by the second and the second process cannot |
3130 | ** proceed because it is blocked by the first. If both processes |
3131 | ** invoke the busy handlers, neither will make any progress. Therefore, |
3132 | ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this |
3133 | ** will induce the first process to release its read lock and allow |
3134 | ** the second process to proceed. |
3135 | ** |
3136 | ** ^The default busy callback is NULL. |
3137 | ** |
3138 | ** ^(There can only be a single busy handler defined for each |
3139 | ** [database connection]. Setting a new busy handler clears any |
3140 | ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()] |
3141 | ** or evaluating [PRAGMA busy_timeout=N] will change the |
3142 | ** busy handler and thus clear any previously set busy handler. |
3143 | ** |
3144 | ** The busy callback should not take any actions which modify the |
3145 | ** database connection that invoked the busy handler. In other words, |
3146 | ** the busy handler is not reentrant. Any such actions |
3147 | ** result in undefined behavior. |
3148 | ** |
3149 | ** A busy handler must not close the database connection |
3150 | ** or [prepared statement] that invoked the busy handler. |
3151 | */ |
3152 | SQLITE_API int sqlite3_busy_handler(sqlite3*,int(*)(void*,int),void*); |
3153 | |
3154 | /* |
3155 | ** CAPI3REF: Set A Busy Timeout |
3156 | ** METHOD: sqlite3 |
3157 | ** |
3158 | ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps |
3159 | ** for a specified amount of time when a table is locked. ^The handler |
3160 | ** will sleep multiple times until at least "ms" milliseconds of sleeping |
3161 | ** have accumulated. ^After at least "ms" milliseconds of sleeping, |
3162 | ** the handler returns 0 which causes [sqlite3_step()] to return |
3163 | ** [SQLITE_BUSY]. |
3164 | ** |
3165 | ** ^Calling this routine with an argument less than or equal to zero |
3166 | ** turns off all busy handlers. |
3167 | ** |
3168 | ** ^(There can only be a single busy handler for a particular |
3169 | ** [database connection] at any given moment. If another busy handler |
3170 | ** was defined (using [sqlite3_busy_handler()]) prior to calling |
3171 | ** this routine, that other busy handler is cleared.)^ |
3172 | ** |
3173 | ** See also: [PRAGMA busy_timeout] |
3174 | */ |
3175 | SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms); |
3176 | |
3177 | /* |
3178 | ** CAPI3REF: Convenience Routines For Running Queries |
3179 | ** METHOD: sqlite3 |
3180 | ** |
3181 | ** This is a legacy interface that is preserved for backwards compatibility. |
3182 | ** Use of this interface is not recommended. |
3183 | ** |
3184 | ** Definition: A <b>result table</b> is memory data structure created by the |
3185 | ** [sqlite3_get_table()] interface. A result table records the |
3186 | ** complete query results from one or more queries. |
3187 | ** |
3188 | ** The table conceptually has a number of rows and columns. But |
3189 | ** these numbers are not part of the result table itself. These |
3190 | ** numbers are obtained separately. Let N be the number of rows |
3191 | ** and M be the number of columns. |
3192 | ** |
3193 | ** A result table is an array of pointers to zero-terminated UTF-8 strings. |
3194 | ** There are (N+1)*M elements in the array. The first M pointers point |
3195 | ** to zero-terminated strings that contain the names of the columns. |
3196 | ** The remaining entries all point to query results. NULL values result |
3197 | ** in NULL pointers. All other values are in their UTF-8 zero-terminated |
3198 | ** string representation as returned by [sqlite3_column_text()]. |
3199 | ** |
3200 | ** A result table might consist of one or more memory allocations. |
3201 | ** It is not safe to pass a result table directly to [sqlite3_free()]. |
3202 | ** A result table should be deallocated using [sqlite3_free_table()]. |
3203 | ** |
3204 | ** ^(As an example of the result table format, suppose a query result |
3205 | ** is as follows: |
3206 | ** |
3207 | ** <blockquote><pre> |
3208 | ** Name | Age |
3209 | ** ----------------------- |
3210 | ** Alice | 43 |
3211 | ** Bob | 28 |
3212 | ** Cindy | 21 |
3213 | ** </pre></blockquote> |
3214 | ** |
3215 | ** There are two columns (M==2) and three rows (N==3). Thus the |
3216 | ** result table has 8 entries. Suppose the result table is stored |
3217 | ** in an array named azResult. Then azResult holds this content: |
3218 | ** |
3219 | ** <blockquote><pre> |
3220 | ** azResult[0] = "Name"; |
3221 | ** azResult[1] = "Age"; |
3222 | ** azResult[2] = "Alice"; |
3223 | ** azResult[3] = "43"; |
3224 | ** azResult[4] = "Bob"; |
3225 | ** azResult[5] = "28"; |
3226 | ** azResult[6] = "Cindy"; |
3227 | ** azResult[7] = "21"; |
3228 | ** </pre></blockquote>)^ |
3229 | ** |
3230 | ** ^The sqlite3_get_table() function evaluates one or more |
3231 | ** semicolon-separated SQL statements in the zero-terminated UTF-8 |
3232 | ** string of its 2nd parameter and returns a result table to the |
3233 | ** pointer given in its 3rd parameter. |
3234 | ** |
3235 | ** After the application has finished with the result from sqlite3_get_table(), |
3236 | ** it must pass the result table pointer to sqlite3_free_table() in order to |
3237 | ** release the memory that was malloced. Because of the way the |
3238 | ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling |
3239 | ** function must not try to call [sqlite3_free()] directly. Only |
3240 | ** [sqlite3_free_table()] is able to release the memory properly and safely. |
3241 | ** |
3242 | ** The sqlite3_get_table() interface is implemented as a wrapper around |
3243 | ** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access |
3244 | ** to any internal data structures of SQLite. It uses only the public |
3245 | ** interface defined here. As a consequence, errors that occur in the |
3246 | ** wrapper layer outside of the internal [sqlite3_exec()] call are not |
3247 | ** reflected in subsequent calls to [sqlite3_errcode()] or |
3248 | ** [sqlite3_errmsg()]. |
3249 | */ |
3250 | SQLITE_API int sqlite3_get_table( |
3251 | sqlite3 *db, /* An open database */ |
3252 | const char *zSql, /* SQL to be evaluated */ |
3253 | char ***pazResult, /* Results of the query */ |
3254 | int *pnRow, /* Number of result rows written here */ |
3255 | int *pnColumn, /* Number of result columns written here */ |
3256 | char **pzErrmsg /* Error msg written here */ |
3257 | ); |
3258 | SQLITE_API void sqlite3_free_table(char **result); |
3259 | |
3260 | /* |
3261 | ** CAPI3REF: Formatted String Printing Functions |
3262 | ** |
3263 | ** These routines are work-alikes of the "printf()" family of functions |
3264 | ** from the standard C library. |
3265 | ** These routines understand most of the common formatting options from |
3266 | ** the standard library printf() |
3267 | ** plus some additional non-standard formats ([%q], [%Q], [%w], and [%z]). |
3268 | ** See the [built-in printf()] documentation for details. |
3269 | ** |
3270 | ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their |
3271 | ** results into memory obtained from [sqlite3_malloc64()]. |
3272 | ** The strings returned by these two routines should be |
3273 | ** released by [sqlite3_free()]. ^Both routines return a |
3274 | ** NULL pointer if [sqlite3_malloc64()] is unable to allocate enough |
3275 | ** memory to hold the resulting string. |
3276 | ** |
3277 | ** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from |
3278 | ** the standard C library. The result is written into the |
3279 | ** buffer supplied as the second parameter whose size is given by |
3280 | ** the first parameter. Note that the order of the |
3281 | ** first two parameters is reversed from snprintf().)^ This is an |
3282 | ** historical accident that cannot be fixed without breaking |
3283 | ** backwards compatibility. ^(Note also that sqlite3_snprintf() |
3284 | ** returns a pointer to its buffer instead of the number of |
3285 | ** characters actually written into the buffer.)^ We admit that |
3286 | ** the number of characters written would be a more useful return |
3287 | ** value but we cannot change the implementation of sqlite3_snprintf() |
3288 | ** now without breaking compatibility. |
3289 | ** |
3290 | ** ^As long as the buffer size is greater than zero, sqlite3_snprintf() |
3291 | ** guarantees that the buffer is always zero-terminated. ^The first |
3292 | ** parameter "n" is the total size of the buffer, including space for |
3293 | ** the zero terminator. So the longest string that can be completely |
3294 | ** written will be n-1 characters. |
3295 | ** |
3296 | ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf(). |
3297 | ** |
3298 | ** See also: [built-in printf()], [printf() SQL function] |
3299 | */ |
3300 | SQLITE_API char *sqlite3_mprintf(const char*,...); |
3301 | SQLITE_API char *sqlite3_vmprintf(const char*, va_list); |
3302 | SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...); |
3303 | SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list); |
3304 | |
3305 | /* |
3306 | ** CAPI3REF: Memory Allocation Subsystem |
3307 | ** |
3308 | ** The SQLite core uses these three routines for all of its own |
3309 | ** internal memory allocation needs. "Core" in the previous sentence |
3310 | ** does not include operating-system specific [VFS] implementation. The |
3311 | ** Windows VFS uses native malloc() and free() for some operations. |
3312 | ** |
3313 | ** ^The sqlite3_malloc() routine returns a pointer to a block |
3314 | ** of memory at least N bytes in length, where N is the parameter. |
3315 | ** ^If sqlite3_malloc() is unable to obtain sufficient free |
3316 | ** memory, it returns a NULL pointer. ^If the parameter N to |
3317 | ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns |
3318 | ** a NULL pointer. |
3319 | ** |
3320 | ** ^The sqlite3_malloc64(N) routine works just like |
3321 | ** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead |
3322 | ** of a signed 32-bit integer. |
3323 | ** |
3324 | ** ^Calling sqlite3_free() with a pointer previously returned |
3325 | ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so |
3326 | ** that it might be reused. ^The sqlite3_free() routine is |
3327 | ** a no-op if is called with a NULL pointer. Passing a NULL pointer |
3328 | ** to sqlite3_free() is harmless. After being freed, memory |
3329 | ** should neither be read nor written. Even reading previously freed |
3330 | ** memory might result in a segmentation fault or other severe error. |
3331 | ** Memory corruption, a segmentation fault, or other severe error |
3332 | ** might result if sqlite3_free() is called with a non-NULL pointer that |
3333 | ** was not obtained from sqlite3_malloc() or sqlite3_realloc(). |
3334 | ** |
3335 | ** ^The sqlite3_realloc(X,N) interface attempts to resize a |
3336 | ** prior memory allocation X to be at least N bytes. |
3337 | ** ^If the X parameter to sqlite3_realloc(X,N) |
3338 | ** is a NULL pointer then its behavior is identical to calling |
3339 | ** sqlite3_malloc(N). |
3340 | ** ^If the N parameter to sqlite3_realloc(X,N) is zero or |
3341 | ** negative then the behavior is exactly the same as calling |
3342 | ** sqlite3_free(X). |
3343 | ** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation |
3344 | ** of at least N bytes in size or NULL if insufficient memory is available. |
3345 | ** ^If M is the size of the prior allocation, then min(N,M) bytes |
3346 | ** of the prior allocation are copied into the beginning of buffer returned |
3347 | ** by sqlite3_realloc(X,N) and the prior allocation is freed. |
3348 | ** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the |
3349 | ** prior allocation is not freed. |
3350 | ** |
3351 | ** ^The sqlite3_realloc64(X,N) interfaces works the same as |
3352 | ** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead |
3353 | ** of a 32-bit signed integer. |
3354 | ** |
3355 | ** ^If X is a memory allocation previously obtained from sqlite3_malloc(), |
3356 | ** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then |
3357 | ** sqlite3_msize(X) returns the size of that memory allocation in bytes. |
3358 | ** ^The value returned by sqlite3_msize(X) might be larger than the number |
3359 | ** of bytes requested when X was allocated. ^If X is a NULL pointer then |
3360 | ** sqlite3_msize(X) returns zero. If X points to something that is not |
3361 | ** the beginning of memory allocation, or if it points to a formerly |
3362 | ** valid memory allocation that has now been freed, then the behavior |
3363 | ** of sqlite3_msize(X) is undefined and possibly harmful. |
3364 | ** |
3365 | ** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(), |
3366 | ** sqlite3_malloc64(), and sqlite3_realloc64() |
3367 | ** is always aligned to at least an 8 byte boundary, or to a |
3368 | ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time |
3369 | ** option is used. |
3370 | ** |
3371 | ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()] |
3372 | ** must be either NULL or else pointers obtained from a prior |
3373 | ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have |
3374 | ** not yet been released. |
3375 | ** |
3376 | ** The application must not read or write any part of |
3377 | ** a block of memory after it has been released using |
3378 | ** [sqlite3_free()] or [sqlite3_realloc()]. |
3379 | */ |
3380 | SQLITE_API void *sqlite3_malloc(int); |
3381 | SQLITE_API void *sqlite3_malloc64(sqlite3_uint64); |
3382 | SQLITE_API void *sqlite3_realloc(void*, int); |
3383 | SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64); |
3384 | SQLITE_API void sqlite3_free(void*); |
3385 | SQLITE_API sqlite3_uint64 sqlite3_msize(void*); |
3386 | |
3387 | /* |
3388 | ** CAPI3REF: Memory Allocator Statistics |
3389 | ** |
3390 | ** SQLite provides these two interfaces for reporting on the status |
3391 | ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()] |
3392 | ** routines, which form the built-in memory allocation subsystem. |
3393 | ** |
3394 | ** ^The [sqlite3_memory_used()] routine returns the number of bytes |
3395 | ** of memory currently outstanding (malloced but not freed). |
3396 | ** ^The [sqlite3_memory_highwater()] routine returns the maximum |
3397 | ** value of [sqlite3_memory_used()] since the high-water mark |
3398 | ** was last reset. ^The values returned by [sqlite3_memory_used()] and |
3399 | ** [sqlite3_memory_highwater()] include any overhead |
3400 | ** added by SQLite in its implementation of [sqlite3_malloc()], |
3401 | ** but not overhead added by the any underlying system library |
3402 | ** routines that [sqlite3_malloc()] may call. |
3403 | ** |
3404 | ** ^The memory high-water mark is reset to the current value of |
3405 | ** [sqlite3_memory_used()] if and only if the parameter to |
3406 | ** [sqlite3_memory_highwater()] is true. ^The value returned |
3407 | ** by [sqlite3_memory_highwater(1)] is the high-water mark |
3408 | ** prior to the reset. |
3409 | */ |
3410 | SQLITE_API sqlite3_int64 sqlite3_memory_used(void); |
3411 | SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag); |
3412 | |
3413 | /* |
3414 | ** CAPI3REF: Pseudo-Random Number Generator |
3415 | ** |
3416 | ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to |
3417 | ** select random [ROWID | ROWIDs] when inserting new records into a table that |
3418 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
3419 | ** the built-in random() and randomblob() SQL functions. This interface allows |
3420 | ** applications to access the same PRNG for other purposes. |
3421 | ** |
3422 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
3423 | ** ^The P parameter can be a NULL pointer. |
3424 | ** |
3425 | ** ^If this routine has not been previously called or if the previous |
3426 | ** call had N less than one or a NULL pointer for P, then the PRNG is |
3427 | ** seeded using randomness obtained from the xRandomness method of |
3428 | ** the default [sqlite3_vfs] object. |
3429 | ** ^If the previous call to this routine had an N of 1 or more and a |
3430 | ** non-NULL P then the pseudo-randomness is generated |
3431 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
3432 | ** method. |
3433 | */ |
3434 | SQLITE_API void sqlite3_randomness(int N, void *P); |
3435 | |
3436 | /* |
3437 | ** CAPI3REF: Compile-Time Authorization Callbacks |
3438 | ** METHOD: sqlite3 |
3439 | ** KEYWORDS: {authorizer callback} |
3440 | ** |
3441 | ** ^This routine registers an authorizer callback with a particular |
3442 | ** [database connection], supplied in the first argument. |
3443 | ** ^The authorizer callback is invoked as SQL statements are being compiled |
3444 | ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], |
3445 | ** [sqlite3_prepare_v3()], [sqlite3_prepare16()], [sqlite3_prepare16_v2()], |
3446 | ** and [sqlite3_prepare16_v3()]. ^At various |
3447 | ** points during the compilation process, as logic is being created |
3448 | ** to perform various actions, the authorizer callback is invoked to |
3449 | ** see if those actions are allowed. ^The authorizer callback should |
3450 | ** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the |
3451 | ** specific action but allow the SQL statement to continue to be |
3452 | ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be |
3453 | ** rejected with an error. ^If the authorizer callback returns |
3454 | ** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY] |
3455 | ** then the [sqlite3_prepare_v2()] or equivalent call that triggered |
3456 | ** the authorizer will fail with an error message. |
3457 | ** |
3458 | ** When the callback returns [SQLITE_OK], that means the operation |
3459 | ** requested is ok. ^When the callback returns [SQLITE_DENY], the |
3460 | ** [sqlite3_prepare_v2()] or equivalent call that triggered the |
3461 | ** authorizer will fail with an error message explaining that |
3462 | ** access is denied. |
3463 | ** |
3464 | ** ^The first parameter to the authorizer callback is a copy of the third |
3465 | ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter |
3466 | ** to the callback is an integer [SQLITE_COPY | action code] that specifies |
3467 | ** the particular action to be authorized. ^The third through sixth parameters |
3468 | ** to the callback are either NULL pointers or zero-terminated strings |
3469 | ** that contain additional details about the action to be authorized. |
3470 | ** Applications must always be prepared to encounter a NULL pointer in any |
3471 | ** of the third through the sixth parameters of the authorization callback. |
3472 | ** |
3473 | ** ^If the action code is [SQLITE_READ] |
3474 | ** and the callback returns [SQLITE_IGNORE] then the |
3475 | ** [prepared statement] statement is constructed to substitute |
3476 | ** a NULL value in place of the table column that would have |
3477 | ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE] |
3478 | ** return can be used to deny an untrusted user access to individual |
3479 | ** columns of a table. |
3480 | ** ^When a table is referenced by a [SELECT] but no column values are |
3481 | ** extracted from that table (for example in a query like |
3482 | ** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback |
3483 | ** is invoked once for that table with a column name that is an empty string. |
3484 | ** ^If the action code is [SQLITE_DELETE] and the callback returns |
3485 | ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the |
3486 | ** [truncate optimization] is disabled and all rows are deleted individually. |
3487 | ** |
3488 | ** An authorizer is used when [sqlite3_prepare | preparing] |
3489 | ** SQL statements from an untrusted source, to ensure that the SQL statements |
3490 | ** do not try to access data they are not allowed to see, or that they do not |
3491 | ** try to execute malicious statements that damage the database. For |
3492 | ** example, an application may allow a user to enter arbitrary |
3493 | ** SQL queries for evaluation by a database. But the application does |
3494 | ** not want the user to be able to make arbitrary changes to the |
3495 | ** database. An authorizer could then be put in place while the |
3496 | ** user-entered SQL is being [sqlite3_prepare | prepared] that |
3497 | ** disallows everything except [SELECT] statements. |
3498 | ** |
3499 | ** Applications that need to process SQL from untrusted sources |
3500 | ** might also consider lowering resource limits using [sqlite3_limit()] |
3501 | ** and limiting database size using the [max_page_count] [PRAGMA] |
3502 | ** in addition to using an authorizer. |
3503 | ** |
3504 | ** ^(Only a single authorizer can be in place on a database connection |
3505 | ** at a time. Each call to sqlite3_set_authorizer overrides the |
3506 | ** previous call.)^ ^Disable the authorizer by installing a NULL callback. |
3507 | ** The authorizer is disabled by default. |
3508 | ** |
3509 | ** The authorizer callback must not do anything that will modify |
3510 | ** the database connection that invoked the authorizer callback. |
3511 | ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their |
3512 | ** database connections for the meaning of "modify" in this paragraph. |
3513 | ** |
3514 | ** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the |
3515 | ** statement might be re-prepared during [sqlite3_step()] due to a |
3516 | ** schema change. Hence, the application should ensure that the |
3517 | ** correct authorizer callback remains in place during the [sqlite3_step()]. |
3518 | ** |
3519 | ** ^Note that the authorizer callback is invoked only during |
3520 | ** [sqlite3_prepare()] or its variants. Authorization is not |
3521 | ** performed during statement evaluation in [sqlite3_step()], unless |
3522 | ** as stated in the previous paragraph, sqlite3_step() invokes |
3523 | ** sqlite3_prepare_v2() to reprepare a statement after a schema change. |
3524 | */ |
3525 | SQLITE_API int sqlite3_set_authorizer( |
3526 | sqlite3*, |
3527 | int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), |
3528 | void *pUserData |
3529 | ); |
3530 | |
3531 | /* |
3532 | ** CAPI3REF: Authorizer Return Codes |
3533 | ** |
3534 | ** The [sqlite3_set_authorizer | authorizer callback function] must |
3535 | ** return either [SQLITE_OK] or one of these two constants in order |
3536 | ** to signal SQLite whether or not the action is permitted. See the |
3537 | ** [sqlite3_set_authorizer | authorizer documentation] for additional |
3538 | ** information. |
3539 | ** |
3540 | ** Note that SQLITE_IGNORE is also used as a [conflict resolution mode] |
3541 | ** returned from the [sqlite3_vtab_on_conflict()] interface. |
3542 | */ |
3543 | #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ |
3544 | #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ |
3545 | |
3546 | /* |
3547 | ** CAPI3REF: Authorizer Action Codes |
3548 | ** |
3549 | ** The [sqlite3_set_authorizer()] interface registers a callback function |
3550 | ** that is invoked to authorize certain SQL statement actions. The |
3551 | ** second parameter to the callback is an integer code that specifies |
3552 | ** what action is being authorized. These are the integer action codes that |
3553 | ** the authorizer callback may be passed. |
3554 | ** |
3555 | ** These action code values signify what kind of operation is to be |
3556 | ** authorized. The 3rd and 4th parameters to the authorization |
3557 | ** callback function will be parameters or NULL depending on which of these |
3558 | ** codes is used as the second parameter. ^(The 5th parameter to the |
3559 | ** authorizer callback is the name of the database ("main", "temp", |
3560 | ** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback |
3561 | ** is the name of the inner-most trigger or view that is responsible for |
3562 | ** the access attempt or NULL if this access attempt is directly from |
3563 | ** top-level SQL code. |
3564 | */ |
3565 | /******************************************* 3rd ************ 4th ***********/ |
3566 | #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */ |
3567 | #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */ |
3568 | #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */ |
3569 | #define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */ |
3570 | #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */ |
3571 | #define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */ |
3572 | #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */ |
3573 | #define SQLITE_CREATE_VIEW 8 /* View Name NULL */ |
3574 | #define SQLITE_DELETE 9 /* Table Name NULL */ |
3575 | #define SQLITE_DROP_INDEX 10 /* Index Name Table Name */ |
3576 | #define SQLITE_DROP_TABLE 11 /* Table Name NULL */ |
3577 | #define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */ |
3578 | #define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */ |
3579 | #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */ |
3580 | #define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */ |
3581 | #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */ |
3582 | #define SQLITE_DROP_VIEW 17 /* View Name NULL */ |
3583 | #define SQLITE_INSERT 18 /* Table Name NULL */ |
3584 | #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */ |
3585 | #define SQLITE_READ 20 /* Table Name Column Name */ |
3586 | #define SQLITE_SELECT 21 /* NULL NULL */ |
3587 | #define SQLITE_TRANSACTION 22 /* Operation NULL */ |
3588 | #define SQLITE_UPDATE 23 /* Table Name Column Name */ |
3589 | #define SQLITE_ATTACH 24 /* Filename NULL */ |
3590 | #define SQLITE_DETACH 25 /* Database Name NULL */ |
3591 | #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */ |
3592 | #define SQLITE_REINDEX 27 /* Index Name NULL */ |
3593 | #define SQLITE_ANALYZE 28 /* Table Name NULL */ |
3594 | #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */ |
3595 | #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */ |
3596 | #define SQLITE_FUNCTION 31 /* NULL Function Name */ |
3597 | #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */ |
3598 | #define SQLITE_COPY 0 /* No longer used */ |
3599 | #define SQLITE_RECURSIVE 33 /* NULL NULL */ |
3600 | |
3601 | /* |
3602 | ** CAPI3REF: Tracing And Profiling Functions |
3603 | ** METHOD: sqlite3 |
3604 | ** |
3605 | ** These routines are deprecated. Use the [sqlite3_trace_v2()] interface |
3606 | ** instead of the routines described here. |
3607 | ** |
3608 | ** These routines register callback functions that can be used for |
3609 | ** tracing and profiling the execution of SQL statements. |
3610 | ** |
3611 | ** ^The callback function registered by sqlite3_trace() is invoked at |
3612 | ** various times when an SQL statement is being run by [sqlite3_step()]. |
3613 | ** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the |
3614 | ** SQL statement text as the statement first begins executing. |
3615 | ** ^(Additional sqlite3_trace() callbacks might occur |
3616 | ** as each triggered subprogram is entered. The callbacks for triggers |
3617 | ** contain a UTF-8 SQL comment that identifies the trigger.)^ |
3618 | ** |
3619 | ** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit |
3620 | ** the length of [bound parameter] expansion in the output of sqlite3_trace(). |
3621 | ** |
3622 | ** ^The callback function registered by sqlite3_profile() is invoked |
3623 | ** as each SQL statement finishes. ^The profile callback contains |
3624 | ** the original statement text and an estimate of wall-clock time |
3625 | ** of how long that statement took to run. ^The profile callback |
3626 | ** time is in units of nanoseconds, however the current implementation |
3627 | ** is only capable of millisecond resolution so the six least significant |
3628 | ** digits in the time are meaningless. Future versions of SQLite |
3629 | ** might provide greater resolution on the profiler callback. Invoking |
3630 | ** either [sqlite3_trace()] or [sqlite3_trace_v2()] will cancel the |
3631 | ** profile callback. |
3632 | */ |
3633 | SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(sqlite3*, |
3634 | void(*xTrace)(void*,const char*), void*); |
3635 | SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*, |
3636 | void(*xProfile)(void*,const char*,sqlite3_uint64), void*); |
3637 | |
3638 | /* |
3639 | ** CAPI3REF: SQL Trace Event Codes |
3640 | ** KEYWORDS: SQLITE_TRACE |
3641 | ** |
3642 | ** These constants identify classes of events that can be monitored |
3643 | ** using the [sqlite3_trace_v2()] tracing logic. The M argument |
3644 | ** to [sqlite3_trace_v2(D,M,X,P)] is an OR-ed combination of one or more of |
3645 | ** the following constants. ^The first argument to the trace callback |
3646 | ** is one of the following constants. |
3647 | ** |
3648 | ** New tracing constants may be added in future releases. |
3649 | ** |
3650 | ** ^A trace callback has four arguments: xCallback(T,C,P,X). |
3651 | ** ^The T argument is one of the integer type codes above. |
3652 | ** ^The C argument is a copy of the context pointer passed in as the |
3653 | ** fourth argument to [sqlite3_trace_v2()]. |
3654 | ** The P and X arguments are pointers whose meanings depend on T. |
3655 | ** |
3656 | ** <dl> |
3657 | ** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt> |
3658 | ** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement |
3659 | ** first begins running and possibly at other times during the |
3660 | ** execution of the prepared statement, such as at the start of each |
3661 | ** trigger subprogram. ^The P argument is a pointer to the |
3662 | ** [prepared statement]. ^The X argument is a pointer to a string which |
3663 | ** is the unexpanded SQL text of the prepared statement or an SQL comment |
3664 | ** that indicates the invocation of a trigger. ^The callback can compute |
3665 | ** the same text that would have been returned by the legacy [sqlite3_trace()] |
3666 | ** interface by using the X argument when X begins with "--" and invoking |
3667 | ** [sqlite3_expanded_sql(P)] otherwise. |
3668 | ** |
3669 | ** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt> |
3670 | ** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same |
3671 | ** information as is provided by the [sqlite3_profile()] callback. |
3672 | ** ^The P argument is a pointer to the [prepared statement] and the |
3673 | ** X argument points to a 64-bit integer which is approximately |
3674 | ** the number of nanoseconds that the prepared statement took to run. |
3675 | ** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes. |
3676 | ** |
3677 | ** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt> |
3678 | ** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared |
3679 | ** statement generates a single row of result. |
3680 | ** ^The P argument is a pointer to the [prepared statement] and the |
3681 | ** X argument is unused. |
3682 | ** |
3683 | ** [[SQLITE_TRACE_CLOSE]] <dt>SQLITE_TRACE_CLOSE</dt> |
3684 | ** <dd>^An SQLITE_TRACE_CLOSE callback is invoked when a database |
3685 | ** connection closes. |
3686 | ** ^The P argument is a pointer to the [database connection] object |
3687 | ** and the X argument is unused. |
3688 | ** </dl> |
3689 | */ |
3690 | #define SQLITE_TRACE_STMT 0x01 |
3691 | #define SQLITE_TRACE_PROFILE 0x02 |
3692 | #define SQLITE_TRACE_ROW 0x04 |
3693 | #define SQLITE_TRACE_CLOSE 0x08 |
3694 | |
3695 | /* |
3696 | ** CAPI3REF: SQL Trace Hook |
3697 | ** METHOD: sqlite3 |
3698 | ** |
3699 | ** ^The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback |
3700 | ** function X against [database connection] D, using property mask M |
3701 | ** and context pointer P. ^If the X callback is |
3702 | ** NULL or if the M mask is zero, then tracing is disabled. The |
3703 | ** M argument should be the bitwise OR-ed combination of |
3704 | ** zero or more [SQLITE_TRACE] constants. |
3705 | ** |
3706 | ** ^Each call to either sqlite3_trace(D,X,P) or sqlite3_trace_v2(D,M,X,P) |
3707 | ** overrides (cancels) all prior calls to sqlite3_trace(D,X,P) or |
3708 | ** sqlite3_trace_v2(D,M,X,P) for the [database connection] D. Each |
3709 | ** database connection may have at most one trace callback. |
3710 | ** |
3711 | ** ^The X callback is invoked whenever any of the events identified by |
3712 | ** mask M occur. ^The integer return value from the callback is currently |
3713 | ** ignored, though this may change in future releases. Callback |
3714 | ** implementations should return zero to ensure future compatibility. |
3715 | ** |
3716 | ** ^A trace callback is invoked with four arguments: callback(T,C,P,X). |
3717 | ** ^The T argument is one of the [SQLITE_TRACE] |
3718 | ** constants to indicate why the callback was invoked. |
3719 | ** ^The C argument is a copy of the context pointer. |
3720 | ** The P and X arguments are pointers whose meanings depend on T. |
3721 | ** |
3722 | ** The sqlite3_trace_v2() interface is intended to replace the legacy |
3723 | ** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which |
3724 | ** are deprecated. |
3725 | */ |
3726 | SQLITE_API int sqlite3_trace_v2( |
3727 | sqlite3*, |
3728 | unsigned uMask, |
3729 | int(*xCallback)(unsigned,void*,void*,void*), |
3730 | void *pCtx |
3731 | ); |
3732 | |
3733 | /* |
3734 | ** CAPI3REF: Query Progress Callbacks |
3735 | ** METHOD: sqlite3 |
3736 | ** |
3737 | ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback |
3738 | ** function X to be invoked periodically during long running calls to |
3739 | ** [sqlite3_step()] and [sqlite3_prepare()] and similar for |
3740 | ** database connection D. An example use for this |
3741 | ** interface is to keep a GUI updated during a large query. |
3742 | ** |
3743 | ** ^The parameter P is passed through as the only parameter to the |
3744 | ** callback function X. ^The parameter N is the approximate number of |
3745 | ** [virtual machine instructions] that are evaluated between successive |
3746 | ** invocations of the callback X. ^If N is less than one then the progress |
3747 | ** handler is disabled. |
3748 | ** |
3749 | ** ^Only a single progress handler may be defined at one time per |
3750 | ** [database connection]; setting a new progress handler cancels the |
3751 | ** old one. ^Setting parameter X to NULL disables the progress handler. |
3752 | ** ^The progress handler is also disabled by setting N to a value less |
3753 | ** than 1. |
3754 | ** |
3755 | ** ^If the progress callback returns non-zero, the operation is |
3756 | ** interrupted. This feature can be used to implement a |
3757 | ** "Cancel" button on a GUI progress dialog box. |
3758 | ** |
3759 | ** The progress handler callback must not do anything that will modify |
3760 | ** the database connection that invoked the progress handler. |
3761 | ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their |
3762 | ** database connections for the meaning of "modify" in this paragraph. |
3763 | ** |
3764 | ** The progress handler callback would originally only be invoked from the |
3765 | ** bytecode engine. It still might be invoked during [sqlite3_prepare()] |
3766 | ** and similar because those routines might force a reparse of the schema |
3767 | ** which involves running the bytecode engine. However, beginning with |
3768 | ** SQLite version 3.41.0, the progress handler callback might also be |
3769 | ** invoked directly from [sqlite3_prepare()] while analyzing and generating |
3770 | ** code for complex queries. |
3771 | */ |
3772 | SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); |
3773 | |
3774 | /* |
3775 | ** CAPI3REF: Opening A New Database Connection |
3776 | ** CONSTRUCTOR: sqlite3 |
3777 | ** |
3778 | ** ^These routines open an SQLite database file as specified by the |
3779 | ** filename argument. ^The filename argument is interpreted as UTF-8 for |
3780 | ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte |
3781 | ** order for sqlite3_open16(). ^(A [database connection] handle is usually |
3782 | ** returned in *ppDb, even if an error occurs. The only exception is that |
3783 | ** if SQLite is unable to allocate memory to hold the [sqlite3] object, |
3784 | ** a NULL will be written into *ppDb instead of a pointer to the [sqlite3] |
3785 | ** object.)^ ^(If the database is opened (and/or created) successfully, then |
3786 | ** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The |
3787 | ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain |
3788 | ** an English language description of the error following a failure of any |
3789 | ** of the sqlite3_open() routines. |
3790 | ** |
3791 | ** ^The default encoding will be UTF-8 for databases created using |
3792 | ** sqlite3_open() or sqlite3_open_v2(). ^The default encoding for databases |
3793 | ** created using sqlite3_open16() will be UTF-16 in the native byte order. |
3794 | ** |
3795 | ** Whether or not an error occurs when it is opened, resources |
3796 | ** associated with the [database connection] handle should be released by |
3797 | ** passing it to [sqlite3_close()] when it is no longer required. |
3798 | ** |
3799 | ** The sqlite3_open_v2() interface works like sqlite3_open() |
3800 | ** except that it accepts two additional parameters for additional control |
3801 | ** over the new database connection. ^(The flags parameter to |
3802 | ** sqlite3_open_v2() must include, at a minimum, one of the following |
3803 | ** three flag combinations:)^ |
3804 | ** |
3805 | ** <dl> |
3806 | ** ^(<dt>[SQLITE_OPEN_READONLY]</dt> |
3807 | ** <dd>The database is opened in read-only mode. If the database does |
3808 | ** not already exist, an error is returned.</dd>)^ |
3809 | ** |
3810 | ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt> |
3811 | ** <dd>The database is opened for reading and writing if possible, or |
3812 | ** reading only if the file is write protected by the operating |
3813 | ** system. In either case the database must already exist, otherwise |
3814 | ** an error is returned. For historical reasons, if opening in |
3815 | ** read-write mode fails due to OS-level permissions, an attempt is |
3816 | ** made to open it in read-only mode. [sqlite3_db_readonly()] can be |
3817 | ** used to determine whether the database is actually |
3818 | ** read-write.</dd>)^ |
3819 | ** |
3820 | ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt> |
3821 | ** <dd>The database is opened for reading and writing, and is created if |
3822 | ** it does not already exist. This is the behavior that is always used for |
3823 | ** sqlite3_open() and sqlite3_open16().</dd>)^ |
3824 | ** </dl> |
3825 | ** |
3826 | ** In addition to the required flags, the following optional flags are |
3827 | ** also supported: |
3828 | ** |
3829 | ** <dl> |
3830 | ** ^(<dt>[SQLITE_OPEN_URI]</dt> |
3831 | ** <dd>The filename can be interpreted as a URI if this flag is set.</dd>)^ |
3832 | ** |
3833 | ** ^(<dt>[SQLITE_OPEN_MEMORY]</dt> |
3834 | ** <dd>The database will be opened as an in-memory database. The database |
3835 | ** is named by the "filename" argument for the purposes of cache-sharing, |
3836 | ** if shared cache mode is enabled, but the "filename" is otherwise ignored. |
3837 | ** </dd>)^ |
3838 | ** |
3839 | ** ^(<dt>[SQLITE_OPEN_NOMUTEX]</dt> |
3840 | ** <dd>The new database connection will use the "multi-thread" |
3841 | ** [threading mode].)^ This means that separate threads are allowed |
3842 | ** to use SQLite at the same time, as long as each thread is using |
3843 | ** a different [database connection]. |
3844 | ** |
3845 | ** ^(<dt>[SQLITE_OPEN_FULLMUTEX]</dt> |
3846 | ** <dd>The new database connection will use the "serialized" |
3847 | ** [threading mode].)^ This means the multiple threads can safely |
3848 | ** attempt to use the same database connection at the same time. |
3849 | ** (Mutexes will block any actual concurrency, but in this mode |
3850 | ** there is no harm in trying.) |
3851 | ** |
3852 | ** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt> |
3853 | ** <dd>The database is opened [shared cache] enabled, overriding |
3854 | ** the default shared cache setting provided by |
3855 | ** [sqlite3_enable_shared_cache()].)^ |
3856 | ** The [use of shared cache mode is discouraged] and hence shared cache |
3857 | ** capabilities may be omitted from many builds of SQLite. In such cases, |
3858 | ** this option is a no-op. |
3859 | ** |
3860 | ** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt> |
3861 | ** <dd>The database is opened [shared cache] disabled, overriding |
3862 | ** the default shared cache setting provided by |
3863 | ** [sqlite3_enable_shared_cache()].)^ |
3864 | ** |
3865 | ** [[OPEN_EXRESCODE]] ^(<dt>[SQLITE_OPEN_EXRESCODE]</dt> |
3866 | ** <dd>The database connection comes up in "extended result code mode". |
3867 | ** In other words, the database behaves has if |
3868 | ** [sqlite3_extended_result_codes(db,1)] where called on the database |
3869 | ** connection as soon as the connection is created. In addition to setting |
3870 | ** the extended result code mode, this flag also causes [sqlite3_open_v2()] |
3871 | ** to return an extended result code.</dd> |
3872 | ** |
3873 | ** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt> |
3874 | ** <dd>The database filename is not allowed to contain a symbolic link</dd> |
3875 | ** </dl>)^ |
3876 | ** |
3877 | ** If the 3rd parameter to sqlite3_open_v2() is not one of the |
3878 | ** required combinations shown above optionally combined with other |
3879 | ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits] |
3880 | ** then the behavior is undefined. Historic versions of SQLite |
3881 | ** have silently ignored surplus bits in the flags parameter to |
3882 | ** sqlite3_open_v2(), however that behavior might not be carried through |
3883 | ** into future versions of SQLite and so applications should not rely |
3884 | ** upon it. Note in particular that the SQLITE_OPEN_EXCLUSIVE flag is a no-op |
3885 | ** for sqlite3_open_v2(). The SQLITE_OPEN_EXCLUSIVE does *not* cause |
3886 | ** the open to fail if the database already exists. The SQLITE_OPEN_EXCLUSIVE |
3887 | ** flag is intended for use by the [sqlite3_vfs|VFS interface] only, and not |
3888 | ** by sqlite3_open_v2(). |
3889 | ** |
3890 | ** ^The fourth parameter to sqlite3_open_v2() is the name of the |
3891 | ** [sqlite3_vfs] object that defines the operating system interface that |
3892 | ** the new database connection should use. ^If the fourth parameter is |
3893 | ** a NULL pointer then the default [sqlite3_vfs] object is used. |
3894 | ** |
3895 | ** ^If the filename is ":memory:", then a private, temporary in-memory database |
3896 | ** is created for the connection. ^This in-memory database will vanish when |
3897 | ** the database connection is closed. Future versions of SQLite might |
3898 | ** make use of additional special filenames that begin with the ":" character. |
3899 | ** It is recommended that when a database filename actually does begin with |
3900 | ** a ":" character you should prefix the filename with a pathname such as |
3901 | ** "./" to avoid ambiguity. |
3902 | ** |
3903 | ** ^If the filename is an empty string, then a private, temporary |
3904 | ** on-disk database will be created. ^This private database will be |
3905 | ** automatically deleted as soon as the database connection is closed. |
3906 | ** |
3907 | ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3> |
3908 | ** |
3909 | ** ^If [URI filename] interpretation is enabled, and the filename argument |
3910 | ** begins with "file:", then the filename is interpreted as a URI. ^URI |
3911 | ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is |
3912 | ** set in the third argument to sqlite3_open_v2(), or if it has |
3913 | ** been enabled globally using the [SQLITE_CONFIG_URI] option with the |
3914 | ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option. |
3915 | ** URI filename interpretation is turned off |
3916 | ** by default, but future releases of SQLite might enable URI filename |
3917 | ** interpretation by default. See "[URI filenames]" for additional |
3918 | ** information. |
3919 | ** |
3920 | ** URI filenames are parsed according to RFC 3986. ^If the URI contains an |
3921 | ** authority, then it must be either an empty string or the string |
3922 | ** "localhost". ^If the authority is not an empty string or "localhost", an |
3923 | ** error is returned to the caller. ^The fragment component of a URI, if |
3924 | ** present, is ignored. |
3925 | ** |
3926 | ** ^SQLite uses the path component of the URI as the name of the disk file |
3927 | ** which contains the database. ^If the path begins with a '/' character, |
3928 | ** then it is interpreted as an absolute path. ^If the path does not begin |
3929 | ** with a '/' (meaning that the authority section is omitted from the URI) |
3930 | ** then the path is interpreted as a relative path. |
3931 | ** ^(On windows, the first component of an absolute path |
3932 | ** is a drive specification (e.g. "C:").)^ |
3933 | ** |
3934 | ** [[core URI query parameters]] |
3935 | ** The query component of a URI may contain parameters that are interpreted |
3936 | ** either by SQLite itself, or by a [VFS | custom VFS implementation]. |
3937 | ** SQLite and its built-in [VFSes] interpret the |
3938 | ** following query parameters: |
3939 | ** |
3940 | ** <ul> |
3941 | ** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of |
3942 | ** a VFS object that provides the operating system interface that should |
3943 | ** be used to access the database file on disk. ^If this option is set to |
3944 | ** an empty string the default VFS object is used. ^Specifying an unknown |
3945 | ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is |
3946 | ** present, then the VFS specified by the option takes precedence over |
3947 | ** the value passed as the fourth parameter to sqlite3_open_v2(). |
3948 | ** |
3949 | ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw", |
3950 | ** "rwc", or "memory". Attempting to set it to any other value is |
3951 | ** an error)^. |
3952 | ** ^If "ro" is specified, then the database is opened for read-only |
3953 | ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the |
3954 | ** third argument to sqlite3_open_v2(). ^If the mode option is set to |
3955 | ** "rw", then the database is opened for read-write (but not create) |
3956 | ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had |
3957 | ** been set. ^Value "rwc" is equivalent to setting both |
3958 | ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is |
3959 | ** set to "memory" then a pure [in-memory database] that never reads |
3960 | ** or writes from disk is used. ^It is an error to specify a value for |
3961 | ** the mode parameter that is less restrictive than that specified by |
3962 | ** the flags passed in the third parameter to sqlite3_open_v2(). |
3963 | ** |
3964 | ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or |
3965 | ** "private". ^Setting it to "shared" is equivalent to setting the |
3966 | ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to |
3967 | ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is |
3968 | ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit. |
3969 | ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in |
3970 | ** a URI filename, its value overrides any behavior requested by setting |
3971 | ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag. |
3972 | ** |
3973 | ** <li> <b>psow</b>: ^The psow parameter indicates whether or not the |
3974 | ** [powersafe overwrite] property does or does not apply to the |
3975 | ** storage media on which the database file resides. |
3976 | ** |
3977 | ** <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter |
3978 | ** which if set disables file locking in rollback journal modes. This |
3979 | ** is useful for accessing a database on a filesystem that does not |
3980 | ** support locking. Caution: Database corruption might result if two |
3981 | ** or more processes write to the same database and any one of those |
3982 | ** processes uses nolock=1. |
3983 | ** |
3984 | ** <li> <b>immutable</b>: ^The immutable parameter is a boolean query |
3985 | ** parameter that indicates that the database file is stored on |
3986 | ** read-only media. ^When immutable is set, SQLite assumes that the |
3987 | ** database file cannot be changed, even by a process with higher |
3988 | ** privilege, and so the database is opened read-only and all locking |
3989 | ** and change detection is disabled. Caution: Setting the immutable |
3990 | ** property on a database file that does in fact change can result |
3991 | ** in incorrect query results and/or [SQLITE_CORRUPT] errors. |
3992 | ** See also: [SQLITE_IOCAP_IMMUTABLE]. |
3993 | ** |
3994 | ** </ul> |
3995 | ** |
3996 | ** ^Specifying an unknown parameter in the query component of a URI is not an |
3997 | ** error. Future versions of SQLite might understand additional query |
3998 | ** parameters. See "[query parameters with special meaning to SQLite]" for |
3999 | ** additional information. |
4000 | ** |
4001 | ** [[URI filename examples]] <h3>URI filename examples</h3> |
4002 | ** |
4003 | ** <table border="1" align=center cellpadding=5> |
4004 | ** <tr><th> URI filenames <th> Results |
4005 | ** <tr><td> file:data.db <td> |
4006 | ** Open the file "data.db" in the current directory. |
4007 | ** <tr><td> file:/home/fred/data.db<br> |
4008 | ** file:///home/fred/data.db <br> |
4009 | ** file://localhost/home/fred/data.db <br> <td> |
4010 | ** Open the database file "/home/fred/data.db". |
4011 | ** <tr><td> file://darkstar/home/fred/data.db <td> |
4012 | ** An error. "darkstar" is not a recognized authority. |
4013 | ** <tr><td style="white-space:nowrap"> |
4014 | ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db |
4015 | ** <td> Windows only: Open the file "data.db" on fred's desktop on drive |
4016 | ** C:. Note that the %20 escaping in this example is not strictly |
4017 | ** necessary - space characters can be used literally |
4018 | ** in URI filenames. |
4019 | ** <tr><td> file:data.db?mode=ro&cache=private <td> |
4020 | ** Open file "data.db" in the current directory for read-only access. |
4021 | ** Regardless of whether or not shared-cache mode is enabled by |
4022 | ** default, use a private cache. |
4023 | ** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td> |
4024 | ** Open file "/home/fred/data.db". Use the special VFS "unix-dotfile" |
4025 | ** that uses dot-files in place of posix advisory locking. |
4026 | ** <tr><td> file:data.db?mode=readonly <td> |
4027 | ** An error. "readonly" is not a valid option for the "mode" parameter. |
4028 | ** Use "ro" instead: "file:data.db?mode=ro". |
4029 | ** </table> |
4030 | ** |
4031 | ** ^URI hexadecimal escape sequences (%HH) are supported within the path and |
4032 | ** query components of a URI. A hexadecimal escape sequence consists of a |
4033 | ** percent sign - "%" - followed by exactly two hexadecimal digits |
4034 | ** specifying an octet value. ^Before the path or query components of a |
4035 | ** URI filename are interpreted, they are encoded using UTF-8 and all |
4036 | ** hexadecimal escape sequences replaced by a single byte containing the |
4037 | ** corresponding octet. If this process generates an invalid UTF-8 encoding, |
4038 | ** the results are undefined. |
4039 | ** |
4040 | ** <b>Note to Windows users:</b> The encoding used for the filename argument |
4041 | ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever |
4042 | ** codepage is currently defined. Filenames containing international |
4043 | ** characters must be converted to UTF-8 prior to passing them into |
4044 | ** sqlite3_open() or sqlite3_open_v2(). |
4045 | ** |
4046 | ** <b>Note to Windows Runtime users:</b> The temporary directory must be set |
4047 | ** prior to calling sqlite3_open() or sqlite3_open_v2(). Otherwise, various |
4048 | ** features that require the use of temporary files may fail. |
4049 | ** |
4050 | ** See also: [sqlite3_temp_directory] |
4051 | */ |
4052 | SQLITE_API int sqlite3_open( |
4053 | const char *filename, /* Database filename (UTF-8) */ |
4054 | sqlite3 **ppDb /* OUT: SQLite db handle */ |
4055 | ); |
4056 | SQLITE_API int sqlite3_open16( |
4057 | const void *filename, /* Database filename (UTF-16) */ |
4058 | sqlite3 **ppDb /* OUT: SQLite db handle */ |
4059 | ); |
4060 | SQLITE_API int sqlite3_open_v2( |
4061 | const char *filename, /* Database filename (UTF-8) */ |
4062 | sqlite3 **ppDb, /* OUT: SQLite db handle */ |
4063 | int flags, /* Flags */ |
4064 | const char *zVfs /* Name of VFS module to use */ |
4065 | ); |
4066 | |
4067 | /* |
4068 | ** CAPI3REF: Obtain Values For URI Parameters |
4069 | ** |
4070 | ** These are utility routines, useful to [VFS|custom VFS implementations], |
4071 | ** that check if a database file was a URI that contained a specific query |
4072 | ** parameter, and if so obtains the value of that query parameter. |
4073 | ** |
4074 | ** The first parameter to these interfaces (hereafter referred to |
4075 | ** as F) must be one of: |
4076 | ** <ul> |
4077 | ** <li> A database filename pointer created by the SQLite core and |
4078 | ** passed into the xOpen() method of a VFS implementation, or |
4079 | ** <li> A filename obtained from [sqlite3_db_filename()], or |
4080 | ** <li> A new filename constructed using [sqlite3_create_filename()]. |
4081 | ** </ul> |
4082 | ** If the F parameter is not one of the above, then the behavior is |
4083 | ** undefined and probably undesirable. Older versions of SQLite were |
4084 | ** more tolerant of invalid F parameters than newer versions. |
4085 | ** |
4086 | ** If F is a suitable filename (as described in the previous paragraph) |
4087 | ** and if P is the name of the query parameter, then |
4088 | ** sqlite3_uri_parameter(F,P) returns the value of the P |
4089 | ** parameter if it exists or a NULL pointer if P does not appear as a |
4090 | ** query parameter on F. If P is a query parameter of F and it |
4091 | ** has no explicit value, then sqlite3_uri_parameter(F,P) returns |
4092 | ** a pointer to an empty string. |
4093 | ** |
4094 | ** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean |
4095 | ** parameter and returns true (1) or false (0) according to the value |
4096 | ** of P. The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the |
4097 | ** value of query parameter P is one of "yes", "true", or "on" in any |
4098 | ** case or if the value begins with a non-zero number. The |
4099 | ** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of |
4100 | ** query parameter P is one of "no", "false", or "off" in any case or |
4101 | ** if the value begins with a numeric zero. If P is not a query |
4102 | ** parameter on F or if the value of P does not match any of the |
4103 | ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0). |
4104 | ** |
4105 | ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a |
4106 | ** 64-bit signed integer and returns that integer, or D if P does not |
4107 | ** exist. If the value of P is something other than an integer, then |
4108 | ** zero is returned. |
4109 | ** |
4110 | ** The sqlite3_uri_key(F,N) returns a pointer to the name (not |
4111 | ** the value) of the N-th query parameter for filename F, or a NULL |
4112 | ** pointer if N is less than zero or greater than the number of query |
4113 | ** parameters minus 1. The N value is zero-based so N should be 0 to obtain |
4114 | ** the name of the first query parameter, 1 for the second parameter, and |
4115 | ** so forth. |
4116 | ** |
4117 | ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and |
4118 | ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and |
4119 | ** is not a database file pathname pointer that the SQLite core passed |
4120 | ** into the xOpen VFS method, then the behavior of this routine is undefined |
4121 | ** and probably undesirable. |
4122 | ** |
4123 | ** Beginning with SQLite [version 3.31.0] ([dateof:3.31.0]) the input F |
4124 | ** parameter can also be the name of a rollback journal file or WAL file |
4125 | ** in addition to the main database file. Prior to version 3.31.0, these |
4126 | ** routines would only work if F was the name of the main database file. |
4127 | ** When the F parameter is the name of the rollback journal or WAL file, |
4128 | ** it has access to all the same query parameters as were found on the |
4129 | ** main database file. |
4130 | ** |
4131 | ** See the [URI filename] documentation for additional information. |
4132 | */ |
4133 | SQLITE_API const char *sqlite3_uri_parameter(sqlite3_filename z, const char *zParam); |
4134 | SQLITE_API int sqlite3_uri_boolean(sqlite3_filename z, const char *zParam, int bDefault); |
4135 | SQLITE_API sqlite3_int64 sqlite3_uri_int64(sqlite3_filename, const char*, sqlite3_int64); |
4136 | SQLITE_API const char *sqlite3_uri_key(sqlite3_filename z, int N); |
4137 | |
4138 | /* |
4139 | ** CAPI3REF: Translate filenames |
4140 | ** |
4141 | ** These routines are available to [VFS|custom VFS implementations] for |
4142 | ** translating filenames between the main database file, the journal file, |
4143 | ** and the WAL file. |
4144 | ** |
4145 | ** If F is the name of an sqlite database file, journal file, or WAL file |
4146 | ** passed by the SQLite core into the VFS, then sqlite3_filename_database(F) |
4147 | ** returns the name of the corresponding database file. |
4148 | ** |
4149 | ** If F is the name of an sqlite database file, journal file, or WAL file |
4150 | ** passed by the SQLite core into the VFS, or if F is a database filename |
4151 | ** obtained from [sqlite3_db_filename()], then sqlite3_filename_journal(F) |
4152 | ** returns the name of the corresponding rollback journal file. |
4153 | ** |
4154 | ** If F is the name of an sqlite database file, journal file, or WAL file |
4155 | ** that was passed by the SQLite core into the VFS, or if F is a database |
4156 | ** filename obtained from [sqlite3_db_filename()], then |
4157 | ** sqlite3_filename_wal(F) returns the name of the corresponding |
4158 | ** WAL file. |
4159 | ** |
4160 | ** In all of the above, if F is not the name of a database, journal or WAL |
4161 | ** filename passed into the VFS from the SQLite core and F is not the |
4162 | ** return value from [sqlite3_db_filename()], then the result is |
4163 | ** undefined and is likely a memory access violation. |
4164 | */ |
4165 | SQLITE_API const char *sqlite3_filename_database(sqlite3_filename); |
4166 | SQLITE_API const char *sqlite3_filename_journal(sqlite3_filename); |
4167 | SQLITE_API const char *sqlite3_filename_wal(sqlite3_filename); |
4168 | |
4169 | /* |
4170 | ** CAPI3REF: Database File Corresponding To A Journal |
4171 | ** |
4172 | ** ^If X is the name of a rollback or WAL-mode journal file that is |
4173 | ** passed into the xOpen method of [sqlite3_vfs], then |
4174 | ** sqlite3_database_file_object(X) returns a pointer to the [sqlite3_file] |
4175 | ** object that represents the main database file. |
4176 | ** |
4177 | ** This routine is intended for use in custom [VFS] implementations |
4178 | ** only. It is not a general-purpose interface. |
4179 | ** The argument sqlite3_file_object(X) must be a filename pointer that |
4180 | ** has been passed into [sqlite3_vfs].xOpen method where the |
4181 | ** flags parameter to xOpen contains one of the bits |
4182 | ** [SQLITE_OPEN_MAIN_JOURNAL] or [SQLITE_OPEN_WAL]. Any other use |
4183 | ** of this routine results in undefined and probably undesirable |
4184 | ** behavior. |
4185 | */ |
4186 | SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*); |
4187 | |
4188 | /* |
4189 | ** CAPI3REF: Create and Destroy VFS Filenames |
4190 | ** |
4191 | ** These interfaces are provided for use by [VFS shim] implementations and |
4192 | ** are not useful outside of that context. |
4193 | ** |
4194 | ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of |
4195 | ** database filename D with corresponding journal file J and WAL file W and |
4196 | ** with N URI parameters key/values pairs in the array P. The result from |
4197 | ** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that |
4198 | ** is safe to pass to routines like: |
4199 | ** <ul> |
4200 | ** <li> [sqlite3_uri_parameter()], |
4201 | ** <li> [sqlite3_uri_boolean()], |
4202 | ** <li> [sqlite3_uri_int64()], |
4203 | ** <li> [sqlite3_uri_key()], |
4204 | ** <li> [sqlite3_filename_database()], |
4205 | ** <li> [sqlite3_filename_journal()], or |
4206 | ** <li> [sqlite3_filename_wal()]. |
4207 | ** </ul> |
4208 | ** If a memory allocation error occurs, sqlite3_create_filename() might |
4209 | ** return a NULL pointer. The memory obtained from sqlite3_create_filename(X) |
4210 | ** must be released by a corresponding call to sqlite3_free_filename(Y). |
4211 | ** |
4212 | ** The P parameter in sqlite3_create_filename(D,J,W,N,P) should be an array |
4213 | ** of 2*N pointers to strings. Each pair of pointers in this array corresponds |
4214 | ** to a key and value for a query parameter. The P parameter may be a NULL |
4215 | ** pointer if N is zero. None of the 2*N pointers in the P array may be |
4216 | ** NULL pointers and key pointers should not be empty strings. |
4217 | ** None of the D, J, or W parameters to sqlite3_create_filename(D,J,W,N,P) may |
4218 | ** be NULL pointers, though they can be empty strings. |
4219 | ** |
4220 | ** The sqlite3_free_filename(Y) routine releases a memory allocation |
4221 | ** previously obtained from sqlite3_create_filename(). Invoking |
4222 | ** sqlite3_free_filename(Y) where Y is a NULL pointer is a harmless no-op. |
4223 | ** |
4224 | ** If the Y parameter to sqlite3_free_filename(Y) is anything other |
4225 | ** than a NULL pointer or a pointer previously acquired from |
4226 | ** sqlite3_create_filename(), then bad things such as heap |
4227 | ** corruption or segfaults may occur. The value Y should not be |
4228 | ** used again after sqlite3_free_filename(Y) has been called. This means |
4229 | ** that if the [sqlite3_vfs.xOpen()] method of a VFS has been called using Y, |
4230 | ** then the corresponding [sqlite3_module.xClose() method should also be |
4231 | ** invoked prior to calling sqlite3_free_filename(Y). |
4232 | */ |
4233 | SQLITE_API sqlite3_filename sqlite3_create_filename( |
4234 | const char *zDatabase, |
4235 | const char *zJournal, |
4236 | const char *zWal, |
4237 | int nParam, |
4238 | const char **azParam |
4239 | ); |
4240 | SQLITE_API void sqlite3_free_filename(sqlite3_filename); |
4241 | |
4242 | /* |
4243 | ** CAPI3REF: Error Codes And Messages |
4244 | ** METHOD: sqlite3 |
4245 | ** |
4246 | ** ^If the most recent sqlite3_* API call associated with |
4247 | ** [database connection] D failed, then the sqlite3_errcode(D) interface |
4248 | ** returns the numeric [result code] or [extended result code] for that |
4249 | ** API call. |
4250 | ** ^The sqlite3_extended_errcode() |
4251 | ** interface is the same except that it always returns the |
4252 | ** [extended result code] even when extended result codes are |
4253 | ** disabled. |
4254 | ** |
4255 | ** The values returned by sqlite3_errcode() and/or |
4256 | ** sqlite3_extended_errcode() might change with each API call. |
4257 | ** Except, there are some interfaces that are guaranteed to never |
4258 | ** change the value of the error code. The error-code preserving |
4259 | ** interfaces include the following: |
4260 | ** |
4261 | ** <ul> |
4262 | ** <li> sqlite3_errcode() |
4263 | ** <li> sqlite3_extended_errcode() |
4264 | ** <li> sqlite3_errmsg() |
4265 | ** <li> sqlite3_errmsg16() |
4266 | ** <li> sqlite3_error_offset() |
4267 | ** </ul> |
4268 | ** |
4269 | ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language |
4270 | ** text that describes the error, as either UTF-8 or UTF-16 respectively. |
4271 | ** ^(Memory to hold the error message string is managed internally. |
4272 | ** The application does not need to worry about freeing the result. |
4273 | ** However, the error string might be overwritten or deallocated by |
4274 | ** subsequent calls to other SQLite interface functions.)^ |
4275 | ** |
4276 | ** ^The sqlite3_errstr() interface returns the English-language text |
4277 | ** that describes the [result code], as UTF-8. |
4278 | ** ^(Memory to hold the error message string is managed internally |
4279 | ** and must not be freed by the application)^. |
4280 | ** |
4281 | ** ^If the most recent error references a specific token in the input |
4282 | ** SQL, the sqlite3_error_offset() interface returns the byte offset |
4283 | ** of the start of that token. ^The byte offset returned by |
4284 | ** sqlite3_error_offset() assumes that the input SQL is UTF8. |
4285 | ** ^If the most recent error does not reference a specific token in the input |
4286 | ** SQL, then the sqlite3_error_offset() function returns -1. |
4287 | ** |
4288 | ** When the serialized [threading mode] is in use, it might be the |
4289 | ** case that a second error occurs on a separate thread in between |
4290 | ** the time of the first error and the call to these interfaces. |
4291 | ** When that happens, the second error will be reported since these |
4292 | ** interfaces always report the most recent result. To avoid |
4293 | ** this, each thread can obtain exclusive use of the [database connection] D |
4294 | ** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning |
4295 | ** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after |
4296 | ** all calls to the interfaces listed here are completed. |
4297 | ** |
4298 | ** If an interface fails with SQLITE_MISUSE, that means the interface |
4299 | ** was invoked incorrectly by the application. In that case, the |
4300 | ** error code and message may or may not be set. |
4301 | */ |
4302 | SQLITE_API int sqlite3_errcode(sqlite3 *db); |
4303 | SQLITE_API int sqlite3_extended_errcode(sqlite3 *db); |
4304 | SQLITE_API const char *sqlite3_errmsg(sqlite3*); |
4305 | SQLITE_API const void *sqlite3_errmsg16(sqlite3*); |
4306 | SQLITE_API const char *sqlite3_errstr(int); |
4307 | SQLITE_API int sqlite3_error_offset(sqlite3 *db); |
4308 | |
4309 | /* |
4310 | ** CAPI3REF: Prepared Statement Object |
4311 | ** KEYWORDS: {prepared statement} {prepared statements} |
4312 | ** |
4313 | ** An instance of this object represents a single SQL statement that |
4314 | ** has been compiled into binary form and is ready to be evaluated. |
4315 | ** |
4316 | ** Think of each SQL statement as a separate computer program. The |
4317 | ** original SQL text is source code. A prepared statement object |
4318 | ** is the compiled object code. All SQL must be converted into a |
4319 | ** prepared statement before it can be run. |
4320 | ** |
4321 | ** The life-cycle of a prepared statement object usually goes like this: |
4322 | ** |
4323 | ** <ol> |
4324 | ** <li> Create the prepared statement object using [sqlite3_prepare_v2()]. |
4325 | ** <li> Bind values to [parameters] using the sqlite3_bind_*() |
4326 | ** interfaces. |
4327 | ** <li> Run the SQL by calling [sqlite3_step()] one or more times. |
4328 | ** <li> Reset the prepared statement using [sqlite3_reset()] then go back |
4329 | ** to step 2. Do this zero or more times. |
4330 | ** <li> Destroy the object using [sqlite3_finalize()]. |
4331 | ** </ol> |
4332 | */ |
4333 | typedef struct sqlite3_stmt sqlite3_stmt; |
4334 | |
4335 | /* |
4336 | ** CAPI3REF: Run-time Limits |
4337 | ** METHOD: sqlite3 |
4338 | ** |
4339 | ** ^(This interface allows the size of various constructs to be limited |
4340 | ** on a connection by connection basis. The first parameter is the |
4341 | ** [database connection] whose limit is to be set or queried. The |
4342 | ** second parameter is one of the [limit categories] that define a |
4343 | ** class of constructs to be size limited. The third parameter is the |
4344 | ** new limit for that construct.)^ |
4345 | ** |
4346 | ** ^If the new limit is a negative number, the limit is unchanged. |
4347 | ** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a |
4348 | ** [limits | hard upper bound] |
4349 | ** set at compile-time by a C preprocessor macro called |
4350 | ** [limits | SQLITE_MAX_<i>NAME</i>]. |
4351 | ** (The "_LIMIT_" in the name is changed to "_MAX_".))^ |
4352 | ** ^Attempts to increase a limit above its hard upper bound are |
4353 | ** silently truncated to the hard upper bound. |
4354 | ** |
4355 | ** ^Regardless of whether or not the limit was changed, the |
4356 | ** [sqlite3_limit()] interface returns the prior value of the limit. |
4357 | ** ^Hence, to find the current value of a limit without changing it, |
4358 | ** simply invoke this interface with the third parameter set to -1. |
4359 | ** |
4360 | ** Run-time limits are intended for use in applications that manage |
4361 | ** both their own internal database and also databases that are controlled |
4362 | ** by untrusted external sources. An example application might be a |
4363 | ** web browser that has its own databases for storing history and |
4364 | ** separate databases controlled by JavaScript applications downloaded |
4365 | ** off the Internet. The internal databases can be given the |
4366 | ** large, default limits. Databases managed by external sources can |
4367 | ** be given much smaller limits designed to prevent a denial of service |
4368 | ** attack. Developers might also want to use the [sqlite3_set_authorizer()] |
4369 | ** interface to further control untrusted SQL. The size of the database |
4370 | ** created by an untrusted script can be contained using the |
4371 | ** [max_page_count] [PRAGMA]. |
4372 | ** |
4373 | ** New run-time limit categories may be added in future releases. |
4374 | */ |
4375 | SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal); |
4376 | |
4377 | /* |
4378 | ** CAPI3REF: Run-Time Limit Categories |
4379 | ** KEYWORDS: {limit category} {*limit categories} |
4380 | ** |
4381 | ** These constants define various performance limits |
4382 | ** that can be lowered at run-time using [sqlite3_limit()]. |
4383 | ** The synopsis of the meanings of the various limits is shown below. |
4384 | ** Additional information is available at [limits | Limits in SQLite]. |
4385 | ** |
4386 | ** <dl> |
4387 | ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt> |
4388 | ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^ |
4389 | ** |
4390 | ** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt> |
4391 | ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^ |
4392 | ** |
4393 | ** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt> |
4394 | ** <dd>The maximum number of columns in a table definition or in the |
4395 | ** result set of a [SELECT] or the maximum number of columns in an index |
4396 | ** or in an ORDER BY or GROUP BY clause.</dd>)^ |
4397 | ** |
4398 | ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> |
4399 | ** <dd>The maximum depth of the parse tree on any expression.</dd>)^ |
4400 | ** |
4401 | ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt> |
4402 | ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^ |
4403 | ** |
4404 | ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt> |
4405 | ** <dd>The maximum number of instructions in a virtual machine program |
4406 | ** used to implement an SQL statement. If [sqlite3_prepare_v2()] or |
4407 | ** the equivalent tries to allocate space for more than this many opcodes |
4408 | ** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^ |
4409 | ** |
4410 | ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt> |
4411 | ** <dd>The maximum number of arguments on a function.</dd>)^ |
4412 | ** |
4413 | ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt> |
4414 | ** <dd>The maximum number of [ATTACH | attached databases].)^</dd> |
4415 | ** |
4416 | ** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]] |
4417 | ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt> |
4418 | ** <dd>The maximum length of the pattern argument to the [LIKE] or |
4419 | ** [GLOB] operators.</dd>)^ |
4420 | ** |
4421 | ** [[SQLITE_LIMIT_VARIABLE_NUMBER]] |
4422 | ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> |
4423 | ** <dd>The maximum index number of any [parameter] in an SQL statement.)^ |
4424 | ** |
4425 | ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> |
4426 | ** <dd>The maximum depth of recursion for triggers.</dd>)^ |
4427 | ** |
4428 | ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt> |
4429 | ** <dd>The maximum number of auxiliary worker threads that a single |
4430 | ** [prepared statement] may start.</dd>)^ |
4431 | ** </dl> |
4432 | */ |
4433 | #define SQLITE_LIMIT_LENGTH 0 |
4434 | #define SQLITE_LIMIT_SQL_LENGTH 1 |
4435 | #define SQLITE_LIMIT_COLUMN 2 |
4436 | #define SQLITE_LIMIT_EXPR_DEPTH 3 |
4437 | #define SQLITE_LIMIT_COMPOUND_SELECT 4 |
4438 | #define SQLITE_LIMIT_VDBE_OP 5 |
4439 | #define SQLITE_LIMIT_FUNCTION_ARG 6 |
4440 | #define SQLITE_LIMIT_ATTACHED 7 |
4441 | #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8 |
4442 | #define SQLITE_LIMIT_VARIABLE_NUMBER 9 |
4443 | #define SQLITE_LIMIT_TRIGGER_DEPTH 10 |
4444 | #define SQLITE_LIMIT_WORKER_THREADS 11 |
4445 | |
4446 | /* |
4447 | ** CAPI3REF: Prepare Flags |
4448 | ** |
4449 | ** These constants define various flags that can be passed into |
4450 | ** "prepFlags" parameter of the [sqlite3_prepare_v3()] and |
4451 | ** [sqlite3_prepare16_v3()] interfaces. |
4452 | ** |
4453 | ** New flags may be added in future releases of SQLite. |
4454 | ** |
4455 | ** <dl> |
4456 | ** [[SQLITE_PREPARE_PERSISTENT]] ^(<dt>SQLITE_PREPARE_PERSISTENT</dt> |
4457 | ** <dd>The SQLITE_PREPARE_PERSISTENT flag is a hint to the query planner |
4458 | ** that the prepared statement will be retained for a long time and |
4459 | ** probably reused many times.)^ ^Without this flag, [sqlite3_prepare_v3()] |
4460 | ** and [sqlite3_prepare16_v3()] assume that the prepared statement will |
4461 | ** be used just once or at most a few times and then destroyed using |
4462 | ** [sqlite3_finalize()] relatively soon. The current implementation acts |
4463 | ** on this hint by avoiding the use of [lookaside memory] so as not to |
4464 | ** deplete the limited store of lookaside memory. Future versions of |
4465 | ** SQLite may act on this hint differently. |
4466 | ** |
4467 | ** [[SQLITE_PREPARE_NORMALIZE]] <dt>SQLITE_PREPARE_NORMALIZE</dt> |
4468 | ** <dd>The SQLITE_PREPARE_NORMALIZE flag is a no-op. This flag used |
4469 | ** to be required for any prepared statement that wanted to use the |
4470 | ** [sqlite3_normalized_sql()] interface. However, the |
4471 | ** [sqlite3_normalized_sql()] interface is now available to all |
4472 | ** prepared statements, regardless of whether or not they use this |
4473 | ** flag. |
4474 | ** |
4475 | ** [[SQLITE_PREPARE_NO_VTAB]] <dt>SQLITE_PREPARE_NO_VTAB</dt> |
4476 | ** <dd>The SQLITE_PREPARE_NO_VTAB flag causes the SQL compiler |
4477 | ** to return an error (error code SQLITE_ERROR) if the statement uses |
4478 | ** any virtual tables. |
4479 | ** </dl> |
4480 | */ |
4481 | #define SQLITE_PREPARE_PERSISTENT 0x01 |
4482 | #define SQLITE_PREPARE_NORMALIZE 0x02 |
4483 | #define SQLITE_PREPARE_NO_VTAB 0x04 |
4484 | |
4485 | /* |
4486 | ** CAPI3REF: Compiling An SQL Statement |
4487 | ** KEYWORDS: {SQL statement compiler} |
4488 | ** METHOD: sqlite3 |
4489 | ** CONSTRUCTOR: sqlite3_stmt |
4490 | ** |
4491 | ** To execute an SQL statement, it must first be compiled into a byte-code |
4492 | ** program using one of these routines. Or, in other words, these routines |
4493 | ** are constructors for the [prepared statement] object. |
4494 | ** |
4495 | ** The preferred routine to use is [sqlite3_prepare_v2()]. The |
4496 | ** [sqlite3_prepare()] interface is legacy and should be avoided. |
4497 | ** [sqlite3_prepare_v3()] has an extra "prepFlags" option that is used |
4498 | ** for special purposes. |
4499 | ** |
4500 | ** The use of the UTF-8 interfaces is preferred, as SQLite currently |
4501 | ** does all parsing using UTF-8. The UTF-16 interfaces are provided |
4502 | ** as a convenience. The UTF-16 interfaces work by converting the |
4503 | ** input text into UTF-8, then invoking the corresponding UTF-8 interface. |
4504 | ** |
4505 | ** The first argument, "db", is a [database connection] obtained from a |
4506 | ** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or |
4507 | ** [sqlite3_open16()]. The database connection must not have been closed. |
4508 | ** |
4509 | ** The second argument, "zSql", is the statement to be compiled, encoded |
4510 | ** as either UTF-8 or UTF-16. The sqlite3_prepare(), sqlite3_prepare_v2(), |
4511 | ** and sqlite3_prepare_v3() |
4512 | ** interfaces use UTF-8, and sqlite3_prepare16(), sqlite3_prepare16_v2(), |
4513 | ** and sqlite3_prepare16_v3() use UTF-16. |
4514 | ** |
4515 | ** ^If the nByte argument is negative, then zSql is read up to the |
4516 | ** first zero terminator. ^If nByte is positive, then it is the |
4517 | ** number of bytes read from zSql. ^If nByte is zero, then no prepared |
4518 | ** statement is generated. |
4519 | ** If the caller knows that the supplied string is nul-terminated, then |
4520 | ** there is a small performance advantage to passing an nByte parameter that |
4521 | ** is the number of bytes in the input string <i>including</i> |
4522 | ** the nul-terminator. |
4523 | ** |
4524 | ** ^If pzTail is not NULL then *pzTail is made to point to the first byte |
4525 | ** past the end of the first SQL statement in zSql. These routines only |
4526 | ** compile the first statement in zSql, so *pzTail is left pointing to |
4527 | ** what remains uncompiled. |
4528 | ** |
4529 | ** ^*ppStmt is left pointing to a compiled [prepared statement] that can be |
4530 | ** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set |
4531 | ** to NULL. ^If the input text contains no SQL (if the input is an empty |
4532 | ** string or a comment) then *ppStmt is set to NULL. |
4533 | ** The calling procedure is responsible for deleting the compiled |
4534 | ** SQL statement using [sqlite3_finalize()] after it has finished with it. |
4535 | ** ppStmt may not be NULL. |
4536 | ** |
4537 | ** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK]; |
4538 | ** otherwise an [error code] is returned. |
4539 | ** |
4540 | ** The sqlite3_prepare_v2(), sqlite3_prepare_v3(), sqlite3_prepare16_v2(), |
4541 | ** and sqlite3_prepare16_v3() interfaces are recommended for all new programs. |
4542 | ** The older interfaces (sqlite3_prepare() and sqlite3_prepare16()) |
4543 | ** are retained for backwards compatibility, but their use is discouraged. |
4544 | ** ^In the "vX" interfaces, the prepared statement |
4545 | ** that is returned (the [sqlite3_stmt] object) contains a copy of the |
4546 | ** original SQL text. This causes the [sqlite3_step()] interface to |
4547 | ** behave differently in three ways: |
4548 | ** |
4549 | ** <ol> |
4550 | ** <li> |
4551 | ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it |
4552 | ** always used to do, [sqlite3_step()] will automatically recompile the SQL |
4553 | ** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY] |
4554 | ** retries will occur before sqlite3_step() gives up and returns an error. |
4555 | ** </li> |
4556 | ** |
4557 | ** <li> |
4558 | ** ^When an error occurs, [sqlite3_step()] will return one of the detailed |
4559 | ** [error codes] or [extended error codes]. ^The legacy behavior was that |
4560 | ** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code |
4561 | ** and the application would have to make a second call to [sqlite3_reset()] |
4562 | ** in order to find the underlying cause of the problem. With the "v2" prepare |
4563 | ** interfaces, the underlying reason for the error is returned immediately. |
4564 | ** </li> |
4565 | ** |
4566 | ** <li> |
4567 | ** ^If the specific value bound to a [parameter | host parameter] in the |
4568 | ** WHERE clause might influence the choice of query plan for a statement, |
4569 | ** then the statement will be automatically recompiled, as if there had been |
4570 | ** a schema change, on the first [sqlite3_step()] call following any change |
4571 | ** to the [sqlite3_bind_text | bindings] of that [parameter]. |
4572 | ** ^The specific value of a WHERE-clause [parameter] might influence the |
4573 | ** choice of query plan if the parameter is the left-hand side of a [LIKE] |
4574 | ** or [GLOB] operator or if the parameter is compared to an indexed column |
4575 | ** and the [SQLITE_ENABLE_STAT4] compile-time option is enabled. |
4576 | ** </li> |
4577 | ** </ol> |
4578 | ** |
4579 | ** <p>^sqlite3_prepare_v3() differs from sqlite3_prepare_v2() only in having |
4580 | ** the extra prepFlags parameter, which is a bit array consisting of zero or |
4581 | ** more of the [SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_*] flags. ^The |
4582 | ** sqlite3_prepare_v2() interface works exactly the same as |
4583 | ** sqlite3_prepare_v3() with a zero prepFlags parameter. |
4584 | */ |
4585 | SQLITE_API int sqlite3_prepare( |
4586 | sqlite3 *db, /* Database handle */ |
4587 | const char *zSql, /* SQL statement, UTF-8 encoded */ |
4588 | int nByte, /* Maximum length of zSql in bytes. */ |
4589 | sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
4590 | const char **pzTail /* OUT: Pointer to unused portion of zSql */ |
4591 | ); |
4592 | SQLITE_API int sqlite3_prepare_v2( |
4593 | sqlite3 *db, /* Database handle */ |
4594 | const char *zSql, /* SQL statement, UTF-8 encoded */ |
4595 | int nByte, /* Maximum length of zSql in bytes. */ |
4596 | sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
4597 | const char **pzTail /* OUT: Pointer to unused portion of zSql */ |
4598 | ); |
4599 | SQLITE_API int sqlite3_prepare_v3( |
4600 | sqlite3 *db, /* Database handle */ |
4601 | const char *zSql, /* SQL statement, UTF-8 encoded */ |
4602 | int nByte, /* Maximum length of zSql in bytes. */ |
4603 | unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */ |
4604 | sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
4605 | const char **pzTail /* OUT: Pointer to unused portion of zSql */ |
4606 | ); |
4607 | SQLITE_API int sqlite3_prepare16( |
4608 | sqlite3 *db, /* Database handle */ |
4609 | const void *zSql, /* SQL statement, UTF-16 encoded */ |
4610 | int nByte, /* Maximum length of zSql in bytes. */ |
4611 | sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
4612 | const void **pzTail /* OUT: Pointer to unused portion of zSql */ |
4613 | ); |
4614 | SQLITE_API int sqlite3_prepare16_v2( |
4615 | sqlite3 *db, /* Database handle */ |
4616 | const void *zSql, /* SQL statement, UTF-16 encoded */ |
4617 | int nByte, /* Maximum length of zSql in bytes. */ |
4618 | sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
4619 | const void **pzTail /* OUT: Pointer to unused portion of zSql */ |
4620 | ); |
4621 | SQLITE_API int sqlite3_prepare16_v3( |
4622 | sqlite3 *db, /* Database handle */ |
4623 | const void *zSql, /* SQL statement, UTF-16 encoded */ |
4624 | int nByte, /* Maximum length of zSql in bytes. */ |
4625 | unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */ |
4626 | sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
4627 | const void **pzTail /* OUT: Pointer to unused portion of zSql */ |
4628 | ); |
4629 | |
4630 | /* |
4631 | ** CAPI3REF: Retrieving Statement SQL |
4632 | ** METHOD: sqlite3_stmt |
4633 | ** |
4634 | ** ^The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-8 |
4635 | ** SQL text used to create [prepared statement] P if P was |
4636 | ** created by [sqlite3_prepare_v2()], [sqlite3_prepare_v3()], |
4637 | ** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()]. |
4638 | ** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-8 |
4639 | ** string containing the SQL text of prepared statement P with |
4640 | ** [bound parameters] expanded. |
4641 | ** ^The sqlite3_normalized_sql(P) interface returns a pointer to a UTF-8 |
4642 | ** string containing the normalized SQL text of prepared statement P. The |
4643 | ** semantics used to normalize a SQL statement are unspecified and subject |
4644 | ** to change. At a minimum, literal values will be replaced with suitable |
4645 | ** placeholders. |
4646 | ** |
4647 | ** ^(For example, if a prepared statement is created using the SQL |
4648 | ** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 2345 |
4649 | ** and parameter :xyz is unbound, then sqlite3_sql() will return |
4650 | ** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql() |
4651 | ** will return "SELECT 2345,NULL".)^ |
4652 | ** |
4653 | ** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory |
4654 | ** is available to hold the result, or if the result would exceed the |
4655 | ** the maximum string length determined by the [SQLITE_LIMIT_LENGTH]. |
4656 | ** |
4657 | ** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of |
4658 | ** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time |
4659 | ** option causes sqlite3_expanded_sql() to always return NULL. |
4660 | ** |
4661 | ** ^The strings returned by sqlite3_sql(P) and sqlite3_normalized_sql(P) |
4662 | ** are managed by SQLite and are automatically freed when the prepared |
4663 | ** statement is finalized. |
4664 | ** ^The string returned by sqlite3_expanded_sql(P), on the other hand, |
4665 | ** is obtained from [sqlite3_malloc()] and must be freed by the application |
4666 | ** by passing it to [sqlite3_free()]. |
4667 | ** |
4668 | ** ^The sqlite3_normalized_sql() interface is only available if |
4669 | ** the [SQLITE_ENABLE_NORMALIZE] compile-time option is defined. |
4670 | */ |
4671 | SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt); |
4672 | SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt); |
4673 | #ifdef SQLITE_ENABLE_NORMALIZE |
4674 | SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt); |
4675 | #endif |
4676 | |
4677 | /* |
4678 | ** CAPI3REF: Determine If An SQL Statement Writes The Database |
4679 | ** METHOD: sqlite3_stmt |
4680 | ** |
4681 | ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if |
4682 | ** and only if the [prepared statement] X makes no direct changes to |
4683 | ** the content of the database file. |
4684 | ** |
4685 | ** Note that [application-defined SQL functions] or |
4686 | ** [virtual tables] might change the database indirectly as a side effect. |
4687 | ** ^(For example, if an application defines a function "eval()" that |
4688 | ** calls [sqlite3_exec()], then the following SQL statement would |
4689 | ** change the database file through side-effects: |
4690 | ** |
4691 | ** <blockquote><pre> |
4692 | ** SELECT eval('DELETE FROM t1') FROM t2; |
4693 | ** </pre></blockquote> |
4694 | ** |
4695 | ** But because the [SELECT] statement does not change the database file |
4696 | ** directly, sqlite3_stmt_readonly() would still return true.)^ |
4697 | ** |
4698 | ** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK], |
4699 | ** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true, |
4700 | ** since the statements themselves do not actually modify the database but |
4701 | ** rather they control the timing of when other statements modify the |
4702 | ** database. ^The [ATTACH] and [DETACH] statements also cause |
4703 | ** sqlite3_stmt_readonly() to return true since, while those statements |
4704 | ** change the configuration of a database connection, they do not make |
4705 | ** changes to the content of the database files on disk. |
4706 | ** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since |
4707 | ** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and |
4708 | ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so |
4709 | ** sqlite3_stmt_readonly() returns false for those commands. |
4710 | ** |
4711 | ** ^This routine returns false if there is any possibility that the |
4712 | ** statement might change the database file. ^A false return does |
4713 | ** not guarantee that the statement will change the database file. |
4714 | ** ^For example, an UPDATE statement might have a WHERE clause that |
4715 | ** makes it a no-op, but the sqlite3_stmt_readonly() result would still |
4716 | ** be false. ^Similarly, a CREATE TABLE IF NOT EXISTS statement is a |
4717 | ** read-only no-op if the table already exists, but |
4718 | ** sqlite3_stmt_readonly() still returns false for such a statement. |
4719 | ** |
4720 | ** ^If prepared statement X is an [EXPLAIN] or [EXPLAIN QUERY PLAN] |
4721 | ** statement, then sqlite3_stmt_readonly(X) returns the same value as |
4722 | ** if the EXPLAIN or EXPLAIN QUERY PLAN prefix were omitted. |
4723 | */ |
4724 | SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); |
4725 | |
4726 | /* |
4727 | ** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement |
4728 | ** METHOD: sqlite3_stmt |
4729 | ** |
4730 | ** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the |
4731 | ** prepared statement S is an EXPLAIN statement, or 2 if the |
4732 | ** statement S is an EXPLAIN QUERY PLAN. |
4733 | ** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is |
4734 | ** an ordinary statement or a NULL pointer. |
4735 | */ |
4736 | SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt); |
4737 | |
4738 | /* |
4739 | ** CAPI3REF: Change The EXPLAIN Setting For A Prepared Statement |
4740 | ** METHOD: sqlite3_stmt |
4741 | ** |
4742 | ** The sqlite3_stmt_explain(S,E) interface changes the EXPLAIN |
4743 | ** setting for [prepared statement] S. If E is zero, then S becomes |
4744 | ** a normal prepared statement. If E is 1, then S behaves as if |
4745 | ** its SQL text began with "[EXPLAIN]". If E is 2, then S behaves as if |
4746 | ** its SQL text began with "[EXPLAIN QUERY PLAN]". |
4747 | ** |
4748 | ** Calling sqlite3_stmt_explain(S,E) might cause S to be reprepared. |
4749 | ** SQLite tries to avoid a reprepare, but a reprepare might be necessary |
4750 | ** on the first transition into EXPLAIN or EXPLAIN QUERY PLAN mode. |
4751 | ** |
4752 | ** Because of the potential need to reprepare, a call to |
4753 | ** sqlite3_stmt_explain(S,E) will fail with SQLITE_ERROR if S cannot be |
4754 | ** reprepared because it was created using [sqlite3_prepare()] instead of |
4755 | ** the newer [sqlite3_prepare_v2()] or [sqlite3_prepare_v3()] interfaces and |
4756 | ** hence has no saved SQL text with which to reprepare. |
4757 | ** |
4758 | ** Changing the explain setting for a prepared statement does not change |
4759 | ** the original SQL text for the statement. Hence, if the SQL text originally |
4760 | ** began with EXPLAIN or EXPLAIN QUERY PLAN, but sqlite3_stmt_explain(S,0) |
4761 | ** is called to convert the statement into an ordinary statement, the EXPLAIN |
4762 | ** or EXPLAIN QUERY PLAN keywords will still appear in the sqlite3_sql(S) |
4763 | ** output, even though the statement now acts like a normal SQL statement. |
4764 | ** |
4765 | ** This routine returns SQLITE_OK if the explain mode is successfully |
4766 | ** changed, or an error code if the explain mode could not be changed. |
4767 | ** The explain mode cannot be changed while a statement is active. |
4768 | ** Hence, it is good practice to call [sqlite3_reset(S)] |
4769 | ** immediately prior to calling sqlite3_stmt_explain(S,E). |
4770 | */ |
4771 | SQLITE_API int sqlite3_stmt_explain(sqlite3_stmt *pStmt, int eMode); |
4772 | |
4773 | /* |
4774 | ** CAPI3REF: Determine If A Prepared Statement Has Been Reset |
4775 | ** METHOD: sqlite3_stmt |
4776 | ** |
4777 | ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the |
4778 | ** [prepared statement] S has been stepped at least once using |
4779 | ** [sqlite3_step(S)] but has neither run to completion (returned |
4780 | ** [SQLITE_DONE] from [sqlite3_step(S)]) nor |
4781 | ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S) |
4782 | ** interface returns false if S is a NULL pointer. If S is not a |
4783 | ** NULL pointer and is not a pointer to a valid [prepared statement] |
4784 | ** object, then the behavior is undefined and probably undesirable. |
4785 | ** |
4786 | ** This interface can be used in combination [sqlite3_next_stmt()] |
4787 | ** to locate all prepared statements associated with a database |
4788 | ** connection that are in need of being reset. This can be used, |
4789 | ** for example, in diagnostic routines to search for prepared |
4790 | ** statements that are holding a transaction open. |
4791 | */ |
4792 | SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*); |
4793 | |
4794 | /* |
4795 | ** CAPI3REF: Dynamically Typed Value Object |
4796 | ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value} |
4797 | ** |
4798 | ** SQLite uses the sqlite3_value object to represent all values |
4799 | ** that can be stored in a database table. SQLite uses dynamic typing |
4800 | ** for the values it stores. ^Values stored in sqlite3_value objects |
4801 | ** can be integers, floating point values, strings, BLOBs, or NULL. |
4802 | ** |
4803 | ** An sqlite3_value object may be either "protected" or "unprotected". |
4804 | ** Some interfaces require a protected sqlite3_value. Other interfaces |
4805 | ** will accept either a protected or an unprotected sqlite3_value. |
4806 | ** Every interface that accepts sqlite3_value arguments specifies |
4807 | ** whether or not it requires a protected sqlite3_value. The |
4808 | ** [sqlite3_value_dup()] interface can be used to construct a new |
4809 | ** protected sqlite3_value from an unprotected sqlite3_value. |
4810 | ** |
4811 | ** The terms "protected" and "unprotected" refer to whether or not |
4812 | ** a mutex is held. An internal mutex is held for a protected |
4813 | ** sqlite3_value object but no mutex is held for an unprotected |
4814 | ** sqlite3_value object. If SQLite is compiled to be single-threaded |
4815 | ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0) |
4816 | ** or if SQLite is run in one of reduced mutex modes |
4817 | ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD] |
4818 | ** then there is no distinction between protected and unprotected |
4819 | ** sqlite3_value objects and they can be used interchangeably. However, |
4820 | ** for maximum code portability it is recommended that applications |
4821 | ** still make the distinction between protected and unprotected |
4822 | ** sqlite3_value objects even when not strictly required. |
4823 | ** |
4824 | ** ^The sqlite3_value objects that are passed as parameters into the |
4825 | ** implementation of [application-defined SQL functions] are protected. |
4826 | ** ^The sqlite3_value objects returned by [sqlite3_vtab_rhs_value()] |
4827 | ** are protected. |
4828 | ** ^The sqlite3_value object returned by |
4829 | ** [sqlite3_column_value()] is unprotected. |
4830 | ** Unprotected sqlite3_value objects may only be used as arguments |
4831 | ** to [sqlite3_result_value()], [sqlite3_bind_value()], and |
4832 | ** [sqlite3_value_dup()]. |
4833 | ** The [sqlite3_value_blob | sqlite3_value_type()] family of |
4834 | ** interfaces require protected sqlite3_value objects. |
4835 | */ |
4836 | typedef struct sqlite3_value sqlite3_value; |
4837 | |
4838 | /* |
4839 | ** CAPI3REF: SQL Function Context Object |
4840 | ** |
4841 | ** The context in which an SQL function executes is stored in an |
4842 | ** sqlite3_context object. ^A pointer to an sqlite3_context object |
4843 | ** is always first parameter to [application-defined SQL functions]. |
4844 | ** The application-defined SQL function implementation will pass this |
4845 | ** pointer through into calls to [sqlite3_result_int | sqlite3_result()], |
4846 | ** [sqlite3_aggregate_context()], [sqlite3_user_data()], |
4847 | ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()], |
4848 | ** and/or [sqlite3_set_auxdata()]. |
4849 | */ |
4850 | typedef struct sqlite3_context sqlite3_context; |
4851 | |
4852 | /* |
4853 | ** CAPI3REF: Binding Values To Prepared Statements |
4854 | ** KEYWORDS: {host parameter} {host parameters} {host parameter name} |
4855 | ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} |
4856 | ** METHOD: sqlite3_stmt |
4857 | ** |
4858 | ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants, |
4859 | ** literals may be replaced by a [parameter] that matches one of following |
4860 | ** templates: |
4861 | ** |
4862 | ** <ul> |
4863 | ** <li> ? |
4864 | ** <li> ?NNN |
4865 | ** <li> :VVV |
4866 | ** <li> @VVV |
4867 | ** <li> $VVV |
4868 | ** </ul> |
4869 | ** |
4870 | ** In the templates above, NNN represents an integer literal, |
4871 | ** and VVV represents an alphanumeric identifier.)^ ^The values of these |
4872 | ** parameters (also called "host parameter names" or "SQL parameters") |
4873 | ** can be set using the sqlite3_bind_*() routines defined here. |
4874 | ** |
4875 | ** ^The first argument to the sqlite3_bind_*() routines is always |
4876 | ** a pointer to the [sqlite3_stmt] object returned from |
4877 | ** [sqlite3_prepare_v2()] or its variants. |
4878 | ** |
4879 | ** ^The second argument is the index of the SQL parameter to be set. |
4880 | ** ^The leftmost SQL parameter has an index of 1. ^When the same named |
4881 | ** SQL parameter is used more than once, second and subsequent |
4882 | ** occurrences have the same index as the first occurrence. |
4883 | ** ^The index for named parameters can be looked up using the |
4884 | ** [sqlite3_bind_parameter_index()] API if desired. ^The index |
4885 | ** for "?NNN" parameters is the value of NNN. |
4886 | ** ^The NNN value must be between 1 and the [sqlite3_limit()] |
4887 | ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 32766). |
4888 | ** |
4889 | ** ^The third argument is the value to bind to the parameter. |
4890 | ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16() |
4891 | ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter |
4892 | ** is ignored and the end result is the same as sqlite3_bind_null(). |
4893 | ** ^If the third parameter to sqlite3_bind_text() is not NULL, then |
4894 | ** it should be a pointer to well-formed UTF8 text. |
4895 | ** ^If the third parameter to sqlite3_bind_text16() is not NULL, then |
4896 | ** it should be a pointer to well-formed UTF16 text. |
4897 | ** ^If the third parameter to sqlite3_bind_text64() is not NULL, then |
4898 | ** it should be a pointer to a well-formed unicode string that is |
4899 | ** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16 |
4900 | ** otherwise. |
4901 | ** |
4902 | ** [[byte-order determination rules]] ^The byte-order of |
4903 | ** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF) |
4904 | ** found in first character, which is removed, or in the absence of a BOM |
4905 | ** the byte order is the native byte order of the host |
4906 | ** machine for sqlite3_bind_text16() or the byte order specified in |
4907 | ** the 6th parameter for sqlite3_bind_text64().)^ |
4908 | ** ^If UTF16 input text contains invalid unicode |
4909 | ** characters, then SQLite might change those invalid characters |
4910 | ** into the unicode replacement character: U+FFFD. |
4911 | ** |
4912 | ** ^(In those routines that have a fourth argument, its value is the |
4913 | ** number of bytes in the parameter. To be clear: the value is the |
4914 | ** number of <u>bytes</u> in the value, not the number of characters.)^ |
4915 | ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16() |
4916 | ** is negative, then the length of the string is |
4917 | ** the number of bytes up to the first zero terminator. |
4918 | ** If the fourth parameter to sqlite3_bind_blob() is negative, then |
4919 | ** the behavior is undefined. |
4920 | ** If a non-negative fourth parameter is provided to sqlite3_bind_text() |
4921 | ** or sqlite3_bind_text16() or sqlite3_bind_text64() then |
4922 | ** that parameter must be the byte offset |
4923 | ** where the NUL terminator would occur assuming the string were NUL |
4924 | ** terminated. If any NUL characters occurs at byte offsets less than |
4925 | ** the value of the fourth parameter then the resulting string value will |
4926 | ** contain embedded NULs. The result of expressions involving strings |
4927 | ** with embedded NULs is undefined. |
4928 | ** |
4929 | ** ^The fifth argument to the BLOB and string binding interfaces controls |
4930 | ** or indicates the lifetime of the object referenced by the third parameter. |
4931 | ** These three options exist: |
4932 | ** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished |
4933 | ** with it may be passed. ^It is called to dispose of the BLOB or string even |
4934 | ** if the call to the bind API fails, except the destructor is not called if |
4935 | ** the third parameter is a NULL pointer or the fourth parameter is negative. |
4936 | ** ^ (2) The special constant, [SQLITE_STATIC], may be passed to indicate that |
4937 | ** the application remains responsible for disposing of the object. ^In this |
4938 | ** case, the object and the provided pointer to it must remain valid until |
4939 | ** either the prepared statement is finalized or the same SQL parameter is |
4940 | ** bound to something else, whichever occurs sooner. |
4941 | ** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the |
4942 | ** object is to be copied prior to the return from sqlite3_bind_*(). ^The |
4943 | ** object and pointer to it must remain valid until then. ^SQLite will then |
4944 | ** manage the lifetime of its private copy. |
4945 | ** |
4946 | ** ^The sixth argument to sqlite3_bind_text64() must be one of |
4947 | ** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE] |
4948 | ** to specify the encoding of the text in the third parameter. If |
4949 | ** the sixth argument to sqlite3_bind_text64() is not one of the |
4950 | ** allowed values shown above, or if the text encoding is different |
4951 | ** from the encoding specified by the sixth parameter, then the behavior |
4952 | ** is undefined. |
4953 | ** |
4954 | ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that |
4955 | ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory |
4956 | ** (just an integer to hold its size) while it is being processed. |
4957 | ** Zeroblobs are intended to serve as placeholders for BLOBs whose |
4958 | ** content is later written using |
4959 | ** [sqlite3_blob_open | incremental BLOB I/O] routines. |
4960 | ** ^A negative value for the zeroblob results in a zero-length BLOB. |
4961 | ** |
4962 | ** ^The sqlite3_bind_pointer(S,I,P,T,D) routine causes the I-th parameter in |
4963 | ** [prepared statement] S to have an SQL value of NULL, but to also be |
4964 | ** associated with the pointer P of type T. ^D is either a NULL pointer or |
4965 | ** a pointer to a destructor function for P. ^SQLite will invoke the |
4966 | ** destructor D with a single argument of P when it is finished using |
4967 | ** P. The T parameter should be a static string, preferably a string |
4968 | ** literal. The sqlite3_bind_pointer() routine is part of the |
4969 | ** [pointer passing interface] added for SQLite 3.20.0. |
4970 | ** |
4971 | ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer |
4972 | ** for the [prepared statement] or with a prepared statement for which |
4973 | ** [sqlite3_step()] has been called more recently than [sqlite3_reset()], |
4974 | ** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_() |
4975 | ** routine is passed a [prepared statement] that has been finalized, the |
4976 | ** result is undefined and probably harmful. |
4977 | ** |
4978 | ** ^Bindings are not cleared by the [sqlite3_reset()] routine. |
4979 | ** ^Unbound parameters are interpreted as NULL. |
4980 | ** |
4981 | ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an |
4982 | ** [error code] if anything goes wrong. |
4983 | ** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB |
4984 | ** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or |
4985 | ** [SQLITE_MAX_LENGTH]. |
4986 | ** ^[SQLITE_RANGE] is returned if the parameter |
4987 | ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails. |
4988 | ** |
4989 | ** See also: [sqlite3_bind_parameter_count()], |
4990 | ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()]. |
4991 | */ |
4992 | SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); |
4993 | SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64, |
4994 | void(*)(void*)); |
4995 | SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double); |
4996 | SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int); |
4997 | SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); |
4998 | SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int); |
4999 | SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*)); |
5000 | SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*)); |
5001 | SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64, |
5002 | void(*)(void*), unsigned char encoding); |
5003 | SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); |
5004 | SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*, const char*,void(*)(void*)); |
5005 | SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); |
5006 | SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64); |
5007 | |
5008 | /* |
5009 | ** CAPI3REF: Number Of SQL Parameters |
5010 | ** METHOD: sqlite3_stmt |
5011 | ** |
5012 | ** ^This routine can be used to find the number of [SQL parameters] |
5013 | ** in a [prepared statement]. SQL parameters are tokens of the |
5014 | ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as |
5015 | ** placeholders for values that are [sqlite3_bind_blob | bound] |
5016 | ** to the parameters at a later time. |
5017 | ** |
5018 | ** ^(This routine actually returns the index of the largest (rightmost) |
5019 | ** parameter. For all forms except ?NNN, this will correspond to the |
5020 | ** number of unique parameters. If parameters of the ?NNN form are used, |
5021 | ** there may be gaps in the list.)^ |
5022 | ** |
5023 | ** See also: [sqlite3_bind_blob|sqlite3_bind()], |
5024 | ** [sqlite3_bind_parameter_name()], and |
5025 | ** [sqlite3_bind_parameter_index()]. |
5026 | */ |
5027 | SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*); |
5028 | |
5029 | /* |
5030 | ** CAPI3REF: Name Of A Host Parameter |
5031 | ** METHOD: sqlite3_stmt |
5032 | ** |
5033 | ** ^The sqlite3_bind_parameter_name(P,N) interface returns |
5034 | ** the name of the N-th [SQL parameter] in the [prepared statement] P. |
5035 | ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA" |
5036 | ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA" |
5037 | ** respectively. |
5038 | ** In other words, the initial ":" or "$" or "@" or "?" |
5039 | ** is included as part of the name.)^ |
5040 | ** ^Parameters of the form "?" without a following integer have no name |
5041 | ** and are referred to as "nameless" or "anonymous parameters". |
5042 | ** |
5043 | ** ^The first host parameter has an index of 1, not 0. |
5044 | ** |
5045 | ** ^If the value N is out of range or if the N-th parameter is |
5046 | ** nameless, then NULL is returned. ^The returned string is |
5047 | ** always in UTF-8 encoding even if the named parameter was |
5048 | ** originally specified as UTF-16 in [sqlite3_prepare16()], |
5049 | ** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()]. |
5050 | ** |
5051 | ** See also: [sqlite3_bind_blob|sqlite3_bind()], |
5052 | ** [sqlite3_bind_parameter_count()], and |
5053 | ** [sqlite3_bind_parameter_index()]. |
5054 | */ |
5055 | SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); |
5056 | |
5057 | /* |
5058 | ** CAPI3REF: Index Of A Parameter With A Given Name |
5059 | ** METHOD: sqlite3_stmt |
5060 | ** |
5061 | ** ^Return the index of an SQL parameter given its name. ^The |
5062 | ** index value returned is suitable for use as the second |
5063 | ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero |
5064 | ** is returned if no matching parameter is found. ^The parameter |
5065 | ** name must be given in UTF-8 even if the original statement |
5066 | ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()] or |
5067 | ** [sqlite3_prepare16_v3()]. |
5068 | ** |
5069 | ** See also: [sqlite3_bind_blob|sqlite3_bind()], |
5070 | ** [sqlite3_bind_parameter_count()], and |
5071 | ** [sqlite3_bind_parameter_name()]. |
5072 | */ |
5073 | SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); |
5074 | |
5075 | /* |
5076 | ** CAPI3REF: Reset All Bindings On A Prepared Statement |
5077 | ** METHOD: sqlite3_stmt |
5078 | ** |
5079 | ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset |
5080 | ** the [sqlite3_bind_blob | bindings] on a [prepared statement]. |
5081 | ** ^Use this routine to reset all host parameters to NULL. |
5082 | */ |
5083 | SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*); |
5084 | |
5085 | /* |
5086 | ** CAPI3REF: Number Of Columns In A Result Set |
5087 | ** METHOD: sqlite3_stmt |
5088 | ** |
5089 | ** ^Return the number of columns in the result set returned by the |
5090 | ** [prepared statement]. ^If this routine returns 0, that means the |
5091 | ** [prepared statement] returns no data (for example an [UPDATE]). |
5092 | ** ^However, just because this routine returns a positive number does not |
5093 | ** mean that one or more rows of data will be returned. ^A SELECT statement |
5094 | ** will always have a positive sqlite3_column_count() but depending on the |
5095 | ** WHERE clause constraints and the table content, it might return no rows. |
5096 | ** |
5097 | ** See also: [sqlite3_data_count()] |
5098 | */ |
5099 | SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt); |
5100 | |
5101 | /* |
5102 | ** CAPI3REF: Column Names In A Result Set |
5103 | ** METHOD: sqlite3_stmt |
5104 | ** |
5105 | ** ^These routines return the name assigned to a particular column |
5106 | ** in the result set of a [SELECT] statement. ^The sqlite3_column_name() |
5107 | ** interface returns a pointer to a zero-terminated UTF-8 string |
5108 | ** and sqlite3_column_name16() returns a pointer to a zero-terminated |
5109 | ** UTF-16 string. ^The first parameter is the [prepared statement] |
5110 | ** that implements the [SELECT] statement. ^The second parameter is the |
5111 | ** column number. ^The leftmost column is number 0. |
5112 | ** |
5113 | ** ^The returned string pointer is valid until either the [prepared statement] |
5114 | ** is destroyed by [sqlite3_finalize()] or until the statement is automatically |
5115 | ** reprepared by the first call to [sqlite3_step()] for a particular run |
5116 | ** or until the next call to |
5117 | ** sqlite3_column_name() or sqlite3_column_name16() on the same column. |
5118 | ** |
5119 | ** ^If sqlite3_malloc() fails during the processing of either routine |
5120 | ** (for example during a conversion from UTF-8 to UTF-16) then a |
5121 | ** NULL pointer is returned. |
5122 | ** |
5123 | ** ^The name of a result column is the value of the "AS" clause for |
5124 | ** that column, if there is an AS clause. If there is no AS clause |
5125 | ** then the name of the column is unspecified and may change from |
5126 | ** one release of SQLite to the next. |
5127 | */ |
5128 | SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N); |
5129 | SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N); |
5130 | |
5131 | /* |
5132 | ** CAPI3REF: Source Of Data In A Query Result |
5133 | ** METHOD: sqlite3_stmt |
5134 | ** |
5135 | ** ^These routines provide a means to determine the database, table, and |
5136 | ** table column that is the origin of a particular result column in |
5137 | ** [SELECT] statement. |
5138 | ** ^The name of the database or table or column can be returned as |
5139 | ** either a UTF-8 or UTF-16 string. ^The _database_ routines return |
5140 | ** the database name, the _table_ routines return the table name, and |
5141 | ** the origin_ routines return the column name. |
5142 | ** ^The returned string is valid until the [prepared statement] is destroyed |
5143 | ** using [sqlite3_finalize()] or until the statement is automatically |
5144 | ** reprepared by the first call to [sqlite3_step()] for a particular run |
5145 | ** or until the same information is requested |
5146 | ** again in a different encoding. |
5147 | ** |
5148 | ** ^The names returned are the original un-aliased names of the |
5149 | ** database, table, and column. |
5150 | ** |
5151 | ** ^The first argument to these interfaces is a [prepared statement]. |
5152 | ** ^These functions return information about the Nth result column returned by |
5153 | ** the statement, where N is the second function argument. |
5154 | ** ^The left-most column is column 0 for these routines. |
5155 | ** |
5156 | ** ^If the Nth column returned by the statement is an expression or |
5157 | ** subquery and is not a column value, then all of these functions return |
5158 | ** NULL. ^These routines might also return NULL if a memory allocation error |
5159 | ** occurs. ^Otherwise, they return the name of the attached database, table, |
5160 | ** or column that query result column was extracted from. |
5161 | ** |
5162 | ** ^As with all other SQLite APIs, those whose names end with "16" return |
5163 | ** UTF-16 encoded strings and the other functions return UTF-8. |
5164 | ** |
5165 | ** ^These APIs are only available if the library was compiled with the |
5166 | ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol. |
5167 | ** |
5168 | ** If two or more threads call one or more |
5169 | ** [sqlite3_column_database_name | column metadata interfaces] |
5170 | ** for the same [prepared statement] and result column |
5171 | ** at the same time then the results are undefined. |
5172 | */ |
5173 | SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int); |
5174 | SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int); |
5175 | SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int); |
5176 | SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int); |
5177 | SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int); |
5178 | SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); |
5179 | |
5180 | /* |
5181 | ** CAPI3REF: Declared Datatype Of A Query Result |
5182 | ** METHOD: sqlite3_stmt |
5183 | ** |
5184 | ** ^(The first parameter is a [prepared statement]. |
5185 | ** If this statement is a [SELECT] statement and the Nth column of the |
5186 | ** returned result set of that [SELECT] is a table column (not an |
5187 | ** expression or subquery) then the declared type of the table |
5188 | ** column is returned.)^ ^If the Nth column of the result set is an |
5189 | ** expression or subquery, then a NULL pointer is returned. |
5190 | ** ^The returned string is always UTF-8 encoded. |
5191 | ** |
5192 | ** ^(For example, given the database schema: |
5193 | ** |
5194 | ** CREATE TABLE t1(c1 VARIANT); |
5195 | ** |
5196 | ** and the following statement to be compiled: |
5197 | ** |
5198 | ** SELECT c1 + 1, c1 FROM t1; |
5199 | ** |
5200 | ** this routine would return the string "VARIANT" for the second result |
5201 | ** column (i==1), and a NULL pointer for the first result column (i==0).)^ |
5202 | ** |
5203 | ** ^SQLite uses dynamic run-time typing. ^So just because a column |
5204 | ** is declared to contain a particular type does not mean that the |
5205 | ** data stored in that column is of the declared type. SQLite is |
5206 | ** strongly typed, but the typing is dynamic not static. ^Type |
5207 | ** is associated with individual values, not with the containers |
5208 | ** used to hold those values. |
5209 | */ |
5210 | SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int); |
5211 | SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int); |
5212 | |
5213 | /* |
5214 | ** CAPI3REF: Evaluate An SQL Statement |
5215 | ** METHOD: sqlite3_stmt |
5216 | ** |
5217 | ** After a [prepared statement] has been prepared using any of |
5218 | ** [sqlite3_prepare_v2()], [sqlite3_prepare_v3()], [sqlite3_prepare16_v2()], |
5219 | ** or [sqlite3_prepare16_v3()] or one of the legacy |
5220 | ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function |
5221 | ** must be called one or more times to evaluate the statement. |
5222 | ** |
5223 | ** The details of the behavior of the sqlite3_step() interface depend |
5224 | ** on whether the statement was prepared using the newer "vX" interfaces |
5225 | ** [sqlite3_prepare_v3()], [sqlite3_prepare_v2()], [sqlite3_prepare16_v3()], |
5226 | ** [sqlite3_prepare16_v2()] or the older legacy |
5227 | ** interfaces [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the |
5228 | ** new "vX" interface is recommended for new applications but the legacy |
5229 | ** interface will continue to be supported. |
5230 | ** |
5231 | ** ^In the legacy interface, the return value will be either [SQLITE_BUSY], |
5232 | ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE]. |
5233 | ** ^With the "v2" interface, any of the other [result codes] or |
5234 | ** [extended result codes] might be returned as well. |
5235 | ** |
5236 | ** ^[SQLITE_BUSY] means that the database engine was unable to acquire the |
5237 | ** database locks it needs to do its job. ^If the statement is a [COMMIT] |
5238 | ** or occurs outside of an explicit transaction, then you can retry the |
5239 | ** statement. If the statement is not a [COMMIT] and occurs within an |
5240 | ** explicit transaction then you should rollback the transaction before |
5241 | ** continuing. |
5242 | ** |
5243 | ** ^[SQLITE_DONE] means that the statement has finished executing |
5244 | ** successfully. sqlite3_step() should not be called again on this virtual |
5245 | ** machine without first calling [sqlite3_reset()] to reset the virtual |
5246 | ** machine back to its initial state. |
5247 | ** |
5248 | ** ^If the SQL statement being executed returns any data, then [SQLITE_ROW] |
5249 | ** is returned each time a new row of data is ready for processing by the |
5250 | ** caller. The values may be accessed using the [column access functions]. |
5251 | ** sqlite3_step() is called again to retrieve the next row of data. |
5252 | ** |
5253 | ** ^[SQLITE_ERROR] means that a run-time error (such as a constraint |
5254 | ** violation) has occurred. sqlite3_step() should not be called again on |
5255 | ** the VM. More information may be found by calling [sqlite3_errmsg()]. |
5256 | ** ^With the legacy interface, a more specific error code (for example, |
5257 | ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth) |
5258 | ** can be obtained by calling [sqlite3_reset()] on the |
5259 | ** [prepared statement]. ^In the "v2" interface, |
5260 | ** the more specific error code is returned directly by sqlite3_step(). |
5261 | ** |
5262 | ** [SQLITE_MISUSE] means that the this routine was called inappropriately. |
5263 | ** Perhaps it was called on a [prepared statement] that has |
5264 | ** already been [sqlite3_finalize | finalized] or on one that had |
5265 | ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could |
5266 | ** be the case that the same database connection is being used by two or |
5267 | ** more threads at the same moment in time. |
5268 | ** |
5269 | ** For all versions of SQLite up to and including 3.6.23.1, a call to |
5270 | ** [sqlite3_reset()] was required after sqlite3_step() returned anything |
5271 | ** other than [SQLITE_ROW] before any subsequent invocation of |
5272 | ** sqlite3_step(). Failure to reset the prepared statement using |
5273 | ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from |
5274 | ** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1], |
5275 | ** sqlite3_step() began |
5276 | ** calling [sqlite3_reset()] automatically in this circumstance rather |
5277 | ** than returning [SQLITE_MISUSE]. This is not considered a compatibility |
5278 | ** break because any application that ever receives an SQLITE_MISUSE error |
5279 | ** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option |
5280 | ** can be used to restore the legacy behavior. |
5281 | ** |
5282 | ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step() |
5283 | ** API always returns a generic error code, [SQLITE_ERROR], following any |
5284 | ** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call |
5285 | ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the |
5286 | ** specific [error codes] that better describes the error. |
5287 | ** We admit that this is a goofy design. The problem has been fixed |
5288 | ** with the "v2" interface. If you prepare all of your SQL statements |
5289 | ** using [sqlite3_prepare_v3()] or [sqlite3_prepare_v2()] |
5290 | ** or [sqlite3_prepare16_v2()] or [sqlite3_prepare16_v3()] instead |
5291 | ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces, |
5292 | ** then the more specific [error codes] are returned directly |
5293 | ** by sqlite3_step(). The use of the "vX" interfaces is recommended. |
5294 | */ |
5295 | SQLITE_API int sqlite3_step(sqlite3_stmt*); |
5296 | |
5297 | /* |
5298 | ** CAPI3REF: Number of columns in a result set |
5299 | ** METHOD: sqlite3_stmt |
5300 | ** |
5301 | ** ^The sqlite3_data_count(P) interface returns the number of columns in the |
5302 | ** current row of the result set of [prepared statement] P. |
5303 | ** ^If prepared statement P does not have results ready to return |
5304 | ** (via calls to the [sqlite3_column_int | sqlite3_column()] family of |
5305 | ** interfaces) then sqlite3_data_count(P) returns 0. |
5306 | ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer. |
5307 | ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to |
5308 | ** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P) |
5309 | ** will return non-zero if previous call to [sqlite3_step](P) returned |
5310 | ** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum] |
5311 | ** where it always returns zero since each step of that multi-step |
5312 | ** pragma returns 0 columns of data. |
5313 | ** |
5314 | ** See also: [sqlite3_column_count()] |
5315 | */ |
5316 | SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); |
5317 | |
5318 | /* |
5319 | ** CAPI3REF: Fundamental Datatypes |
5320 | ** KEYWORDS: SQLITE_TEXT |
5321 | ** |
5322 | ** ^(Every value in SQLite has one of five fundamental datatypes: |
5323 | ** |
5324 | ** <ul> |
5325 | ** <li> 64-bit signed integer |
5326 | ** <li> 64-bit IEEE floating point number |
5327 | ** <li> string |
5328 | ** <li> BLOB |
5329 | ** <li> NULL |
5330 | ** </ul>)^ |
5331 | ** |
5332 | ** These constants are codes for each of those types. |
5333 | ** |
5334 | ** Note that the SQLITE_TEXT constant was also used in SQLite version 2 |
5335 | ** for a completely different meaning. Software that links against both |
5336 | ** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not |
5337 | ** SQLITE_TEXT. |
5338 | */ |
5339 | #define SQLITE_INTEGER 1 |
5340 | #define SQLITE_FLOAT 2 |
5341 | #define SQLITE_BLOB 4 |
5342 | #define SQLITE_NULL 5 |
5343 | #ifdef SQLITE_TEXT |
5344 | # undef SQLITE_TEXT |
5345 | #else |
5346 | # define SQLITE_TEXT 3 |
5347 | #endif |
5348 | #define SQLITE3_TEXT 3 |
5349 | |
5350 | /* |
5351 | ** CAPI3REF: Result Values From A Query |
5352 | ** KEYWORDS: {column access functions} |
5353 | ** METHOD: sqlite3_stmt |
5354 | ** |
5355 | ** <b>Summary:</b> |
5356 | ** <blockquote><table border=0 cellpadding=0 cellspacing=0> |
5357 | ** <tr><td><b>sqlite3_column_blob</b><td>→<td>BLOB result |
5358 | ** <tr><td><b>sqlite3_column_double</b><td>→<td>REAL result |
5359 | ** <tr><td><b>sqlite3_column_int</b><td>→<td>32-bit INTEGER result |
5360 | ** <tr><td><b>sqlite3_column_int64</b><td>→<td>64-bit INTEGER result |
5361 | ** <tr><td><b>sqlite3_column_text</b><td>→<td>UTF-8 TEXT result |
5362 | ** <tr><td><b>sqlite3_column_text16</b><td>→<td>UTF-16 TEXT result |
5363 | ** <tr><td><b>sqlite3_column_value</b><td>→<td>The result as an |
5364 | ** [sqlite3_value|unprotected sqlite3_value] object. |
5365 | ** <tr><td> <td> <td> |
5366 | ** <tr><td><b>sqlite3_column_bytes</b><td>→<td>Size of a BLOB |
5367 | ** or a UTF-8 TEXT result in bytes |
5368 | ** <tr><td><b>sqlite3_column_bytes16 </b> |
5369 | ** <td>→ <td>Size of UTF-16 |
5370 | ** TEXT in bytes |
5371 | ** <tr><td><b>sqlite3_column_type</b><td>→<td>Default |
5372 | ** datatype of the result |
5373 | ** </table></blockquote> |
5374 | ** |
5375 | ** <b>Details:</b> |
5376 | ** |
5377 | ** ^These routines return information about a single column of the current |
5378 | ** result row of a query. ^In every case the first argument is a pointer |
5379 | ** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*] |
5380 | ** that was returned from [sqlite3_prepare_v2()] or one of its variants) |
5381 | ** and the second argument is the index of the column for which information |
5382 | ** should be returned. ^The leftmost column of the result set has the index 0. |
5383 | ** ^The number of columns in the result can be determined using |
5384 | ** [sqlite3_column_count()]. |
5385 | ** |
5386 | ** If the SQL statement does not currently point to a valid row, or if the |
5387 | ** column index is out of range, the result is undefined. |
5388 | ** These routines may only be called when the most recent call to |
5389 | ** [sqlite3_step()] has returned [SQLITE_ROW] and neither |
5390 | ** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently. |
5391 | ** If any of these routines are called after [sqlite3_reset()] or |
5392 | ** [sqlite3_finalize()] or after [sqlite3_step()] has returned |
5393 | ** something other than [SQLITE_ROW], the results are undefined. |
5394 | ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()] |
5395 | ** are called from a different thread while any of these routines |
5396 | ** are pending, then the results are undefined. |
5397 | ** |
5398 | ** The first six interfaces (_blob, _double, _int, _int64, _text, and _text16) |
5399 | ** each return the value of a result column in a specific data format. If |
5400 | ** the result column is not initially in the requested format (for example, |
5401 | ** if the query returns an integer but the sqlite3_column_text() interface |
5402 | ** is used to extract the value) then an automatic type conversion is performed. |
5403 | ** |
5404 | ** ^The sqlite3_column_type() routine returns the |
5405 | ** [SQLITE_INTEGER | datatype code] for the initial data type |
5406 | ** of the result column. ^The returned value is one of [SQLITE_INTEGER], |
5407 | ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. |
5408 | ** The return value of sqlite3_column_type() can be used to decide which |
5409 | ** of the first six interface should be used to extract the column value. |
5410 | ** The value returned by sqlite3_column_type() is only meaningful if no |
5411 | ** automatic type conversions have occurred for the value in question. |
5412 | ** After a type conversion, the result of calling sqlite3_column_type() |
5413 | ** is undefined, though harmless. Future |
5414 | ** versions of SQLite may change the behavior of sqlite3_column_type() |
5415 | ** following a type conversion. |
5416 | ** |
5417 | ** If the result is a BLOB or a TEXT string, then the sqlite3_column_bytes() |
5418 | ** or sqlite3_column_bytes16() interfaces can be used to determine the size |
5419 | ** of that BLOB or string. |
5420 | ** |
5421 | ** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes() |
5422 | ** routine returns the number of bytes in that BLOB or string. |
5423 | ** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts |
5424 | ** the string to UTF-8 and then returns the number of bytes. |
5425 | ** ^If the result is a numeric value then sqlite3_column_bytes() uses |
5426 | ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns |
5427 | ** the number of bytes in that string. |
5428 | ** ^If the result is NULL, then sqlite3_column_bytes() returns zero. |
5429 | ** |
5430 | ** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16() |
5431 | ** routine returns the number of bytes in that BLOB or string. |
5432 | ** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts |
5433 | ** the string to UTF-16 and then returns the number of bytes. |
5434 | ** ^If the result is a numeric value then sqlite3_column_bytes16() uses |
5435 | ** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns |
5436 | ** the number of bytes in that string. |
5437 | ** ^If the result is NULL, then sqlite3_column_bytes16() returns zero. |
5438 | ** |
5439 | ** ^The values returned by [sqlite3_column_bytes()] and |
5440 | ** [sqlite3_column_bytes16()] do not include the zero terminators at the end |
5441 | ** of the string. ^For clarity: the values returned by |
5442 | ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of |
5443 | ** bytes in the string, not the number of characters. |
5444 | ** |
5445 | ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(), |
5446 | ** even empty strings, are always zero-terminated. ^The return |
5447 | ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer. |
5448 | ** |
5449 | ** ^Strings returned by sqlite3_column_text16() always have the endianness |
5450 | ** which is native to the platform, regardless of the text encoding set |
5451 | ** for the database. |
5452 | ** |
5453 | ** <b>Warning:</b> ^The object returned by [sqlite3_column_value()] is an |
5454 | ** [unprotected sqlite3_value] object. In a multithreaded environment, |
5455 | ** an unprotected sqlite3_value object may only be used safely with |
5456 | ** [sqlite3_bind_value()] and [sqlite3_result_value()]. |
5457 | ** If the [unprotected sqlite3_value] object returned by |
5458 | ** [sqlite3_column_value()] is used in any other way, including calls |
5459 | ** to routines like [sqlite3_value_int()], [sqlite3_value_text()], |
5460 | ** or [sqlite3_value_bytes()], the behavior is not threadsafe. |
5461 | ** Hence, the sqlite3_column_value() interface |
5462 | ** is normally only useful within the implementation of |
5463 | ** [application-defined SQL functions] or [virtual tables], not within |
5464 | ** top-level application code. |
5465 | ** |
5466 | ** These routines may attempt to convert the datatype of the result. |
5467 | ** ^For example, if the internal representation is FLOAT and a text result |
5468 | ** is requested, [sqlite3_snprintf()] is used internally to perform the |
5469 | ** conversion automatically. ^(The following table details the conversions |
5470 | ** that are applied: |
5471 | ** |
5472 | ** <blockquote> |
5473 | ** <table border="1"> |
5474 | ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion |
5475 | ** |
5476 | ** <tr><td> NULL <td> INTEGER <td> Result is 0 |
5477 | ** <tr><td> NULL <td> FLOAT <td> Result is 0.0 |
5478 | ** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer |
5479 | ** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer |
5480 | ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float |
5481 | ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer |
5482 | ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT |
5483 | ** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER |
5484 | ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float |
5485 | ** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB |
5486 | ** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER |
5487 | ** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL |
5488 | ** <tr><td> TEXT <td> BLOB <td> No change |
5489 | ** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER |
5490 | ** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL |
5491 | ** <tr><td> BLOB <td> TEXT <td> [CAST] to TEXT, ensure zero terminator |
5492 | ** </table> |
5493 | ** </blockquote>)^ |
5494 | ** |
5495 | ** Note that when type conversions occur, pointers returned by prior |
5496 | ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or |
5497 | ** sqlite3_column_text16() may be invalidated. |
5498 | ** Type conversions and pointer invalidations might occur |
5499 | ** in the following cases: |
5500 | ** |
5501 | ** <ul> |
5502 | ** <li> The initial content is a BLOB and sqlite3_column_text() or |
5503 | ** sqlite3_column_text16() is called. A zero-terminator might |
5504 | ** need to be added to the string.</li> |
5505 | ** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or |
5506 | ** sqlite3_column_text16() is called. The content must be converted |
5507 | ** to UTF-16.</li> |
5508 | ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or |
5509 | ** sqlite3_column_text() is called. The content must be converted |
5510 | ** to UTF-8.</li> |
5511 | ** </ul> |
5512 | ** |
5513 | ** ^Conversions between UTF-16be and UTF-16le are always done in place and do |
5514 | ** not invalidate a prior pointer, though of course the content of the buffer |
5515 | ** that the prior pointer references will have been modified. Other kinds |
5516 | ** of conversion are done in place when it is possible, but sometimes they |
5517 | ** are not possible and in those cases prior pointers are invalidated. |
5518 | ** |
5519 | ** The safest policy is to invoke these routines |
5520 | ** in one of the following ways: |
5521 | ** |
5522 | ** <ul> |
5523 | ** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li> |
5524 | ** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li> |
5525 | ** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li> |
5526 | ** </ul> |
5527 | ** |
5528 | ** In other words, you should call sqlite3_column_text(), |
5529 | ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result |
5530 | ** into the desired format, then invoke sqlite3_column_bytes() or |
5531 | ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls |
5532 | ** to sqlite3_column_text() or sqlite3_column_blob() with calls to |
5533 | ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16() |
5534 | ** with calls to sqlite3_column_bytes(). |
5535 | ** |
5536 | ** ^The pointers returned are valid until a type conversion occurs as |
5537 | ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or |
5538 | ** [sqlite3_finalize()] is called. ^The memory space used to hold strings |
5539 | ** and BLOBs is freed automatically. Do not pass the pointers returned |
5540 | ** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into |
5541 | ** [sqlite3_free()]. |
5542 | ** |
5543 | ** As long as the input parameters are correct, these routines will only |
5544 | ** fail if an out-of-memory error occurs during a format conversion. |
5545 | ** Only the following subset of interfaces are subject to out-of-memory |
5546 | ** errors: |
5547 | ** |
5548 | ** <ul> |
5549 | ** <li> sqlite3_column_blob() |
5550 | ** <li> sqlite3_column_text() |
5551 | ** <li> sqlite3_column_text16() |
5552 | ** <li> sqlite3_column_bytes() |
5553 | ** <li> sqlite3_column_bytes16() |
5554 | ** </ul> |
5555 | ** |
5556 | ** If an out-of-memory error occurs, then the return value from these |
5557 | ** routines is the same as if the column had contained an SQL NULL value. |
5558 | ** Valid SQL NULL returns can be distinguished from out-of-memory errors |
5559 | ** by invoking the [sqlite3_errcode()] immediately after the suspect |
5560 | ** return value is obtained and before any |
5561 | ** other SQLite interface is called on the same [database connection]. |
5562 | */ |
5563 | SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); |
5564 | SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol); |
5565 | SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol); |
5566 | SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol); |
5567 | SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); |
5568 | SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol); |
5569 | SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol); |
5570 | SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol); |
5571 | SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol); |
5572 | SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol); |
5573 | |
5574 | /* |
5575 | ** CAPI3REF: Destroy A Prepared Statement Object |
5576 | ** DESTRUCTOR: sqlite3_stmt |
5577 | ** |
5578 | ** ^The sqlite3_finalize() function is called to delete a [prepared statement]. |
5579 | ** ^If the most recent evaluation of the statement encountered no errors |
5580 | ** or if the statement is never been evaluated, then sqlite3_finalize() returns |
5581 | ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then |
5582 | ** sqlite3_finalize(S) returns the appropriate [error code] or |
5583 | ** [extended error code]. |
5584 | ** |
5585 | ** ^The sqlite3_finalize(S) routine can be called at any point during |
5586 | ** the life cycle of [prepared statement] S: |
5587 | ** before statement S is ever evaluated, after |
5588 | ** one or more calls to [sqlite3_reset()], or after any call |
5589 | ** to [sqlite3_step()] regardless of whether or not the statement has |
5590 | ** completed execution. |
5591 | ** |
5592 | ** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op. |
5593 | ** |
5594 | ** The application must finalize every [prepared statement] in order to avoid |
5595 | ** resource leaks. It is a grievous error for the application to try to use |
5596 | ** a prepared statement after it has been finalized. Any use of a prepared |
5597 | ** statement after it has been finalized can result in undefined and |
5598 | ** undesirable behavior such as segfaults and heap corruption. |
5599 | */ |
5600 | SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt); |
5601 | |
5602 | /* |
5603 | ** CAPI3REF: Reset A Prepared Statement Object |
5604 | ** METHOD: sqlite3_stmt |
5605 | ** |
5606 | ** The sqlite3_reset() function is called to reset a [prepared statement] |
5607 | ** object back to its initial state, ready to be re-executed. |
5608 | ** ^Any SQL statement variables that had values bound to them using |
5609 | ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values. |
5610 | ** Use [sqlite3_clear_bindings()] to reset the bindings. |
5611 | ** |
5612 | ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S |
5613 | ** back to the beginning of its program. |
5614 | ** |
5615 | ** ^The return code from [sqlite3_reset(S)] indicates whether or not |
5616 | ** the previous evaluation of prepared statement S completed successfully. |
5617 | ** ^If [sqlite3_step(S)] has never before been called on S or if |
5618 | ** [sqlite3_step(S)] has not been called since the previous call |
5619 | ** to [sqlite3_reset(S)], then [sqlite3_reset(S)] will return |
5620 | ** [SQLITE_OK]. |
5621 | ** |
5622 | ** ^If the most recent call to [sqlite3_step(S)] for the |
5623 | ** [prepared statement] S indicated an error, then |
5624 | ** [sqlite3_reset(S)] returns an appropriate [error code]. |
5625 | ** ^The [sqlite3_reset(S)] interface might also return an [error code] |
5626 | ** if there were no prior errors but the process of resetting |
5627 | ** the prepared statement caused a new error. ^For example, if an |
5628 | ** [INSERT] statement with a [RETURNING] clause is only stepped one time, |
5629 | ** that one call to [sqlite3_step(S)] might return SQLITE_ROW but |
5630 | ** the overall statement might still fail and the [sqlite3_reset(S)] call |
5631 | ** might return SQLITE_BUSY if locking constraints prevent the |
5632 | ** database change from committing. Therefore, it is important that |
5633 | ** applications check the return code from [sqlite3_reset(S)] even if |
5634 | ** no prior call to [sqlite3_step(S)] indicated a problem. |
5635 | ** |
5636 | ** ^The [sqlite3_reset(S)] interface does not change the values |
5637 | ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S. |
5638 | */ |
5639 | SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); |
5640 | |
5641 | /* |
5642 | ** CAPI3REF: Create Or Redefine SQL Functions |
5643 | ** KEYWORDS: {function creation routines} |
5644 | ** METHOD: sqlite3 |
5645 | ** |
5646 | ** ^These functions (collectively known as "function creation routines") |
5647 | ** are used to add SQL functions or aggregates or to redefine the behavior |
5648 | ** of existing SQL functions or aggregates. The only differences between |
5649 | ** the three "sqlite3_create_function*" routines are the text encoding |
5650 | ** expected for the second parameter (the name of the function being |
5651 | ** created) and the presence or absence of a destructor callback for |
5652 | ** the application data pointer. Function sqlite3_create_window_function() |
5653 | ** is similar, but allows the user to supply the extra callback functions |
5654 | ** needed by [aggregate window functions]. |
5655 | ** |
5656 | ** ^The first parameter is the [database connection] to which the SQL |
5657 | ** function is to be added. ^If an application uses more than one database |
5658 | ** connection then application-defined SQL functions must be added |
5659 | ** to each database connection separately. |
5660 | ** |
5661 | ** ^The second parameter is the name of the SQL function to be created or |
5662 | ** redefined. ^The length of the name is limited to 255 bytes in a UTF-8 |
5663 | ** representation, exclusive of the zero-terminator. ^Note that the name |
5664 | ** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes. |
5665 | ** ^Any attempt to create a function with a longer name |
5666 | ** will result in [SQLITE_MISUSE] being returned. |
5667 | ** |
5668 | ** ^The third parameter (nArg) |
5669 | ** is the number of arguments that the SQL function or |
5670 | ** aggregate takes. ^If this parameter is -1, then the SQL function or |
5671 | ** aggregate may take any number of arguments between 0 and the limit |
5672 | ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third |
5673 | ** parameter is less than -1 or greater than 127 then the behavior is |
5674 | ** undefined. |
5675 | ** |
5676 | ** ^The fourth parameter, eTextRep, specifies what |
5677 | ** [SQLITE_UTF8 | text encoding] this SQL function prefers for |
5678 | ** its parameters. The application should set this parameter to |
5679 | ** [SQLITE_UTF16LE] if the function implementation invokes |
5680 | ** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the |
5681 | ** implementation invokes [sqlite3_value_text16be()] on an input, or |
5682 | ** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8] |
5683 | ** otherwise. ^The same SQL function may be registered multiple times using |
5684 | ** different preferred text encodings, with different implementations for |
5685 | ** each encoding. |
5686 | ** ^When multiple implementations of the same function are available, SQLite |
5687 | ** will pick the one that involves the least amount of data conversion. |
5688 | ** |
5689 | ** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC] |
5690 | ** to signal that the function will always return the same result given |
5691 | ** the same inputs within a single SQL statement. Most SQL functions are |
5692 | ** deterministic. The built-in [random()] SQL function is an example of a |
5693 | ** function that is not deterministic. The SQLite query planner is able to |
5694 | ** perform additional optimizations on deterministic functions, so use |
5695 | ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible. |
5696 | ** |
5697 | ** ^The fourth parameter may also optionally include the [SQLITE_DIRECTONLY] |
5698 | ** flag, which if present prevents the function from being invoked from |
5699 | ** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions, |
5700 | ** index expressions, or the WHERE clause of partial indexes. |
5701 | ** |
5702 | ** For best security, the [SQLITE_DIRECTONLY] flag is recommended for |
5703 | ** all application-defined SQL functions that do not need to be |
5704 | ** used inside of triggers, view, CHECK constraints, or other elements of |
5705 | ** the database schema. This flags is especially recommended for SQL |
5706 | ** functions that have side effects or reveal internal application state. |
5707 | ** Without this flag, an attacker might be able to modify the schema of |
5708 | ** a database file to include invocations of the function with parameters |
5709 | ** chosen by the attacker, which the application will then execute when |
5710 | ** the database file is opened and read. |
5711 | ** |
5712 | ** ^(The fifth parameter is an arbitrary pointer. The implementation of the |
5713 | ** function can gain access to this pointer using [sqlite3_user_data()].)^ |
5714 | ** |
5715 | ** ^The sixth, seventh and eighth parameters passed to the three |
5716 | ** "sqlite3_create_function*" functions, xFunc, xStep and xFinal, are |
5717 | ** pointers to C-language functions that implement the SQL function or |
5718 | ** aggregate. ^A scalar SQL function requires an implementation of the xFunc |
5719 | ** callback only; NULL pointers must be passed as the xStep and xFinal |
5720 | ** parameters. ^An aggregate SQL function requires an implementation of xStep |
5721 | ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing |
5722 | ** SQL function or aggregate, pass NULL pointers for all three function |
5723 | ** callbacks. |
5724 | ** |
5725 | ** ^The sixth, seventh, eighth and ninth parameters (xStep, xFinal, xValue |
5726 | ** and xInverse) passed to sqlite3_create_window_function are pointers to |
5727 | ** C-language callbacks that implement the new function. xStep and xFinal |
5728 | ** must both be non-NULL. xValue and xInverse may either both be NULL, in |
5729 | ** which case a regular aggregate function is created, or must both be |
5730 | ** non-NULL, in which case the new function may be used as either an aggregate |
5731 | ** or aggregate window function. More details regarding the implementation |
5732 | ** of aggregate window functions are |
5733 | ** [user-defined window functions|available here]. |
5734 | ** |
5735 | ** ^(If the final parameter to sqlite3_create_function_v2() or |
5736 | ** sqlite3_create_window_function() is not NULL, then it is destructor for |
5737 | ** the application data pointer. The destructor is invoked when the function |
5738 | ** is deleted, either by being overloaded or when the database connection |
5739 | ** closes.)^ ^The destructor is also invoked if the call to |
5740 | ** sqlite3_create_function_v2() fails. ^When the destructor callback is |
5741 | ** invoked, it is passed a single argument which is a copy of the application |
5742 | ** data pointer which was the fifth parameter to sqlite3_create_function_v2(). |
5743 | ** |
5744 | ** ^It is permitted to register multiple implementations of the same |
5745 | ** functions with the same name but with either differing numbers of |
5746 | ** arguments or differing preferred text encodings. ^SQLite will use |
5747 | ** the implementation that most closely matches the way in which the |
5748 | ** SQL function is used. ^A function implementation with a non-negative |
5749 | ** nArg parameter is a better match than a function implementation with |
5750 | ** a negative nArg. ^A function where the preferred text encoding |
5751 | ** matches the database encoding is a better |
5752 | ** match than a function where the encoding is different. |
5753 | ** ^A function where the encoding difference is between UTF16le and UTF16be |
5754 | ** is a closer match than a function where the encoding difference is |
5755 | ** between UTF8 and UTF16. |
5756 | ** |
5757 | ** ^Built-in functions may be overloaded by new application-defined functions. |
5758 | ** |
5759 | ** ^An application-defined function is permitted to call other |
5760 | ** SQLite interfaces. However, such calls must not |
5761 | ** close the database connection nor finalize or reset the prepared |
5762 | ** statement in which the function is running. |
5763 | */ |
5764 | SQLITE_API int sqlite3_create_function( |
5765 | sqlite3 *db, |
5766 | const char *zFunctionName, |
5767 | int nArg, |
5768 | int eTextRep, |
5769 | void *pApp, |
5770 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**), |
5771 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
5772 | void (*xFinal)(sqlite3_context*) |
5773 | ); |
5774 | SQLITE_API int sqlite3_create_function16( |
5775 | sqlite3 *db, |
5776 | const void *zFunctionName, |
5777 | int nArg, |
5778 | int eTextRep, |
5779 | void *pApp, |
5780 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**), |
5781 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
5782 | void (*xFinal)(sqlite3_context*) |
5783 | ); |
5784 | SQLITE_API int sqlite3_create_function_v2( |
5785 | sqlite3 *db, |
5786 | const char *zFunctionName, |
5787 | int nArg, |
5788 | int eTextRep, |
5789 | void *pApp, |
5790 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**), |
5791 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
5792 | void (*xFinal)(sqlite3_context*), |
5793 | void(*xDestroy)(void*) |
5794 | ); |
5795 | SQLITE_API int sqlite3_create_window_function( |
5796 | sqlite3 *db, |
5797 | const char *zFunctionName, |
5798 | int nArg, |
5799 | int eTextRep, |
5800 | void *pApp, |
5801 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
5802 | void (*xFinal)(sqlite3_context*), |
5803 | void (*xValue)(sqlite3_context*), |
5804 | void (*xInverse)(sqlite3_context*,int,sqlite3_value**), |
5805 | void(*xDestroy)(void*) |
5806 | ); |
5807 | |
5808 | /* |
5809 | ** CAPI3REF: Text Encodings |
5810 | ** |
5811 | ** These constant define integer codes that represent the various |
5812 | ** text encodings supported by SQLite. |
5813 | */ |
5814 | #define SQLITE_UTF8 1 /* IMP: R-37514-35566 */ |
5815 | #define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */ |
5816 | #define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */ |
5817 | #define SQLITE_UTF16 4 /* Use native byte order */ |
5818 | #define SQLITE_ANY 5 /* Deprecated */ |
5819 | #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ |
5820 | |
5821 | /* |
5822 | ** CAPI3REF: Function Flags |
5823 | ** |
5824 | ** These constants may be ORed together with the |
5825 | ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument |
5826 | ** to [sqlite3_create_function()], [sqlite3_create_function16()], or |
5827 | ** [sqlite3_create_function_v2()]. |
5828 | ** |
5829 | ** <dl> |
5830 | ** [[SQLITE_DETERMINISTIC]] <dt>SQLITE_DETERMINISTIC</dt><dd> |
5831 | ** The SQLITE_DETERMINISTIC flag means that the new function always gives |
5832 | ** the same output when the input parameters are the same. |
5833 | ** The [abs|abs() function] is deterministic, for example, but |
5834 | ** [randomblob|randomblob()] is not. Functions must |
5835 | ** be deterministic in order to be used in certain contexts such as |
5836 | ** with the WHERE clause of [partial indexes] or in [generated columns]. |
5837 | ** SQLite might also optimize deterministic functions by factoring them |
5838 | ** out of inner loops. |
5839 | ** </dd> |
5840 | ** |
5841 | ** [[SQLITE_DIRECTONLY]] <dt>SQLITE_DIRECTONLY</dt><dd> |
5842 | ** The SQLITE_DIRECTONLY flag means that the function may only be invoked |
5843 | ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in |
5844 | ** schema structures such as [CHECK constraints], [DEFAULT clauses], |
5845 | ** [expression indexes], [partial indexes], or [generated columns]. |
5846 | ** <p> |
5847 | ** The SQLITE_DIRECTONLY flag is recommended for any |
5848 | ** [application-defined SQL function] |
5849 | ** that has side-effects or that could potentially leak sensitive information. |
5850 | ** This will prevent attacks in which an application is tricked |
5851 | ** into using a database file that has had its schema surreptitiously |
5852 | ** modified to invoke the application-defined function in ways that are |
5853 | ** harmful. |
5854 | ** <p> |
5855 | ** Some people say it is good practice to set SQLITE_DIRECTONLY on all |
5856 | ** [application-defined SQL functions], regardless of whether or not they |
5857 | ** are security sensitive, as doing so prevents those functions from being used |
5858 | ** inside of the database schema, and thus ensures that the database |
5859 | ** can be inspected and modified using generic tools (such as the [CLI]) |
5860 | ** that do not have access to the application-defined functions. |
5861 | ** </dd> |
5862 | ** |
5863 | ** [[SQLITE_INNOCUOUS]] <dt>SQLITE_INNOCUOUS</dt><dd> |
5864 | ** The SQLITE_INNOCUOUS flag means that the function is unlikely |
5865 | ** to cause problems even if misused. An innocuous function should have |
5866 | ** no side effects and should not depend on any values other than its |
5867 | ** input parameters. The [abs|abs() function] is an example of an |
5868 | ** innocuous function. |
5869 | ** The [load_extension() SQL function] is not innocuous because of its |
5870 | ** side effects. |
5871 | ** <p> SQLITE_INNOCUOUS is similar to SQLITE_DETERMINISTIC, but is not |
5872 | ** exactly the same. The [random|random() function] is an example of a |
5873 | ** function that is innocuous but not deterministic. |
5874 | ** <p>Some heightened security settings |
5875 | ** ([SQLITE_DBCONFIG_TRUSTED_SCHEMA] and [PRAGMA trusted_schema=OFF]) |
5876 | ** disable the use of SQL functions inside views and triggers and in |
5877 | ** schema structures such as [CHECK constraints], [DEFAULT clauses], |
5878 | ** [expression indexes], [partial indexes], and [generated columns] unless |
5879 | ** the function is tagged with SQLITE_INNOCUOUS. Most built-in functions |
5880 | ** are innocuous. Developers are advised to avoid using the |
5881 | ** SQLITE_INNOCUOUS flag for application-defined functions unless the |
5882 | ** function has been carefully audited and found to be free of potentially |
5883 | ** security-adverse side-effects and information-leaks. |
5884 | ** </dd> |
5885 | ** |
5886 | ** [[SQLITE_SUBTYPE]] <dt>SQLITE_SUBTYPE</dt><dd> |
5887 | ** The SQLITE_SUBTYPE flag indicates to SQLite that a function may call |
5888 | ** [sqlite3_value_subtype()] to inspect the sub-types of its arguments. |
5889 | ** Specifying this flag makes no difference for scalar or aggregate user |
5890 | ** functions. However, if it is not specified for a user-defined window |
5891 | ** function, then any sub-types belonging to arguments passed to the window |
5892 | ** function may be discarded before the window function is called (i.e. |
5893 | ** sqlite3_value_subtype() will always return 0). |
5894 | ** </dd> |
5895 | ** </dl> |
5896 | */ |
5897 | #define SQLITE_DETERMINISTIC 0x000000800 |
5898 | #define SQLITE_DIRECTONLY 0x000080000 |
5899 | #define SQLITE_SUBTYPE 0x000100000 |
5900 | #define SQLITE_INNOCUOUS 0x000200000 |
5901 | |
5902 | /* |
5903 | ** CAPI3REF: Deprecated Functions |
5904 | ** DEPRECATED |
5905 | ** |
5906 | ** These functions are [deprecated]. In order to maintain |
5907 | ** backwards compatibility with older code, these functions continue |
5908 | ** to be supported. However, new applications should avoid |
5909 | ** the use of these functions. To encourage programmers to avoid |
5910 | ** these functions, we will not explain what they do. |
5911 | */ |
5912 | #ifndef SQLITE_OMIT_DEPRECATED |
5913 | SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*); |
5914 | SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*); |
5915 | SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*); |
5916 | SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void); |
5917 | SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void); |
5918 | SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int), |
5919 | void*,sqlite3_int64); |
5920 | #endif |
5921 | |
5922 | /* |
5923 | ** CAPI3REF: Obtaining SQL Values |
5924 | ** METHOD: sqlite3_value |
5925 | ** |
5926 | ** <b>Summary:</b> |
5927 | ** <blockquote><table border=0 cellpadding=0 cellspacing=0> |
5928 | ** <tr><td><b>sqlite3_value_blob</b><td>→<td>BLOB value |
5929 | ** <tr><td><b>sqlite3_value_double</b><td>→<td>REAL value |
5930 | ** <tr><td><b>sqlite3_value_int</b><td>→<td>32-bit INTEGER value |
5931 | ** <tr><td><b>sqlite3_value_int64</b><td>→<td>64-bit INTEGER value |
5932 | ** <tr><td><b>sqlite3_value_pointer</b><td>→<td>Pointer value |
5933 | ** <tr><td><b>sqlite3_value_text</b><td>→<td>UTF-8 TEXT value |
5934 | ** <tr><td><b>sqlite3_value_text16</b><td>→<td>UTF-16 TEXT value in |
5935 | ** the native byteorder |
5936 | ** <tr><td><b>sqlite3_value_text16be</b><td>→<td>UTF-16be TEXT value |
5937 | ** <tr><td><b>sqlite3_value_text16le</b><td>→<td>UTF-16le TEXT value |
5938 | ** <tr><td> <td> <td> |
5939 | ** <tr><td><b>sqlite3_value_bytes</b><td>→<td>Size of a BLOB |
5940 | ** or a UTF-8 TEXT in bytes |
5941 | ** <tr><td><b>sqlite3_value_bytes16 </b> |
5942 | ** <td>→ <td>Size of UTF-16 |
5943 | ** TEXT in bytes |
5944 | ** <tr><td><b>sqlite3_value_type</b><td>→<td>Default |
5945 | ** datatype of the value |
5946 | ** <tr><td><b>sqlite3_value_numeric_type </b> |
5947 | ** <td>→ <td>Best numeric datatype of the value |
5948 | ** <tr><td><b>sqlite3_value_nochange </b> |
5949 | ** <td>→ <td>True if the column is unchanged in an UPDATE |
5950 | ** against a virtual table. |
5951 | ** <tr><td><b>sqlite3_value_frombind </b> |
5952 | ** <td>→ <td>True if value originated from a [bound parameter] |
5953 | ** </table></blockquote> |
5954 | ** |
5955 | ** <b>Details:</b> |
5956 | ** |
5957 | ** These routines extract type, size, and content information from |
5958 | ** [protected sqlite3_value] objects. Protected sqlite3_value objects |
5959 | ** are used to pass parameter information into the functions that |
5960 | ** implement [application-defined SQL functions] and [virtual tables]. |
5961 | ** |
5962 | ** These routines work only with [protected sqlite3_value] objects. |
5963 | ** Any attempt to use these routines on an [unprotected sqlite3_value] |
5964 | ** is not threadsafe. |
5965 | ** |
5966 | ** ^These routines work just like the corresponding [column access functions] |
5967 | ** except that these routines take a single [protected sqlite3_value] object |
5968 | ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number. |
5969 | ** |
5970 | ** ^The sqlite3_value_text16() interface extracts a UTF-16 string |
5971 | ** in the native byte-order of the host machine. ^The |
5972 | ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces |
5973 | ** extract UTF-16 strings as big-endian and little-endian respectively. |
5974 | ** |
5975 | ** ^If [sqlite3_value] object V was initialized |
5976 | ** using [sqlite3_bind_pointer(S,I,P,X,D)] or [sqlite3_result_pointer(C,P,X,D)] |
5977 | ** and if X and Y are strings that compare equal according to strcmp(X,Y), |
5978 | ** then sqlite3_value_pointer(V,Y) will return the pointer P. ^Otherwise, |
5979 | ** sqlite3_value_pointer(V,Y) returns a NULL. The sqlite3_bind_pointer() |
5980 | ** routine is part of the [pointer passing interface] added for SQLite 3.20.0. |
5981 | ** |
5982 | ** ^(The sqlite3_value_type(V) interface returns the |
5983 | ** [SQLITE_INTEGER | datatype code] for the initial datatype of the |
5984 | ** [sqlite3_value] object V. The returned value is one of [SQLITE_INTEGER], |
5985 | ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].)^ |
5986 | ** Other interfaces might change the datatype for an sqlite3_value object. |
5987 | ** For example, if the datatype is initially SQLITE_INTEGER and |
5988 | ** sqlite3_value_text(V) is called to extract a text value for that |
5989 | ** integer, then subsequent calls to sqlite3_value_type(V) might return |
5990 | ** SQLITE_TEXT. Whether or not a persistent internal datatype conversion |
5991 | ** occurs is undefined and may change from one release of SQLite to the next. |
5992 | ** |
5993 | ** ^(The sqlite3_value_numeric_type() interface attempts to apply |
5994 | ** numeric affinity to the value. This means that an attempt is |
5995 | ** made to convert the value to an integer or floating point. If |
5996 | ** such a conversion is possible without loss of information (in other |
5997 | ** words, if the value is a string that looks like a number) |
5998 | ** then the conversion is performed. Otherwise no conversion occurs. |
5999 | ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^ |
6000 | ** |
6001 | ** ^Within the [xUpdate] method of a [virtual table], the |
6002 | ** sqlite3_value_nochange(X) interface returns true if and only if |
6003 | ** the column corresponding to X is unchanged by the UPDATE operation |
6004 | ** that the xUpdate method call was invoked to implement and if |
6005 | ** and the prior [xColumn] method call that was invoked to extracted |
6006 | ** the value for that column returned without setting a result (probably |
6007 | ** because it queried [sqlite3_vtab_nochange()] and found that the column |
6008 | ** was unchanging). ^Within an [xUpdate] method, any value for which |
6009 | ** sqlite3_value_nochange(X) is true will in all other respects appear |
6010 | ** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other |
6011 | ** than within an [xUpdate] method call for an UPDATE statement, then |
6012 | ** the return value is arbitrary and meaningless. |
6013 | ** |
6014 | ** ^The sqlite3_value_frombind(X) interface returns non-zero if the |
6015 | ** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()] |
6016 | ** interfaces. ^If X comes from an SQL literal value, or a table column, |
6017 | ** or an expression, then sqlite3_value_frombind(X) returns zero. |
6018 | ** |
6019 | ** Please pay particular attention to the fact that the pointer returned |
6020 | ** from [sqlite3_value_blob()], [sqlite3_value_text()], or |
6021 | ** [sqlite3_value_text16()] can be invalidated by a subsequent call to |
6022 | ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()], |
6023 | ** or [sqlite3_value_text16()]. |
6024 | ** |
6025 | ** These routines must be called from the same thread as |
6026 | ** the SQL function that supplied the [sqlite3_value*] parameters. |
6027 | ** |
6028 | ** As long as the input parameter is correct, these routines can only |
6029 | ** fail if an out-of-memory error occurs during a format conversion. |
6030 | ** Only the following subset of interfaces are subject to out-of-memory |
6031 | ** errors: |
6032 | ** |
6033 | ** <ul> |
6034 | ** <li> sqlite3_value_blob() |
6035 | ** <li> sqlite3_value_text() |
6036 | ** <li> sqlite3_value_text16() |
6037 | ** <li> sqlite3_value_text16le() |
6038 | ** <li> sqlite3_value_text16be() |
6039 | ** <li> sqlite3_value_bytes() |
6040 | ** <li> sqlite3_value_bytes16() |
6041 | ** </ul> |
6042 | ** |
6043 | ** If an out-of-memory error occurs, then the return value from these |
6044 | ** routines is the same as if the column had contained an SQL NULL value. |
6045 | ** Valid SQL NULL returns can be distinguished from out-of-memory errors |
6046 | ** by invoking the [sqlite3_errcode()] immediately after the suspect |
6047 | ** return value is obtained and before any |
6048 | ** other SQLite interface is called on the same [database connection]. |
6049 | */ |
6050 | SQLITE_API const void *sqlite3_value_blob(sqlite3_value*); |
6051 | SQLITE_API double sqlite3_value_double(sqlite3_value*); |
6052 | SQLITE_API int sqlite3_value_int(sqlite3_value*); |
6053 | SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*); |
6054 | SQLITE_API void *sqlite3_value_pointer(sqlite3_value*, const char*); |
6055 | SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*); |
6056 | SQLITE_API const void *sqlite3_value_text16(sqlite3_value*); |
6057 | SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*); |
6058 | SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*); |
6059 | SQLITE_API int sqlite3_value_bytes(sqlite3_value*); |
6060 | SQLITE_API int sqlite3_value_bytes16(sqlite3_value*); |
6061 | SQLITE_API int sqlite3_value_type(sqlite3_value*); |
6062 | SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*); |
6063 | SQLITE_API int sqlite3_value_nochange(sqlite3_value*); |
6064 | SQLITE_API int sqlite3_value_frombind(sqlite3_value*); |
6065 | |
6066 | /* |
6067 | ** CAPI3REF: Report the internal text encoding state of an sqlite3_value object |
6068 | ** METHOD: sqlite3_value |
6069 | ** |
6070 | ** ^(The sqlite3_value_encoding(X) interface returns one of [SQLITE_UTF8], |
6071 | ** [SQLITE_UTF16BE], or [SQLITE_UTF16LE] according to the current text encoding |
6072 | ** of the value X, assuming that X has type TEXT.)^ If sqlite3_value_type(X) |
6073 | ** returns something other than SQLITE_TEXT, then the return value from |
6074 | ** sqlite3_value_encoding(X) is meaningless. ^Calls to |
6075 | ** [sqlite3_value_text(X)], [sqlite3_value_text16(X)], [sqlite3_value_text16be(X)], |
6076 | ** [sqlite3_value_text16le(X)], [sqlite3_value_bytes(X)], or |
6077 | ** [sqlite3_value_bytes16(X)] might change the encoding of the value X and |
6078 | ** thus change the return from subsequent calls to sqlite3_value_encoding(X). |
6079 | ** |
6080 | ** This routine is intended for used by applications that test and validate |
6081 | ** the SQLite implementation. This routine is inquiring about the opaque |
6082 | ** internal state of an [sqlite3_value] object. Ordinary applications should |
6083 | ** not need to know what the internal state of an sqlite3_value object is and |
6084 | ** hence should not need to use this interface. |
6085 | */ |
6086 | SQLITE_API int sqlite3_value_encoding(sqlite3_value*); |
6087 | |
6088 | /* |
6089 | ** CAPI3REF: Finding The Subtype Of SQL Values |
6090 | ** METHOD: sqlite3_value |
6091 | ** |
6092 | ** The sqlite3_value_subtype(V) function returns the subtype for |
6093 | ** an [application-defined SQL function] argument V. The subtype |
6094 | ** information can be used to pass a limited amount of context from |
6095 | ** one SQL function to another. Use the [sqlite3_result_subtype()] |
6096 | ** routine to set the subtype for the return value of an SQL function. |
6097 | */ |
6098 | SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value*); |
6099 | |
6100 | /* |
6101 | ** CAPI3REF: Copy And Free SQL Values |
6102 | ** METHOD: sqlite3_value |
6103 | ** |
6104 | ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value] |
6105 | ** object D and returns a pointer to that copy. ^The [sqlite3_value] returned |
6106 | ** is a [protected sqlite3_value] object even if the input is not. |
6107 | ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a |
6108 | ** memory allocation fails. ^If V is a [pointer value], then the result |
6109 | ** of sqlite3_value_dup(V) is a NULL value. |
6110 | ** |
6111 | ** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object |
6112 | ** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer |
6113 | ** then sqlite3_value_free(V) is a harmless no-op. |
6114 | */ |
6115 | SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value*); |
6116 | SQLITE_API void sqlite3_value_free(sqlite3_value*); |
6117 | |
6118 | /* |
6119 | ** CAPI3REF: Obtain Aggregate Function Context |
6120 | ** METHOD: sqlite3_context |
6121 | ** |
6122 | ** Implementations of aggregate SQL functions use this |
6123 | ** routine to allocate memory for storing their state. |
6124 | ** |
6125 | ** ^The first time the sqlite3_aggregate_context(C,N) routine is called |
6126 | ** for a particular aggregate function, SQLite allocates |
6127 | ** N bytes of memory, zeroes out that memory, and returns a pointer |
6128 | ** to the new memory. ^On second and subsequent calls to |
6129 | ** sqlite3_aggregate_context() for the same aggregate function instance, |
6130 | ** the same buffer is returned. Sqlite3_aggregate_context() is normally |
6131 | ** called once for each invocation of the xStep callback and then one |
6132 | ** last time when the xFinal callback is invoked. ^(When no rows match |
6133 | ** an aggregate query, the xStep() callback of the aggregate function |
6134 | ** implementation is never called and xFinal() is called exactly once. |
6135 | ** In those cases, sqlite3_aggregate_context() might be called for the |
6136 | ** first time from within xFinal().)^ |
6137 | ** |
6138 | ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer |
6139 | ** when first called if N is less than or equal to zero or if a memory |
6140 | ** allocation error occurs. |
6141 | ** |
6142 | ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is |
6143 | ** determined by the N parameter on first successful call. Changing the |
6144 | ** value of N in any subsequent call to sqlite3_aggregate_context() within |
6145 | ** the same aggregate function instance will not resize the memory |
6146 | ** allocation.)^ Within the xFinal callback, it is customary to set |
6147 | ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no |
6148 | ** pointless memory allocations occur. |
6149 | ** |
6150 | ** ^SQLite automatically frees the memory allocated by |
6151 | ** sqlite3_aggregate_context() when the aggregate query concludes. |
6152 | ** |
6153 | ** The first parameter must be a copy of the |
6154 | ** [sqlite3_context | SQL function context] that is the first parameter |
6155 | ** to the xStep or xFinal callback routine that implements the aggregate |
6156 | ** function. |
6157 | ** |
6158 | ** This routine must be called from the same thread in which |
6159 | ** the aggregate SQL function is running. |
6160 | */ |
6161 | SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); |
6162 | |
6163 | /* |
6164 | ** CAPI3REF: User Data For Functions |
6165 | ** METHOD: sqlite3_context |
6166 | ** |
6167 | ** ^The sqlite3_user_data() interface returns a copy of |
6168 | ** the pointer that was the pUserData parameter (the 5th parameter) |
6169 | ** of the [sqlite3_create_function()] |
6170 | ** and [sqlite3_create_function16()] routines that originally |
6171 | ** registered the application defined function. |
6172 | ** |
6173 | ** This routine must be called from the same thread in which |
6174 | ** the application-defined function is running. |
6175 | */ |
6176 | SQLITE_API void *sqlite3_user_data(sqlite3_context*); |
6177 | |
6178 | /* |
6179 | ** CAPI3REF: Database Connection For Functions |
6180 | ** METHOD: sqlite3_context |
6181 | ** |
6182 | ** ^The sqlite3_context_db_handle() interface returns a copy of |
6183 | ** the pointer to the [database connection] (the 1st parameter) |
6184 | ** of the [sqlite3_create_function()] |
6185 | ** and [sqlite3_create_function16()] routines that originally |
6186 | ** registered the application defined function. |
6187 | */ |
6188 | SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*); |
6189 | |
6190 | /* |
6191 | ** CAPI3REF: Function Auxiliary Data |
6192 | ** METHOD: sqlite3_context |
6193 | ** |
6194 | ** These functions may be used by (non-aggregate) SQL functions to |
6195 | ** associate metadata with argument values. If the same value is passed to |
6196 | ** multiple invocations of the same SQL function during query execution, under |
6197 | ** some circumstances the associated metadata may be preserved. An example |
6198 | ** of where this might be useful is in a regular-expression matching |
6199 | ** function. The compiled version of the regular expression can be stored as |
6200 | ** metadata associated with the pattern string. |
6201 | ** Then as long as the pattern string remains the same, |
6202 | ** the compiled regular expression can be reused on multiple |
6203 | ** invocations of the same function. |
6204 | ** |
6205 | ** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the metadata |
6206 | ** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument |
6207 | ** value to the application-defined function. ^N is zero for the left-most |
6208 | ** function argument. ^If there is no metadata |
6209 | ** associated with the function argument, the sqlite3_get_auxdata(C,N) interface |
6210 | ** returns a NULL pointer. |
6211 | ** |
6212 | ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th |
6213 | ** argument of the application-defined function. ^Subsequent |
6214 | ** calls to sqlite3_get_auxdata(C,N) return P from the most recent |
6215 | ** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or |
6216 | ** NULL if the metadata has been discarded. |
6217 | ** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL, |
6218 | ** SQLite will invoke the destructor function X with parameter P exactly |
6219 | ** once, when the metadata is discarded. |
6220 | ** SQLite is free to discard the metadata at any time, including: <ul> |
6221 | ** <li> ^(when the corresponding function parameter changes)^, or |
6222 | ** <li> ^(when [sqlite3_reset()] or [sqlite3_finalize()] is called for the |
6223 | ** SQL statement)^, or |
6224 | ** <li> ^(when sqlite3_set_auxdata() is invoked again on the same |
6225 | ** parameter)^, or |
6226 | ** <li> ^(during the original sqlite3_set_auxdata() call when a memory |
6227 | ** allocation error occurs.)^ </ul> |
6228 | ** |
6229 | ** Note the last bullet in particular. The destructor X in |
6230 | ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the |
6231 | ** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata() |
6232 | ** should be called near the end of the function implementation and the |
6233 | ** function implementation should not make any use of P after |
6234 | ** sqlite3_set_auxdata() has been called. |
6235 | ** |
6236 | ** ^(In practice, metadata is preserved between function calls for |
6237 | ** function parameters that are compile-time constants, including literal |
6238 | ** values and [parameters] and expressions composed from the same.)^ |
6239 | ** |
6240 | ** The value of the N parameter to these interfaces should be non-negative. |
6241 | ** Future enhancements may make use of negative N values to define new |
6242 | ** kinds of function caching behavior. |
6243 | ** |
6244 | ** These routines must be called from the same thread in which |
6245 | ** the SQL function is running. |
6246 | */ |
6247 | SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N); |
6248 | SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*)); |
6249 | |
6250 | |
6251 | /* |
6252 | ** CAPI3REF: Constants Defining Special Destructor Behavior |
6253 | ** |
6254 | ** These are special values for the destructor that is passed in as the |
6255 | ** final argument to routines like [sqlite3_result_blob()]. ^If the destructor |
6256 | ** argument is SQLITE_STATIC, it means that the content pointer is constant |
6257 | ** and will never change. It does not need to be destroyed. ^The |
6258 | ** SQLITE_TRANSIENT value means that the content will likely change in |
6259 | ** the near future and that SQLite should make its own private copy of |
6260 | ** the content before returning. |
6261 | ** |
6262 | ** The typedef is necessary to work around problems in certain |
6263 | ** C++ compilers. |
6264 | */ |
6265 | typedef void (*sqlite3_destructor_type)(void*); |
6266 | #define SQLITE_STATIC ((sqlite3_destructor_type)0) |
6267 | #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) |
6268 | |
6269 | /* |
6270 | ** CAPI3REF: Setting The Result Of An SQL Function |
6271 | ** METHOD: sqlite3_context |
6272 | ** |
6273 | ** These routines are used by the xFunc or xFinal callbacks that |
6274 | ** implement SQL functions and aggregates. See |
6275 | ** [sqlite3_create_function()] and [sqlite3_create_function16()] |
6276 | ** for additional information. |
6277 | ** |
6278 | ** These functions work very much like the [parameter binding] family of |
6279 | ** functions used to bind values to host parameters in prepared statements. |
6280 | ** Refer to the [SQL parameter] documentation for additional information. |
6281 | ** |
6282 | ** ^The sqlite3_result_blob() interface sets the result from |
6283 | ** an application-defined function to be the BLOB whose content is pointed |
6284 | ** to by the second parameter and which is N bytes long where N is the |
6285 | ** third parameter. |
6286 | ** |
6287 | ** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N) |
6288 | ** interfaces set the result of the application-defined function to be |
6289 | ** a BLOB containing all zero bytes and N bytes in size. |
6290 | ** |
6291 | ** ^The sqlite3_result_double() interface sets the result from |
6292 | ** an application-defined function to be a floating point value specified |
6293 | ** by its 2nd argument. |
6294 | ** |
6295 | ** ^The sqlite3_result_error() and sqlite3_result_error16() functions |
6296 | ** cause the implemented SQL function to throw an exception. |
6297 | ** ^SQLite uses the string pointed to by the |
6298 | ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16() |
6299 | ** as the text of an error message. ^SQLite interprets the error |
6300 | ** message string from sqlite3_result_error() as UTF-8. ^SQLite |
6301 | ** interprets the string from sqlite3_result_error16() as UTF-16 using |
6302 | ** the same [byte-order determination rules] as [sqlite3_bind_text16()]. |
6303 | ** ^If the third parameter to sqlite3_result_error() |
6304 | ** or sqlite3_result_error16() is negative then SQLite takes as the error |
6305 | ** message all text up through the first zero character. |
6306 | ** ^If the third parameter to sqlite3_result_error() or |
6307 | ** sqlite3_result_error16() is non-negative then SQLite takes that many |
6308 | ** bytes (not characters) from the 2nd parameter as the error message. |
6309 | ** ^The sqlite3_result_error() and sqlite3_result_error16() |
6310 | ** routines make a private copy of the error message text before |
6311 | ** they return. Hence, the calling function can deallocate or |
6312 | ** modify the text after they return without harm. |
6313 | ** ^The sqlite3_result_error_code() function changes the error code |
6314 | ** returned by SQLite as a result of an error in a function. ^By default, |
6315 | ** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error() |
6316 | ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR. |
6317 | ** |
6318 | ** ^The sqlite3_result_error_toobig() interface causes SQLite to throw an |
6319 | ** error indicating that a string or BLOB is too long to represent. |
6320 | ** |
6321 | ** ^The sqlite3_result_error_nomem() interface causes SQLite to throw an |
6322 | ** error indicating that a memory allocation failed. |
6323 | ** |
6324 | ** ^The sqlite3_result_int() interface sets the return value |
6325 | ** of the application-defined function to be the 32-bit signed integer |
6326 | ** value given in the 2nd argument. |
6327 | ** ^The sqlite3_result_int64() interface sets the return value |
6328 | ** of the application-defined function to be the 64-bit signed integer |
6329 | ** value given in the 2nd argument. |
6330 | ** |
6331 | ** ^The sqlite3_result_null() interface sets the return value |
6332 | ** of the application-defined function to be NULL. |
6333 | ** |
6334 | ** ^The sqlite3_result_text(), sqlite3_result_text16(), |
6335 | ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces |
6336 | ** set the return value of the application-defined function to be |
6337 | ** a text string which is represented as UTF-8, UTF-16 native byte order, |
6338 | ** UTF-16 little endian, or UTF-16 big endian, respectively. |
6339 | ** ^The sqlite3_result_text64() interface sets the return value of an |
6340 | ** application-defined function to be a text string in an encoding |
6341 | ** specified by the fifth (and last) parameter, which must be one |
6342 | ** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]. |
6343 | ** ^SQLite takes the text result from the application from |
6344 | ** the 2nd parameter of the sqlite3_result_text* interfaces. |
6345 | ** ^If the 3rd parameter to any of the sqlite3_result_text* interfaces |
6346 | ** other than sqlite3_result_text64() is negative, then SQLite computes |
6347 | ** the string length itself by searching the 2nd parameter for the first |
6348 | ** zero character. |
6349 | ** ^If the 3rd parameter to the sqlite3_result_text* interfaces |
6350 | ** is non-negative, then as many bytes (not characters) of the text |
6351 | ** pointed to by the 2nd parameter are taken as the application-defined |
6352 | ** function result. If the 3rd parameter is non-negative, then it |
6353 | ** must be the byte offset into the string where the NUL terminator would |
6354 | ** appear if the string where NUL terminated. If any NUL characters occur |
6355 | ** in the string at a byte offset that is less than the value of the 3rd |
6356 | ** parameter, then the resulting string will contain embedded NULs and the |
6357 | ** result of expressions operating on strings with embedded NULs is undefined. |
6358 | ** ^If the 4th parameter to the sqlite3_result_text* interfaces |
6359 | ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that |
6360 | ** function as the destructor on the text or BLOB result when it has |
6361 | ** finished using that result. |
6362 | ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to |
6363 | ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite |
6364 | ** assumes that the text or BLOB result is in constant space and does not |
6365 | ** copy the content of the parameter nor call a destructor on the content |
6366 | ** when it has finished using that result. |
6367 | ** ^If the 4th parameter to the sqlite3_result_text* interfaces |
6368 | ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT |
6369 | ** then SQLite makes a copy of the result into space obtained |
6370 | ** from [sqlite3_malloc()] before it returns. |
6371 | ** |
6372 | ** ^For the sqlite3_result_text16(), sqlite3_result_text16le(), and |
6373 | ** sqlite3_result_text16be() routines, and for sqlite3_result_text64() |
6374 | ** when the encoding is not UTF8, if the input UTF16 begins with a |
6375 | ** byte-order mark (BOM, U+FEFF) then the BOM is removed from the |
6376 | ** string and the rest of the string is interpreted according to the |
6377 | ** byte-order specified by the BOM. ^The byte-order specified by |
6378 | ** the BOM at the beginning of the text overrides the byte-order |
6379 | ** specified by the interface procedure. ^So, for example, if |
6380 | ** sqlite3_result_text16le() is invoked with text that begins |
6381 | ** with bytes 0xfe, 0xff (a big-endian byte-order mark) then the |
6382 | ** first two bytes of input are skipped and the remaining input |
6383 | ** is interpreted as UTF16BE text. |
6384 | ** |
6385 | ** ^For UTF16 input text to the sqlite3_result_text16(), |
6386 | ** sqlite3_result_text16be(), sqlite3_result_text16le(), and |
6387 | ** sqlite3_result_text64() routines, if the text contains invalid |
6388 | ** UTF16 characters, the invalid characters might be converted |
6389 | ** into the unicode replacement character, U+FFFD. |
6390 | ** |
6391 | ** ^The sqlite3_result_value() interface sets the result of |
6392 | ** the application-defined function to be a copy of the |
6393 | ** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The |
6394 | ** sqlite3_result_value() interface makes a copy of the [sqlite3_value] |
6395 | ** so that the [sqlite3_value] specified in the parameter may change or |
6396 | ** be deallocated after sqlite3_result_value() returns without harm. |
6397 | ** ^A [protected sqlite3_value] object may always be used where an |
6398 | ** [unprotected sqlite3_value] object is required, so either |
6399 | ** kind of [sqlite3_value] object can be used with this interface. |
6400 | ** |
6401 | ** ^The sqlite3_result_pointer(C,P,T,D) interface sets the result to an |
6402 | ** SQL NULL value, just like [sqlite3_result_null(C)], except that it |
6403 | ** also associates the host-language pointer P or type T with that |
6404 | ** NULL value such that the pointer can be retrieved within an |
6405 | ** [application-defined SQL function] using [sqlite3_value_pointer()]. |
6406 | ** ^If the D parameter is not NULL, then it is a pointer to a destructor |
6407 | ** for the P parameter. ^SQLite invokes D with P as its only argument |
6408 | ** when SQLite is finished with P. The T parameter should be a static |
6409 | ** string and preferably a string literal. The sqlite3_result_pointer() |
6410 | ** routine is part of the [pointer passing interface] added for SQLite 3.20.0. |
6411 | ** |
6412 | ** If these routines are called from within the different thread |
6413 | ** than the one containing the application-defined function that received |
6414 | ** the [sqlite3_context] pointer, the results are undefined. |
6415 | */ |
6416 | SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); |
6417 | SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*, |
6418 | sqlite3_uint64,void(*)(void*)); |
6419 | SQLITE_API void sqlite3_result_double(sqlite3_context*, double); |
6420 | SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int); |
6421 | SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int); |
6422 | SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*); |
6423 | SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*); |
6424 | SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int); |
6425 | SQLITE_API void sqlite3_result_int(sqlite3_context*, int); |
6426 | SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64); |
6427 | SQLITE_API void sqlite3_result_null(sqlite3_context*); |
6428 | SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*)); |
6429 | SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64, |
6430 | void(*)(void*), unsigned char encoding); |
6431 | SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*)); |
6432 | SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*)); |
6433 | SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*)); |
6434 | SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*); |
6435 | SQLITE_API void sqlite3_result_pointer(sqlite3_context*, void*,const char*,void(*)(void*)); |
6436 | SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n); |
6437 | SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n); |
6438 | |
6439 | |
6440 | /* |
6441 | ** CAPI3REF: Setting The Subtype Of An SQL Function |
6442 | ** METHOD: sqlite3_context |
6443 | ** |
6444 | ** The sqlite3_result_subtype(C,T) function causes the subtype of |
6445 | ** the result from the [application-defined SQL function] with |
6446 | ** [sqlite3_context] C to be the value T. Only the lower 8 bits |
6447 | ** of the subtype T are preserved in current versions of SQLite; |
6448 | ** higher order bits are discarded. |
6449 | ** The number of subtype bytes preserved by SQLite might increase |
6450 | ** in future releases of SQLite. |
6451 | */ |
6452 | SQLITE_API void sqlite3_result_subtype(sqlite3_context*,unsigned int); |
6453 | |
6454 | /* |
6455 | ** CAPI3REF: Define New Collating Sequences |
6456 | ** METHOD: sqlite3 |
6457 | ** |
6458 | ** ^These functions add, remove, or modify a [collation] associated |
6459 | ** with the [database connection] specified as the first argument. |
6460 | ** |
6461 | ** ^The name of the collation is a UTF-8 string |
6462 | ** for sqlite3_create_collation() and sqlite3_create_collation_v2() |
6463 | ** and a UTF-16 string in native byte order for sqlite3_create_collation16(). |
6464 | ** ^Collation names that compare equal according to [sqlite3_strnicmp()] are |
6465 | ** considered to be the same name. |
6466 | ** |
6467 | ** ^(The third argument (eTextRep) must be one of the constants: |
6468 | ** <ul> |
6469 | ** <li> [SQLITE_UTF8], |
6470 | ** <li> [SQLITE_UTF16LE], |
6471 | ** <li> [SQLITE_UTF16BE], |
6472 | ** <li> [SQLITE_UTF16], or |
6473 | ** <li> [SQLITE_UTF16_ALIGNED]. |
6474 | ** </ul>)^ |
6475 | ** ^The eTextRep argument determines the encoding of strings passed |
6476 | ** to the collating function callback, xCompare. |
6477 | ** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep |
6478 | ** force strings to be UTF16 with native byte order. |
6479 | ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin |
6480 | ** on an even byte address. |
6481 | ** |
6482 | ** ^The fourth argument, pArg, is an application data pointer that is passed |
6483 | ** through as the first argument to the collating function callback. |
6484 | ** |
6485 | ** ^The fifth argument, xCompare, is a pointer to the collating function. |
6486 | ** ^Multiple collating functions can be registered using the same name but |
6487 | ** with different eTextRep parameters and SQLite will use whichever |
6488 | ** function requires the least amount of data transformation. |
6489 | ** ^If the xCompare argument is NULL then the collating function is |
6490 | ** deleted. ^When all collating functions having the same name are deleted, |
6491 | ** that collation is no longer usable. |
6492 | ** |
6493 | ** ^The collating function callback is invoked with a copy of the pArg |
6494 | ** application data pointer and with two strings in the encoding specified |
6495 | ** by the eTextRep argument. The two integer parameters to the collating |
6496 | ** function callback are the length of the two strings, in bytes. The collating |
6497 | ** function must return an integer that is negative, zero, or positive |
6498 | ** if the first string is less than, equal to, or greater than the second, |
6499 | ** respectively. A collating function must always return the same answer |
6500 | ** given the same inputs. If two or more collating functions are registered |
6501 | ** to the same collation name (using different eTextRep values) then all |
6502 | ** must give an equivalent answer when invoked with equivalent strings. |
6503 | ** The collating function must obey the following properties for all |
6504 | ** strings A, B, and C: |
6505 | ** |
6506 | ** <ol> |
6507 | ** <li> If A==B then B==A. |
6508 | ** <li> If A==B and B==C then A==C. |
6509 | ** <li> If A<B THEN B>A. |
6510 | ** <li> If A<B and B<C then A<C. |
6511 | ** </ol> |
6512 | ** |
6513 | ** If a collating function fails any of the above constraints and that |
6514 | ** collating function is registered and used, then the behavior of SQLite |
6515 | ** is undefined. |
6516 | ** |
6517 | ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation() |
6518 | ** with the addition that the xDestroy callback is invoked on pArg when |
6519 | ** the collating function is deleted. |
6520 | ** ^Collating functions are deleted when they are overridden by later |
6521 | ** calls to the collation creation functions or when the |
6522 | ** [database connection] is closed using [sqlite3_close()]. |
6523 | ** |
6524 | ** ^The xDestroy callback is <u>not</u> called if the |
6525 | ** sqlite3_create_collation_v2() function fails. Applications that invoke |
6526 | ** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should |
6527 | ** check the return code and dispose of the application data pointer |
6528 | ** themselves rather than expecting SQLite to deal with it for them. |
6529 | ** This is different from every other SQLite interface. The inconsistency |
6530 | ** is unfortunate but cannot be changed without breaking backwards |
6531 | ** compatibility. |
6532 | ** |
6533 | ** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()]. |
6534 | */ |
6535 | SQLITE_API int sqlite3_create_collation( |
6536 | sqlite3*, |
6537 | const char *zName, |
6538 | int eTextRep, |
6539 | void *pArg, |
6540 | int(*xCompare)(void*,int,const void*,int,const void*) |
6541 | ); |
6542 | SQLITE_API int sqlite3_create_collation_v2( |
6543 | sqlite3*, |
6544 | const char *zName, |
6545 | int eTextRep, |
6546 | void *pArg, |
6547 | int(*xCompare)(void*,int,const void*,int,const void*), |
6548 | void(*xDestroy)(void*) |
6549 | ); |
6550 | SQLITE_API int sqlite3_create_collation16( |
6551 | sqlite3*, |
6552 | const void *zName, |
6553 | int eTextRep, |
6554 | void *pArg, |
6555 | int(*xCompare)(void*,int,const void*,int,const void*) |
6556 | ); |
6557 | |
6558 | /* |
6559 | ** CAPI3REF: Collation Needed Callbacks |
6560 | ** METHOD: sqlite3 |
6561 | ** |
6562 | ** ^To avoid having to register all collation sequences before a database |
6563 | ** can be used, a single callback function may be registered with the |
6564 | ** [database connection] to be invoked whenever an undefined collation |
6565 | ** sequence is required. |
6566 | ** |
6567 | ** ^If the function is registered using the sqlite3_collation_needed() API, |
6568 | ** then it is passed the names of undefined collation sequences as strings |
6569 | ** encoded in UTF-8. ^If sqlite3_collation_needed16() is used, |
6570 | ** the names are passed as UTF-16 in machine native byte order. |
6571 | ** ^A call to either function replaces the existing collation-needed callback. |
6572 | ** |
6573 | ** ^(When the callback is invoked, the first argument passed is a copy |
6574 | ** of the second argument to sqlite3_collation_needed() or |
6575 | ** sqlite3_collation_needed16(). The second argument is the database |
6576 | ** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE], |
6577 | ** or [SQLITE_UTF16LE], indicating the most desirable form of the collation |
6578 | ** sequence function required. The fourth parameter is the name of the |
6579 | ** required collation sequence.)^ |
6580 | ** |
6581 | ** The callback function should register the desired collation using |
6582 | ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or |
6583 | ** [sqlite3_create_collation_v2()]. |
6584 | */ |
6585 | SQLITE_API int sqlite3_collation_needed( |
6586 | sqlite3*, |
6587 | void*, |
6588 | void(*)(void*,sqlite3*,int eTextRep,const char*) |
6589 | ); |
6590 | SQLITE_API int sqlite3_collation_needed16( |
6591 | sqlite3*, |
6592 | void*, |
6593 | void(*)(void*,sqlite3*,int eTextRep,const void*) |
6594 | ); |
6595 | |
6596 | #ifdef SQLITE_ENABLE_CEROD |
6597 | /* |
6598 | ** Specify the activation key for a CEROD database. Unless |
6599 | ** activated, none of the CEROD routines will work. |
6600 | */ |
6601 | SQLITE_API void sqlite3_activate_cerod( |
6602 | const char *zPassPhrase /* Activation phrase */ |
6603 | ); |
6604 | #endif |
6605 | |
6606 | /* |
6607 | ** CAPI3REF: Suspend Execution For A Short Time |
6608 | ** |
6609 | ** The sqlite3_sleep() function causes the current thread to suspend execution |
6610 | ** for at least a number of milliseconds specified in its parameter. |
6611 | ** |
6612 | ** If the operating system does not support sleep requests with |
6613 | ** millisecond time resolution, then the time will be rounded up to |
6614 | ** the nearest second. The number of milliseconds of sleep actually |
6615 | ** requested from the operating system is returned. |
6616 | ** |
6617 | ** ^SQLite implements this interface by calling the xSleep() |
6618 | ** method of the default [sqlite3_vfs] object. If the xSleep() method |
6619 | ** of the default VFS is not implemented correctly, or not implemented at |
6620 | ** all, then the behavior of sqlite3_sleep() may deviate from the description |
6621 | ** in the previous paragraphs. |
6622 | ** |
6623 | ** If a negative argument is passed to sqlite3_sleep() the results vary by |
6624 | ** VFS and operating system. Some system treat a negative argument as an |
6625 | ** instruction to sleep forever. Others understand it to mean do not sleep |
6626 | ** at all. ^In SQLite version 3.42.0 and later, a negative |
6627 | ** argument passed into sqlite3_sleep() is changed to zero before it is relayed |
6628 | ** down into the xSleep method of the VFS. |
6629 | */ |
6630 | SQLITE_API int sqlite3_sleep(int); |
6631 | |
6632 | /* |
6633 | ** CAPI3REF: Name Of The Folder Holding Temporary Files |
6634 | ** |
6635 | ** ^(If this global variable is made to point to a string which is |
6636 | ** the name of a folder (a.k.a. directory), then all temporary files |
6637 | ** created by SQLite when using a built-in [sqlite3_vfs | VFS] |
6638 | ** will be placed in that directory.)^ ^If this variable |
6639 | ** is a NULL pointer, then SQLite performs a search for an appropriate |
6640 | ** temporary file directory. |
6641 | ** |
6642 | ** Applications are strongly discouraged from using this global variable. |
6643 | ** It is required to set a temporary folder on Windows Runtime (WinRT). |
6644 | ** But for all other platforms, it is highly recommended that applications |
6645 | ** neither read nor write this variable. This global variable is a relic |
6646 | ** that exists for backwards compatibility of legacy applications and should |
6647 | ** be avoided in new projects. |
6648 | ** |
6649 | ** It is not safe to read or modify this variable in more than one |
6650 | ** thread at a time. It is not safe to read or modify this variable |
6651 | ** if a [database connection] is being used at the same time in a separate |
6652 | ** thread. |
6653 | ** It is intended that this variable be set once |
6654 | ** as part of process initialization and before any SQLite interface |
6655 | ** routines have been called and that this variable remain unchanged |
6656 | ** thereafter. |
6657 | ** |
6658 | ** ^The [temp_store_directory pragma] may modify this variable and cause |
6659 | ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore, |
6660 | ** the [temp_store_directory pragma] always assumes that any string |
6661 | ** that this variable points to is held in memory obtained from |
6662 | ** [sqlite3_malloc] and the pragma may attempt to free that memory |
6663 | ** using [sqlite3_free]. |
6664 | ** Hence, if this variable is modified directly, either it should be |
6665 | ** made NULL or made to point to memory obtained from [sqlite3_malloc] |
6666 | ** or else the use of the [temp_store_directory pragma] should be avoided. |
6667 | ** Except when requested by the [temp_store_directory pragma], SQLite |
6668 | ** does not free the memory that sqlite3_temp_directory points to. If |
6669 | ** the application wants that memory to be freed, it must do |
6670 | ** so itself, taking care to only do so after all [database connection] |
6671 | ** objects have been destroyed. |
6672 | ** |
6673 | ** <b>Note to Windows Runtime users:</b> The temporary directory must be set |
6674 | ** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various |
6675 | ** features that require the use of temporary files may fail. Here is an |
6676 | ** example of how to do this using C++ with the Windows Runtime: |
6677 | ** |
6678 | ** <blockquote><pre> |
6679 | ** LPCWSTR zPath = Windows::Storage::ApplicationData::Current-> |
6680 | ** TemporaryFolder->Path->Data(); |
6681 | ** char zPathBuf[MAX_PATH + 1]; |
6682 | ** memset(zPathBuf, 0, sizeof(zPathBuf)); |
6683 | ** WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf, sizeof(zPathBuf), |
6684 | ** NULL, NULL); |
6685 | ** sqlite3_temp_directory = sqlite3_mprintf("%s", zPathBuf); |
6686 | ** </pre></blockquote> |
6687 | */ |
6688 | SQLITE_API char *sqlite3_temp_directory; |
6689 | |
6690 | /* |
6691 | ** CAPI3REF: Name Of The Folder Holding Database Files |
6692 | ** |
6693 | ** ^(If this global variable is made to point to a string which is |
6694 | ** the name of a folder (a.k.a. directory), then all database files |
6695 | ** specified with a relative pathname and created or accessed by |
6696 | ** SQLite when using a built-in windows [sqlite3_vfs | VFS] will be assumed |
6697 | ** to be relative to that directory.)^ ^If this variable is a NULL |
6698 | ** pointer, then SQLite assumes that all database files specified |
6699 | ** with a relative pathname are relative to the current directory |
6700 | ** for the process. Only the windows VFS makes use of this global |
6701 | ** variable; it is ignored by the unix VFS. |
6702 | ** |
6703 | ** Changing the value of this variable while a database connection is |
6704 | ** open can result in a corrupt database. |
6705 | ** |
6706 | ** It is not safe to read or modify this variable in more than one |
6707 | ** thread at a time. It is not safe to read or modify this variable |
6708 | ** if a [database connection] is being used at the same time in a separate |
6709 | ** thread. |
6710 | ** It is intended that this variable be set once |
6711 | ** as part of process initialization and before any SQLite interface |
6712 | ** routines have been called and that this variable remain unchanged |
6713 | ** thereafter. |
6714 | ** |
6715 | ** ^The [data_store_directory pragma] may modify this variable and cause |
6716 | ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore, |
6717 | ** the [data_store_directory pragma] always assumes that any string |
6718 | ** that this variable points to is held in memory obtained from |
6719 | ** [sqlite3_malloc] and the pragma may attempt to free that memory |
6720 | ** using [sqlite3_free]. |
6721 | ** Hence, if this variable is modified directly, either it should be |
6722 | ** made NULL or made to point to memory obtained from [sqlite3_malloc] |
6723 | ** or else the use of the [data_store_directory pragma] should be avoided. |
6724 | */ |
6725 | SQLITE_API char *sqlite3_data_directory; |
6726 | |
6727 | /* |
6728 | ** CAPI3REF: Win32 Specific Interface |
6729 | ** |
6730 | ** These interfaces are available only on Windows. The |
6731 | ** [sqlite3_win32_set_directory] interface is used to set the value associated |
6732 | ** with the [sqlite3_temp_directory] or [sqlite3_data_directory] variable, to |
6733 | ** zValue, depending on the value of the type parameter. The zValue parameter |
6734 | ** should be NULL to cause the previous value to be freed via [sqlite3_free]; |
6735 | ** a non-NULL value will be copied into memory obtained from [sqlite3_malloc] |
6736 | ** prior to being used. The [sqlite3_win32_set_directory] interface returns |
6737 | ** [SQLITE_OK] to indicate success, [SQLITE_ERROR] if the type is unsupported, |
6738 | ** or [SQLITE_NOMEM] if memory could not be allocated. The value of the |
6739 | ** [sqlite3_data_directory] variable is intended to act as a replacement for |
6740 | ** the current directory on the sub-platforms of Win32 where that concept is |
6741 | ** not present, e.g. WinRT and UWP. The [sqlite3_win32_set_directory8] and |
6742 | ** [sqlite3_win32_set_directory16] interfaces behave exactly the same as the |
6743 | ** sqlite3_win32_set_directory interface except the string parameter must be |
6744 | ** UTF-8 or UTF-16, respectively. |
6745 | */ |
6746 | SQLITE_API int sqlite3_win32_set_directory( |
6747 | unsigned long type, /* Identifier for directory being set or reset */ |
6748 | void *zValue /* New value for directory being set or reset */ |
6749 | ); |
6750 | SQLITE_API int sqlite3_win32_set_directory8(unsigned long type, const char *zValue); |
6751 | SQLITE_API int sqlite3_win32_set_directory16(unsigned long type, const void *zValue); |
6752 | |
6753 | /* |
6754 | ** CAPI3REF: Win32 Directory Types |
6755 | ** |
6756 | ** These macros are only available on Windows. They define the allowed values |
6757 | ** for the type argument to the [sqlite3_win32_set_directory] interface. |
6758 | */ |
6759 | #define SQLITE_WIN32_DATA_DIRECTORY_TYPE 1 |
6760 | #define SQLITE_WIN32_TEMP_DIRECTORY_TYPE 2 |
6761 | |
6762 | /* |
6763 | ** CAPI3REF: Test For Auto-Commit Mode |
6764 | ** KEYWORDS: {autocommit mode} |
6765 | ** METHOD: sqlite3 |
6766 | ** |
6767 | ** ^The sqlite3_get_autocommit() interface returns non-zero or |
6768 | ** zero if the given database connection is or is not in autocommit mode, |
6769 | ** respectively. ^Autocommit mode is on by default. |
6770 | ** ^Autocommit mode is disabled by a [BEGIN] statement. |
6771 | ** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK]. |
6772 | ** |
6773 | ** If certain kinds of errors occur on a statement within a multi-statement |
6774 | ** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR], |
6775 | ** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the |
6776 | ** transaction might be rolled back automatically. The only way to |
6777 | ** find out whether SQLite automatically rolled back the transaction after |
6778 | ** an error is to use this function. |
6779 | ** |
6780 | ** If another thread changes the autocommit status of the database |
6781 | ** connection while this routine is running, then the return value |
6782 | ** is undefined. |
6783 | */ |
6784 | SQLITE_API int sqlite3_get_autocommit(sqlite3*); |
6785 | |
6786 | /* |
6787 | ** CAPI3REF: Find The Database Handle Of A Prepared Statement |
6788 | ** METHOD: sqlite3_stmt |
6789 | ** |
6790 | ** ^The sqlite3_db_handle interface returns the [database connection] handle |
6791 | ** to which a [prepared statement] belongs. ^The [database connection] |
6792 | ** returned by sqlite3_db_handle is the same [database connection] |
6793 | ** that was the first argument |
6794 | ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to |
6795 | ** create the statement in the first place. |
6796 | */ |
6797 | SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*); |
6798 | |
6799 | /* |
6800 | ** CAPI3REF: Return The Schema Name For A Database Connection |
6801 | ** METHOD: sqlite3 |
6802 | ** |
6803 | ** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name |
6804 | ** for the N-th database on database connection D, or a NULL pointer of N is |
6805 | ** out of range. An N value of 0 means the main database file. An N of 1 is |
6806 | ** the "temp" schema. Larger values of N correspond to various ATTACH-ed |
6807 | ** databases. |
6808 | ** |
6809 | ** Space to hold the string that is returned by sqlite3_db_name() is managed |
6810 | ** by SQLite itself. The string might be deallocated by any operation that |
6811 | ** changes the schema, including [ATTACH] or [DETACH] or calls to |
6812 | ** [sqlite3_serialize()] or [sqlite3_deserialize()], even operations that |
6813 | ** occur on a different thread. Applications that need to |
6814 | ** remember the string long-term should make their own copy. Applications that |
6815 | ** are accessing the same database connection simultaneously on multiple |
6816 | ** threads should mutex-protect calls to this API and should make their own |
6817 | ** private copy of the result prior to releasing the mutex. |
6818 | */ |
6819 | SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N); |
6820 | |
6821 | /* |
6822 | ** CAPI3REF: Return The Filename For A Database Connection |
6823 | ** METHOD: sqlite3 |
6824 | ** |
6825 | ** ^The sqlite3_db_filename(D,N) interface returns a pointer to the filename |
6826 | ** associated with database N of connection D. |
6827 | ** ^If there is no attached database N on the database |
6828 | ** connection D, or if database N is a temporary or in-memory database, then |
6829 | ** this function will return either a NULL pointer or an empty string. |
6830 | ** |
6831 | ** ^The string value returned by this routine is owned and managed by |
6832 | ** the database connection. ^The value will be valid until the database N |
6833 | ** is [DETACH]-ed or until the database connection closes. |
6834 | ** |
6835 | ** ^The filename returned by this function is the output of the |
6836 | ** xFullPathname method of the [VFS]. ^In other words, the filename |
6837 | ** will be an absolute pathname, even if the filename used |
6838 | ** to open the database originally was a URI or relative pathname. |
6839 | ** |
6840 | ** If the filename pointer returned by this routine is not NULL, then it |
6841 | ** can be used as the filename input parameter to these routines: |
6842 | ** <ul> |
6843 | ** <li> [sqlite3_uri_parameter()] |
6844 | ** <li> [sqlite3_uri_boolean()] |
6845 | ** <li> [sqlite3_uri_int64()] |
6846 | ** <li> [sqlite3_filename_database()] |
6847 | ** <li> [sqlite3_filename_journal()] |
6848 | ** <li> [sqlite3_filename_wal()] |
6849 | ** </ul> |
6850 | */ |
6851 | SQLITE_API sqlite3_filename sqlite3_db_filename(sqlite3 *db, const char *zDbName); |
6852 | |
6853 | /* |
6854 | ** CAPI3REF: Determine if a database is read-only |
6855 | ** METHOD: sqlite3 |
6856 | ** |
6857 | ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N |
6858 | ** of connection D is read-only, 0 if it is read/write, or -1 if N is not |
6859 | ** the name of a database on connection D. |
6860 | */ |
6861 | SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName); |
6862 | |
6863 | /* |
6864 | ** CAPI3REF: Determine the transaction state of a database |
6865 | ** METHOD: sqlite3 |
6866 | ** |
6867 | ** ^The sqlite3_txn_state(D,S) interface returns the current |
6868 | ** [transaction state] of schema S in database connection D. ^If S is NULL, |
6869 | ** then the highest transaction state of any schema on database connection D |
6870 | ** is returned. Transaction states are (in order of lowest to highest): |
6871 | ** <ol> |
6872 | ** <li value="0"> SQLITE_TXN_NONE |
6873 | ** <li value="1"> SQLITE_TXN_READ |
6874 | ** <li value="2"> SQLITE_TXN_WRITE |
6875 | ** </ol> |
6876 | ** ^If the S argument to sqlite3_txn_state(D,S) is not the name of |
6877 | ** a valid schema, then -1 is returned. |
6878 | */ |
6879 | SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema); |
6880 | |
6881 | /* |
6882 | ** CAPI3REF: Allowed return values from [sqlite3_txn_state()] |
6883 | ** KEYWORDS: {transaction state} |
6884 | ** |
6885 | ** These constants define the current transaction state of a database file. |
6886 | ** ^The [sqlite3_txn_state(D,S)] interface returns one of these |
6887 | ** constants in order to describe the transaction state of schema S |
6888 | ** in [database connection] D. |
6889 | ** |
6890 | ** <dl> |
6891 | ** [[SQLITE_TXN_NONE]] <dt>SQLITE_TXN_NONE</dt> |
6892 | ** <dd>The SQLITE_TXN_NONE state means that no transaction is currently |
6893 | ** pending.</dd> |
6894 | ** |
6895 | ** [[SQLITE_TXN_READ]] <dt>SQLITE_TXN_READ</dt> |
6896 | ** <dd>The SQLITE_TXN_READ state means that the database is currently |
6897 | ** in a read transaction. Content has been read from the database file |
6898 | ** but nothing in the database file has changed. The transaction state |
6899 | ** will advanced to SQLITE_TXN_WRITE if any changes occur and there are |
6900 | ** no other conflicting concurrent write transactions. The transaction |
6901 | ** state will revert to SQLITE_TXN_NONE following a [ROLLBACK] or |
6902 | ** [COMMIT].</dd> |
6903 | ** |
6904 | ** [[SQLITE_TXN_WRITE]] <dt>SQLITE_TXN_WRITE</dt> |
6905 | ** <dd>The SQLITE_TXN_WRITE state means that the database is currently |
6906 | ** in a write transaction. Content has been written to the database file |
6907 | ** but has not yet committed. The transaction state will change to |
6908 | ** to SQLITE_TXN_NONE at the next [ROLLBACK] or [COMMIT].</dd> |
6909 | */ |
6910 | #define SQLITE_TXN_NONE 0 |
6911 | #define SQLITE_TXN_READ 1 |
6912 | #define SQLITE_TXN_WRITE 2 |
6913 | |
6914 | /* |
6915 | ** CAPI3REF: Find the next prepared statement |
6916 | ** METHOD: sqlite3 |
6917 | ** |
6918 | ** ^This interface returns a pointer to the next [prepared statement] after |
6919 | ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL |
6920 | ** then this interface returns a pointer to the first prepared statement |
6921 | ** associated with the database connection pDb. ^If no prepared statement |
6922 | ** satisfies the conditions of this routine, it returns NULL. |
6923 | ** |
6924 | ** The [database connection] pointer D in a call to |
6925 | ** [sqlite3_next_stmt(D,S)] must refer to an open database |
6926 | ** connection and in particular must not be a NULL pointer. |
6927 | */ |
6928 | SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); |
6929 | |
6930 | /* |
6931 | ** CAPI3REF: Commit And Rollback Notification Callbacks |
6932 | ** METHOD: sqlite3 |
6933 | ** |
6934 | ** ^The sqlite3_commit_hook() interface registers a callback |
6935 | ** function to be invoked whenever a transaction is [COMMIT | committed]. |
6936 | ** ^Any callback set by a previous call to sqlite3_commit_hook() |
6937 | ** for the same database connection is overridden. |
6938 | ** ^The sqlite3_rollback_hook() interface registers a callback |
6939 | ** function to be invoked whenever a transaction is [ROLLBACK | rolled back]. |
6940 | ** ^Any callback set by a previous call to sqlite3_rollback_hook() |
6941 | ** for the same database connection is overridden. |
6942 | ** ^The pArg argument is passed through to the callback. |
6943 | ** ^If the callback on a commit hook function returns non-zero, |
6944 | ** then the commit is converted into a rollback. |
6945 | ** |
6946 | ** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions |
6947 | ** return the P argument from the previous call of the same function |
6948 | ** on the same [database connection] D, or NULL for |
6949 | ** the first call for each function on D. |
6950 | ** |
6951 | ** The commit and rollback hook callbacks are not reentrant. |
6952 | ** The callback implementation must not do anything that will modify |
6953 | ** the database connection that invoked the callback. Any actions |
6954 | ** to modify the database connection must be deferred until after the |
6955 | ** completion of the [sqlite3_step()] call that triggered the commit |
6956 | ** or rollback hook in the first place. |
6957 | ** Note that running any other SQL statements, including SELECT statements, |
6958 | ** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify |
6959 | ** the database connections for the meaning of "modify" in this paragraph. |
6960 | ** |
6961 | ** ^Registering a NULL function disables the callback. |
6962 | ** |
6963 | ** ^When the commit hook callback routine returns zero, the [COMMIT] |
6964 | ** operation is allowed to continue normally. ^If the commit hook |
6965 | ** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK]. |
6966 | ** ^The rollback hook is invoked on a rollback that results from a commit |
6967 | ** hook returning non-zero, just as it would be with any other rollback. |
6968 | ** |
6969 | ** ^For the purposes of this API, a transaction is said to have been |
6970 | ** rolled back if an explicit "ROLLBACK" statement is executed, or |
6971 | ** an error or constraint causes an implicit rollback to occur. |
6972 | ** ^The rollback callback is not invoked if a transaction is |
6973 | ** automatically rolled back because the database connection is closed. |
6974 | ** |
6975 | ** See also the [sqlite3_update_hook()] interface. |
6976 | */ |
6977 | SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); |
6978 | SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); |
6979 | |
6980 | /* |
6981 | ** CAPI3REF: Autovacuum Compaction Amount Callback |
6982 | ** METHOD: sqlite3 |
6983 | ** |
6984 | ** ^The sqlite3_autovacuum_pages(D,C,P,X) interface registers a callback |
6985 | ** function C that is invoked prior to each autovacuum of the database |
6986 | ** file. ^The callback is passed a copy of the generic data pointer (P), |
6987 | ** the schema-name of the attached database that is being autovacuumed, |
6988 | ** the size of the database file in pages, the number of free pages, |
6989 | ** and the number of bytes per page, respectively. The callback should |
6990 | ** return the number of free pages that should be removed by the |
6991 | ** autovacuum. ^If the callback returns zero, then no autovacuum happens. |
6992 | ** ^If the value returned is greater than or equal to the number of |
6993 | ** free pages, then a complete autovacuum happens. |
6994 | ** |
6995 | ** <p>^If there are multiple ATTACH-ed database files that are being |
6996 | ** modified as part of a transaction commit, then the autovacuum pages |
6997 | ** callback is invoked separately for each file. |
6998 | ** |
6999 | ** <p><b>The callback is not reentrant.</b> The callback function should |
7000 | ** not attempt to invoke any other SQLite interface. If it does, bad |
7001 | ** things may happen, including segmentation faults and corrupt database |
7002 | ** files. The callback function should be a simple function that |
7003 | ** does some arithmetic on its input parameters and returns a result. |
7004 | ** |
7005 | ** ^The X parameter to sqlite3_autovacuum_pages(D,C,P,X) is an optional |
7006 | ** destructor for the P parameter. ^If X is not NULL, then X(P) is |
7007 | ** invoked whenever the database connection closes or when the callback |
7008 | ** is overwritten by another invocation of sqlite3_autovacuum_pages(). |
7009 | ** |
7010 | ** <p>^There is only one autovacuum pages callback per database connection. |
7011 | ** ^Each call to the sqlite3_autovacuum_pages() interface overrides all |
7012 | ** previous invocations for that database connection. ^If the callback |
7013 | ** argument (C) to sqlite3_autovacuum_pages(D,C,P,X) is a NULL pointer, |
7014 | ** then the autovacuum steps callback is cancelled. The return value |
7015 | ** from sqlite3_autovacuum_pages() is normally SQLITE_OK, but might |
7016 | ** be some other error code if something goes wrong. The current |
7017 | ** implementation will only return SQLITE_OK or SQLITE_MISUSE, but other |
7018 | ** return codes might be added in future releases. |
7019 | ** |
7020 | ** <p>If no autovacuum pages callback is specified (the usual case) or |
7021 | ** a NULL pointer is provided for the callback, |
7022 | ** then the default behavior is to vacuum all free pages. So, in other |
7023 | ** words, the default behavior is the same as if the callback function |
7024 | ** were something like this: |
7025 | ** |
7026 | ** <blockquote><pre> |
7027 | ** unsigned int demonstration_autovac_pages_callback( |
7028 | ** void *pClientData, |
7029 | ** const char *zSchema, |
7030 | ** unsigned int nDbPage, |
7031 | ** unsigned int nFreePage, |
7032 | ** unsigned int nBytePerPage |
7033 | ** ){ |
7034 | ** return nFreePage; |
7035 | ** } |
7036 | ** </pre></blockquote> |
7037 | */ |
7038 | SQLITE_API int sqlite3_autovacuum_pages( |
7039 | sqlite3 *db, |
7040 | unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int), |
7041 | void*, |
7042 | void(*)(void*) |
7043 | ); |
7044 | |
7045 | |
7046 | /* |
7047 | ** CAPI3REF: Data Change Notification Callbacks |
7048 | ** METHOD: sqlite3 |
7049 | ** |
7050 | ** ^The sqlite3_update_hook() interface registers a callback function |
7051 | ** with the [database connection] identified by the first argument |
7052 | ** to be invoked whenever a row is updated, inserted or deleted in |
7053 | ** a [rowid table]. |
7054 | ** ^Any callback set by a previous call to this function |
7055 | ** for the same database connection is overridden. |
7056 | ** |
7057 | ** ^The second argument is a pointer to the function to invoke when a |
7058 | ** row is updated, inserted or deleted in a rowid table. |
7059 | ** ^The first argument to the callback is a copy of the third argument |
7060 | ** to sqlite3_update_hook(). |
7061 | ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE], |
7062 | ** or [SQLITE_UPDATE], depending on the operation that caused the callback |
7063 | ** to be invoked. |
7064 | ** ^The third and fourth arguments to the callback contain pointers to the |
7065 | ** database and table name containing the affected row. |
7066 | ** ^The final callback parameter is the [rowid] of the row. |
7067 | ** ^In the case of an update, this is the [rowid] after the update takes place. |
7068 | ** |
7069 | ** ^(The update hook is not invoked when internal system tables are |
7070 | ** modified (i.e. sqlite_sequence).)^ |
7071 | ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified. |
7072 | ** |
7073 | ** ^In the current implementation, the update hook |
7074 | ** is not invoked when conflicting rows are deleted because of an |
7075 | ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook |
7076 | ** invoked when rows are deleted using the [truncate optimization]. |
7077 | ** The exceptions defined in this paragraph might change in a future |
7078 | ** release of SQLite. |
7079 | ** |
7080 | ** The update hook implementation must not do anything that will modify |
7081 | ** the database connection that invoked the update hook. Any actions |
7082 | ** to modify the database connection must be deferred until after the |
7083 | ** completion of the [sqlite3_step()] call that triggered the update hook. |
7084 | ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their |
7085 | ** database connections for the meaning of "modify" in this paragraph. |
7086 | ** |
7087 | ** ^The sqlite3_update_hook(D,C,P) function |
7088 | ** returns the P argument from the previous call |
7089 | ** on the same [database connection] D, or NULL for |
7090 | ** the first call on D. |
7091 | ** |
7092 | ** See also the [sqlite3_commit_hook()], [sqlite3_rollback_hook()], |
7093 | ** and [sqlite3_preupdate_hook()] interfaces. |
7094 | */ |
7095 | SQLITE_API void *sqlite3_update_hook( |
7096 | sqlite3*, |
7097 | void(*)(void *,int ,char const *,char const *,sqlite3_int64), |
7098 | void* |
7099 | ); |
7100 | |
7101 | /* |
7102 | ** CAPI3REF: Enable Or Disable Shared Pager Cache |
7103 | ** |
7104 | ** ^(This routine enables or disables the sharing of the database cache |
7105 | ** and schema data structures between [database connection | connections] |
7106 | ** to the same database. Sharing is enabled if the argument is true |
7107 | ** and disabled if the argument is false.)^ |
7108 | ** |
7109 | ** This interface is omitted if SQLite is compiled with |
7110 | ** [-DSQLITE_OMIT_SHARED_CACHE]. The [-DSQLITE_OMIT_SHARED_CACHE] |
7111 | ** compile-time option is recommended because the |
7112 | ** [use of shared cache mode is discouraged]. |
7113 | ** |
7114 | ** ^Cache sharing is enabled and disabled for an entire process. |
7115 | ** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]). |
7116 | ** In prior versions of SQLite, |
7117 | ** sharing was enabled or disabled for each thread separately. |
7118 | ** |
7119 | ** ^(The cache sharing mode set by this interface effects all subsequent |
7120 | ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()]. |
7121 | ** Existing database connections continue to use the sharing mode |
7122 | ** that was in effect at the time they were opened.)^ |
7123 | ** |
7124 | ** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled |
7125 | ** successfully. An [error code] is returned otherwise.)^ |
7126 | ** |
7127 | ** ^Shared cache is disabled by default. It is recommended that it stay |
7128 | ** that way. In other words, do not use this routine. This interface |
7129 | ** continues to be provided for historical compatibility, but its use is |
7130 | ** discouraged. Any use of shared cache is discouraged. If shared cache |
7131 | ** must be used, it is recommended that shared cache only be enabled for |
7132 | ** individual database connections using the [sqlite3_open_v2()] interface |
7133 | ** with the [SQLITE_OPEN_SHAREDCACHE] flag. |
7134 | ** |
7135 | ** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0 |
7136 | ** and will always return SQLITE_MISUSE. On those systems, |
7137 | ** shared cache mode should be enabled per-database connection via |
7138 | ** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE]. |
7139 | ** |
7140 | ** This interface is threadsafe on processors where writing a |
7141 | ** 32-bit integer is atomic. |
7142 | ** |
7143 | ** See Also: [SQLite Shared-Cache Mode] |
7144 | */ |
7145 | SQLITE_API int sqlite3_enable_shared_cache(int); |
7146 | |
7147 | /* |
7148 | ** CAPI3REF: Attempt To Free Heap Memory |
7149 | ** |
7150 | ** ^The sqlite3_release_memory() interface attempts to free N bytes |
7151 | ** of heap memory by deallocating non-essential memory allocations |
7152 | ** held by the database library. Memory used to cache database |
7153 | ** pages to improve performance is an example of non-essential memory. |
7154 | ** ^sqlite3_release_memory() returns the number of bytes actually freed, |
7155 | ** which might be more or less than the amount requested. |
7156 | ** ^The sqlite3_release_memory() routine is a no-op returning zero |
7157 | ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT]. |
7158 | ** |
7159 | ** See also: [sqlite3_db_release_memory()] |
7160 | */ |
7161 | SQLITE_API int sqlite3_release_memory(int); |
7162 | |
7163 | /* |
7164 | ** CAPI3REF: Free Memory Used By A Database Connection |
7165 | ** METHOD: sqlite3 |
7166 | ** |
7167 | ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap |
7168 | ** memory as possible from database connection D. Unlike the |
7169 | ** [sqlite3_release_memory()] interface, this interface is in effect even |
7170 | ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is |
7171 | ** omitted. |
7172 | ** |
7173 | ** See also: [sqlite3_release_memory()] |
7174 | */ |
7175 | SQLITE_API int sqlite3_db_release_memory(sqlite3*); |
7176 | |
7177 | /* |
7178 | ** CAPI3REF: Impose A Limit On Heap Size |
7179 | ** |
7180 | ** These interfaces impose limits on the amount of heap memory that will be |
7181 | ** by all database connections within a single process. |
7182 | ** |
7183 | ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the |
7184 | ** soft limit on the amount of heap memory that may be allocated by SQLite. |
7185 | ** ^SQLite strives to keep heap memory utilization below the soft heap |
7186 | ** limit by reducing the number of pages held in the page cache |
7187 | ** as heap memory usages approaches the limit. |
7188 | ** ^The soft heap limit is "soft" because even though SQLite strives to stay |
7189 | ** below the limit, it will exceed the limit rather than generate |
7190 | ** an [SQLITE_NOMEM] error. In other words, the soft heap limit |
7191 | ** is advisory only. |
7192 | ** |
7193 | ** ^The sqlite3_hard_heap_limit64(N) interface sets a hard upper bound of |
7194 | ** N bytes on the amount of memory that will be allocated. ^The |
7195 | ** sqlite3_hard_heap_limit64(N) interface is similar to |
7196 | ** sqlite3_soft_heap_limit64(N) except that memory allocations will fail |
7197 | ** when the hard heap limit is reached. |
7198 | ** |
7199 | ** ^The return value from both sqlite3_soft_heap_limit64() and |
7200 | ** sqlite3_hard_heap_limit64() is the size of |
7201 | ** the heap limit prior to the call, or negative in the case of an |
7202 | ** error. ^If the argument N is negative |
7203 | ** then no change is made to the heap limit. Hence, the current |
7204 | ** size of heap limits can be determined by invoking |
7205 | ** sqlite3_soft_heap_limit64(-1) or sqlite3_hard_heap_limit(-1). |
7206 | ** |
7207 | ** ^Setting the heap limits to zero disables the heap limiter mechanism. |
7208 | ** |
7209 | ** ^The soft heap limit may not be greater than the hard heap limit. |
7210 | ** ^If the hard heap limit is enabled and if sqlite3_soft_heap_limit(N) |
7211 | ** is invoked with a value of N that is greater than the hard heap limit, |
7212 | ** the soft heap limit is set to the value of the hard heap limit. |
7213 | ** ^The soft heap limit is automatically enabled whenever the hard heap |
7214 | ** limit is enabled. ^When sqlite3_hard_heap_limit64(N) is invoked and |
7215 | ** the soft heap limit is outside the range of 1..N, then the soft heap |
7216 | ** limit is set to N. ^Invoking sqlite3_soft_heap_limit64(0) when the |
7217 | ** hard heap limit is enabled makes the soft heap limit equal to the |
7218 | ** hard heap limit. |
7219 | ** |
7220 | ** The memory allocation limits can also be adjusted using |
7221 | ** [PRAGMA soft_heap_limit] and [PRAGMA hard_heap_limit]. |
7222 | ** |
7223 | ** ^(The heap limits are not enforced in the current implementation |
7224 | ** if one or more of following conditions are true: |
7225 | ** |
7226 | ** <ul> |
7227 | ** <li> The limit value is set to zero. |
7228 | ** <li> Memory accounting is disabled using a combination of the |
7229 | ** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and |
7230 | ** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option. |
7231 | ** <li> An alternative page cache implementation is specified using |
7232 | ** [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...). |
7233 | ** <li> The page cache allocates from its own memory pool supplied |
7234 | ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than |
7235 | ** from the heap. |
7236 | ** </ul>)^ |
7237 | ** |
7238 | ** The circumstances under which SQLite will enforce the heap limits may |
7239 | ** changes in future releases of SQLite. |
7240 | */ |
7241 | SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N); |
7242 | SQLITE_API sqlite3_int64 sqlite3_hard_heap_limit64(sqlite3_int64 N); |
7243 | |
7244 | /* |
7245 | ** CAPI3REF: Deprecated Soft Heap Limit Interface |
7246 | ** DEPRECATED |
7247 | ** |
7248 | ** This is a deprecated version of the [sqlite3_soft_heap_limit64()] |
7249 | ** interface. This routine is provided for historical compatibility |
7250 | ** only. All new applications should use the |
7251 | ** [sqlite3_soft_heap_limit64()] interface rather than this one. |
7252 | */ |
7253 | SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N); |
7254 | |
7255 | |
7256 | /* |
7257 | ** CAPI3REF: Extract Metadata About A Column Of A Table |
7258 | ** METHOD: sqlite3 |
7259 | ** |
7260 | ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns |
7261 | ** information about column C of table T in database D |
7262 | ** on [database connection] X.)^ ^The sqlite3_table_column_metadata() |
7263 | ** interface returns SQLITE_OK and fills in the non-NULL pointers in |
7264 | ** the final five arguments with appropriate values if the specified |
7265 | ** column exists. ^The sqlite3_table_column_metadata() interface returns |
7266 | ** SQLITE_ERROR if the specified column does not exist. |
7267 | ** ^If the column-name parameter to sqlite3_table_column_metadata() is a |
7268 | ** NULL pointer, then this routine simply checks for the existence of the |
7269 | ** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it |
7270 | ** does not. If the table name parameter T in a call to |
7271 | ** sqlite3_table_column_metadata(X,D,T,C,...) is NULL then the result is |
7272 | ** undefined behavior. |
7273 | ** |
7274 | ** ^The column is identified by the second, third and fourth parameters to |
7275 | ** this function. ^(The second parameter is either the name of the database |
7276 | ** (i.e. "main", "temp", or an attached database) containing the specified |
7277 | ** table or NULL.)^ ^If it is NULL, then all attached databases are searched |
7278 | ** for the table using the same algorithm used by the database engine to |
7279 | ** resolve unqualified table references. |
7280 | ** |
7281 | ** ^The third and fourth parameters to this function are the table and column |
7282 | ** name of the desired column, respectively. |
7283 | ** |
7284 | ** ^Metadata is returned by writing to the memory locations passed as the 5th |
7285 | ** and subsequent parameters to this function. ^Any of these arguments may be |
7286 | ** NULL, in which case the corresponding element of metadata is omitted. |
7287 | ** |
7288 | ** ^(<blockquote> |
7289 | ** <table border="1"> |
7290 | ** <tr><th> Parameter <th> Output<br>Type <th> Description |
7291 | ** |
7292 | ** <tr><td> 5th <td> const char* <td> Data type |
7293 | ** <tr><td> 6th <td> const char* <td> Name of default collation sequence |
7294 | ** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint |
7295 | ** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY |
7296 | ** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT] |
7297 | ** </table> |
7298 | ** </blockquote>)^ |
7299 | ** |
7300 | ** ^The memory pointed to by the character pointers returned for the |
7301 | ** declaration type and collation sequence is valid until the next |
7302 | ** call to any SQLite API function. |
7303 | ** |
7304 | ** ^If the specified table is actually a view, an [error code] is returned. |
7305 | ** |
7306 | ** ^If the specified column is "rowid", "oid" or "_rowid_" and the table |
7307 | ** is not a [WITHOUT ROWID] table and an |
7308 | ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output |
7309 | ** parameters are set for the explicitly declared column. ^(If there is no |
7310 | ** [INTEGER PRIMARY KEY] column, then the outputs |
7311 | ** for the [rowid] are set as follows: |
7312 | ** |
7313 | ** <pre> |
7314 | ** data type: "INTEGER" |
7315 | ** collation sequence: "BINARY" |
7316 | ** not null: 0 |
7317 | ** primary key: 1 |
7318 | ** auto increment: 0 |
7319 | ** </pre>)^ |
7320 | ** |
7321 | ** ^This function causes all database schemas to be read from disk and |
7322 | ** parsed, if that has not already been done, and returns an error if |
7323 | ** any errors are encountered while loading the schema. |
7324 | */ |
7325 | SQLITE_API int sqlite3_table_column_metadata( |
7326 | sqlite3 *db, /* Connection handle */ |
7327 | const char *zDbName, /* Database name or NULL */ |
7328 | const char *zTableName, /* Table name */ |
7329 | const char *zColumnName, /* Column name */ |
7330 | char const **pzDataType, /* OUTPUT: Declared data type */ |
7331 | char const **pzCollSeq, /* OUTPUT: Collation sequence name */ |
7332 | int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */ |
7333 | int *pPrimaryKey, /* OUTPUT: True if column part of PK */ |
7334 | int *pAutoinc /* OUTPUT: True if column is auto-increment */ |
7335 | ); |
7336 | |
7337 | /* |
7338 | ** CAPI3REF: Load An Extension |
7339 | ** METHOD: sqlite3 |
7340 | ** |
7341 | ** ^This interface loads an SQLite extension library from the named file. |
7342 | ** |
7343 | ** ^The sqlite3_load_extension() interface attempts to load an |
7344 | ** [SQLite extension] library contained in the file zFile. If |
7345 | ** the file cannot be loaded directly, attempts are made to load |
7346 | ** with various operating-system specific extensions added. |
7347 | ** So for example, if "samplelib" cannot be loaded, then names like |
7348 | ** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might |
7349 | ** be tried also. |
7350 | ** |
7351 | ** ^The entry point is zProc. |
7352 | ** ^(zProc may be 0, in which case SQLite will try to come up with an |
7353 | ** entry point name on its own. It first tries "sqlite3_extension_init". |
7354 | ** If that does not work, it constructs a name "sqlite3_X_init" where the |
7355 | ** X is consists of the lower-case equivalent of all ASCII alphabetic |
7356 | ** characters in the filename from the last "/" to the first following |
7357 | ** "." and omitting any initial "lib".)^ |
7358 | ** ^The sqlite3_load_extension() interface returns |
7359 | ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong. |
7360 | ** ^If an error occurs and pzErrMsg is not 0, then the |
7361 | ** [sqlite3_load_extension()] interface shall attempt to |
7362 | ** fill *pzErrMsg with error message text stored in memory |
7363 | ** obtained from [sqlite3_malloc()]. The calling function |
7364 | ** should free this memory by calling [sqlite3_free()]. |
7365 | ** |
7366 | ** ^Extension loading must be enabled using |
7367 | ** [sqlite3_enable_load_extension()] or |
7368 | ** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL) |
7369 | ** prior to calling this API, |
7370 | ** otherwise an error will be returned. |
7371 | ** |
7372 | ** <b>Security warning:</b> It is recommended that the |
7373 | ** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this |
7374 | ** interface. The use of the [sqlite3_enable_load_extension()] interface |
7375 | ** should be avoided. This will keep the SQL function [load_extension()] |
7376 | ** disabled and prevent SQL injections from giving attackers |
7377 | ** access to extension loading capabilities. |
7378 | ** |
7379 | ** See also the [load_extension() SQL function]. |
7380 | */ |
7381 | SQLITE_API int sqlite3_load_extension( |
7382 | sqlite3 *db, /* Load the extension into this database connection */ |
7383 | const char *zFile, /* Name of the shared library containing extension */ |
7384 | const char *zProc, /* Entry point. Derived from zFile if 0 */ |
7385 | char **pzErrMsg /* Put error message here if not 0 */ |
7386 | ); |
7387 | |
7388 | /* |
7389 | ** CAPI3REF: Enable Or Disable Extension Loading |
7390 | ** METHOD: sqlite3 |
7391 | ** |
7392 | ** ^So as not to open security holes in older applications that are |
7393 | ** unprepared to deal with [extension loading], and as a means of disabling |
7394 | ** [extension loading] while evaluating user-entered SQL, the following API |
7395 | ** is provided to turn the [sqlite3_load_extension()] mechanism on and off. |
7396 | ** |
7397 | ** ^Extension loading is off by default. |
7398 | ** ^Call the sqlite3_enable_load_extension() routine with onoff==1 |
7399 | ** to turn extension loading on and call it with onoff==0 to turn |
7400 | ** it back off again. |
7401 | ** |
7402 | ** ^This interface enables or disables both the C-API |
7403 | ** [sqlite3_load_extension()] and the SQL function [load_extension()]. |
7404 | ** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..) |
7405 | ** to enable or disable only the C-API.)^ |
7406 | ** |
7407 | ** <b>Security warning:</b> It is recommended that extension loading |
7408 | ** be enabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method |
7409 | ** rather than this interface, so the [load_extension()] SQL function |
7410 | ** remains disabled. This will prevent SQL injections from giving attackers |
7411 | ** access to extension loading capabilities. |
7412 | */ |
7413 | SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff); |
7414 | |
7415 | /* |
7416 | ** CAPI3REF: Automatically Load Statically Linked Extensions |
7417 | ** |
7418 | ** ^This interface causes the xEntryPoint() function to be invoked for |
7419 | ** each new [database connection] that is created. The idea here is that |
7420 | ** xEntryPoint() is the entry point for a statically linked [SQLite extension] |
7421 | ** that is to be automatically loaded into all new database connections. |
7422 | ** |
7423 | ** ^(Even though the function prototype shows that xEntryPoint() takes |
7424 | ** no arguments and returns void, SQLite invokes xEntryPoint() with three |
7425 | ** arguments and expects an integer result as if the signature of the |
7426 | ** entry point where as follows: |
7427 | ** |
7428 | ** <blockquote><pre> |
7429 | ** int xEntryPoint( |
7430 | ** sqlite3 *db, |
7431 | ** const char **pzErrMsg, |
7432 | ** const struct sqlite3_api_routines *pThunk |
7433 | ** ); |
7434 | ** </pre></blockquote>)^ |
7435 | ** |
7436 | ** If the xEntryPoint routine encounters an error, it should make *pzErrMsg |
7437 | ** point to an appropriate error message (obtained from [sqlite3_mprintf()]) |
7438 | ** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg |
7439 | ** is NULL before calling the xEntryPoint(). ^SQLite will invoke |
7440 | ** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any |
7441 | ** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()], |
7442 | ** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail. |
7443 | ** |
7444 | ** ^Calling sqlite3_auto_extension(X) with an entry point X that is already |
7445 | ** on the list of automatic extensions is a harmless no-op. ^No entry point |
7446 | ** will be called more than once for each database connection that is opened. |
7447 | ** |
7448 | ** See also: [sqlite3_reset_auto_extension()] |
7449 | ** and [sqlite3_cancel_auto_extension()] |
7450 | */ |
7451 | SQLITE_API int sqlite3_auto_extension(void(*xEntryPoint)(void)); |
7452 | |
7453 | /* |
7454 | ** CAPI3REF: Cancel Automatic Extension Loading |
7455 | ** |
7456 | ** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the |
7457 | ** initialization routine X that was registered using a prior call to |
7458 | ** [sqlite3_auto_extension(X)]. ^The [sqlite3_cancel_auto_extension(X)] |
7459 | ** routine returns 1 if initialization routine X was successfully |
7460 | ** unregistered and it returns 0 if X was not on the list of initialization |
7461 | ** routines. |
7462 | */ |
7463 | SQLITE_API int sqlite3_cancel_auto_extension(void(*xEntryPoint)(void)); |
7464 | |
7465 | /* |
7466 | ** CAPI3REF: Reset Automatic Extension Loading |
7467 | ** |
7468 | ** ^This interface disables all automatic extensions previously |
7469 | ** registered using [sqlite3_auto_extension()]. |
7470 | */ |
7471 | SQLITE_API void sqlite3_reset_auto_extension(void); |
7472 | |
7473 | /* |
7474 | ** Structures used by the virtual table interface |
7475 | */ |
7476 | typedef struct sqlite3_vtab sqlite3_vtab; |
7477 | typedef struct sqlite3_index_info sqlite3_index_info; |
7478 | typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor; |
7479 | typedef struct sqlite3_module sqlite3_module; |
7480 | |
7481 | /* |
7482 | ** CAPI3REF: Virtual Table Object |
7483 | ** KEYWORDS: sqlite3_module {virtual table module} |
7484 | ** |
7485 | ** This structure, sometimes called a "virtual table module", |
7486 | ** defines the implementation of a [virtual table]. |
7487 | ** This structure consists mostly of methods for the module. |
7488 | ** |
7489 | ** ^A virtual table module is created by filling in a persistent |
7490 | ** instance of this structure and passing a pointer to that instance |
7491 | ** to [sqlite3_create_module()] or [sqlite3_create_module_v2()]. |
7492 | ** ^The registration remains valid until it is replaced by a different |
7493 | ** module or until the [database connection] closes. The content |
7494 | ** of this structure must not change while it is registered with |
7495 | ** any database connection. |
7496 | */ |
7497 | struct sqlite3_module { |
7498 | int iVersion; |
7499 | int (*xCreate)(sqlite3*, void *pAux, |
7500 | int argc, const char *const*argv, |
7501 | sqlite3_vtab **ppVTab, char**); |
7502 | int (*xConnect)(sqlite3*, void *pAux, |
7503 | int argc, const char *const*argv, |
7504 | sqlite3_vtab **ppVTab, char**); |
7505 | int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*); |
7506 | int (*xDisconnect)(sqlite3_vtab *pVTab); |
7507 | int (*xDestroy)(sqlite3_vtab *pVTab); |
7508 | int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor); |
7509 | int (*xClose)(sqlite3_vtab_cursor*); |
7510 | int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr, |
7511 | int argc, sqlite3_value **argv); |
7512 | int (*xNext)(sqlite3_vtab_cursor*); |
7513 | int (*xEof)(sqlite3_vtab_cursor*); |
7514 | int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int); |
7515 | int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid); |
7516 | int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *); |
7517 | int (*xBegin)(sqlite3_vtab *pVTab); |
7518 | int (*xSync)(sqlite3_vtab *pVTab); |
7519 | int (*xCommit)(sqlite3_vtab *pVTab); |
7520 | int (*xRollback)(sqlite3_vtab *pVTab); |
7521 | int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName, |
7522 | void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), |
7523 | void **ppArg); |
7524 | int (*xRename)(sqlite3_vtab *pVtab, const char *zNew); |
7525 | /* The methods above are in version 1 of the sqlite_module object. Those |
7526 | ** below are for version 2 and greater. */ |
7527 | int (*xSavepoint)(sqlite3_vtab *pVTab, int); |
7528 | int (*xRelease)(sqlite3_vtab *pVTab, int); |
7529 | int (*xRollbackTo)(sqlite3_vtab *pVTab, int); |
7530 | /* The methods above are in versions 1 and 2 of the sqlite_module object. |
7531 | ** Those below are for version 3 and greater. */ |
7532 | int (*xShadowName)(const char*); |
7533 | }; |
7534 | |
7535 | /* |
7536 | ** CAPI3REF: Virtual Table Indexing Information |
7537 | ** KEYWORDS: sqlite3_index_info |
7538 | ** |
7539 | ** The sqlite3_index_info structure and its substructures is used as part |
7540 | ** of the [virtual table] interface to |
7541 | ** pass information into and receive the reply from the [xBestIndex] |
7542 | ** method of a [virtual table module]. The fields under **Inputs** are the |
7543 | ** inputs to xBestIndex and are read-only. xBestIndex inserts its |
7544 | ** results into the **Outputs** fields. |
7545 | ** |
7546 | ** ^(The aConstraint[] array records WHERE clause constraints of the form: |
7547 | ** |
7548 | ** <blockquote>column OP expr</blockquote> |
7549 | ** |
7550 | ** where OP is =, <, <=, >, or >=.)^ ^(The particular operator is |
7551 | ** stored in aConstraint[].op using one of the |
7552 | ** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^ |
7553 | ** ^(The index of the column is stored in |
7554 | ** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the |
7555 | ** expr on the right-hand side can be evaluated (and thus the constraint |
7556 | ** is usable) and false if it cannot.)^ |
7557 | ** |
7558 | ** ^The optimizer automatically inverts terms of the form "expr OP column" |
7559 | ** and makes other simplifications to the WHERE clause in an attempt to |
7560 | ** get as many WHERE clause terms into the form shown above as possible. |
7561 | ** ^The aConstraint[] array only reports WHERE clause terms that are |
7562 | ** relevant to the particular virtual table being queried. |
7563 | ** |
7564 | ** ^Information about the ORDER BY clause is stored in aOrderBy[]. |
7565 | ** ^Each term of aOrderBy records a column of the ORDER BY clause. |
7566 | ** |
7567 | ** The colUsed field indicates which columns of the virtual table may be |
7568 | ** required by the current scan. Virtual table columns are numbered from |
7569 | ** zero in the order in which they appear within the CREATE TABLE statement |
7570 | ** passed to sqlite3_declare_vtab(). For the first 63 columns (columns 0-62), |
7571 | ** the corresponding bit is set within the colUsed mask if the column may be |
7572 | ** required by SQLite. If the table has at least 64 columns and any column |
7573 | ** to the right of the first 63 is required, then bit 63 of colUsed is also |
7574 | ** set. In other words, column iCol may be required if the expression |
7575 | ** (colUsed & ((sqlite3_uint64)1 << (iCol>=63 ? 63 : iCol))) evaluates to |
7576 | ** non-zero. |
7577 | ** |
7578 | ** The [xBestIndex] method must fill aConstraintUsage[] with information |
7579 | ** about what parameters to pass to xFilter. ^If argvIndex>0 then |
7580 | ** the right-hand side of the corresponding aConstraint[] is evaluated |
7581 | ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit |
7582 | ** is true, then the constraint is assumed to be fully handled by the |
7583 | ** virtual table and might not be checked again by the byte code.)^ ^(The |
7584 | ** aConstraintUsage[].omit flag is an optimization hint. When the omit flag |
7585 | ** is left in its default setting of false, the constraint will always be |
7586 | ** checked separately in byte code. If the omit flag is change to true, then |
7587 | ** the constraint may or may not be checked in byte code. In other words, |
7588 | ** when the omit flag is true there is no guarantee that the constraint will |
7589 | ** not be checked again using byte code.)^ |
7590 | ** |
7591 | ** ^The idxNum and idxStr values are recorded and passed into the |
7592 | ** [xFilter] method. |
7593 | ** ^[sqlite3_free()] is used to free idxStr if and only if |
7594 | ** needToFreeIdxStr is true. |
7595 | ** |
7596 | ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in |
7597 | ** the correct order to satisfy the ORDER BY clause so that no separate |
7598 | ** sorting step is required. |
7599 | ** |
7600 | ** ^The estimatedCost value is an estimate of the cost of a particular |
7601 | ** strategy. A cost of N indicates that the cost of the strategy is similar |
7602 | ** to a linear scan of an SQLite table with N rows. A cost of log(N) |
7603 | ** indicates that the expense of the operation is similar to that of a |
7604 | ** binary search on a unique indexed field of an SQLite table with N rows. |
7605 | ** |
7606 | ** ^The estimatedRows value is an estimate of the number of rows that |
7607 | ** will be returned by the strategy. |
7608 | ** |
7609 | ** The xBestIndex method may optionally populate the idxFlags field with a |
7610 | ** mask of SQLITE_INDEX_SCAN_* flags. Currently there is only one such flag - |
7611 | ** SQLITE_INDEX_SCAN_UNIQUE. If the xBestIndex method sets this flag, SQLite |
7612 | ** assumes that the strategy may visit at most one row. |
7613 | ** |
7614 | ** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then |
7615 | ** SQLite also assumes that if a call to the xUpdate() method is made as |
7616 | ** part of the same statement to delete or update a virtual table row and the |
7617 | ** implementation returns SQLITE_CONSTRAINT, then there is no need to rollback |
7618 | ** any database changes. In other words, if the xUpdate() returns |
7619 | ** SQLITE_CONSTRAINT, the database contents must be exactly as they were |
7620 | ** before xUpdate was called. By contrast, if SQLITE_INDEX_SCAN_UNIQUE is not |
7621 | ** set and xUpdate returns SQLITE_CONSTRAINT, any database changes made by |
7622 | ** the xUpdate method are automatically rolled back by SQLite. |
7623 | ** |
7624 | ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info |
7625 | ** structure for SQLite [version 3.8.2] ([dateof:3.8.2]). |
7626 | ** If a virtual table extension is |
7627 | ** used with an SQLite version earlier than 3.8.2, the results of attempting |
7628 | ** to read or write the estimatedRows field are undefined (but are likely |
7629 | ** to include crashing the application). The estimatedRows field should |
7630 | ** therefore only be used if [sqlite3_libversion_number()] returns a |
7631 | ** value greater than or equal to 3008002. Similarly, the idxFlags field |
7632 | ** was added for [version 3.9.0] ([dateof:3.9.0]). |
7633 | ** It may therefore only be used if |
7634 | ** sqlite3_libversion_number() returns a value greater than or equal to |
7635 | ** 3009000. |
7636 | */ |
7637 | struct sqlite3_index_info { |
7638 | /* Inputs */ |
7639 | int nConstraint; /* Number of entries in aConstraint */ |
7640 | struct sqlite3_index_constraint { |
7641 | int iColumn; /* Column constrained. -1 for ROWID */ |
7642 | unsigned char op; /* Constraint operator */ |
7643 | unsigned char usable; /* True if this constraint is usable */ |
7644 | int iTermOffset; /* Used internally - xBestIndex should ignore */ |
7645 | } *aConstraint; /* Table of WHERE clause constraints */ |
7646 | int nOrderBy; /* Number of terms in the ORDER BY clause */ |
7647 | struct sqlite3_index_orderby { |
7648 | int iColumn; /* Column number */ |
7649 | unsigned char desc; /* True for DESC. False for ASC. */ |
7650 | } *aOrderBy; /* The ORDER BY clause */ |
7651 | /* Outputs */ |
7652 | struct sqlite3_index_constraint_usage { |
7653 | int argvIndex; /* if >0, constraint is part of argv to xFilter */ |
7654 | unsigned char omit; /* Do not code a test for this constraint */ |
7655 | } *aConstraintUsage; |
7656 | int idxNum; /* Number used to identify the index */ |
7657 | char *idxStr; /* String, possibly obtained from sqlite3_malloc */ |
7658 | int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */ |
7659 | int orderByConsumed; /* True if output is already ordered */ |
7660 | double estimatedCost; /* Estimated cost of using this index */ |
7661 | /* Fields below are only available in SQLite 3.8.2 and later */ |
7662 | sqlite3_int64 estimatedRows; /* Estimated number of rows returned */ |
7663 | /* Fields below are only available in SQLite 3.9.0 and later */ |
7664 | int idxFlags; /* Mask of SQLITE_INDEX_SCAN_* flags */ |
7665 | /* Fields below are only available in SQLite 3.10.0 and later */ |
7666 | sqlite3_uint64 colUsed; /* Input: Mask of columns used by statement */ |
7667 | }; |
7668 | |
7669 | /* |
7670 | ** CAPI3REF: Virtual Table Scan Flags |
7671 | ** |
7672 | ** Virtual table implementations are allowed to set the |
7673 | ** [sqlite3_index_info].idxFlags field to some combination of |
7674 | ** these bits. |
7675 | */ |
7676 | #define SQLITE_INDEX_SCAN_UNIQUE 1 /* Scan visits at most 1 row */ |
7677 | |
7678 | /* |
7679 | ** CAPI3REF: Virtual Table Constraint Operator Codes |
7680 | ** |
7681 | ** These macros define the allowed values for the |
7682 | ** [sqlite3_index_info].aConstraint[].op field. Each value represents |
7683 | ** an operator that is part of a constraint term in the WHERE clause of |
7684 | ** a query that uses a [virtual table]. |
7685 | ** |
7686 | ** ^The left-hand operand of the operator is given by the corresponding |
7687 | ** aConstraint[].iColumn field. ^An iColumn of -1 indicates the left-hand |
7688 | ** operand is the rowid. |
7689 | ** The SQLITE_INDEX_CONSTRAINT_LIMIT and SQLITE_INDEX_CONSTRAINT_OFFSET |
7690 | ** operators have no left-hand operand, and so for those operators the |
7691 | ** corresponding aConstraint[].iColumn is meaningless and should not be |
7692 | ** used. |
7693 | ** |
7694 | ** All operator values from SQLITE_INDEX_CONSTRAINT_FUNCTION through |
7695 | ** value 255 are reserved to represent functions that are overloaded |
7696 | ** by the [xFindFunction|xFindFunction method] of the virtual table |
7697 | ** implementation. |
7698 | ** |
7699 | ** The right-hand operands for each constraint might be accessible using |
7700 | ** the [sqlite3_vtab_rhs_value()] interface. Usually the right-hand |
7701 | ** operand is only available if it appears as a single constant literal |
7702 | ** in the input SQL. If the right-hand operand is another column or an |
7703 | ** expression (even a constant expression) or a parameter, then the |
7704 | ** sqlite3_vtab_rhs_value() probably will not be able to extract it. |
7705 | ** ^The SQLITE_INDEX_CONSTRAINT_ISNULL and |
7706 | ** SQLITE_INDEX_CONSTRAINT_ISNOTNULL operators have no right-hand operand |
7707 | ** and hence calls to sqlite3_vtab_rhs_value() for those operators will |
7708 | ** always return SQLITE_NOTFOUND. |
7709 | ** |
7710 | ** The collating sequence to be used for comparison can be found using |
7711 | ** the [sqlite3_vtab_collation()] interface. For most real-world virtual |
7712 | ** tables, the collating sequence of constraints does not matter (for example |
7713 | ** because the constraints are numeric) and so the sqlite3_vtab_collation() |
7714 | ** interface is not commonly needed. |
7715 | */ |
7716 | #define SQLITE_INDEX_CONSTRAINT_EQ 2 |
7717 | #define SQLITE_INDEX_CONSTRAINT_GT 4 |
7718 | #define SQLITE_INDEX_CONSTRAINT_LE 8 |
7719 | #define SQLITE_INDEX_CONSTRAINT_LT 16 |
7720 | #define SQLITE_INDEX_CONSTRAINT_GE 32 |
7721 | #define SQLITE_INDEX_CONSTRAINT_MATCH 64 |
7722 | #define SQLITE_INDEX_CONSTRAINT_LIKE 65 |
7723 | #define SQLITE_INDEX_CONSTRAINT_GLOB 66 |
7724 | #define SQLITE_INDEX_CONSTRAINT_REGEXP 67 |
7725 | #define SQLITE_INDEX_CONSTRAINT_NE 68 |
7726 | #define SQLITE_INDEX_CONSTRAINT_ISNOT 69 |
7727 | #define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70 |
7728 | #define SQLITE_INDEX_CONSTRAINT_ISNULL 71 |
7729 | #define SQLITE_INDEX_CONSTRAINT_IS 72 |
7730 | #define SQLITE_INDEX_CONSTRAINT_LIMIT 73 |
7731 | #define SQLITE_INDEX_CONSTRAINT_OFFSET 74 |
7732 | #define SQLITE_INDEX_CONSTRAINT_FUNCTION 150 |
7733 | |
7734 | /* |
7735 | ** CAPI3REF: Register A Virtual Table Implementation |
7736 | ** METHOD: sqlite3 |
7737 | ** |
7738 | ** ^These routines are used to register a new [virtual table module] name. |
7739 | ** ^Module names must be registered before |
7740 | ** creating a new [virtual table] using the module and before using a |
7741 | ** preexisting [virtual table] for the module. |
7742 | ** |
7743 | ** ^The module name is registered on the [database connection] specified |
7744 | ** by the first parameter. ^The name of the module is given by the |
7745 | ** second parameter. ^The third parameter is a pointer to |
7746 | ** the implementation of the [virtual table module]. ^The fourth |
7747 | ** parameter is an arbitrary client data pointer that is passed through |
7748 | ** into the [xCreate] and [xConnect] methods of the virtual table module |
7749 | ** when a new virtual table is be being created or reinitialized. |
7750 | ** |
7751 | ** ^The sqlite3_create_module_v2() interface has a fifth parameter which |
7752 | ** is a pointer to a destructor for the pClientData. ^SQLite will |
7753 | ** invoke the destructor function (if it is not NULL) when SQLite |
7754 | ** no longer needs the pClientData pointer. ^The destructor will also |
7755 | ** be invoked if the call to sqlite3_create_module_v2() fails. |
7756 | ** ^The sqlite3_create_module() |
7757 | ** interface is equivalent to sqlite3_create_module_v2() with a NULL |
7758 | ** destructor. |
7759 | ** |
7760 | ** ^If the third parameter (the pointer to the sqlite3_module object) is |
7761 | ** NULL then no new module is created and any existing modules with the |
7762 | ** same name are dropped. |
7763 | ** |
7764 | ** See also: [sqlite3_drop_modules()] |
7765 | */ |
7766 | SQLITE_API int sqlite3_create_module( |
7767 | sqlite3 *db, /* SQLite connection to register module with */ |
7768 | const char *zName, /* Name of the module */ |
7769 | const sqlite3_module *p, /* Methods for the module */ |
7770 | void *pClientData /* Client data for xCreate/xConnect */ |
7771 | ); |
7772 | SQLITE_API int sqlite3_create_module_v2( |
7773 | sqlite3 *db, /* SQLite connection to register module with */ |
7774 | const char *zName, /* Name of the module */ |
7775 | const sqlite3_module *p, /* Methods for the module */ |
7776 | void *pClientData, /* Client data for xCreate/xConnect */ |
7777 | void(*xDestroy)(void*) /* Module destructor function */ |
7778 | ); |
7779 | |
7780 | /* |
7781 | ** CAPI3REF: Remove Unnecessary Virtual Table Implementations |
7782 | ** METHOD: sqlite3 |
7783 | ** |
7784 | ** ^The sqlite3_drop_modules(D,L) interface removes all virtual |
7785 | ** table modules from database connection D except those named on list L. |
7786 | ** The L parameter must be either NULL or a pointer to an array of pointers |
7787 | ** to strings where the array is terminated by a single NULL pointer. |
7788 | ** ^If the L parameter is NULL, then all virtual table modules are removed. |
7789 | ** |
7790 | ** See also: [sqlite3_create_module()] |
7791 | */ |
7792 | SQLITE_API int sqlite3_drop_modules( |
7793 | sqlite3 *db, /* Remove modules from this connection */ |
7794 | const char **azKeep /* Except, do not remove the ones named here */ |
7795 | ); |
7796 | |
7797 | /* |
7798 | ** CAPI3REF: Virtual Table Instance Object |
7799 | ** KEYWORDS: sqlite3_vtab |
7800 | ** |
7801 | ** Every [virtual table module] implementation uses a subclass |
7802 | ** of this object to describe a particular instance |
7803 | ** of the [virtual table]. Each subclass will |
7804 | ** be tailored to the specific needs of the module implementation. |
7805 | ** The purpose of this superclass is to define certain fields that are |
7806 | ** common to all module implementations. |
7807 | ** |
7808 | ** ^Virtual tables methods can set an error message by assigning a |
7809 | ** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should |
7810 | ** take care that any prior string is freed by a call to [sqlite3_free()] |
7811 | ** prior to assigning a new string to zErrMsg. ^After the error message |
7812 | ** is delivered up to the client application, the string will be automatically |
7813 | ** freed by sqlite3_free() and the zErrMsg field will be zeroed. |
7814 | */ |
7815 | struct sqlite3_vtab { |
7816 | const sqlite3_module *pModule; /* The module for this virtual table */ |
7817 | int nRef; /* Number of open cursors */ |
7818 | char *zErrMsg; /* Error message from sqlite3_mprintf() */ |
7819 | /* Virtual table implementations will typically add additional fields */ |
7820 | }; |
7821 | |
7822 | /* |
7823 | ** CAPI3REF: Virtual Table Cursor Object |
7824 | ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor} |
7825 | ** |
7826 | ** Every [virtual table module] implementation uses a subclass of the |
7827 | ** following structure to describe cursors that point into the |
7828 | ** [virtual table] and are used |
7829 | ** to loop through the virtual table. Cursors are created using the |
7830 | ** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed |
7831 | ** by the [sqlite3_module.xClose | xClose] method. Cursors are used |
7832 | ** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods |
7833 | ** of the module. Each module implementation will define |
7834 | ** the content of a cursor structure to suit its own needs. |
7835 | ** |
7836 | ** This superclass exists in order to define fields of the cursor that |
7837 | ** are common to all implementations. |
7838 | */ |
7839 | struct sqlite3_vtab_cursor { |
7840 | sqlite3_vtab *pVtab; /* Virtual table of this cursor */ |
7841 | /* Virtual table implementations will typically add additional fields */ |
7842 | }; |
7843 | |
7844 | /* |
7845 | ** CAPI3REF: Declare The Schema Of A Virtual Table |
7846 | ** |
7847 | ** ^The [xCreate] and [xConnect] methods of a |
7848 | ** [virtual table module] call this interface |
7849 | ** to declare the format (the names and datatypes of the columns) of |
7850 | ** the virtual tables they implement. |
7851 | */ |
7852 | SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL); |
7853 | |
7854 | /* |
7855 | ** CAPI3REF: Overload A Function For A Virtual Table |
7856 | ** METHOD: sqlite3 |
7857 | ** |
7858 | ** ^(Virtual tables can provide alternative implementations of functions |
7859 | ** using the [xFindFunction] method of the [virtual table module]. |
7860 | ** But global versions of those functions |
7861 | ** must exist in order to be overloaded.)^ |
7862 | ** |
7863 | ** ^(This API makes sure a global version of a function with a particular |
7864 | ** name and number of parameters exists. If no such function exists |
7865 | ** before this API is called, a new function is created.)^ ^The implementation |
7866 | ** of the new function always causes an exception to be thrown. So |
7867 | ** the new function is not good for anything by itself. Its only |
7868 | ** purpose is to be a placeholder function that can be overloaded |
7869 | ** by a [virtual table]. |
7870 | */ |
7871 | SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg); |
7872 | |
7873 | /* |
7874 | ** CAPI3REF: A Handle To An Open BLOB |
7875 | ** KEYWORDS: {BLOB handle} {BLOB handles} |
7876 | ** |
7877 | ** An instance of this object represents an open BLOB on which |
7878 | ** [sqlite3_blob_open | incremental BLOB I/O] can be performed. |
7879 | ** ^Objects of this type are created by [sqlite3_blob_open()] |
7880 | ** and destroyed by [sqlite3_blob_close()]. |
7881 | ** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces |
7882 | ** can be used to read or write small subsections of the BLOB. |
7883 | ** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes. |
7884 | */ |
7885 | typedef struct sqlite3_blob sqlite3_blob; |
7886 | |
7887 | /* |
7888 | ** CAPI3REF: Open A BLOB For Incremental I/O |
7889 | ** METHOD: sqlite3 |
7890 | ** CONSTRUCTOR: sqlite3_blob |
7891 | ** |
7892 | ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located |
7893 | ** in row iRow, column zColumn, table zTable in database zDb; |
7894 | ** in other words, the same BLOB that would be selected by: |
7895 | ** |
7896 | ** <pre> |
7897 | ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow; |
7898 | ** </pre>)^ |
7899 | ** |
7900 | ** ^(Parameter zDb is not the filename that contains the database, but |
7901 | ** rather the symbolic name of the database. For attached databases, this is |
7902 | ** the name that appears after the AS keyword in the [ATTACH] statement. |
7903 | ** For the main database file, the database name is "main". For TEMP |
7904 | ** tables, the database name is "temp".)^ |
7905 | ** |
7906 | ** ^If the flags parameter is non-zero, then the BLOB is opened for read |
7907 | ** and write access. ^If the flags parameter is zero, the BLOB is opened for |
7908 | ** read-only access. |
7909 | ** |
7910 | ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored |
7911 | ** in *ppBlob. Otherwise an [error code] is returned and, unless the error |
7912 | ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided |
7913 | ** the API is not misused, it is always safe to call [sqlite3_blob_close()] |
7914 | ** on *ppBlob after this function it returns. |
7915 | ** |
7916 | ** This function fails with SQLITE_ERROR if any of the following are true: |
7917 | ** <ul> |
7918 | ** <li> ^(Database zDb does not exist)^, |
7919 | ** <li> ^(Table zTable does not exist within database zDb)^, |
7920 | ** <li> ^(Table zTable is a WITHOUT ROWID table)^, |
7921 | ** <li> ^(Column zColumn does not exist)^, |
7922 | ** <li> ^(Row iRow is not present in the table)^, |
7923 | ** <li> ^(The specified column of row iRow contains a value that is not |
7924 | ** a TEXT or BLOB value)^, |
7925 | ** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE |
7926 | ** constraint and the blob is being opened for read/write access)^, |
7927 | ** <li> ^([foreign key constraints | Foreign key constraints] are enabled, |
7928 | ** column zColumn is part of a [child key] definition and the blob is |
7929 | ** being opened for read/write access)^. |
7930 | ** </ul> |
7931 | ** |
7932 | ** ^Unless it returns SQLITE_MISUSE, this function sets the |
7933 | ** [database connection] error code and message accessible via |
7934 | ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. |
7935 | ** |
7936 | ** A BLOB referenced by sqlite3_blob_open() may be read using the |
7937 | ** [sqlite3_blob_read()] interface and modified by using |
7938 | ** [sqlite3_blob_write()]. The [BLOB handle] can be moved to a |
7939 | ** different row of the same table using the [sqlite3_blob_reopen()] |
7940 | ** interface. However, the column, table, or database of a [BLOB handle] |
7941 | ** cannot be changed after the [BLOB handle] is opened. |
7942 | ** |
7943 | ** ^(If the row that a BLOB handle points to is modified by an |
7944 | ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects |
7945 | ** then the BLOB handle is marked as "expired". |
7946 | ** This is true if any column of the row is changed, even a column |
7947 | ** other than the one the BLOB handle is open on.)^ |
7948 | ** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for |
7949 | ** an expired BLOB handle fail with a return code of [SQLITE_ABORT]. |
7950 | ** ^(Changes written into a BLOB prior to the BLOB expiring are not |
7951 | ** rolled back by the expiration of the BLOB. Such changes will eventually |
7952 | ** commit if the transaction continues to completion.)^ |
7953 | ** |
7954 | ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of |
7955 | ** the opened blob. ^The size of a blob may not be changed by this |
7956 | ** interface. Use the [UPDATE] SQL command to change the size of a |
7957 | ** blob. |
7958 | ** |
7959 | ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces |
7960 | ** and the built-in [zeroblob] SQL function may be used to create a |
7961 | ** zero-filled blob to read or write using the incremental-blob interface. |
7962 | ** |
7963 | ** To avoid a resource leak, every open [BLOB handle] should eventually |
7964 | ** be released by a call to [sqlite3_blob_close()]. |
7965 | ** |
7966 | ** See also: [sqlite3_blob_close()], |
7967 | ** [sqlite3_blob_reopen()], [sqlite3_blob_read()], |
7968 | ** [sqlite3_blob_bytes()], [sqlite3_blob_write()]. |
7969 | */ |
7970 | SQLITE_API int sqlite3_blob_open( |
7971 | sqlite3*, |
7972 | const char *zDb, |
7973 | const char *zTable, |
7974 | const char *zColumn, |
7975 | sqlite3_int64 iRow, |
7976 | int flags, |
7977 | sqlite3_blob **ppBlob |
7978 | ); |
7979 | |
7980 | /* |
7981 | ** CAPI3REF: Move a BLOB Handle to a New Row |
7982 | ** METHOD: sqlite3_blob |
7983 | ** |
7984 | ** ^This function is used to move an existing [BLOB handle] so that it points |
7985 | ** to a different row of the same database table. ^The new row is identified |
7986 | ** by the rowid value passed as the second argument. Only the row can be |
7987 | ** changed. ^The database, table and column on which the blob handle is open |
7988 | ** remain the same. Moving an existing [BLOB handle] to a new row is |
7989 | ** faster than closing the existing handle and opening a new one. |
7990 | ** |
7991 | ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] - |
7992 | ** it must exist and there must be either a blob or text value stored in |
7993 | ** the nominated column.)^ ^If the new row is not present in the table, or if |
7994 | ** it does not contain a blob or text value, or if another error occurs, an |
7995 | ** SQLite error code is returned and the blob handle is considered aborted. |
7996 | ** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or |
7997 | ** [sqlite3_blob_reopen()] on an aborted blob handle immediately return |
7998 | ** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle |
7999 | ** always returns zero. |
8000 | ** |
8001 | ** ^This function sets the database handle error code and message. |
8002 | */ |
8003 | SQLITE_API int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); |
8004 | |
8005 | /* |
8006 | ** CAPI3REF: Close A BLOB Handle |
8007 | ** DESTRUCTOR: sqlite3_blob |
8008 | ** |
8009 | ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed |
8010 | ** unconditionally. Even if this routine returns an error code, the |
8011 | ** handle is still closed.)^ |
8012 | ** |
8013 | ** ^If the blob handle being closed was opened for read-write access, and if |
8014 | ** the database is in auto-commit mode and there are no other open read-write |
8015 | ** blob handles or active write statements, the current transaction is |
8016 | ** committed. ^If an error occurs while committing the transaction, an error |
8017 | ** code is returned and the transaction rolled back. |
8018 | ** |
8019 | ** Calling this function with an argument that is not a NULL pointer or an |
8020 | ** open blob handle results in undefined behaviour. ^Calling this routine |
8021 | ** with a null pointer (such as would be returned by a failed call to |
8022 | ** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function |
8023 | ** is passed a valid open blob handle, the values returned by the |
8024 | ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning. |
8025 | */ |
8026 | SQLITE_API int sqlite3_blob_close(sqlite3_blob *); |
8027 | |
8028 | /* |
8029 | ** CAPI3REF: Return The Size Of An Open BLOB |
8030 | ** METHOD: sqlite3_blob |
8031 | ** |
8032 | ** ^Returns the size in bytes of the BLOB accessible via the |
8033 | ** successfully opened [BLOB handle] in its only argument. ^The |
8034 | ** incremental blob I/O routines can only read or overwriting existing |
8035 | ** blob content; they cannot change the size of a blob. |
8036 | ** |
8037 | ** This routine only works on a [BLOB handle] which has been created |
8038 | ** by a prior successful call to [sqlite3_blob_open()] and which has not |
8039 | ** been closed by [sqlite3_blob_close()]. Passing any other pointer in |
8040 | ** to this routine results in undefined and probably undesirable behavior. |
8041 | */ |
8042 | SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *); |
8043 | |
8044 | /* |
8045 | ** CAPI3REF: Read Data From A BLOB Incrementally |
8046 | ** METHOD: sqlite3_blob |
8047 | ** |
8048 | ** ^(This function is used to read data from an open [BLOB handle] into a |
8049 | ** caller-supplied buffer. N bytes of data are copied into buffer Z |
8050 | ** from the open BLOB, starting at offset iOffset.)^ |
8051 | ** |
8052 | ** ^If offset iOffset is less than N bytes from the end of the BLOB, |
8053 | ** [SQLITE_ERROR] is returned and no data is read. ^If N or iOffset is |
8054 | ** less than zero, [SQLITE_ERROR] is returned and no data is read. |
8055 | ** ^The size of the blob (and hence the maximum value of N+iOffset) |
8056 | ** can be determined using the [sqlite3_blob_bytes()] interface. |
8057 | ** |
8058 | ** ^An attempt to read from an expired [BLOB handle] fails with an |
8059 | ** error code of [SQLITE_ABORT]. |
8060 | ** |
8061 | ** ^(On success, sqlite3_blob_read() returns SQLITE_OK. |
8062 | ** Otherwise, an [error code] or an [extended error code] is returned.)^ |
8063 | ** |
8064 | ** This routine only works on a [BLOB handle] which has been created |
8065 | ** by a prior successful call to [sqlite3_blob_open()] and which has not |
8066 | ** been closed by [sqlite3_blob_close()]. Passing any other pointer in |
8067 | ** to this routine results in undefined and probably undesirable behavior. |
8068 | ** |
8069 | ** See also: [sqlite3_blob_write()]. |
8070 | */ |
8071 | SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); |
8072 | |
8073 | /* |
8074 | ** CAPI3REF: Write Data Into A BLOB Incrementally |
8075 | ** METHOD: sqlite3_blob |
8076 | ** |
8077 | ** ^(This function is used to write data into an open [BLOB handle] from a |
8078 | ** caller-supplied buffer. N bytes of data are copied from the buffer Z |
8079 | ** into the open BLOB, starting at offset iOffset.)^ |
8080 | ** |
8081 | ** ^(On success, sqlite3_blob_write() returns SQLITE_OK. |
8082 | ** Otherwise, an [error code] or an [extended error code] is returned.)^ |
8083 | ** ^Unless SQLITE_MISUSE is returned, this function sets the |
8084 | ** [database connection] error code and message accessible via |
8085 | ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. |
8086 | ** |
8087 | ** ^If the [BLOB handle] passed as the first argument was not opened for |
8088 | ** writing (the flags parameter to [sqlite3_blob_open()] was zero), |
8089 | ** this function returns [SQLITE_READONLY]. |
8090 | ** |
8091 | ** This function may only modify the contents of the BLOB; it is |
8092 | ** not possible to increase the size of a BLOB using this API. |
8093 | ** ^If offset iOffset is less than N bytes from the end of the BLOB, |
8094 | ** [SQLITE_ERROR] is returned and no data is written. The size of the |
8095 | ** BLOB (and hence the maximum value of N+iOffset) can be determined |
8096 | ** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less |
8097 | ** than zero [SQLITE_ERROR] is returned and no data is written. |
8098 | ** |
8099 | ** ^An attempt to write to an expired [BLOB handle] fails with an |
8100 | ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred |
8101 | ** before the [BLOB handle] expired are not rolled back by the |
8102 | ** expiration of the handle, though of course those changes might |
8103 | ** have been overwritten by the statement that expired the BLOB handle |
8104 | ** or by other independent statements. |
8105 | ** |
8106 | ** This routine only works on a [BLOB handle] which has been created |
8107 | ** by a prior successful call to [sqlite3_blob_open()] and which has not |
8108 | ** been closed by [sqlite3_blob_close()]. Passing any other pointer in |
8109 | ** to this routine results in undefined and probably undesirable behavior. |
8110 | ** |
8111 | ** See also: [sqlite3_blob_read()]. |
8112 | */ |
8113 | SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset); |
8114 | |
8115 | /* |
8116 | ** CAPI3REF: Virtual File System Objects |
8117 | ** |
8118 | ** A virtual filesystem (VFS) is an [sqlite3_vfs] object |
8119 | ** that SQLite uses to interact |
8120 | ** with the underlying operating system. Most SQLite builds come with a |
8121 | ** single default VFS that is appropriate for the host computer. |
8122 | ** New VFSes can be registered and existing VFSes can be unregistered. |
8123 | ** The following interfaces are provided. |
8124 | ** |
8125 | ** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name. |
8126 | ** ^Names are case sensitive. |
8127 | ** ^Names are zero-terminated UTF-8 strings. |
8128 | ** ^If there is no match, a NULL pointer is returned. |
8129 | ** ^If zVfsName is NULL then the default VFS is returned. |
8130 | ** |
8131 | ** ^New VFSes are registered with sqlite3_vfs_register(). |
8132 | ** ^Each new VFS becomes the default VFS if the makeDflt flag is set. |
8133 | ** ^The same VFS can be registered multiple times without injury. |
8134 | ** ^To make an existing VFS into the default VFS, register it again |
8135 | ** with the makeDflt flag set. If two different VFSes with the |
8136 | ** same name are registered, the behavior is undefined. If a |
8137 | ** VFS is registered with a name that is NULL or an empty string, |
8138 | ** then the behavior is undefined. |
8139 | ** |
8140 | ** ^Unregister a VFS with the sqlite3_vfs_unregister() interface. |
8141 | ** ^(If the default VFS is unregistered, another VFS is chosen as |
8142 | ** the default. The choice for the new VFS is arbitrary.)^ |
8143 | */ |
8144 | SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName); |
8145 | SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt); |
8146 | SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*); |
8147 | |
8148 | /* |
8149 | ** CAPI3REF: Mutexes |
8150 | ** |
8151 | ** The SQLite core uses these routines for thread |
8152 | ** synchronization. Though they are intended for internal |
8153 | ** use by SQLite, code that links against SQLite is |
8154 | ** permitted to use any of these routines. |
8155 | ** |
8156 | ** The SQLite source code contains multiple implementations |
8157 | ** of these mutex routines. An appropriate implementation |
8158 | ** is selected automatically at compile-time. The following |
8159 | ** implementations are available in the SQLite core: |
8160 | ** |
8161 | ** <ul> |
8162 | ** <li> SQLITE_MUTEX_PTHREADS |
8163 | ** <li> SQLITE_MUTEX_W32 |
8164 | ** <li> SQLITE_MUTEX_NOOP |
8165 | ** </ul> |
8166 | ** |
8167 | ** The SQLITE_MUTEX_NOOP implementation is a set of routines |
8168 | ** that does no real locking and is appropriate for use in |
8169 | ** a single-threaded application. The SQLITE_MUTEX_PTHREADS and |
8170 | ** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix |
8171 | ** and Windows. |
8172 | ** |
8173 | ** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor |
8174 | ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex |
8175 | ** implementation is included with the library. In this case the |
8176 | ** application must supply a custom mutex implementation using the |
8177 | ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function |
8178 | ** before calling sqlite3_initialize() or any other public sqlite3_ |
8179 | ** function that calls sqlite3_initialize(). |
8180 | ** |
8181 | ** ^The sqlite3_mutex_alloc() routine allocates a new |
8182 | ** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc() |
8183 | ** routine returns NULL if it is unable to allocate the requested |
8184 | ** mutex. The argument to sqlite3_mutex_alloc() must one of these |
8185 | ** integer constants: |
8186 | ** |
8187 | ** <ul> |
8188 | ** <li> SQLITE_MUTEX_FAST |
8189 | ** <li> SQLITE_MUTEX_RECURSIVE |
8190 | ** <li> SQLITE_MUTEX_STATIC_MAIN |
8191 | ** <li> SQLITE_MUTEX_STATIC_MEM |
8192 | ** <li> SQLITE_MUTEX_STATIC_OPEN |
8193 | ** <li> SQLITE_MUTEX_STATIC_PRNG |
8194 | ** <li> SQLITE_MUTEX_STATIC_LRU |
8195 | ** <li> SQLITE_MUTEX_STATIC_PMEM |
8196 | ** <li> SQLITE_MUTEX_STATIC_APP1 |
8197 | ** <li> SQLITE_MUTEX_STATIC_APP2 |
8198 | ** <li> SQLITE_MUTEX_STATIC_APP3 |
8199 | ** <li> SQLITE_MUTEX_STATIC_VFS1 |
8200 | ** <li> SQLITE_MUTEX_STATIC_VFS2 |
8201 | ** <li> SQLITE_MUTEX_STATIC_VFS3 |
8202 | ** </ul> |
8203 | ** |
8204 | ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) |
8205 | ** cause sqlite3_mutex_alloc() to create |
8206 | ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE |
8207 | ** is used but not necessarily so when SQLITE_MUTEX_FAST is used. |
8208 | ** The mutex implementation does not need to make a distinction |
8209 | ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does |
8210 | ** not want to. SQLite will only request a recursive mutex in |
8211 | ** cases where it really needs one. If a faster non-recursive mutex |
8212 | ** implementation is available on the host platform, the mutex subsystem |
8213 | ** might return such a mutex in response to SQLITE_MUTEX_FAST. |
8214 | ** |
8215 | ** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other |
8216 | ** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return |
8217 | ** a pointer to a static preexisting mutex. ^Nine static mutexes are |
8218 | ** used by the current version of SQLite. Future versions of SQLite |
8219 | ** may add additional static mutexes. Static mutexes are for internal |
8220 | ** use by SQLite only. Applications that use SQLite mutexes should |
8221 | ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or |
8222 | ** SQLITE_MUTEX_RECURSIVE. |
8223 | ** |
8224 | ** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST |
8225 | ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc() |
8226 | ** returns a different mutex on every call. ^For the static |
8227 | ** mutex types, the same mutex is returned on every call that has |
8228 | ** the same type number. |
8229 | ** |
8230 | ** ^The sqlite3_mutex_free() routine deallocates a previously |
8231 | ** allocated dynamic mutex. Attempting to deallocate a static |
8232 | ** mutex results in undefined behavior. |
8233 | ** |
8234 | ** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt |
8235 | ** to enter a mutex. ^If another thread is already within the mutex, |
8236 | ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return |
8237 | ** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK] |
8238 | ** upon successful entry. ^(Mutexes created using |
8239 | ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread. |
8240 | ** In such cases, the |
8241 | ** mutex must be exited an equal number of times before another thread |
8242 | ** can enter.)^ If the same thread tries to enter any mutex other |
8243 | ** than an SQLITE_MUTEX_RECURSIVE more than once, the behavior is undefined. |
8244 | ** |
8245 | ** ^(Some systems (for example, Windows 95) do not support the operation |
8246 | ** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try() |
8247 | ** will always return SQLITE_BUSY. The SQLite core only ever uses |
8248 | ** sqlite3_mutex_try() as an optimization so this is acceptable |
8249 | ** behavior.)^ |
8250 | ** |
8251 | ** ^The sqlite3_mutex_leave() routine exits a mutex that was |
8252 | ** previously entered by the same thread. The behavior |
8253 | ** is undefined if the mutex is not currently entered by the |
8254 | ** calling thread or is not currently allocated. |
8255 | ** |
8256 | ** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), |
8257 | ** sqlite3_mutex_leave(), or sqlite3_mutex_free() is a NULL pointer, |
8258 | ** then any of the four routines behaves as a no-op. |
8259 | ** |
8260 | ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()]. |
8261 | */ |
8262 | SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int); |
8263 | SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*); |
8264 | SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*); |
8265 | SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*); |
8266 | SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*); |
8267 | |
8268 | /* |
8269 | ** CAPI3REF: Mutex Methods Object |
8270 | ** |
8271 | ** An instance of this structure defines the low-level routines |
8272 | ** used to allocate and use mutexes. |
8273 | ** |
8274 | ** Usually, the default mutex implementations provided by SQLite are |
8275 | ** sufficient, however the application has the option of substituting a custom |
8276 | ** implementation for specialized deployments or systems for which SQLite |
8277 | ** does not provide a suitable implementation. In this case, the application |
8278 | ** creates and populates an instance of this structure to pass |
8279 | ** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option. |
8280 | ** Additionally, an instance of this structure can be used as an |
8281 | ** output variable when querying the system for the current mutex |
8282 | ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option. |
8283 | ** |
8284 | ** ^The xMutexInit method defined by this structure is invoked as |
8285 | ** part of system initialization by the sqlite3_initialize() function. |
8286 | ** ^The xMutexInit routine is called by SQLite exactly once for each |
8287 | ** effective call to [sqlite3_initialize()]. |
8288 | ** |
8289 | ** ^The xMutexEnd method defined by this structure is invoked as |
8290 | ** part of system shutdown by the sqlite3_shutdown() function. The |
8291 | ** implementation of this method is expected to release all outstanding |
8292 | ** resources obtained by the mutex methods implementation, especially |
8293 | ** those obtained by the xMutexInit method. ^The xMutexEnd() |
8294 | ** interface is invoked exactly once for each call to [sqlite3_shutdown()]. |
8295 | ** |
8296 | ** ^(The remaining seven methods defined by this structure (xMutexAlloc, |
8297 | ** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and |
8298 | ** xMutexNotheld) implement the following interfaces (respectively): |
8299 | ** |
8300 | ** <ul> |
8301 | ** <li> [sqlite3_mutex_alloc()] </li> |
8302 | ** <li> [sqlite3_mutex_free()] </li> |
8303 | ** <li> [sqlite3_mutex_enter()] </li> |
8304 | ** <li> [sqlite3_mutex_try()] </li> |
8305 | ** <li> [sqlite3_mutex_leave()] </li> |
8306 | ** <li> [sqlite3_mutex_held()] </li> |
8307 | ** <li> [sqlite3_mutex_notheld()] </li> |
8308 | ** </ul>)^ |
8309 | ** |
8310 | ** The only difference is that the public sqlite3_XXX functions enumerated |
8311 | ** above silently ignore any invocations that pass a NULL pointer instead |
8312 | ** of a valid mutex handle. The implementations of the methods defined |
8313 | ** by this structure are not required to handle this case. The results |
8314 | ** of passing a NULL pointer instead of a valid mutex handle are undefined |
8315 | ** (i.e. it is acceptable to provide an implementation that segfaults if |
8316 | ** it is passed a NULL pointer). |
8317 | ** |
8318 | ** The xMutexInit() method must be threadsafe. It must be harmless to |
8319 | ** invoke xMutexInit() multiple times within the same process and without |
8320 | ** intervening calls to xMutexEnd(). Second and subsequent calls to |
8321 | ** xMutexInit() must be no-ops. |
8322 | ** |
8323 | ** xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()] |
8324 | ** and its associates). Similarly, xMutexAlloc() must not use SQLite memory |
8325 | ** allocation for a static mutex. ^However xMutexAlloc() may use SQLite |
8326 | ** memory allocation for a fast or recursive mutex. |
8327 | ** |
8328 | ** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is |
8329 | ** called, but only if the prior call to xMutexInit returned SQLITE_OK. |
8330 | ** If xMutexInit fails in any way, it is expected to clean up after itself |
8331 | ** prior to returning. |
8332 | */ |
8333 | typedef struct sqlite3_mutex_methods sqlite3_mutex_methods; |
8334 | struct sqlite3_mutex_methods { |
8335 | int (*xMutexInit)(void); |
8336 | int (*xMutexEnd)(void); |
8337 | sqlite3_mutex *(*xMutexAlloc)(int); |
8338 | void (*xMutexFree)(sqlite3_mutex *); |
8339 | void (*xMutexEnter)(sqlite3_mutex *); |
8340 | int (*xMutexTry)(sqlite3_mutex *); |
8341 | void (*xMutexLeave)(sqlite3_mutex *); |
8342 | int (*xMutexHeld)(sqlite3_mutex *); |
8343 | int (*xMutexNotheld)(sqlite3_mutex *); |
8344 | }; |
8345 | |
8346 | /* |
8347 | ** CAPI3REF: Mutex Verification Routines |
8348 | ** |
8349 | ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines |
8350 | ** are intended for use inside assert() statements. The SQLite core |
8351 | ** never uses these routines except inside an assert() and applications |
8352 | ** are advised to follow the lead of the core. The SQLite core only |
8353 | ** provides implementations for these routines when it is compiled |
8354 | ** with the SQLITE_DEBUG flag. External mutex implementations |
8355 | ** are only required to provide these routines if SQLITE_DEBUG is |
8356 | ** defined and if NDEBUG is not defined. |
8357 | ** |
8358 | ** These routines should return true if the mutex in their argument |
8359 | ** is held or not held, respectively, by the calling thread. |
8360 | ** |
8361 | ** The implementation is not required to provide versions of these |
8362 | ** routines that actually work. If the implementation does not provide working |
8363 | ** versions of these routines, it should at least provide stubs that always |
8364 | ** return true so that one does not get spurious assertion failures. |
8365 | ** |
8366 | ** If the argument to sqlite3_mutex_held() is a NULL pointer then |
8367 | ** the routine should return 1. This seems counter-intuitive since |
8368 | ** clearly the mutex cannot be held if it does not exist. But |
8369 | ** the reason the mutex does not exist is because the build is not |
8370 | ** using mutexes. And we do not want the assert() containing the |
8371 | ** call to sqlite3_mutex_held() to fail, so a non-zero return is |
8372 | ** the appropriate thing to do. The sqlite3_mutex_notheld() |
8373 | ** interface should also return 1 when given a NULL pointer. |
8374 | */ |
8375 | #ifndef NDEBUG |
8376 | SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*); |
8377 | SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*); |
8378 | #endif |
8379 | |
8380 | /* |
8381 | ** CAPI3REF: Mutex Types |
8382 | ** |
8383 | ** The [sqlite3_mutex_alloc()] interface takes a single argument |
8384 | ** which is one of these integer constants. |
8385 | ** |
8386 | ** The set of static mutexes may change from one SQLite release to the |
8387 | ** next. Applications that override the built-in mutex logic must be |
8388 | ** prepared to accommodate additional static mutexes. |
8389 | */ |
8390 | #define SQLITE_MUTEX_FAST 0 |
8391 | #define SQLITE_MUTEX_RECURSIVE 1 |
8392 | #define SQLITE_MUTEX_STATIC_MAIN 2 |
8393 | #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */ |
8394 | #define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */ |
8395 | #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */ |
8396 | #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_randomness() */ |
8397 | #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */ |
8398 | #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */ |
8399 | #define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */ |
8400 | #define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */ |
8401 | #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */ |
8402 | #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */ |
8403 | #define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */ |
8404 | #define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */ |
8405 | #define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */ |
8406 | |
8407 | /* Legacy compatibility: */ |
8408 | #define SQLITE_MUTEX_STATIC_MASTER 2 |
8409 | |
8410 | |
8411 | /* |
8412 | ** CAPI3REF: Retrieve the mutex for a database connection |
8413 | ** METHOD: sqlite3 |
8414 | ** |
8415 | ** ^This interface returns a pointer the [sqlite3_mutex] object that |
8416 | ** serializes access to the [database connection] given in the argument |
8417 | ** when the [threading mode] is Serialized. |
8418 | ** ^If the [threading mode] is Single-thread or Multi-thread then this |
8419 | ** routine returns a NULL pointer. |
8420 | */ |
8421 | SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*); |
8422 | |
8423 | /* |
8424 | ** CAPI3REF: Low-Level Control Of Database Files |
8425 | ** METHOD: sqlite3 |
8426 | ** KEYWORDS: {file control} |
8427 | ** |
8428 | ** ^The [sqlite3_file_control()] interface makes a direct call to the |
8429 | ** xFileControl method for the [sqlite3_io_methods] object associated |
8430 | ** with a particular database identified by the second argument. ^The |
8431 | ** name of the database is "main" for the main database or "temp" for the |
8432 | ** TEMP database, or the name that appears after the AS keyword for |
8433 | ** databases that are added using the [ATTACH] SQL command. |
8434 | ** ^A NULL pointer can be used in place of "main" to refer to the |
8435 | ** main database file. |
8436 | ** ^The third and fourth parameters to this routine |
8437 | ** are passed directly through to the second and third parameters of |
8438 | ** the xFileControl method. ^The return value of the xFileControl |
8439 | ** method becomes the return value of this routine. |
8440 | ** |
8441 | ** A few opcodes for [sqlite3_file_control()] are handled directly |
8442 | ** by the SQLite core and never invoke the |
8443 | ** sqlite3_io_methods.xFileControl method. |
8444 | ** ^The [SQLITE_FCNTL_FILE_POINTER] value for the op parameter causes |
8445 | ** a pointer to the underlying [sqlite3_file] object to be written into |
8446 | ** the space pointed to by the 4th parameter. The |
8447 | ** [SQLITE_FCNTL_JOURNAL_POINTER] works similarly except that it returns |
8448 | ** the [sqlite3_file] object associated with the journal file instead of |
8449 | ** the main database. The [SQLITE_FCNTL_VFS_POINTER] opcode returns |
8450 | ** a pointer to the underlying [sqlite3_vfs] object for the file. |
8451 | ** The [SQLITE_FCNTL_DATA_VERSION] returns the data version counter |
8452 | ** from the pager. |
8453 | ** |
8454 | ** ^If the second parameter (zDbName) does not match the name of any |
8455 | ** open database file, then SQLITE_ERROR is returned. ^This error |
8456 | ** code is not remembered and will not be recalled by [sqlite3_errcode()] |
8457 | ** or [sqlite3_errmsg()]. The underlying xFileControl method might |
8458 | ** also return SQLITE_ERROR. There is no way to distinguish between |
8459 | ** an incorrect zDbName and an SQLITE_ERROR return from the underlying |
8460 | ** xFileControl method. |
8461 | ** |
8462 | ** See also: [file control opcodes] |
8463 | */ |
8464 | SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*); |
8465 | |
8466 | /* |
8467 | ** CAPI3REF: Testing Interface |
8468 | ** |
8469 | ** ^The sqlite3_test_control() interface is used to read out internal |
8470 | ** state of SQLite and to inject faults into SQLite for testing |
8471 | ** purposes. ^The first parameter is an operation code that determines |
8472 | ** the number, meaning, and operation of all subsequent parameters. |
8473 | ** |
8474 | ** This interface is not for use by applications. It exists solely |
8475 | ** for verifying the correct operation of the SQLite library. Depending |
8476 | ** on how the SQLite library is compiled, this interface might not exist. |
8477 | ** |
8478 | ** The details of the operation codes, their meanings, the parameters |
8479 | ** they take, and what they do are all subject to change without notice. |
8480 | ** Unlike most of the SQLite API, this function is not guaranteed to |
8481 | ** operate consistently from one release to the next. |
8482 | */ |
8483 | SQLITE_API int sqlite3_test_control(int op, ...); |
8484 | |
8485 | /* |
8486 | ** CAPI3REF: Testing Interface Operation Codes |
8487 | ** |
8488 | ** These constants are the valid operation code parameters used |
8489 | ** as the first argument to [sqlite3_test_control()]. |
8490 | ** |
8491 | ** These parameters and their meanings are subject to change |
8492 | ** without notice. These values are for testing purposes only. |
8493 | ** Applications should not use any of these parameters or the |
8494 | ** [sqlite3_test_control()] interface. |
8495 | */ |
8496 | #define SQLITE_TESTCTRL_FIRST 5 |
8497 | #define SQLITE_TESTCTRL_PRNG_SAVE 5 |
8498 | #define SQLITE_TESTCTRL_PRNG_RESTORE 6 |
8499 | #define SQLITE_TESTCTRL_PRNG_RESET 7 /* NOT USED */ |
8500 | #define SQLITE_TESTCTRL_BITVEC_TEST 8 |
8501 | #define SQLITE_TESTCTRL_FAULT_INSTALL 9 |
8502 | #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10 |
8503 | #define SQLITE_TESTCTRL_PENDING_BYTE 11 |
8504 | #define SQLITE_TESTCTRL_ASSERT 12 |
8505 | #define SQLITE_TESTCTRL_ALWAYS 13 |
8506 | #define SQLITE_TESTCTRL_RESERVE 14 /* NOT USED */ |
8507 | #define SQLITE_TESTCTRL_OPTIMIZATIONS 15 |
8508 | #define SQLITE_TESTCTRL_ISKEYWORD 16 /* NOT USED */ |
8509 | #define SQLITE_TESTCTRL_SCRATCHMALLOC 17 /* NOT USED */ |
8510 | #define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 17 |
8511 | #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18 |
8512 | #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */ |
8513 | #define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD 19 |
8514 | #define SQLITE_TESTCTRL_NEVER_CORRUPT 20 |
8515 | #define SQLITE_TESTCTRL_VDBE_COVERAGE 21 |
8516 | #define SQLITE_TESTCTRL_BYTEORDER 22 |
8517 | #define SQLITE_TESTCTRL_ISINIT 23 |
8518 | #define SQLITE_TESTCTRL_SORTER_MMAP 24 |
8519 | #define SQLITE_TESTCTRL_IMPOSTER 25 |
8520 | #define SQLITE_TESTCTRL_PARSER_COVERAGE 26 |
8521 | #define SQLITE_TESTCTRL_RESULT_INTREAL 27 |
8522 | #define SQLITE_TESTCTRL_PRNG_SEED 28 |
8523 | #define 29 |
8524 | #define SQLITE_TESTCTRL_SEEK_COUNT 30 |
8525 | #define SQLITE_TESTCTRL_TRACEFLAGS 31 |
8526 | #define SQLITE_TESTCTRL_TUNE 32 |
8527 | #define SQLITE_TESTCTRL_LOGEST 33 |
8528 | #define SQLITE_TESTCTRL_USELONGDOUBLE 34 |
8529 | #define SQLITE_TESTCTRL_LAST 34 /* Largest TESTCTRL */ |
8530 | |
8531 | /* |
8532 | ** CAPI3REF: SQL Keyword Checking |
8533 | ** |
8534 | ** These routines provide access to the set of SQL language keywords |
8535 | ** recognized by SQLite. Applications can uses these routines to determine |
8536 | ** whether or not a specific identifier needs to be escaped (for example, |
8537 | ** by enclosing in double-quotes) so as not to confuse the parser. |
8538 | ** |
8539 | ** The sqlite3_keyword_count() interface returns the number of distinct |
8540 | ** keywords understood by SQLite. |
8541 | ** |
8542 | ** The sqlite3_keyword_name(N,Z,L) interface finds the N-th keyword and |
8543 | ** makes *Z point to that keyword expressed as UTF8 and writes the number |
8544 | ** of bytes in the keyword into *L. The string that *Z points to is not |
8545 | ** zero-terminated. The sqlite3_keyword_name(N,Z,L) routine returns |
8546 | ** SQLITE_OK if N is within bounds and SQLITE_ERROR if not. If either Z |
8547 | ** or L are NULL or invalid pointers then calls to |
8548 | ** sqlite3_keyword_name(N,Z,L) result in undefined behavior. |
8549 | ** |
8550 | ** The sqlite3_keyword_check(Z,L) interface checks to see whether or not |
8551 | ** the L-byte UTF8 identifier that Z points to is a keyword, returning non-zero |
8552 | ** if it is and zero if not. |
8553 | ** |
8554 | ** The parser used by SQLite is forgiving. It is often possible to use |
8555 | ** a keyword as an identifier as long as such use does not result in a |
8556 | ** parsing ambiguity. For example, the statement |
8557 | ** "CREATE TABLE BEGIN(REPLACE,PRAGMA,END);" is accepted by SQLite, and |
8558 | ** creates a new table named "BEGIN" with three columns named |
8559 | ** "REPLACE", "PRAGMA", and "END". Nevertheless, best practice is to avoid |
8560 | ** using keywords as identifiers. Common techniques used to avoid keyword |
8561 | ** name collisions include: |
8562 | ** <ul> |
8563 | ** <li> Put all identifier names inside double-quotes. This is the official |
8564 | ** SQL way to escape identifier names. |
8565 | ** <li> Put identifier names inside [...]. This is not standard SQL, |
8566 | ** but it is what SQL Server does and so lots of programmers use this |
8567 | ** technique. |
8568 | ** <li> Begin every identifier with the letter "Z" as no SQL keywords start |
8569 | ** with "Z". |
8570 | ** <li> Include a digit somewhere in every identifier name. |
8571 | ** </ul> |
8572 | ** |
8573 | ** Note that the number of keywords understood by SQLite can depend on |
8574 | ** compile-time options. For example, "VACUUM" is not a keyword if |
8575 | ** SQLite is compiled with the [-DSQLITE_OMIT_VACUUM] option. Also, |
8576 | ** new keywords may be added to future releases of SQLite. |
8577 | */ |
8578 | SQLITE_API int sqlite3_keyword_count(void); |
8579 | SQLITE_API int sqlite3_keyword_name(int,const char**,int*); |
8580 | SQLITE_API int sqlite3_keyword_check(const char*,int); |
8581 | |
8582 | /* |
8583 | ** CAPI3REF: Dynamic String Object |
8584 | ** KEYWORDS: {dynamic string} |
8585 | ** |
8586 | ** An instance of the sqlite3_str object contains a dynamically-sized |
8587 | ** string under construction. |
8588 | ** |
8589 | ** The lifecycle of an sqlite3_str object is as follows: |
8590 | ** <ol> |
8591 | ** <li> ^The sqlite3_str object is created using [sqlite3_str_new()]. |
8592 | ** <li> ^Text is appended to the sqlite3_str object using various |
8593 | ** methods, such as [sqlite3_str_appendf()]. |
8594 | ** <li> ^The sqlite3_str object is destroyed and the string it created |
8595 | ** is returned using the [sqlite3_str_finish()] interface. |
8596 | ** </ol> |
8597 | */ |
8598 | typedef struct sqlite3_str sqlite3_str; |
8599 | |
8600 | /* |
8601 | ** CAPI3REF: Create A New Dynamic String Object |
8602 | ** CONSTRUCTOR: sqlite3_str |
8603 | ** |
8604 | ** ^The [sqlite3_str_new(D)] interface allocates and initializes |
8605 | ** a new [sqlite3_str] object. To avoid memory leaks, the object returned by |
8606 | ** [sqlite3_str_new()] must be freed by a subsequent call to |
8607 | ** [sqlite3_str_finish(X)]. |
8608 | ** |
8609 | ** ^The [sqlite3_str_new(D)] interface always returns a pointer to a |
8610 | ** valid [sqlite3_str] object, though in the event of an out-of-memory |
8611 | ** error the returned object might be a special singleton that will |
8612 | ** silently reject new text, always return SQLITE_NOMEM from |
8613 | ** [sqlite3_str_errcode()], always return 0 for |
8614 | ** [sqlite3_str_length()], and always return NULL from |
8615 | ** [sqlite3_str_finish(X)]. It is always safe to use the value |
8616 | ** returned by [sqlite3_str_new(D)] as the sqlite3_str parameter |
8617 | ** to any of the other [sqlite3_str] methods. |
8618 | ** |
8619 | ** The D parameter to [sqlite3_str_new(D)] may be NULL. If the |
8620 | ** D parameter in [sqlite3_str_new(D)] is not NULL, then the maximum |
8621 | ** length of the string contained in the [sqlite3_str] object will be |
8622 | ** the value set for [sqlite3_limit](D,[SQLITE_LIMIT_LENGTH]) instead |
8623 | ** of [SQLITE_MAX_LENGTH]. |
8624 | */ |
8625 | SQLITE_API sqlite3_str *sqlite3_str_new(sqlite3*); |
8626 | |
8627 | /* |
8628 | ** CAPI3REF: Finalize A Dynamic String |
8629 | ** DESTRUCTOR: sqlite3_str |
8630 | ** |
8631 | ** ^The [sqlite3_str_finish(X)] interface destroys the sqlite3_str object X |
8632 | ** and returns a pointer to a memory buffer obtained from [sqlite3_malloc64()] |
8633 | ** that contains the constructed string. The calling application should |
8634 | ** pass the returned value to [sqlite3_free()] to avoid a memory leak. |
8635 | ** ^The [sqlite3_str_finish(X)] interface may return a NULL pointer if any |
8636 | ** errors were encountered during construction of the string. ^The |
8637 | ** [sqlite3_str_finish(X)] interface will also return a NULL pointer if the |
8638 | ** string in [sqlite3_str] object X is zero bytes long. |
8639 | */ |
8640 | SQLITE_API char *sqlite3_str_finish(sqlite3_str*); |
8641 | |
8642 | /* |
8643 | ** CAPI3REF: Add Content To A Dynamic String |
8644 | ** METHOD: sqlite3_str |
8645 | ** |
8646 | ** These interfaces add content to an sqlite3_str object previously obtained |
8647 | ** from [sqlite3_str_new()]. |
8648 | ** |
8649 | ** ^The [sqlite3_str_appendf(X,F,...)] and |
8650 | ** [sqlite3_str_vappendf(X,F,V)] interfaces uses the [built-in printf] |
8651 | ** functionality of SQLite to append formatted text onto the end of |
8652 | ** [sqlite3_str] object X. |
8653 | ** |
8654 | ** ^The [sqlite3_str_append(X,S,N)] method appends exactly N bytes from string S |
8655 | ** onto the end of the [sqlite3_str] object X. N must be non-negative. |
8656 | ** S must contain at least N non-zero bytes of content. To append a |
8657 | ** zero-terminated string in its entirety, use the [sqlite3_str_appendall()] |
8658 | ** method instead. |
8659 | ** |
8660 | ** ^The [sqlite3_str_appendall(X,S)] method appends the complete content of |
8661 | ** zero-terminated string S onto the end of [sqlite3_str] object X. |
8662 | ** |
8663 | ** ^The [sqlite3_str_appendchar(X,N,C)] method appends N copies of the |
8664 | ** single-byte character C onto the end of [sqlite3_str] object X. |
8665 | ** ^This method can be used, for example, to add whitespace indentation. |
8666 | ** |
8667 | ** ^The [sqlite3_str_reset(X)] method resets the string under construction |
8668 | ** inside [sqlite3_str] object X back to zero bytes in length. |
8669 | ** |
8670 | ** These methods do not return a result code. ^If an error occurs, that fact |
8671 | ** is recorded in the [sqlite3_str] object and can be recovered by a |
8672 | ** subsequent call to [sqlite3_str_errcode(X)]. |
8673 | */ |
8674 | SQLITE_API void sqlite3_str_appendf(sqlite3_str*, const char *zFormat, ...); |
8675 | SQLITE_API void sqlite3_str_vappendf(sqlite3_str*, const |
---|